-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from ToxicBakery/feature/build-config-plugin
#132 Added BuildConfig plugin
- Loading branch information
Showing
22 changed files
with
442 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Build Config | ||
Plugin for viewing the BuildConfig values of the application. | ||
|
||
## Notes | ||
If minification is enabled for your debug builds, you will likely want to update proguard to keep your BuildConfig class. | ||
|
||
Update to match your package name. | ||
``` | ||
-keep class com.willowtreeapps.hyperion.sample.BuildConfig { *; } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apply plugin: 'com.android.library' | ||
apply from: '../publish.gradle' | ||
|
||
group = project.libraryGroup | ||
version = project.libraryVersion | ||
|
||
android { | ||
compileSdkVersion project.compileSdkVersion | ||
buildToolsVersion project.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion project.minSdkVersion | ||
targetSdkVersion project.targetSdkVersion | ||
versionCode buildVersionCode() | ||
versionName version | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
lintOptions { | ||
abortOnError false | ||
} | ||
|
||
resourcePrefix 'hbc_' | ||
} | ||
|
||
dependencies { | ||
testImplementation "junit:junit:4.12" | ||
api project(':hyperion-plugin') | ||
implementation "com.android.support:appcompat-v7:${project.versionSupportLibrary}" | ||
annotationProcessor "com.google.auto.service:auto-service:${project.versionAutoService}" | ||
implementation "com.android.support:recyclerview-v7:${project.versionSupportLibrary}" | ||
implementation "com.android.support:design:${project.versionSupportLibrary}" | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.willowtreeapps.hyperion.buildconfig"> | ||
|
||
<application> | ||
<activity | ||
android:name=".list.BuildConfigListActivity" | ||
android:theme="@style/hbc_BuildConfigActivityTheme" | ||
android:windowSoftInputMode="stateHidden" /> | ||
</application> | ||
|
||
</manifest> |
18 changes: 18 additions & 0 deletions
18
...build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.willowtreeapps.hyperion.buildconfig; | ||
|
||
import android.support.annotation.Nullable; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.willowtreeapps.hyperion.plugin.v1.Plugin; | ||
import com.willowtreeapps.hyperion.plugin.v1.PluginModule; | ||
|
||
@AutoService(Plugin.class) | ||
public class BuildConfigPlugin extends Plugin { | ||
|
||
@Nullable | ||
@Override | ||
public PluginModule createPluginModule() { | ||
return new BuildConfigPluginModule(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPluginModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.willowtreeapps.hyperion.buildconfig; | ||
|
||
import android.content.Intent; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.willowtreeapps.hyperion.buildconfig.list.BuildConfigListActivity; | ||
import com.willowtreeapps.hyperion.plugin.v1.PluginModule; | ||
|
||
class BuildConfigPluginModule extends PluginModule implements View.OnClickListener { | ||
|
||
@Nullable | ||
@Override | ||
public View createPluginView(@NonNull LayoutInflater layoutInflater, @NonNull ViewGroup parent) { | ||
View view = layoutInflater.inflate(R.layout.hbc_item_plugin, parent, false); | ||
view.setOnClickListener(this); | ||
return view; | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
Intent intent = new Intent(getContext(), BuildConfigListActivity.class); | ||
getContext().startActivity(intent); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...g/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.willowtreeapps.hyperion.buildconfig.list; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.Toolbar; | ||
import android.util.Log; | ||
|
||
import com.willowtreeapps.hyperion.buildconfig.R; | ||
import com.willowtreeapps.hyperion.buildconfig.model.BuildConfigValue; | ||
import com.willowtreeapps.hyperion.plugin.v1.HyperionIgnore; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@HyperionIgnore | ||
public class BuildConfigListActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = "BuildConfig"; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.hbc_activity_build_config_list); | ||
setSupportActionBar((Toolbar) findViewById(R.id.tmb_toolbar)); | ||
ActionBar actionBar = getSupportActionBar(); | ||
if (actionBar != null) { | ||
actionBar.setDisplayHomeAsUpEnabled(true); | ||
} | ||
|
||
RecyclerView recyclerView = findViewById(R.id.hbc_recycler); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
recyclerView.setAdapter(new BuildConfigListAdapter(getBuildConfigValues())); | ||
} | ||
|
||
@Override | ||
public boolean onSupportNavigateUp() { | ||
onBackPressed(); | ||
return true; | ||
} | ||
|
||
private List<BuildConfigValue> getBuildConfigValues() { | ||
List<BuildConfigValue> buildConfigValues = new LinkedList<>(); | ||
try { | ||
Class<?> buildConfigClass = Class.forName(getPackageName() + ".BuildConfig"); | ||
Log.d(TAG, "Checking BuildConfig " + buildConfigClass.getName()); | ||
Field[] declaredFields = buildConfigClass.getDeclaredFields(); | ||
for (Field declaredField : declaredFields) { | ||
Log.d(TAG, "Inspecting " + declaredField.toString()); | ||
if (Modifier.isStatic(declaredField.getModifiers())) { | ||
Class<?> fieldType = declaredField.getType(); | ||
String name = declaredField.getName() + " (" + fieldType.getSimpleName() + ")"; | ||
String value = declaredField.get(null).toString(); | ||
buildConfigValues.add(new BuildConfigValue(name, value)); | ||
} | ||
} | ||
} catch (Exception e) { | ||
Log.e(TAG, "Failed to read BuildConfig", e); | ||
} | ||
|
||
return buildConfigValues; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ig/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.willowtreeapps.hyperion.buildconfig.list; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.willowtreeapps.hyperion.buildconfig.R; | ||
import com.willowtreeapps.hyperion.buildconfig.model.BuildConfigValue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
class BuildConfigListAdapter extends RecyclerView.Adapter<BuildConfigViewHolder> { | ||
|
||
private final List<BuildConfigValue> buildConfigValues; | ||
|
||
BuildConfigListAdapter(List<BuildConfigValue> buildConfigValues) { | ||
this.buildConfigValues = new ArrayList<>(buildConfigValues); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public BuildConfigViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
final View itemView = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.hbc_value_row, parent, false); | ||
return new BuildConfigViewHolder(itemView); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull BuildConfigViewHolder holder, int position) { | ||
BuildConfigValue buildConfigValue = buildConfigValues.get(position); | ||
holder.bind(buildConfigValue); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return buildConfigValues.size(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...fig/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.willowtreeapps.hyperion.buildconfig.list; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.willowtreeapps.hyperion.buildconfig.R; | ||
import com.willowtreeapps.hyperion.buildconfig.model.BuildConfigValue; | ||
|
||
class BuildConfigViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private final TextView logDateTextView; | ||
private final TextView logMsgTextView; | ||
|
||
BuildConfigViewHolder(View itemView) { | ||
super(itemView); | ||
logDateTextView = itemView.findViewById(R.id.hbc_name); | ||
logMsgTextView = itemView.findViewById(R.id.hbc_value); | ||
} | ||
|
||
void bind(BuildConfigValue buildConfigValue) { | ||
logDateTextView.setText(buildConfigValue.getName()); | ||
logMsgTextView.setText(buildConfigValue.getValue()); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/model/BuildConfigValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.willowtreeapps.hyperion.buildconfig.model; | ||
|
||
public class BuildConfigValue { | ||
|
||
private final String name; | ||
private final String value; | ||
|
||
public BuildConfigValue(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BuildConfigValue{" + | ||
"name='" + name + '\'' + | ||
", value='" + value + '\'' + | ||
'}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="42dp" android:tint="#969696" | ||
android:viewportHeight="24.0" android:viewportWidth="24.0" | ||
android:width="42dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#FF000000" android:pathData="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z"/> | ||
</vector> |
32 changes: 32 additions & 0 deletions
32
hyperion-build-config/src/main/res/layout/hbc_activity_build_config_list.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true" | ||
android:focusableInTouchMode="true" | ||
tools:context=".list.BuildConfigListActivity"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/tmb_toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:theme="@style/hbc_ActionBar" | ||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" | ||
app:title="@string/hbc_plugin_name" /> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/hbc_recycler" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
app:layoutManager="android.support.v7.widget.LinearLayoutManager" /> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
46 changes: 46 additions & 0 deletions
46
hyperion-build-config/src/main/res/layout/hbc_item_plugin.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:minHeight="131dp" | ||
android:padding="@dimen/hype_plugin_padding" | ||
android:orientation="horizontal" | ||
android:gravity="center_vertical" | ||
android:background="?attr/selectableItemBackground"> | ||
|
||
<android.support.v7.widget.AppCompatImageView | ||
android:layout_width="@dimen/hype_plugin_icon_size" | ||
android:layout_height="@dimen/hype_plugin_icon_size" | ||
android:layout_marginRight="28dp" | ||
android:layout_marginEnd="28dp" | ||
android:src="@drawable/hbc_icon" | ||
app:tint="@color/hype_plugin_color_selector" | ||
android:duplicateParentState="true"/> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:textColor="@color/hype_plugin_color_selector" | ||
android:text="@string/hbc_plugin_name" | ||
android:duplicateParentState="true" | ||
android:textSize="16sp" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:textColor="@color/hype_plugin_color_selector" | ||
android:text="@string/hbc_plugin_subtitle" | ||
android:duplicateParentState="true"/> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
Oops, something went wrong.