-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AugendiagnoseUnlocker: display message on first start -> v1.0.1
- Loading branch information
Showing
15 changed files
with
361 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...dea/augendiagnoseUnlocker/src/main/java/de/jeisfeld/augendiagnoseunlocker/DialogUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package de.jeisfeld.augendiagnoseunlocker; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.app.Dialog; | ||
import android.app.DialogFragment; | ||
import android.content.DialogInterface; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
/** | ||
* Helper class to show standard dialogs. | ||
*/ | ||
public final class DialogUtil { | ||
/** | ||
* Parameter to pass the title to the DialogFragment. | ||
*/ | ||
private static final String PARAM_TITLE = "title"; | ||
/** | ||
* Parameter to pass the message to the DialogFragment (of all types). | ||
*/ | ||
private static final String PARAM_MESSAGE = "message"; | ||
|
||
/** | ||
* Hide default constructor. | ||
*/ | ||
private DialogUtil() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** | ||
* Display an error. | ||
* | ||
* @param activity the current activity | ||
* @param resource the error message | ||
* @param args arguments for the error message | ||
*/ | ||
public static void displayError(@NonNull final Activity activity, final int resource, final Object... args) { | ||
String message = String.format(activity.getString(resource), args); | ||
Bundle bundle = new Bundle(); | ||
bundle.putCharSequence(PARAM_MESSAGE, message); | ||
bundle.putString(PARAM_TITLE, activity.getString(R.string.title_dialog_error)); | ||
|
||
DialogFragment fragment = new DisplayMessageDialogFragment(); | ||
fragment.setArguments(bundle); | ||
fragment.show(activity.getFragmentManager(), fragment.getClass().toString()); | ||
} | ||
|
||
/** | ||
* Fragment to display an error and go back to the current activity. | ||
*/ | ||
public static class DisplayMessageDialogFragment extends DialogFragment { | ||
@Override | ||
public final Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) { | ||
CharSequence message = getArguments().getCharSequence(PARAM_MESSAGE); | ||
String title = getArguments().getString(PARAM_TITLE); | ||
|
||
// Listeners cannot retain functionality when automatically recreated. | ||
// Therefore, dialogs with listeners must be re-created by the activity on orientation change. | ||
boolean preventRecreation = false; | ||
if (savedInstanceState != null) { | ||
preventRecreation = savedInstanceState.getBoolean("preventRecreation"); | ||
} | ||
if (preventRecreation) { | ||
dismiss(); | ||
} | ||
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | ||
builder.setTitle(title) | ||
.setMessage(message) | ||
.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(@NonNull final DialogInterface dialog, final int id) { | ||
dialog.dismiss(); | ||
} | ||
}); | ||
return builder.create(); | ||
} | ||
} | ||
|
||
} |
137 changes: 137 additions & 0 deletions
137
...gnoseUnlocker/src/main/java/de/jeisfeld/augendiagnoseunlocker/DisplayMessageActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package de.jeisfeld.augendiagnoseunlocker; | ||
|
||
import android.app.Activity; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
|
||
/** | ||
* Main activity of the application. | ||
*/ | ||
public class DisplayMessageActivity extends Activity { | ||
/** | ||
* The package name of the eye diagnosis app. | ||
*/ | ||
private static final String PACKAGE_EYE_DIAGNOSIS = "de.eisfeldj.augendiagnose"; | ||
/** | ||
* The package name of the Miniris app. | ||
*/ | ||
private static final String PACKAGE_MINIRIS = "de.jeisfeld.miniris"; | ||
|
||
@Override | ||
protected final void onCreate(final Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
if (isMainAppInstalled()) { | ||
displayUnlimitedUseMessage(); | ||
} | ||
else { | ||
displayMissingMainAppMessage(); | ||
} | ||
} | ||
|
||
/** | ||
* Display the message that the main app is required. | ||
*/ | ||
private void displayMissingMainAppMessage() { | ||
setContentView(R.layout.dialog_missing_main_app); | ||
|
||
findViewById(R.id.buttonEyeDiagnosis).setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(final View v) { | ||
openGooglePlay(PACKAGE_EYE_DIAGNOSIS); | ||
finish(); | ||
} | ||
}); | ||
|
||
findViewById(R.id.buttonMiniris).setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(final View v) { | ||
openGooglePlay(PACKAGE_MINIRIS); | ||
finish(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Display the message that the apps can be used unlimited now. | ||
*/ | ||
private void displayUnlimitedUseMessage() { | ||
setContentView(R.layout.dialog_unlimited_use); | ||
|
||
findViewById(R.id.buttonOk).setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(final View v) { | ||
setEnabled(DisplayMessageActivity.this, false); | ||
finish(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Enable or disable this activity. | ||
* | ||
* @param context The calling context. | ||
* @param enabled true for enabling, false for disabling. | ||
*/ | ||
private static void setEnabled(final Context context, final boolean enabled) { | ||
ComponentName componentName = new ComponentName(context, DisplayMessageActivity.class); | ||
context.getPackageManager().setComponentEnabledSetting(componentName, | ||
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | ||
PackageManager.DONT_KILL_APP); | ||
} | ||
|
||
/** | ||
* Get information if this activity is enabled. | ||
* | ||
* @param context The calling context. | ||
* @return true if enabled. | ||
*/ | ||
protected static boolean isEnabled(final Context context) { | ||
ComponentName componentName = new ComponentName(context, DisplayMessageActivity.class); | ||
return context.getPackageManager().getComponentEnabledSetting(componentName) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED; | ||
} | ||
|
||
/** | ||
* Open Google Play to display a certain app. | ||
* | ||
* @param appPackage The package of the app to be displayed. | ||
*/ | ||
private void openGooglePlay(final String appPackage) { | ||
Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW); | ||
googlePlayIntent.setData(Uri.parse("market://details?id=" + appPackage)); | ||
try { | ||
startActivity(googlePlayIntent); | ||
} | ||
catch (Exception e) { | ||
DialogUtil.displayError(this, R.string.message_dialog_failed_to_open_google_play); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Check if the main app Eye Diagnosis or Miniris is installed. | ||
* | ||
* @return true if installed. | ||
*/ | ||
private boolean isMainAppInstalled() { | ||
return isAppInstalled(PACKAGE_EYE_DIAGNOSIS) || isAppInstalled(PACKAGE_MINIRIS); | ||
} | ||
|
||
/** | ||
* Determine if an app is installed. | ||
* | ||
* @param appPackage the app package name. | ||
* @return true if the app is installed. | ||
*/ | ||
private boolean isAppInstalled(final String appPackage) { | ||
Intent appIntent = getPackageManager().getLaunchIntentForPackage(appPackage); | ||
return appIntent != null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-1.08 KB
(87%)
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-563 Bytes
(88%)
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.41 KB
(88%)
...ndiagnoseIdea/augendiagnoseUnlocker/src/main/res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.49 KB
(89%)
...diagnoseIdea/augendiagnoseUnlocker/src/main/res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions
43
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/layout/dialog_missing_main_app.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="@dimen/activity_margin" | ||
android:text="@string/text_warning" | ||
android:textAppearance="?android:attr/textAppearanceLarge"/> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="@dimen/activity_margin" | ||
android:text="@string/text_message_missing_main_app" | ||
android:textAppearance="?android:attr/textAppearanceMedium"/> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:padding="@dimen/activity_margin"> | ||
|
||
<Button | ||
android:id="@+id/buttonEyeDiagnosis" | ||
android:layout_width="0dp" | ||
android:layout_height="match_parent" | ||
android:layout_margin="0dp" | ||
android:layout_weight="1" | ||
android:text="@string/button_install_eye_diagnosis"/> | ||
|
||
<Button | ||
android:id="@+id/buttonMiniris" | ||
android:layout_width="0dp" | ||
android:layout_height="match_parent" | ||
android:layout_margin="0dp" | ||
android:layout_weight="1" | ||
android:text="@string/button_install_miniris"/> | ||
</LinearLayout> | ||
</LinearLayout> |
28 changes: 28 additions & 0 deletions
28
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/layout/dialog_unlimited_use.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="@dimen/activity_margin" | ||
android:text="@string/text_thanks" | ||
android:textAppearance="?android:attr/textAppearanceLarge"/> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="@dimen/activity_margin" | ||
android:text="@string/text_message_unlimited_use" | ||
android:textAppearance="?android:attr/textAppearanceMedium"/> | ||
|
||
<Button | ||
android:id="@+id/buttonOk" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="@dimen/activity_margin" | ||
android:text="@string/button_ok"/> | ||
|
||
</LinearLayout> |
15 changes: 15 additions & 0 deletions
15
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/values-de/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">Iridology unlocker</string> | ||
<string name="text_warning">Warnung</string> | ||
<string name="text_message_missing_main_app">Dia App „Iridology Unlocker“ kann nicht alleine betrieben werden. Sie dient nur zur Freischaltung der Apps „Augendiagnose“ und „Miniris“. Bitte installieren Sie eine dieser Apps.</string> | ||
<string name="button_install_eye_diagnosis">„Augendiagnose“ installieren</string> | ||
<string name="button_install_miniris">„Miniris“ installieren</string> | ||
<string name="text_thanks">Danke!</string> | ||
<string name="text_message_unlimited_use">Danke für den Erwerb von „Iridology Unlocker“. Sie können nun die Apps „Augendiagnose“ und „Miniris“ auf diesem Gerät unbegrenzt nutzen.</string> | ||
<string name="button_ok">OK</string> | ||
<string name="title_dialog_error">Fehler</string> | ||
<string name="message_dialog_failed_to_open_google_play">Google Play konnte nicht gestartet werden.</string> | ||
|
||
</resources> |
15 changes: 15 additions & 0 deletions
15
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/values-es/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">Iridology unlocker</string> | ||
<string name="text_warning">Aviso</string> | ||
<string name="text_message_missing_main_app">La aplicación «Iridology Unlocker» no se puede ejecutar independiente. Sólo sirve como clave de desbloqueo de las aplicaciones «Diagnóstico ocular» y «Miniris». Por favor, instale una de estas aplicaciones.</string> | ||
<string name="button_install_eye_diagnosis">Instalar «Diagnóstico ocular»</string> | ||
<string name="button_install_miniris">Instalar «Miniris»</string> | ||
<string name="text_thanks">¡Gracias!</string> | ||
<string name="text_message_unlimited_use">Gracias por comprar «Iridology Unlocker». Ahora puede utilizar las aplicaciónes «Diagnóstico ocular» y «Miniris» ilimitadamente en este dispositivo.</string> | ||
<string name="button_ok">OK</string> | ||
<string name="title_dialog_error">Error</string> | ||
<string name="message_dialog_failed_to_open_google_play">Error al abrir Google Play.</string> | ||
|
||
</resources> |
5 changes: 5 additions & 0 deletions
5
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/values-large/dimens.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
|
||
<dimen name="activity_margin">32dp</dimen> | ||
|
||
</resources> |
5 changes: 5 additions & 0 deletions
5
AugendiagnoseIdea/augendiagnoseUnlocker/src/main/res/values/dimens.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
|
||
<dimen name="activity_margin">16dp</dimen> | ||
|
||
</resources> |
Oops, something went wrong.