Skip to content

Commit

Permalink
AugendiagnoseUnlocker: display message on first start -> v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisfeld committed Jan 20, 2016
1 parent eb7b553 commit 3ca04ab
Show file tree
Hide file tree
Showing 15 changed files with 361 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.jeisfeld.augendiagnoseunlocker"
<manifest package="de.jeisfeld.augendiagnoseunlocker"
xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0">
android:versionCode="2"
android:versionName="1.0.1">

<uses-sdk
android:minSdkVersion="15"
Expand All @@ -21,7 +21,18 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false">
android:supportsRtl="false"
android:theme="@android:style/Theme.Holo">
<activity
android:name="de.jeisfeld.augendiagnoseunlocker.DisplayMessageActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="de.jeisfeld.augendiagnoseunlocker.UnlockActivity"
android:label="@string/app_name"
Expand Down
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();
}
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ protected final void onCreate(final Bundle savedInstanceState) {
Intent responseIntent = new Intent();
responseIntent.putExtras(resultData);
setResult(RESULT_OK, responseIntent);

if (DisplayMessageActivity.isEnabled(this)) {
Intent messageIntent = new Intent(this, DisplayMessageActivity.class);
startActivity(messageIntent);
}

finish();
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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>
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>
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>
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>

<dimen name="activity_margin">32dp</dimen>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>

<dimen name="activity_margin">16dp</dimen>

</resources>
Loading

0 comments on commit 3ca04ab

Please sign in to comment.