Skip to content

Commit

Permalink
Merge pull request #133 from ToxicBakery/feature/build-config-plugin
Browse files Browse the repository at this point in the history
#132 Added BuildConfig plugin
  • Loading branch information
Kritarie authored Jul 9, 2018
2 parents 5f7901f + 6498ff2 commit 0f8c1fe
Show file tree
Hide file tree
Showing 22 changed files with 442 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions hyperion-build-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
10 changes: 10 additions & 0 deletions hyperion-build-config/README.md
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 { *; }
```
35 changes: 35 additions & 0 deletions hyperion-build-config/build.gradle
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'
}
11 changes: 11 additions & 0 deletions hyperion-build-config/src/main/AndroidManifest.xml
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>
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();
}

}
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);
}
}
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;
}

}
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();
}
}
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());
}

}
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 + '\'' +
'}';
}

}
5 changes: 5 additions & 0 deletions hyperion-build-config/src/main/res/drawable/hbc_icon.xml
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>
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 hyperion-build-config/src/main/res/layout/hbc_item_plugin.xml
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>
Loading

0 comments on commit 0f8c1fe

Please sign in to comment.