From 2f51d35aec20810500052a8bf751f7862f0e57c9 Mon Sep 17 00:00:00 2001 From: Pedro Diaz Date: Mon, 26 Sep 2016 11:18:58 -0400 Subject: [PATCH] About dialog --- .../icecream/snorlax/app/ui/HomeActivity.java | 90 ++++++++++++++++--- app/src/main/res/drawable/dialog.xml | 15 ++++ app/src/main/res/drawable/ic_github.xml | 14 +++ app/src/main/res/layout/about_dialog.xml | 55 ++++++++++++ app/src/main/res/menu/menu_home.xml | 16 ++++ app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/drawables.xml | 1 + app/src/main/res/values/strings.xml | 17 +++- app/src/main/res/values/styles.xml | 6 ++ 9 files changed, 202 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/drawable/dialog.xml create mode 100644 app/src/main/res/drawable/ic_github.xml create mode 100644 app/src/main/res/layout/about_dialog.xml create mode 100644 app/src/main/res/menu/menu_home.xml diff --git a/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java b/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java index 0cb6d4f..d39eff2 100644 --- a/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java +++ b/app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java @@ -20,17 +20,24 @@ import java.util.concurrent.TimeUnit; import android.annotation.SuppressLint; -import android.content.Context; +import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; +import android.net.Uri; import android.os.Bundle; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; +import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.PreferenceManager; import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.TextView; +import android.widget.Toast; import com.icecream.snorlax.BuildConfig; import com.icecream.snorlax.R; @@ -41,6 +48,7 @@ import butterknife.ButterKnife; import butterknife.Unbinder; import rx.Observable; +import timber.log.Timber; public class HomeActivity extends AppCompatActivity { @@ -52,6 +60,7 @@ public class HomeActivity extends AppCompatActivity { FloatingActionButton mFab; private Unbinder mUnbinder; + private AlertDialog mAboutDialog; @Override protected void onCreate(Bundle savedStateInstanceState) { @@ -69,10 +78,10 @@ protected void onCreate(Bundle savedStateInstanceState) { .map(enabled -> getPackageManager().getLaunchIntentForPackage(BuildConfig.XPOSED_ID)) .map(intent -> { if (intent != null) { - return Snackbar.make(mFab, R.string.xposed_disabled, Snackbar.LENGTH_LONG).setAction(R.string.enable, v -> startActivity(intent)); + return Snackbar.make(mFab, R.string.error_xposed_disabled, Snackbar.LENGTH_LONG).setAction(R.string.enable, v -> startActivity(intent)); } else { - return Snackbar.make(mFab, R.string.xposed_missing, Snackbar.LENGTH_LONG); + return Snackbar.make(mFab, R.string.error_xposed_missing, Snackbar.LENGTH_LONG); } }) .subscribe(Snackbar::show); @@ -84,7 +93,7 @@ protected void onCreate(Bundle savedStateInstanceState) { .map(click -> getPackageManager().getLaunchIntentForPackage(BuildConfig.POKEMON_GO_ID)) .doOnNext(intent -> { if (intent == null) { - Snackbar.make(mFab, R.string.pokemon_missing, Snackbar.LENGTH_LONG).show(); + Snackbar.make(mFab, R.string.error_pokemon_missing, Snackbar.LENGTH_LONG).show(); } }) .filter(intent -> intent != null) @@ -110,34 +119,95 @@ protected void onDestroy() { mUnbinder.unbind(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_home, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.about: + showAbout(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + @SuppressLint("InflateParams") + private void showAbout() { + View view = getLayoutInflater().inflate(R.layout.about_dialog, null, false); + + TextView version = (TextView) view.findViewById(R.id.version); + version.setText(getString(R.string.about_version, BuildConfig.VERSION_NAME)); + + TextView author = (TextView) view.findViewById(R.id.author); + author.setText(getString(R.string.about_author)); + + TextView github = (TextView) view.findViewById(R.id.github); + github.setText(getString(R.string.about_github)); + + TextView thanks = (TextView) view.findViewById(R.id.thanks); + thanks.setText(getString(R.string.about_thanks)); + + mAboutDialog = new AlertDialog.Builder(this, R.style.Snorlax_Dialog) + .setTitle(R.string.app_name) + .setView(view) + .setPositiveButton("Github", (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_repository))))) + .setCancelable(true) + .show(); + } + + @Override + protected void onPause() { + super.onPause(); + + if (mAboutDialog != null && mAboutDialog.isShowing()) { + mAboutDialog.dismiss(); + } + } + public static class SettingsFragment extends PreferenceFragmentCompat { @Override - @SuppressWarnings("deprecation") public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - //Note: this will throw security exception on Nougat - getPreferenceManager().setSharedPreferencesMode(Context.MODE_WORLD_READABLE); addPreferencesFromResource(R.xml.preferences); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - // Remove dividers setDivider(new ColorDrawable(Color.TRANSPARENT)); setDividerHeight(0); } @Override @SuppressLint("SetWorldReadable") - @SuppressWarnings("ResultOfMethodCallIgnored") public void onPause() { super.onPause(); + // Workaround since Google enforce security on Nougat on getPreferenceManager().setSharedPreferencesMode(Context.MODE_WORLD_READABLE); File sharedPrefsDir = new File(getActivity().getApplicationInfo().dataDir, "shared_prefs"); File sharedPrefsFile = new File(sharedPrefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml"); if (sharedPrefsFile.exists()) { - sharedPrefsFile.setReadable(true, false); + try { + if (!sharedPrefsFile.setReadable(true, false)) { + showReadableError(); + return; + } + Timber.d("Set MODE_WORLD_READABLE successfully"); + } + catch (SecurityException exception) { + showReadableError(); + } + } + } + + private void showReadableError() { + if (getActivity() != null) { + Toast.makeText(getActivity(), R.string.error_readable, Toast.LENGTH_LONG).show(); } } } diff --git a/app/src/main/res/drawable/dialog.xml b/app/src/main/res/drawable/dialog.xml new file mode 100644 index 0000000..a0297bb --- /dev/null +++ b/app/src/main/res/drawable/dialog.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_github.xml b/app/src/main/res/drawable/ic_github.xml new file mode 100644 index 0000000..39206a0 --- /dev/null +++ b/app/src/main/res/drawable/ic_github.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/about_dialog.xml b/app/src/main/res/layout/about_dialog.xml new file mode 100644 index 0000000..670248b --- /dev/null +++ b/app/src/main/res/layout/about_dialog.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_home.xml b/app/src/main/res/menu/menu_home.xml new file mode 100644 index 0000000..7df3891 --- /dev/null +++ b/app/src/main/res/menu/menu_home.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 1c0c74a..d59c4e1 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -8,5 +8,7 @@ 6dp 12dp + 16dp + 24dp diff --git a/app/src/main/res/values/drawables.xml b/app/src/main/res/values/drawables.xml index 5b40199..178f24f 100644 --- a/app/src/main/res/values/drawables.xml +++ b/app/src/main/res/values/drawables.xml @@ -1,4 +1,5 @@ @drawable/ic_pokeball + @drawable/ic_github diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4457cf9..ff4130e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,10 +1,19 @@ + About Enable - Snorlax module is not enabled - Install xposed to use Snorlax - Install Pokemon Go to launch it + + Version %1$s + By igoticecream (igoticecream@gmail.com) + This project is open source under the Apache 2.0 license. If you like this module, an star to this repo on my Github will help me a lot. + Special thanks for the github\'s users \'chuparCh0pper\' for his PoGoIV_xposed project and \'ELynx\' for the method used to MITM PokemonGo communication. + https://github.com/igoticecream/Snorlax + + Cannot make preferences world readable + Snorlax module is not enabled + Install xposed to use Snorlax + Install Pokemon Go to launch it %1$s has appeared! IV %1$4.1f%% %2$d/%3$d/%4$d - CP %5$d - LV %6$3.1f - HP %7$d @@ -32,7 +41,7 @@ Catch Notifications catch_notification_key - Enable catch Notifications + Enable catch notifications Show catch result via system toast diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index bdd6945..3c37294 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -15,6 +15,12 @@ true + +