Skip to content

Commit

Permalink
About dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Diaz committed Sep 26, 2016
1 parent 2b44064 commit 2f51d35
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 14 deletions.
90 changes: 80 additions & 10 deletions app/src/main/java/com/icecream/snorlax/app/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +48,7 @@
import butterknife.ButterKnife;
import butterknife.Unbinder;
import rx.Observable;
import timber.log.Timber;

public class HomeActivity extends AppCompatActivity {

Expand All @@ -52,6 +60,7 @@ public class HomeActivity extends AppCompatActivity {
FloatingActionButton mFab;

private Unbinder mUnbinder;
private AlertDialog mAboutDialog;

@Override
protected void onCreate(Bundle savedStateInstanceState) {
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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();
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<inset
xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="16dp"
android:insetLeft="16dp"
android:insetRight="16dp"
android:insetTop="16dp"
>

<shape android:shape="rectangle">
<corners android:radius="2dp"/>
<solid android:color="@color/red_700"/>
</shape>

</inset>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/ic_github.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
>

<path
android:fillColor="@color/grey_600"
android:pathData="M12,2A10,10 0 0,0 2,12C2,16.42 4.87,20.17 8.84,21.5C9.34,21.58 9.5,21.27 9.5,21C9.5,20.77 9.5,20.14 9.5,19.31C6.73,19.91 6.14,17.97 6.14,17.97C5.68,16.81 5.03,16.5 5.03,16.5C4.12,15.88 5.1,15.9 5.1,15.9C6.1,15.97 6.63,16.93 6.63,16.93C7.5,18.45 8.97,18 9.54,17.76C9.63,17.11 9.89,16.67 10.17,16.42C7.95,16.17 5.62,15.31 5.62,11.5C5.62,10.39 6,9.5 6.65,8.79C6.55,8.54 6.2,7.5 6.75,6.15C6.75,6.15 7.59,5.88 9.5,7.17C10.29,6.95 11.15,6.84 12,6.84C12.85,6.84 13.71,6.95 14.5,7.17C16.41,5.88 17.25,6.15 17.25,6.15C17.8,7.5 17.45,8.54 17.35,8.79C18,9.5 18.38,10.39 18.38,11.5C18.38,15.32 16.04,16.16 13.81,16.41C14.17,16.72 14.5,17.33 14.5,18.26C14.5,19.6 14.5,20.68 14.5,21C14.5,21.27 14.66,21.59 15.17,21.5C19.14,20.16 22,16.42 22,12A10,10 0 0,0 12,2Z"
/>
</vector>
55 changes: 55 additions & 0 deletions app/src/main/res/layout/about_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" ?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/margin_vertical_dialog"
android:paddingEnd="@dimen/margin_horizontal_dialog"
android:paddingStart="@dimen/margin_horizontal_dialog"
android:paddingTop="@dimen/margin_vertical_dialog"
>

<TextView
android:id="@+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:textColor="@color/white"
/>

<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:textColor="@color/white"
/>

<TextView
android:id="@+id/github"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:textColor="@color/white"
android:layout_marginTop="8dp"
/>

<TextView
android:id="@+id/thanks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearance"
android:textColor="@color/white"
android:layout_marginTop="8dp"
/>

</LinearLayout>

</android.support.v4.widget.NestedScrollView>
16 changes: 16 additions & 0 deletions app/src/main/res/menu/menu_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<menu
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"
tools:context=".app.ui.HomeActivity"
>

<item
android:id="@+id/about"
android:orderInCategory="100"
android:title="@string/about"
app:showAsAction="never"
/>

</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<!-- Elevation -->
<dimen name="evelation_normal_fab">6dp</dimen>
<dimen name="evelation_pressed_fab">12dp</dimen>
<dimen name="margin_vertical_dialog">16dp</dimen>
<dimen name="margin_horizontal_dialog">24dp</dimen>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/drawables.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<item name="pokeball" type="drawable">@drawable/ic_pokeball</item>
<item name="github" type="drawable">@drawable/ic_github</item>
</resources>
17 changes: 13 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>

<string name="about">About</string>
<string name="enable">Enable</string>
<string name="xposed_disabled">Snorlax module is not enabled</string>
<string name="xposed_missing">Install xposed to use Snorlax</string>
<string name="pokemon_missing">Install Pokemon Go to launch it</string>

<string name="about_version">Version %1$s</string>
<string name="about_author">By igoticecream (igoticecream@gmail.com)</string>
<string name="about_github">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.</string>
<string name="about_thanks">Special thanks for the github\'s users \'chuparCh0pper\' for his PoGoIV_xposed project and \'ELynx\' for the method used to MITM PokemonGo communication.</string>
<string name="about_repository">https://github.com/igoticecream/Snorlax</string>

<string name="error_readable">Cannot make preferences world readable</string>
<string name="error_xposed_disabled">Snorlax module is not enabled</string>
<string name="error_xposed_missing">Install xposed to use Snorlax</string>
<string name="error_pokemon_missing">Install Pokemon Go to launch it</string>

<string name="notification_title">%1$s has appeared!</string>
<string name="notification_content">IV %1$4.1f%% %2$d/%3$d/%4$d - CP %5$d - LV %6$3.1f - HP %7$d</string>
Expand Down Expand Up @@ -32,7 +41,7 @@

<string name="preference_catch_notification">Catch Notifications</string>
<string name="preference_catch_notification_enable_key">catch_notification_key</string>
<string name="preference_catch_notification_enable_title">Enable catch Notifications</string>
<string name="preference_catch_notification_enable_title">Enable catch notifications</string>
<string name="preference_catch_notification_enable_summary">Show catch result via system toast</string>

</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<item name="android:windowTranslucentStatus">true</item>
</style>

<style name="Snorlax.Dialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:windowBackground">@drawable/dialog</item>
</style>

<style name="Snorlax.AppBarOverlay" parent="ThemeOverlay.AppCompat.ActionBar"/>

<style name="Snorlax.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
Expand Down

0 comments on commit 2f51d35

Please sign in to comment.