Skip to content

Commit 0f8c1fe

Browse files
authored
Merge pull request #133 from ToxicBakery/feature/build-config-plugin
#132 Added BuildConfig plugin
2 parents 5f7901f + 6498ff2 commit 0f8c1fe

22 files changed

+442
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ debugImplementation 'com.willowtreeapps.hyperion:hyperion-crash:0.9.23'
7070
debugImplementation 'com.willowtreeapps.hyperion:hyperion-shared-preferences:0.9.23'
7171
debugImplementation 'com.willowtreeapps.hyperion:hyperion-geiger-counter:0.9.23'
7272
debugImplementation 'com.willowtreeapps.hyperion:hyperion-timber:0.9.23'
73+
debugImplementation 'com.willowtreeapps.hyperion:hyperion-build-config:0.9.23'
7374
```
7475

7576
## Adding Plugins
@@ -94,6 +95,7 @@ The following is a list of all plugins that integrate with Hyperion. Please make
9495
- [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).
9596
- [Hyperion-Timber](https://github.com/willowtreeapps/Hyperion-Android/tree/develop/hyperion-timber) - View Timber recorded log messages.
9697
- [Hyperion-Shared-Preferences](https://github.com/willowtreeapps/Hyperion-Android/tree/develop/hyperion-shared-preferences) - View and edit your app\'s key-value storage.
98+
- [Hyperion-Build-Config](https://github.com/willowtreeapps/Hyperion-Android/tree/develop/hyperion-build-config) - View application BuildConfig values.
9799

98100
## License
99101
Hyperion is available under the MIT license. See the LICENSE file for more info.

hyperion-build-config/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

hyperion-build-config/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Build Config
2+
Plugin for viewing the BuildConfig values of the application.
3+
4+
## Notes
5+
If minification is enabled for your debug builds, you will likely want to update proguard to keep your BuildConfig class.
6+
7+
Update to match your package name.
8+
```
9+
-keep class com.willowtreeapps.hyperion.sample.BuildConfig { *; }
10+
```

hyperion-build-config/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apply plugin: 'com.android.library'
2+
apply from: '../publish.gradle'
3+
4+
group = project.libraryGroup
5+
version = project.libraryVersion
6+
7+
android {
8+
compileSdkVersion project.compileSdkVersion
9+
buildToolsVersion project.buildToolsVersion
10+
11+
defaultConfig {
12+
minSdkVersion project.minSdkVersion
13+
targetSdkVersion project.targetSdkVersion
14+
versionCode buildVersionCode()
15+
versionName version
16+
17+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
lintOptions {
21+
abortOnError false
22+
}
23+
24+
resourcePrefix 'hbc_'
25+
}
26+
27+
dependencies {
28+
testImplementation "junit:junit:4.12"
29+
api project(':hyperion-plugin')
30+
implementation "com.android.support:appcompat-v7:${project.versionSupportLibrary}"
31+
annotationProcessor "com.google.auto.service:auto-service:${project.versionAutoService}"
32+
implementation "com.android.support:recyclerview-v7:${project.versionSupportLibrary}"
33+
implementation "com.android.support:design:${project.versionSupportLibrary}"
34+
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.willowtreeapps.hyperion.buildconfig">
3+
4+
<application>
5+
<activity
6+
android:name=".list.BuildConfigListActivity"
7+
android:theme="@style/hbc_BuildConfigActivityTheme"
8+
android:windowSoftInputMode="stateHidden" />
9+
</application>
10+
11+
</manifest>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.willowtreeapps.hyperion.buildconfig;
2+
3+
import android.support.annotation.Nullable;
4+
5+
import com.google.auto.service.AutoService;
6+
import com.willowtreeapps.hyperion.plugin.v1.Plugin;
7+
import com.willowtreeapps.hyperion.plugin.v1.PluginModule;
8+
9+
@AutoService(Plugin.class)
10+
public class BuildConfigPlugin extends Plugin {
11+
12+
@Nullable
13+
@Override
14+
public PluginModule createPluginModule() {
15+
return new BuildConfigPluginModule();
16+
}
17+
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.willowtreeapps.hyperion.buildconfig;
2+
3+
import android.content.Intent;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import com.willowtreeapps.hyperion.buildconfig.list.BuildConfigListActivity;
11+
import com.willowtreeapps.hyperion.plugin.v1.PluginModule;
12+
13+
class BuildConfigPluginModule extends PluginModule implements View.OnClickListener {
14+
15+
@Nullable
16+
@Override
17+
public View createPluginView(@NonNull LayoutInflater layoutInflater, @NonNull ViewGroup parent) {
18+
View view = layoutInflater.inflate(R.layout.hbc_item_plugin, parent, false);
19+
view.setOnClickListener(this);
20+
return view;
21+
}
22+
23+
@Override
24+
public void onClick(View v) {
25+
Intent intent = new Intent(getContext(), BuildConfigListActivity.class);
26+
getContext().startActivity(intent);
27+
}
28+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.willowtreeapps.hyperion.buildconfig.list;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.app.ActionBar;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.support.v7.widget.LinearLayoutManager;
8+
import android.support.v7.widget.RecyclerView;
9+
import android.support.v7.widget.Toolbar;
10+
import android.util.Log;
11+
12+
import com.willowtreeapps.hyperion.buildconfig.R;
13+
import com.willowtreeapps.hyperion.buildconfig.model.BuildConfigValue;
14+
import com.willowtreeapps.hyperion.plugin.v1.HyperionIgnore;
15+
16+
import java.lang.reflect.Field;
17+
import java.lang.reflect.Modifier;
18+
import java.util.LinkedList;
19+
import java.util.List;
20+
21+
@HyperionIgnore
22+
public class BuildConfigListActivity extends AppCompatActivity {
23+
24+
private static final String TAG = "BuildConfig";
25+
26+
@Override
27+
protected void onCreate(@Nullable Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
setContentView(R.layout.hbc_activity_build_config_list);
30+
setSupportActionBar((Toolbar) findViewById(R.id.tmb_toolbar));
31+
ActionBar actionBar = getSupportActionBar();
32+
if (actionBar != null) {
33+
actionBar.setDisplayHomeAsUpEnabled(true);
34+
}
35+
36+
RecyclerView recyclerView = findViewById(R.id.hbc_recycler);
37+
recyclerView.setLayoutManager(new LinearLayoutManager(this));
38+
recyclerView.setAdapter(new BuildConfigListAdapter(getBuildConfigValues()));
39+
}
40+
41+
@Override
42+
public boolean onSupportNavigateUp() {
43+
onBackPressed();
44+
return true;
45+
}
46+
47+
private List<BuildConfigValue> getBuildConfigValues() {
48+
List<BuildConfigValue> buildConfigValues = new LinkedList<>();
49+
try {
50+
Class<?> buildConfigClass = Class.forName(getPackageName() + ".BuildConfig");
51+
Log.d(TAG, "Checking BuildConfig " + buildConfigClass.getName());
52+
Field[] declaredFields = buildConfigClass.getDeclaredFields();
53+
for (Field declaredField : declaredFields) {
54+
Log.d(TAG, "Inspecting " + declaredField.toString());
55+
if (Modifier.isStatic(declaredField.getModifiers())) {
56+
Class<?> fieldType = declaredField.getType();
57+
String name = declaredField.getName() + " (" + fieldType.getSimpleName() + ")";
58+
String value = declaredField.get(null).toString();
59+
buildConfigValues.add(new BuildConfigValue(name, value));
60+
}
61+
}
62+
} catch (Exception e) {
63+
Log.e(TAG, "Failed to read BuildConfig", e);
64+
}
65+
66+
return buildConfigValues;
67+
}
68+
69+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.willowtreeapps.hyperion.buildconfig.list;
2+
3+
import android.support.annotation.NonNull;
4+
import android.support.v7.widget.RecyclerView;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
9+
import com.willowtreeapps.hyperion.buildconfig.R;
10+
import com.willowtreeapps.hyperion.buildconfig.model.BuildConfigValue;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
class BuildConfigListAdapter extends RecyclerView.Adapter<BuildConfigViewHolder> {
16+
17+
private final List<BuildConfigValue> buildConfigValues;
18+
19+
BuildConfigListAdapter(List<BuildConfigValue> buildConfigValues) {
20+
this.buildConfigValues = new ArrayList<>(buildConfigValues);
21+
}
22+
23+
@NonNull
24+
@Override
25+
public BuildConfigViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
26+
final View itemView = LayoutInflater.from(parent.getContext())
27+
.inflate(R.layout.hbc_value_row, parent, false);
28+
return new BuildConfigViewHolder(itemView);
29+
}
30+
31+
@Override
32+
public void onBindViewHolder(@NonNull BuildConfigViewHolder holder, int position) {
33+
BuildConfigValue buildConfigValue = buildConfigValues.get(position);
34+
holder.bind(buildConfigValue);
35+
}
36+
37+
@Override
38+
public int getItemCount() {
39+
return buildConfigValues.size();
40+
}
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.willowtreeapps.hyperion.buildconfig.list;
2+
3+
import android.support.v7.widget.RecyclerView;
4+
import android.view.View;
5+
import android.widget.TextView;
6+
7+
import com.willowtreeapps.hyperion.buildconfig.R;
8+
import com.willowtreeapps.hyperion.buildconfig.model.BuildConfigValue;
9+
10+
class BuildConfigViewHolder extends RecyclerView.ViewHolder {
11+
12+
private final TextView logDateTextView;
13+
private final TextView logMsgTextView;
14+
15+
BuildConfigViewHolder(View itemView) {
16+
super(itemView);
17+
logDateTextView = itemView.findViewById(R.id.hbc_name);
18+
logMsgTextView = itemView.findViewById(R.id.hbc_value);
19+
}
20+
21+
void bind(BuildConfigValue buildConfigValue) {
22+
logDateTextView.setText(buildConfigValue.getName());
23+
logMsgTextView.setText(buildConfigValue.getValue());
24+
}
25+
26+
}

0 commit comments

Comments
 (0)