Merge in SendToDocs changes.

This commit is contained in:
Sandor Dornbush
2011-01-09 22:21:03 -08:00
8 changed files with 69 additions and 28 deletions
@@ -21,38 +21,37 @@ import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
/**
* Displays an EULA ("End User License Agreement") that the user has to accept
* before using the application. Your application should call
* {@link Eula#showEula(android.app.Activity)} in the onCreate() method of the
* first activity. If the user accepts the EULA, it will never be shown again.
* If the user refuses, {@link android.app.Activity#finish()} is invoked on your
* activity.
* This class handles display of EULAs ("End User License Agreements") to the
* user.
*/
class Eula {
private static final String PREFERENCE_EULA_ACCEPTED = "eula.accepted";
private static final String PREFERENCES_EULA = "eula";
private Eula() {}
/**
* Displays the EULA if necessary. This method should be called from the
* onCreate() method of your main Activity.
* onCreate() method of your main Activity. If the user accepts, the EULA
* will never be displayed again. If the user refuses, the activity will
* finish (exit).
*
* @param activity The Activity to finish if the user rejects the EULA
*/
static void showEula(final Activity activity) {
static void showEulaRequireAcceptance(final Activity activity) {
final SharedPreferences preferences =
activity.getSharedPreferences(PREFERENCES_EULA, Activity.MODE_PRIVATE);
if (preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) {
return;
}
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.eula_title);
builder.setCancelable(true);
final AlertDialog.Builder builder = initDialog(activity);
builder.setPositiveButton(R.string.accept,
new DialogInterface.OnClickListener() {
@Override
@@ -73,10 +72,28 @@ class Eula {
refuse(activity);
}
});
builder.setMessage(ResourceUtils.readFile(activity, R.raw.eula));
builder.show();
}
/**
* Display the EULA to the user in an informational context. They won't be
* given the choice of accepting or declining the EULA -- we're simply
* displaying it for them to read.
*/
static void showEula(Context context) {
AlertDialog.Builder builder = initDialog(context);
builder.setPositiveButton(R.string.ok, null);
builder.show();
}
private static AlertDialog.Builder initDialog(Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setCancelable(true);
builder.setTitle(R.string.eula_title);
builder.setMessage(ResourceUtils.readFile(context, R.raw.eula));
return builder;
}
private static void accept(Activity activity, SharedPreferences preferences) {
ApiFeatures.getInstance().getApiPlatformAdapter().applyPreferenceChanges(
preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true));
@@ -87,7 +104,4 @@ class Eula {
private static void refuse(Activity activity) {
activity.finish();
}
private Eula() {
}
}
@@ -46,6 +46,7 @@ public class ExportAllTracks {
public static final int GPX_OPTION_INDEX = 0;
public static final int KML_OPTION_INDEX = 1;
public static final int CSV_OPTION_INDEX = 2;
public static final int TCX_OPTION_INDEX = 3;
private final Activity activity;
private WakeLock wakeLock;
@@ -67,6 +68,11 @@ public class ExportAllTracks {
case CSV_OPTION_INDEX:
format = TrackFileFormat.CSV;
break;
case TCX_OPTION_INDEX:
format = TrackFileFormat.TCX;
break;
default:
Log.w(MyTracksConstants.TAG, "Unknown export format: " + which);
}
}
};
@@ -314,7 +314,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
}
// This will show the eula until the user accepts or quits the app.
Eula.showEula(this);
Eula.showEulaRequireAcceptance(this);
// Check if we got invoked via the VIEW intent:
Intent intent = getIntent();
@@ -19,6 +19,7 @@ import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -74,6 +75,12 @@ public class WelcomeActivity extends Activity {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(view);
builder.setPositiveButton(R.string.ok, null);
builder.setNeutralButton(R.string.license, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Eula.showEula(WelcomeActivity.this);
}
});
builder.setIcon(R.drawable.arrow_icon);
AlertDialog dialog = builder.create();
dialog.show();