forked from upstream-mirrors/OpenTracks
Use the caller pattern for all DialogFragment.
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.fragments.AboutDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.AboutDialogFragment.AboutCaller;
|
||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -30,7 +33,7 @@ import android.widget.TextView;
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class HelpActivity extends AbstractMyTracksActivity {
|
||||
public class HelpActivity extends AbstractMyTracksActivity implements AboutCaller, EulaCaller {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -62,4 +65,15 @@ public class HelpActivity extends AbstractMyTracksActivity {
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.help;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAboutLicense() {
|
||||
EulaDialogFragment.newInstance(true)
|
||||
.show(getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEulaDone() {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ import com.google.android.apps.mytracks.fragments.DeleteAllTrackDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
|
||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller;
|
||||
import com.google.android.apps.mytracks.fragments.WelcomeDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.WelcomeDialogFragment.WelcomeCaller;
|
||||
import com.google.android.apps.mytracks.io.file.ImportActivity;
|
||||
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
||||
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||
@@ -91,7 +93,7 @@ import java.util.Locale;
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
implements ConfirmCaller, DeleteOneTrackCaller {
|
||||
implements EulaCaller, WelcomeCaller, ConfirmCaller, DeleteOneTrackCaller {
|
||||
|
||||
private static final String TAG = TrackListActivity.class.getSimpleName();
|
||||
private static final String START_GPS_KEY = "start_gps_key";
|
||||
@@ -690,6 +692,21 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEulaDone() {
|
||||
if (EulaUtils.getAcceptEula(this)) {
|
||||
showStartupDialogs();
|
||||
return;
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWelcomeDone() {
|
||||
EulaUtils.setShowWelcome(this);
|
||||
showStartupDialogs();
|
||||
}
|
||||
|
||||
private void checkGooglePlayServices() {
|
||||
int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
|
||||
if (code != ConnectionResult.SUCCESS) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.fragments;
|
||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
@@ -35,27 +36,48 @@ import android.widget.TextView;
|
||||
*/
|
||||
public class AboutDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface AboutCaller {
|
||||
|
||||
/**
|
||||
* Called when about license is invoked.
|
||||
*/
|
||||
public void onAboutLicense();
|
||||
}
|
||||
|
||||
public static final String ABOUT_DIALOG_TAG = "aboutDialog";
|
||||
|
||||
private FragmentActivity activity;
|
||||
|
||||
private AboutCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (AboutCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(
|
||||
activity.toString() + " must implement " + AboutCaller.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
View view = activity.getLayoutInflater().inflate(R.layout.about, null);
|
||||
fragmentActivity = getActivity();
|
||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.about, null);
|
||||
TextView aboutVersion = (TextView) view.findViewById(R.id.about_version);
|
||||
aboutVersion.setText(SystemUtils.getMyTracksVersion(activity));
|
||||
return new AlertDialog.Builder(activity)
|
||||
.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
aboutVersion.setText(SystemUtils.getMyTracksVersion(fragmentActivity));
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||
R.string.about_license, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EulaDialogFragment.newInstance(true).show(
|
||||
activity.getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
|
||||
caller.onAboutLicense();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.generic_ok, null)
|
||||
.setTitle(R.string.help_about)
|
||||
.setView(view)
|
||||
}).setPositiveButton(R.string.generic_ok, null).setTitle(R.string.help_about).setView(view)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -68,8 +68,9 @@ public class AddEmailsDialogFragment extends DialogFragment {
|
||||
return addPeopleDialogFragment;
|
||||
}
|
||||
|
||||
private MultiAutoCompleteTextView multiAutoCompleteTextView;
|
||||
private AddEmailsCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
private MultiAutoCompleteTextView multiAutoCompleteTextView;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
@@ -84,13 +85,13 @@ public class AddEmailsDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
FragmentActivity activity = getActivity();
|
||||
View view = activity.getLayoutInflater().inflate(R.layout.add_emails, null);
|
||||
fragmentActivity = getActivity();
|
||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.add_emails, null);
|
||||
multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(R.id.add_emails);
|
||||
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
||||
|
||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.add_emails_item,
|
||||
getCursor(getActivity(), null), new String[] {
|
||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity,
|
||||
R.layout.add_emails_item, getCursor(fragmentActivity, null), new String[] {
|
||||
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA },
|
||||
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
|
||||
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
|
||||
@@ -103,12 +104,13 @@ public class AddEmailsDialogFragment extends DialogFragment {
|
||||
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
||||
@Override
|
||||
public Cursor runQuery(CharSequence constraint) {
|
||||
return getCursor(getActivity(), constraint);
|
||||
return getCursor(fragmentActivity, constraint);
|
||||
}
|
||||
});
|
||||
multiAutoCompleteTextView.setAdapter(adapter);
|
||||
|
||||
return new AlertDialog.Builder(activity).setNegativeButton(R.string.generic_cancel, null)
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||
R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
+10
-6
@@ -29,6 +29,7 @@ import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
/**
|
||||
* A DialogFragment to choose an account.
|
||||
@@ -53,6 +54,7 @@ public class ChooseAccountDialogFragment extends DialogFragment {
|
||||
public static final String CHOOSE_ACCOUNT_DIALOG_TAG = "chooseAccount";
|
||||
|
||||
private ChooseAccountCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
private Account[] accounts;
|
||||
|
||||
@Override
|
||||
@@ -69,17 +71,18 @@ public class ChooseAccountDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
accounts = AccountManager.get(getActivity()).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
fragmentActivity = getActivity();
|
||||
accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
|
||||
if (accounts.length == 1) {
|
||||
PreferencesUtils.setString(getActivity(), R.string.google_account_key, accounts[0].name);
|
||||
PreferencesUtils.setString(fragmentActivity, R.string.google_account_key, accounts[0].name);
|
||||
dismiss();
|
||||
caller.onChooseAccountDone();
|
||||
return;
|
||||
}
|
||||
|
||||
String googleAccount = PreferencesUtils.getString(
|
||||
getActivity(), R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
||||
fragmentActivity, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
if (accounts[i].name.equals(googleAccount)) {
|
||||
dismiss();
|
||||
@@ -92,7 +95,7 @@ public class ChooseAccountDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
if (accounts.length == 0) {
|
||||
return new AlertDialog.Builder(getActivity()).setMessage(
|
||||
return new AlertDialog.Builder(fragmentActivity).setMessage(
|
||||
R.string.send_google_no_account_message).setTitle(R.string.send_google_no_account_title)
|
||||
.setPositiveButton(R.string.generic_ok, null).create();
|
||||
}
|
||||
@@ -100,13 +103,14 @@ public class ChooseAccountDialogFragment extends DialogFragment {
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
choices[i] = accounts[i].name;
|
||||
}
|
||||
return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||
R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.generic_ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||
PreferencesUtils.setString(
|
||||
getActivity(), R.string.google_account_key, accounts[position].name);
|
||||
fragmentActivity, R.string.google_account_key, accounts[position].name);
|
||||
caller.onChooseAccountDone();
|
||||
}
|
||||
}).setSingleChoiceItems(choices, 0, null)
|
||||
|
||||
+17
-17
@@ -69,7 +69,7 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
private ChooseUploadServiceCaller caller;
|
||||
private FragmentActivity activity;
|
||||
private FragmentActivity fragmentActivity;
|
||||
private boolean hideDrive;
|
||||
|
||||
private CheckBox driveCheckBox;
|
||||
@@ -93,10 +93,10 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
fragmentActivity = getActivity();
|
||||
hideDrive = getArguments().getBoolean(KEY_HIDE_DRIVE);
|
||||
|
||||
View view = activity.getLayoutInflater().inflate(R.layout.choose_upload_service, null);
|
||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.choose_upload_service, null);
|
||||
|
||||
view.findViewById(R.id.choose_upload_service_drive_options)
|
||||
.setVisibility(hideDrive ? View.GONE : View.VISIBLE);
|
||||
@@ -107,15 +107,15 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
||||
spreadsheetsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_spreadsheets);
|
||||
|
||||
driveCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||
activity, R.string.send_to_drive_key, PreferencesUtils.SEND_TO_DRIVE_DEFAULT));
|
||||
fragmentActivity, R.string.send_to_drive_key, PreferencesUtils.SEND_TO_DRIVE_DEFAULT));
|
||||
mapsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||
activity, R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
||||
fragmentActivity, R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
||||
fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||
activity, R.string.send_to_fusion_tables_key,
|
||||
fragmentActivity, R.string.send_to_fusion_tables_key,
|
||||
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
|
||||
|
||||
spreadsheetsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||
activity, R.string.send_to_spreadsheets_key,
|
||||
fragmentActivity, R.string.send_to_spreadsheets_key,
|
||||
PreferencesUtils.SEND_TO_SPREADSHEETS_DEFAULT));
|
||||
|
||||
mapsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@@ -129,7 +129,7 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
||||
RadioButton newMapRadioButton = (RadioButton) view.findViewById(
|
||||
R.id.choose_upload_service_new_map);
|
||||
boolean defaultMapPublic = PreferencesUtils.getBoolean(
|
||||
activity, R.string.default_map_public_key, PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT);
|
||||
fragmentActivity, R.string.default_map_public_key, PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT);
|
||||
newMapRadioButton.setText(defaultMapPublic ? R.string.send_google_new_public_map
|
||||
: R.string.send_google_new_unlisted_map);
|
||||
|
||||
@@ -138,7 +138,7 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
||||
|
||||
updateMapsOption();
|
||||
if (PreferencesUtils.getBoolean(
|
||||
activity, R.string.pick_existing_map_key, PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
|
||||
fragmentActivity, R.string.pick_existing_map_key, PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
|
||||
existingMapRadioButton.setChecked(true);
|
||||
} else {
|
||||
newMapRadioButton.setChecked(true);
|
||||
@@ -146,33 +146,33 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
||||
|
||||
// Update fusion table
|
||||
boolean defaultTablePublic = PreferencesUtils.getBoolean(
|
||||
activity, R.string.default_table_public_key, PreferencesUtils.DEFAULT_TABLE_PUBLIC_DEFAULT);
|
||||
fragmentActivity, R.string.default_table_public_key, PreferencesUtils.DEFAULT_TABLE_PUBLIC_DEFAULT);
|
||||
String text = getString(R.string.send_google_fusion_tables) + "\n"
|
||||
+ getString(defaultTablePublic ? R.string.send_google_fusion_tables_public
|
||||
: R.string.send_google_fusion_tables_private);
|
||||
fusionTablesCheckBox.setText(text);
|
||||
|
||||
return new AlertDialog.Builder(activity).setNegativeButton(R.string.generic_cancel, null)
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.send_to_drive_key, driveCheckBox.isChecked());
|
||||
fragmentActivity, R.string.send_to_drive_key, driveCheckBox.isChecked());
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
|
||||
fragmentActivity, R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.send_to_maps_key, mapsCheckBox.isChecked());
|
||||
fragmentActivity, R.string.send_to_maps_key, mapsCheckBox.isChecked());
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.send_to_fusion_tables_key, fusionTablesCheckBox.isChecked());
|
||||
fragmentActivity, R.string.send_to_fusion_tables_key, fusionTablesCheckBox.isChecked());
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.send_to_spreadsheets_key, spreadsheetsCheckBox.isChecked());
|
||||
fragmentActivity, R.string.send_to_spreadsheets_key, spreadsheetsCheckBox.isChecked());
|
||||
if (sendDrive() || mapsCheckBox.isChecked() || fusionTablesCheckBox.isChecked()
|
||||
|| spreadsheetsCheckBox.isChecked()) {
|
||||
caller.onChooseUploadServiceDone(sendDrive(), mapsCheckBox.isChecked(),
|
||||
fusionTablesCheckBox.isChecked(), spreadsheetsCheckBox.isChecked(),
|
||||
existingMapRadioButton.isChecked());
|
||||
} else {
|
||||
Toast.makeText(activity, R.string.send_google_no_service_selected, Toast.LENGTH_LONG)
|
||||
Toast.makeText(fragmentActivity, R.string.send_google_no_service_selected, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
@@ -55,7 +56,7 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
private static final String KEY_DEFAULT_VALUE = "defaultValue";
|
||||
private static final String KEY_MESSAGE = "message";
|
||||
private static final String KEY_TRACK_ID = "trackId";
|
||||
|
||||
|
||||
private CheckBox checkBox;
|
||||
|
||||
public static ConfirmDialogFragment newInstance(
|
||||
@@ -65,13 +66,14 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
bundle.putBoolean(KEY_DEFAULT_VALUE, defaultValue);
|
||||
bundle.putCharSequence(KEY_MESSAGE, message);
|
||||
bundle.putLong(KEY_TRACK_ID, trackId);
|
||||
|
||||
|
||||
ConfirmDialogFragment confirmDialogFragment = new ConfirmDialogFragment();
|
||||
confirmDialogFragment.setArguments(bundle);
|
||||
return confirmDialogFragment;
|
||||
}
|
||||
|
||||
private ConfirmCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
@@ -89,7 +91,8 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
int confirmId = getArguments().getInt(KEY_CONFIRM_ID);
|
||||
boolean defaultValue = getArguments().getBoolean(KEY_DEFAULT_VALUE);
|
||||
if (!PreferencesUtils.getBoolean(getActivity(), confirmId, defaultValue)) {
|
||||
fragmentActivity = getActivity();
|
||||
if (!PreferencesUtils.getBoolean(fragmentActivity, confirmId, defaultValue)) {
|
||||
long trackId = getArguments().getLong(KEY_TRACK_ID);
|
||||
dismiss();
|
||||
caller.onConfirmDone(confirmId, trackId);
|
||||
@@ -98,18 +101,19 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.confirm_dialog, null);
|
||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.confirm_dialog, null);
|
||||
TextView textView = (TextView) view.findViewById(R.id.confirm_dialog_message);
|
||||
textView.setText(getArguments().getCharSequence(KEY_MESSAGE));
|
||||
checkBox = (CheckBox) view.findViewById(R.id.confirm_dialog_check_box);
|
||||
|
||||
return new AlertDialog.Builder(getActivity()).setNegativeButton(android.R.string.cancel, null)
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||
android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int confirmId = getArguments().getInt(KEY_CONFIRM_ID);
|
||||
long trackId = getArguments().getLong(KEY_TRACK_ID);
|
||||
PreferencesUtils.setBoolean(getActivity(), confirmId, !checkBox.isChecked());
|
||||
PreferencesUtils.setBoolean(fragmentActivity, confirmId, !checkBox.isChecked());
|
||||
caller.onConfirmDone(confirmId, trackId);
|
||||
}
|
||||
}).setTitle(R.string.generic_confirm_title).setView(view).create();
|
||||
|
||||
+8
-8
@@ -37,12 +37,12 @@ public class DeleteAllTrackDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String DELETE_ALL_TRACK_DIALOG_TAG = "deleteAllTrackDialog";
|
||||
|
||||
private FragmentActivity activity;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
return DialogUtils.createConfirmationDialog(activity,
|
||||
fragmentActivity = getActivity();
|
||||
return DialogUtils.createConfirmationDialog(fragmentActivity,
|
||||
R.string.track_list_delete_all_confirm_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
@@ -50,14 +50,14 @@ public class DeleteAllTrackDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public void run() {
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||
SyncUtils.disableSync(activity);
|
||||
MyTracksProviderUtils.Factory.get(activity).deleteAllTracks();
|
||||
PreferencesUtils.setLong(activity, R.string.drive_largest_change_id_key,
|
||||
fragmentActivity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||
SyncUtils.disableSync(fragmentActivity);
|
||||
MyTracksProviderUtils.Factory.get(fragmentActivity).deleteAllTracks();
|
||||
PreferencesUtils.setLong(fragmentActivity, R.string.drive_largest_change_id_key,
|
||||
PreferencesUtils.DRIVE_LARGEST_CHANGE_ID_DEFAULT);
|
||||
|
||||
// Clear the drive_deleted_list_key last
|
||||
PreferencesUtils.setString(activity, R.string.drive_deleted_list_key,
|
||||
PreferencesUtils.setString(fragmentActivity, R.string.drive_deleted_list_key,
|
||||
PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
|
||||
}
|
||||
}).start();
|
||||
|
||||
+1
-1
@@ -62,8 +62,8 @@ public class DeleteOneMarkerDialogFragment extends DialogFragment {
|
||||
return deleteOneMarkerDialogFragment;
|
||||
}
|
||||
|
||||
private FragmentActivity fragmentActivity;
|
||||
private DeleteOneMarkerCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
|
||||
+1
-1
@@ -67,8 +67,8 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
||||
return deleteOneTrackDialogFragment;
|
||||
}
|
||||
|
||||
private FragmentActivity fragmentActivity;
|
||||
private DeleteOneTrackCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package com.google.android.apps.mytracks.fragments;
|
||||
|
||||
import com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.apps.mytracks.util.EulaUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
@@ -37,6 +37,19 @@ import java.util.Locale;
|
||||
*/
|
||||
public class EulaDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface EulaCaller {
|
||||
|
||||
/**
|
||||
* Called when eula is done.
|
||||
*/
|
||||
public void onEulaDone();
|
||||
}
|
||||
|
||||
public static final String EULA_DIALOG_TAG = "eulaDialog";
|
||||
private static final String KEY_HAS_ACCEPTED = "hasAccepted";
|
||||
private static final String GOOGLE_URL = "m.google.com";
|
||||
@@ -56,65 +69,60 @@ public class EulaDialogFragment extends DialogFragment {
|
||||
return eulaDialogFragment;
|
||||
}
|
||||
|
||||
private FragmentActivity activity;
|
||||
|
||||
private EulaCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface arg0) {
|
||||
if (!getArguments().getBoolean(KEY_HAS_ACCEPTED)) {
|
||||
exitApp();
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (EulaCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(
|
||||
activity.toString() + " must implement " + EulaCaller.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
|
||||
fragmentActivity = getActivity();
|
||||
|
||||
boolean hasAccepted = getArguments().getBoolean(KEY_HAS_ACCEPTED);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||
.setMessage(getEulaText())
|
||||
.setTitle(R.string.eula_title);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(fragmentActivity).setMessage(
|
||||
getEulaText()).setTitle(R.string.eula_title);
|
||||
|
||||
if (hasAccepted) {
|
||||
builder.setPositiveButton(R.string.generic_ok, null);
|
||||
} else {
|
||||
builder.setNegativeButton(R.string.eula_decline, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
exitApp();
|
||||
caller.onEulaDone();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
}).setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EulaUtils.setAcceptEula(activity);
|
||||
EulaUtils.setAcceptEula(fragmentActivity);
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.metric_units_key, !Locale.US.equals(Locale.getDefault()));
|
||||
TrackListActivity trackListActivity = (TrackListActivity) activity;
|
||||
trackListActivity.showStartupDialogs();
|
||||
fragmentActivity, R.string.metric_units_key, !Locale.US.equals(Locale.getDefault()));
|
||||
caller.onEulaDone();
|
||||
}
|
||||
});
|
||||
}
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the application.
|
||||
*/
|
||||
private void exitApp() {
|
||||
activity.finish();
|
||||
@Override
|
||||
public void onCancel(DialogInterface arg0) {
|
||||
caller.onEulaDone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the EULA text.
|
||||
*
|
||||
*/
|
||||
private String getEulaText() {
|
||||
String tos = getString(R.string.eula_date)
|
||||
+ "\n\n"
|
||||
+ getString(R.string.eula_body, GOOGLE_URL)
|
||||
+ "\n\n"
|
||||
+ getString(R.string.eula_footer, GOOGLE_URL)
|
||||
+ "\n\n"
|
||||
String tos = getString(R.string.eula_date) + "\n\n" + getString(R.string.eula_body, GOOGLE_URL)
|
||||
+ "\n\n" + getString(R.string.eula_footer, GOOGLE_URL) + "\n\n"
|
||||
+ getString(R.string.eula_copyright_year);
|
||||
boolean isKorean = getResources().getConfiguration().locale.getLanguage().equals(KOREAN);
|
||||
if (isKorean) {
|
||||
|
||||
+7
-7
@@ -52,23 +52,23 @@ public class FrequencyDialogFragment extends DialogFragment {
|
||||
return frequencyDialogFragment;
|
||||
}
|
||||
|
||||
private FragmentActivity activity;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
fragmentActivity = getActivity();
|
||||
|
||||
final int preferenceId = getArguments().getInt(KEY_PREFERENCE_ID);
|
||||
int defaultValue = getArguments().getInt(KEY_DEFAULT_VALUE);
|
||||
int titleId = getArguments().getInt(KEY_TITLE_ID);
|
||||
int frequencyValue = PreferencesUtils.getInt(activity, preferenceId, defaultValue);
|
||||
int frequencyValue = PreferencesUtils.getInt(fragmentActivity, preferenceId, defaultValue);
|
||||
|
||||
return new AlertDialog.Builder(activity)
|
||||
return new AlertDialog.Builder(fragmentActivity)
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int listIndex = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||
PreferencesUtils.setInt(activity, preferenceId, getFrequencyValue(listIndex));
|
||||
PreferencesUtils.setInt(fragmentActivity, preferenceId, getFrequencyValue(listIndex));
|
||||
}
|
||||
})
|
||||
.setSingleChoiceItems(getFrequencyDisplayOptions(), getListIndex(frequencyValue), null)
|
||||
@@ -81,8 +81,8 @@ public class FrequencyDialogFragment extends DialogFragment {
|
||||
*/
|
||||
private String[] getFrequencyDisplayOptions() {
|
||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
return StringUtils.getFrequencyOptions(activity, metricUnits);
|
||||
fragmentActivity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
return StringUtils.getFrequencyOptions(fragmentActivity, metricUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-4
@@ -39,12 +39,12 @@ public class InstallEarthDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String INSTALL_EARTH_DIALOG_TAG = "installEarthDialog";
|
||||
|
||||
private FragmentActivity activity;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
return new AlertDialog.Builder(activity)
|
||||
fragmentActivity = getActivity();
|
||||
return new AlertDialog.Builder(fragmentActivity)
|
||||
.setMessage(R.string.track_detail_install_earth_message)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@@ -55,7 +55,7 @@ public class InstallEarthDialogFragment extends DialogFragment {
|
||||
startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(
|
||||
activity, R.string.track_detail_install_earth_error, Toast.LENGTH_LONG)
|
||||
fragmentActivity, R.string.track_detail_install_earth_error, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
+40
-25
@@ -16,10 +16,9 @@
|
||||
|
||||
package com.google.android.apps.mytracks.fragments;
|
||||
|
||||
import com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.apps.mytracks.util.EulaUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
@@ -34,33 +33,49 @@ import android.support.v4.app.FragmentActivity;
|
||||
*/
|
||||
public class WelcomeDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface WelcomeCaller {
|
||||
|
||||
/**
|
||||
* Called when choose account is done.
|
||||
*/
|
||||
public void onWelcomeDone();
|
||||
}
|
||||
|
||||
public static final String WELCOME_DIALOG_TAG = "welcomeDialog";
|
||||
|
||||
private FragmentActivity activity;
|
||||
|
||||
private WelcomeCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface arg0) {
|
||||
onDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
return new AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onDone();
|
||||
}
|
||||
})
|
||||
.setTitle(R.string.welcome_title)
|
||||
.setMessage(R.string.welcome_message)
|
||||
.create();
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (WelcomeCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(
|
||||
activity.toString() + " must implement " + WelcomeCaller.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
private void onDone() {
|
||||
EulaUtils.setShowWelcome(activity);
|
||||
TrackListActivity trackListActivity = (TrackListActivity) activity;
|
||||
trackListActivity.showStartupDialogs();
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
fragmentActivity = getActivity();
|
||||
return new AlertDialog.Builder(fragmentActivity).setPositiveButton(
|
||||
R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
caller.onWelcomeDone();
|
||||
}
|
||||
}).setTitle(R.string.welcome_title).setMessage(R.string.welcome_message).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface arg0) {
|
||||
caller.onWelcomeDone();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user