diff --git a/README.md b/README.md index b798d880..c04f997f 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ debugImplementation 'com.willowtreeapps.hyperion:hyperion-crash:0.9.23' debugImplementation 'com.willowtreeapps.hyperion:hyperion-shared-preferences:0.9.23' debugImplementation 'com.willowtreeapps.hyperion:hyperion-geiger-counter:0.9.23' debugImplementation 'com.willowtreeapps.hyperion:hyperion-timber:0.9.23' +debugImplementation 'com.willowtreeapps.hyperion:hyperion-build-config:0.9.23' ``` ## Adding Plugins @@ -94,6 +95,7 @@ The following is a list of all plugins that integrate with Hyperion. Please make - [Hyperion-Geiger-Counter](https://github.com/willowtreeapps/Hyperion-Android/tree/develop/hyperion-geiger-counter) - Check animation performance by listening for dropped frames. Please turn up the media volume. Haptic feedback is also supported. Inspired by [KMCGeigerCounter](https://github.com/kconner/KMCGeigerCounter). - [Hyperion-Timber](https://github.com/willowtreeapps/Hyperion-Android/tree/develop/hyperion-timber) - View Timber recorded log messages. - [Hyperion-Shared-Preferences](https://github.com/willowtreeapps/Hyperion-Android/tree/develop/hyperion-shared-preferences) - View and edit your app\'s key-value storage. +- [Hyperion-Build-Config](https://github.com/willowtreeapps/Hyperion-Android/tree/develop/hyperion-build-config) - View application BuildConfig values. ## License Hyperion is available under the MIT license. See the LICENSE file for more info. diff --git a/hyperion-build-config/.gitignore b/hyperion-build-config/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/hyperion-build-config/.gitignore @@ -0,0 +1 @@ +/build diff --git a/hyperion-build-config/README.md b/hyperion-build-config/README.md new file mode 100644 index 00000000..c2ee2803 --- /dev/null +++ b/hyperion-build-config/README.md @@ -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 { *; } +``` diff --git a/hyperion-build-config/build.gradle b/hyperion-build-config/build.gradle new file mode 100644 index 00000000..dc3d5d27 --- /dev/null +++ b/hyperion-build-config/build.gradle @@ -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' +} \ No newline at end of file diff --git a/hyperion-build-config/src/main/AndroidManifest.xml b/hyperion-build-config/src/main/AndroidManifest.xml new file mode 100644 index 00000000..9a5953e1 --- /dev/null +++ b/hyperion-build-config/src/main/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPlugin.java b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPlugin.java new file mode 100644 index 00000000..3d7ba621 --- /dev/null +++ b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPlugin.java @@ -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(); + } + +} diff --git a/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPluginModule.java b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPluginModule.java new file mode 100644 index 00000000..ecc28063 --- /dev/null +++ b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/BuildConfigPluginModule.java @@ -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); + } +} \ No newline at end of file diff --git a/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListActivity.java b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListActivity.java new file mode 100644 index 00000000..82b7cd6f --- /dev/null +++ b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListActivity.java @@ -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 getBuildConfigValues() { + List 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; + } + +} \ No newline at end of file diff --git a/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListAdapter.java b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListAdapter.java new file mode 100644 index 00000000..149827e4 --- /dev/null +++ b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigListAdapter.java @@ -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 { + + private final List buildConfigValues; + + BuildConfigListAdapter(List 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(); + } +} \ No newline at end of file diff --git a/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigViewHolder.java b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigViewHolder.java new file mode 100644 index 00000000..416c40c1 --- /dev/null +++ b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/list/BuildConfigViewHolder.java @@ -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()); + } + +} \ No newline at end of file diff --git a/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/model/BuildConfigValue.java b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/model/BuildConfigValue.java new file mode 100644 index 00000000..4ff3df16 --- /dev/null +++ b/hyperion-build-config/src/main/java/com/willowtreeapps/hyperion/buildconfig/model/BuildConfigValue.java @@ -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 + '\'' + + '}'; + } + +} diff --git a/hyperion-build-config/src/main/res/drawable/hbc_icon.xml b/hyperion-build-config/src/main/res/drawable/hbc_icon.xml new file mode 100644 index 00000000..bd4a1f99 --- /dev/null +++ b/hyperion-build-config/src/main/res/drawable/hbc_icon.xml @@ -0,0 +1,5 @@ + + + diff --git a/hyperion-build-config/src/main/res/layout/hbc_activity_build_config_list.xml b/hyperion-build-config/src/main/res/layout/hbc_activity_build_config_list.xml new file mode 100644 index 00000000..ab6b906b --- /dev/null +++ b/hyperion-build-config/src/main/res/layout/hbc_activity_build_config_list.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/hyperion-build-config/src/main/res/layout/hbc_item_plugin.xml b/hyperion-build-config/src/main/res/layout/hbc_item_plugin.xml new file mode 100644 index 00000000..2cf71f77 --- /dev/null +++ b/hyperion-build-config/src/main/res/layout/hbc_item_plugin.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hyperion-build-config/src/main/res/layout/hbc_value_row.xml b/hyperion-build-config/src/main/res/layout/hbc_value_row.xml new file mode 100644 index 00000000..da0e9792 --- /dev/null +++ b/hyperion-build-config/src/main/res/layout/hbc_value_row.xml @@ -0,0 +1,43 @@ + + + + + + + + \ No newline at end of file diff --git a/hyperion-build-config/src/main/res/values-v17/styles.xml b/hyperion-build-config/src/main/res/values-v17/styles.xml new file mode 100644 index 00000000..ea49077a --- /dev/null +++ b/hyperion-build-config/src/main/res/values-v17/styles.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/hyperion-build-config/src/main/res/values/colors.xml b/hyperion-build-config/src/main/res/values/colors.xml new file mode 100644 index 00000000..698bdf31 --- /dev/null +++ b/hyperion-build-config/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #2196F3 + #1976D2 + #FF9800 + \ No newline at end of file diff --git a/hyperion-build-config/src/main/res/values/strings.xml b/hyperion-build-config/src/main/res/values/strings.xml new file mode 100644 index 00000000..a41949e3 --- /dev/null +++ b/hyperion-build-config/src/main/res/values/strings.xml @@ -0,0 +1,6 @@ + + + Hyperion-BuildConfig + BuildConfig + View the application BuildConfig values. + \ No newline at end of file diff --git a/hyperion-build-config/src/main/res/values/styles.xml b/hyperion-build-config/src/main/res/values/styles.xml new file mode 100644 index 00000000..2ec7e13f --- /dev/null +++ b/hyperion-build-config/src/main/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + \ No newline at end of file diff --git a/hyperion-sample/build.gradle b/hyperion-sample/build.gradle index 707cb7bf..a7cedc58 100644 --- a/hyperion-sample/build.gradle +++ b/hyperion-sample/build.gradle @@ -53,4 +53,5 @@ dependencies { debugImplementation project(':hyperion-geiger-counter') debugImplementation project(':hyperion-timber') debugImplementation project(':hyperion-sqlite') + debugImplementation project(':hyperion-build-config') } \ No newline at end of file diff --git a/hyperion-sample/proguard-rules.pro b/hyperion-sample/proguard-rules.pro index 38dd506f..998c9bab 100644 --- a/hyperion-sample/proguard-rules.pro +++ b/hyperion-sample/proguard-rules.pro @@ -23,3 +23,5 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + +-keep class com.willowtreeapps.hyperion.sample.BuildConfig { *; } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index dee4ca28..fce0e30b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,4 +17,5 @@ include ':hyperion-sample', ':hyperion-shared-preferences', ':hyperion-geiger-counter', ':hyperion-timber', - ':hyperion-sqlite' \ No newline at end of file + ':hyperion-sqlite', + ':hyperion-build-config' \ No newline at end of file