forked from upstream-mirrors/OpenTracks
For FragmentDialog, always use the activity obtain during onCreate.
To prevent null pointer when user clicks a button.
This commit is contained in:
@@ -24,6 +24,7 @@ import android.app.Dialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -36,17 +37,20 @@ public class AboutDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
public static final String ABOUT_DIALOG_TAG = "aboutDialog";
|
public static final String ABOUT_DIALOG_TAG = "aboutDialog";
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
View view = getActivity().getLayoutInflater().inflate(R.layout.about, null);
|
activity = getActivity();
|
||||||
|
View view = activity.getLayoutInflater().inflate(R.layout.about, null);
|
||||||
TextView aboutVersion = (TextView) view.findViewById(R.id.about_version);
|
TextView aboutVersion = (TextView) view.findViewById(R.id.about_version);
|
||||||
aboutVersion.setText(SystemUtils.getMyTracksVersion(getActivity()));
|
aboutVersion.setText(SystemUtils.getMyTracksVersion(activity));
|
||||||
return new AlertDialog.Builder(getActivity())
|
return new AlertDialog.Builder(activity)
|
||||||
.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
|
.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EulaDialogFragment.newInstance(true).show(
|
EulaDialogFragment.newInstance(true).show(
|
||||||
getActivity().getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
|
activity.getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setPositiveButton(R.string.generic_ok, null)
|
.setPositiveButton(R.string.generic_ok, null)
|
||||||
|
|||||||
+20
-16
@@ -26,52 +26,56 @@ import android.app.Dialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to check preferred units.
|
* A DialogFragment to check preferred units.
|
||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public class CheckUnitsDialogFragment extends DialogFragment {
|
public class CheckUnitsDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public static final String CHECK_UNITS_DIALOG_TAG = "checkUnitsDialog";
|
public static final String CHECK_UNITS_DIALOG_TAG = "checkUnitsDialog";
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface arg0) {
|
public void onCancel(DialogInterface arg0) {
|
||||||
onDone();
|
onDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
Locale defaultLocale = Locale.getDefault();
|
activity = getActivity();
|
||||||
|
|
||||||
|
Locale defaultLocale = Locale.getDefault();
|
||||||
boolean defaultMetric = !defaultLocale.equals(Locale.US) && !defaultLocale.equals(Locale.UK);
|
boolean defaultMetric = !defaultLocale.equals(Locale.US) && !defaultLocale.equals(Locale.UK);
|
||||||
PreferencesUtils.setBoolean(getActivity(), R.string.metric_units_key, defaultMetric);
|
PreferencesUtils.setBoolean(activity, R.string.metric_units_key, defaultMetric);
|
||||||
final String metric = getString(R.string.settings_stats_units_metric);
|
final String metric = getString(R.string.settings_stats_units_metric);
|
||||||
final String imperial = getString(R.string.settings_stats_units_imperial);
|
final String imperial = getString(R.string.settings_stats_units_imperial);
|
||||||
final CharSequence[] items = defaultMetric ? new CharSequence[] { metric, imperial }
|
final CharSequence[] items = defaultMetric ? new CharSequence[] { metric, imperial }
|
||||||
: new CharSequence[] { imperial, metric };
|
: new CharSequence[] { imperial, metric };
|
||||||
return new AlertDialog.Builder(getActivity())
|
return new AlertDialog.Builder(activity).setPositiveButton(
|
||||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setBoolean(
|
||||||
getActivity(), R.string.metric_units_key, items[position].equals(metric));
|
activity, R.string.metric_units_key, items[position].equals(metric));
|
||||||
onDone();
|
onDone();
|
||||||
}
|
}
|
||||||
})
|
}).setSingleChoiceItems(items, 0, null).setTitle(R.string.settings_stats_units_title)
|
||||||
.setSingleChoiceItems(items, 0, null)
|
.create();
|
||||||
.setTitle(R.string.settings_stats_units_title).create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tasks to perform when done.
|
* Tasks to perform when done.
|
||||||
*/
|
*/
|
||||||
private void onDone() {
|
private void onDone() {
|
||||||
EulaUtils.setShowCheckUnits(getActivity());
|
EulaUtils.setShowCheckUnits(activity);
|
||||||
TrackListActivity trackListActivity = (TrackListActivity) getActivity();
|
TrackListActivity trackListActivity = (TrackListActivity) activity;
|
||||||
trackListActivity.showStartupDialogs();
|
trackListActivity.showStartupDialogs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+20
-16
@@ -28,6 +28,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
@@ -57,6 +58,7 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
|||||||
return chooseUploadServiceDialogFragment;
|
return chooseUploadServiceDialogFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
private SendRequest sendRequest;
|
private SendRequest sendRequest;
|
||||||
|
|
||||||
private CheckBox mapsCheckBox;
|
private CheckBox mapsCheckBox;
|
||||||
@@ -68,20 +70,22 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
activity = getActivity();
|
||||||
sendRequest = getArguments().getParcelable(KEY_SEND_REQUEST);
|
sendRequest = getArguments().getParcelable(KEY_SEND_REQUEST);
|
||||||
View view = getActivity().getLayoutInflater().inflate(R.layout.choose_upload_service, null);
|
|
||||||
|
View view = activity.getLayoutInflater().inflate(R.layout.choose_upload_service, null);
|
||||||
|
|
||||||
mapsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_maps);
|
mapsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_maps);
|
||||||
fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_fusion_tables);
|
fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_fusion_tables);
|
||||||
docsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_docs);
|
docsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_docs);
|
||||||
|
|
||||||
mapsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
mapsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
getActivity(), R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
activity, R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
||||||
fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
|
fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
getActivity(), R.string.send_to_fusion_tables_key,
|
activity, R.string.send_to_fusion_tables_key,
|
||||||
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
|
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
|
||||||
docsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
docsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
getActivity(), R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
|
activity, R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
|
||||||
|
|
||||||
mapsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
mapsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
public void onCheckedChanged(CompoundButton button, boolean checked) {
|
public void onCheckedChanged(CompoundButton button, boolean checked) {
|
||||||
@@ -93,7 +97,7 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
RadioButton newMapRadioButton = (RadioButton) view.findViewById(
|
RadioButton newMapRadioButton = (RadioButton) view.findViewById(
|
||||||
R.id.choose_upload_service_new_map);
|
R.id.choose_upload_service_new_map);
|
||||||
boolean defaultMapPublic = PreferencesUtils.getBoolean(getActivity(),
|
boolean defaultMapPublic = PreferencesUtils.getBoolean(activity,
|
||||||
R.string.default_map_public_key, PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT);
|
R.string.default_map_public_key, PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT);
|
||||||
newMapRadioButton.setText(defaultMapPublic ? R.string.send_google_new_public_map
|
newMapRadioButton.setText(defaultMapPublic ? R.string.send_google_new_public_map
|
||||||
: R.string.send_google_new_unlisted_map);
|
: R.string.send_google_new_unlisted_map);
|
||||||
@@ -102,31 +106,31 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
|||||||
R.id.choose_upload_service_existing_map);
|
R.id.choose_upload_service_existing_map);
|
||||||
|
|
||||||
updateMapsOption();
|
updateMapsOption();
|
||||||
if (PreferencesUtils.getBoolean(getActivity(), R.string.pick_existing_map_key,
|
if (PreferencesUtils.getBoolean(activity, R.string.pick_existing_map_key,
|
||||||
PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
|
PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
|
||||||
existingMapRadioButton.setChecked(true);
|
existingMapRadioButton.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
newMapRadioButton.setChecked(true);
|
newMapRadioButton.setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
|
return new AlertDialog.Builder(activity).setNegativeButton(R.string.generic_cancel, null)
|
||||||
.setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setBoolean(
|
||||||
getActivity(), R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
|
activity, R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
|
||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setBoolean(
|
||||||
getActivity(), R.string.send_to_maps_key, mapsCheckBox.isChecked());
|
activity, R.string.send_to_maps_key, mapsCheckBox.isChecked());
|
||||||
PreferencesUtils.setBoolean(getActivity(), R.string.send_to_fusion_tables_key,
|
PreferencesUtils.setBoolean(activity, R.string.send_to_fusion_tables_key,
|
||||||
fusionTablesCheckBox.isChecked());
|
fusionTablesCheckBox.isChecked());
|
||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setBoolean(
|
||||||
getActivity(), R.string.send_to_docs_key, docsCheckBox.isChecked());
|
activity, R.string.send_to_docs_key, docsCheckBox.isChecked());
|
||||||
if (mapsCheckBox.isChecked() || fusionTablesCheckBox.isChecked()
|
if (mapsCheckBox.isChecked() || fusionTablesCheckBox.isChecked()
|
||||||
|| docsCheckBox.isChecked()) {
|
|| docsCheckBox.isChecked()) {
|
||||||
startNextActivity();
|
startNextActivity();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
getActivity(), R.string.send_google_no_service_selected, Toast.LENGTH_LONG)
|
activity, R.string.send_google_no_service_selected, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,7 +156,7 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
|||||||
sendRequest.setSendDocs(docsCheckBox.isChecked());
|
sendRequest.setSendDocs(docsCheckBox.isChecked());
|
||||||
sendRequest.setNewMap(!existingMapRadioButton.isChecked());
|
sendRequest.setNewMap(!existingMapRadioButton.isChecked());
|
||||||
sendStats();
|
sendStats();
|
||||||
Intent intent = IntentUtils.newIntent(getActivity(), AccountChooserActivity.class)
|
Intent intent = IntentUtils.newIntent(activity, AccountChooserActivity.class)
|
||||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
@@ -162,13 +166,13 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
|||||||
*/
|
*/
|
||||||
private void sendStats() {
|
private void sendStats() {
|
||||||
if (sendRequest.isSendMaps()) {
|
if (sendRequest.isSendMaps()) {
|
||||||
AnalyticsUtils.sendPageViews(getActivity(), "/send/maps");
|
AnalyticsUtils.sendPageViews(activity, "/send/maps");
|
||||||
}
|
}
|
||||||
if (sendRequest.isSendFusionTables()) {
|
if (sendRequest.isSendFusionTables()) {
|
||||||
AnalyticsUtils.sendPageViews(getActivity(), "/send/fusion_tables");
|
AnalyticsUtils.sendPageViews(activity, "/send/fusion_tables");
|
||||||
}
|
}
|
||||||
if (sendRequest.isSendDocs()) {
|
if (sendRequest.isSendDocs()) {
|
||||||
AnalyticsUtils.sendPageViews(getActivity(), "/send/docs");
|
AnalyticsUtils.sendPageViews(activity, "/send/docs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -24,6 +24,7 @@ import android.app.Dialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to delete all tracks.
|
* A DialogFragment to delete all tracks.
|
||||||
@@ -34,16 +35,19 @@ public class DeleteAllTrackDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
public static final String DELETE_ALL_TRACK_DIALOG_TAG = "deleteAllTrackDialog";
|
public static final String DELETE_ALL_TRACK_DIALOG_TAG = "deleteAllTrackDialog";
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return DialogUtils.createConfirmationDialog(getActivity(),
|
activity = getActivity();
|
||||||
|
return DialogUtils.createConfirmationDialog(activity,
|
||||||
R.string.track_list_delete_all_confirm_message, new DialogInterface.OnClickListener() {
|
R.string.track_list_delete_all_confirm_message, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MyTracksProviderUtils.Factory.get(getActivity()).deleteAllTracks();
|
MyTracksProviderUtils.Factory.get(activity).deleteAllTracks();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-5
@@ -28,6 +28,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to delete one marker.
|
* A DialogFragment to delete one marker.
|
||||||
@@ -50,25 +51,28 @@ public class DeleteOneMarkerDialogFragment extends DialogFragment {
|
|||||||
return deleteOneMarkerDialogFragment;
|
return deleteOneMarkerDialogFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return DialogUtils.createConfirmationDialog(getActivity(),
|
activity = getActivity();
|
||||||
|
return DialogUtils.createConfirmationDialog(activity,
|
||||||
R.string.marker_delete_one_marker_confirm_message, new DialogInterface.OnClickListener() {
|
R.string.marker_delete_one_marker_confirm_message, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MyTracksProviderUtils.Factory.get(getActivity()).deleteWaypoint(
|
MyTracksProviderUtils.Factory.get(activity).deleteWaypoint(
|
||||||
getArguments().getLong(KEY_MARKER_ID),
|
getArguments().getLong(KEY_MARKER_ID),
|
||||||
new DescriptionGeneratorImpl(getActivity()));
|
new DescriptionGeneratorImpl(activity));
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
Intent intent = IntentUtils.newIntent(getActivity(), MarkerListActivity.class)
|
Intent intent = IntentUtils.newIntent(activity, MarkerListActivity.class)
|
||||||
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, getArguments().getLong(KEY_TRACK_ID));
|
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, getArguments().getLong(KEY_TRACK_ID));
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
// Close the activity since its content can change after delete.
|
// Close the activity since its content can change after delete.
|
||||||
getActivity().finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-5
@@ -32,6 +32,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to delete one track.
|
* A DialogFragment to delete one track.
|
||||||
@@ -52,8 +53,6 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
|||||||
public TrackRecordingServiceConnection getTrackRecordingServiceConnection();
|
public TrackRecordingServiceConnection getTrackRecordingServiceConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private DeleteOneTrackCaller caller;
|
|
||||||
|
|
||||||
public static DeleteOneTrackDialogFragment newInstance(long trackId) {
|
public static DeleteOneTrackDialogFragment newInstance(long trackId) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putLong(KEY_TRACK_ID, trackId);
|
bundle.putLong(KEY_TRACK_ID, trackId);
|
||||||
@@ -63,6 +62,9 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
|||||||
return deleteOneTrackDialogFragment;
|
return deleteOneTrackDialogFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
private DeleteOneTrackCaller caller;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
@@ -75,12 +77,13 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return DialogUtils.createConfirmationDialog(getActivity(),
|
activity = getActivity();
|
||||||
|
return DialogUtils.createConfirmationDialog(activity,
|
||||||
R.string.track_detail_delete_confirm_message, new DialogInterface.OnClickListener() {
|
R.string.track_detail_delete_confirm_message, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
final long trackId = getArguments().getLong(KEY_TRACK_ID);
|
final long trackId = getArguments().getLong(KEY_TRACK_ID);
|
||||||
final Context context = getActivity();
|
final Context context = activity;
|
||||||
if (trackId == PreferencesUtils.getLong(context, R.string.recording_track_id_key)) {
|
if (trackId == PreferencesUtils.getLong(context, R.string.recording_track_id_key)) {
|
||||||
TrackRecordingServiceConnectionUtils.stopRecording(
|
TrackRecordingServiceConnectionUtils.stopRecording(
|
||||||
context, caller.getTrackRecordingServiceConnection(), false);
|
context, caller.getTrackRecordingServiceConnection(), false);
|
||||||
@@ -94,7 +97,7 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
|||||||
Intent intent = IntentUtils.newIntent(context, TrackListActivity.class);
|
Intent intent = IntentUtils.newIntent(context, TrackListActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
// Close the activity since its content can change after delete
|
// Close the activity since its content can change after delete
|
||||||
getActivity().finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.app.Dialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to show EULA.
|
* A DialogFragment to show EULA.
|
||||||
@@ -52,6 +53,8 @@ public class EulaDialogFragment extends DialogFragment {
|
|||||||
return eulaDialogFragment;
|
return eulaDialogFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface arg0) {
|
public void onCancel(DialogInterface arg0) {
|
||||||
if (!getArguments().getBoolean(KEY_HAS_ACCEPTED)) {
|
if (!getArguments().getBoolean(KEY_HAS_ACCEPTED)) {
|
||||||
@@ -61,8 +64,10 @@ public class EulaDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
activity = getActivity();
|
||||||
|
|
||||||
boolean hasAccepted = getArguments().getBoolean(KEY_HAS_ACCEPTED);
|
boolean hasAccepted = getArguments().getBoolean(KEY_HAS_ACCEPTED);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||||
.setMessage(getEulaText())
|
.setMessage(getEulaText())
|
||||||
.setTitle(R.string.eula_title);
|
.setTitle(R.string.eula_title);
|
||||||
|
|
||||||
@@ -78,8 +83,8 @@ public class EulaDialogFragment extends DialogFragment {
|
|||||||
.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EulaUtils.setAcceptEula(getActivity());
|
EulaUtils.setAcceptEula(activity);
|
||||||
TrackListActivity trackListActivity = (TrackListActivity) getActivity();
|
TrackListActivity trackListActivity = (TrackListActivity) activity;
|
||||||
trackListActivity.showStartupDialogs();
|
trackListActivity.showStartupDialogs();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -91,7 +96,7 @@ public class EulaDialogFragment extends DialogFragment {
|
|||||||
* Exits the application.
|
* Exits the application.
|
||||||
*/
|
*/
|
||||||
private void exitApp() {
|
private void exitApp() {
|
||||||
getActivity().finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+9
-4
@@ -24,6 +24,7 @@ import android.app.Dialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to configure frequency.
|
* A DialogFragment to configure frequency.
|
||||||
@@ -50,19 +51,23 @@ public class FrequencyDialogFragment extends DialogFragment {
|
|||||||
return frequencyDialogFragment;
|
return frequencyDialogFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
activity = getActivity();
|
||||||
|
|
||||||
final int preferenceId = getArguments().getInt(KEY_PREFERENCE_ID);
|
final int preferenceId = getArguments().getInt(KEY_PREFERENCE_ID);
|
||||||
int defaultValue = getArguments().getInt(KEY_DEFAULT_VALUE);
|
int defaultValue = getArguments().getInt(KEY_DEFAULT_VALUE);
|
||||||
int titleId = getArguments().getInt(KEY_TITLE_ID);
|
int titleId = getArguments().getInt(KEY_TITLE_ID);
|
||||||
int frequencyValue = PreferencesUtils.getInt(getActivity(), preferenceId, defaultValue);
|
int frequencyValue = PreferencesUtils.getInt(activity, preferenceId, defaultValue);
|
||||||
|
|
||||||
return new AlertDialog.Builder(getActivity())
|
return new AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
int listIndex = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
int listIndex = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||||
PreferencesUtils.setInt(getActivity(), preferenceId, getFrequencyValue(listIndex));
|
PreferencesUtils.setInt(activity, preferenceId, getFrequencyValue(listIndex));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setSingleChoiceItems(getFrequencyDisplayOptions(), getListIndex(frequencyValue), null)
|
.setSingleChoiceItems(getFrequencyDisplayOptions(), getListIndex(frequencyValue), null)
|
||||||
@@ -75,7 +80,7 @@ public class FrequencyDialogFragment extends DialogFragment {
|
|||||||
*/
|
*/
|
||||||
private String[] getFrequencyDisplayOptions() {
|
private String[] getFrequencyDisplayOptions() {
|
||||||
boolean metricUnits = PreferencesUtils.getBoolean(
|
boolean metricUnits = PreferencesUtils.getBoolean(
|
||||||
getActivity(), R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||||
String[] values = getResources().getStringArray(R.array.frequency_values);
|
String[] values = getResources().getStringArray(R.array.frequency_values);
|
||||||
String[] options = new String[values.length];
|
String[] options = new String[values.length];
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
|||||||
+6
-2
@@ -27,6 +27,7 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,9 +39,12 @@ public class InstallEarthDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
public static final String INSTALL_EARTH_DIALOG_TAG = "installEarthDialog";
|
public static final String INSTALL_EARTH_DIALOG_TAG = "installEarthDialog";
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return new AlertDialog.Builder(getActivity())
|
activity = getActivity();
|
||||||
|
return new AlertDialog.Builder(activity)
|
||||||
.setMessage(R.string.track_detail_install_earth_message)
|
.setMessage(R.string.track_detail_install_earth_message)
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@@ -51,7 +55,7 @@ public class InstallEarthDialogFragment extends DialogFragment {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
getActivity(), R.string.track_detail_install_earth_error, Toast.LENGTH_LONG)
|
activity, R.string.track_detail_install_earth_error, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.app.Dialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFrament to show the welcome info.
|
* A DialogFrament to show the welcome info.
|
||||||
@@ -35,6 +36,8 @@ public class WelcomeDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
public static final String WELCOME_DIALOG_TAG = "welcomeDialog";
|
public static final String WELCOME_DIALOG_TAG = "welcomeDialog";
|
||||||
|
|
||||||
|
private FragmentActivity activity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface arg0) {
|
public void onCancel(DialogInterface arg0) {
|
||||||
onDone();
|
onDone();
|
||||||
@@ -42,7 +45,8 @@ public class WelcomeDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return new AlertDialog.Builder(getActivity())
|
activity = getActivity();
|
||||||
|
return new AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
@@ -55,8 +59,8 @@ public class WelcomeDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onDone() {
|
private void onDone() {
|
||||||
EulaUtils.setShowWelcome(getActivity());
|
EulaUtils.setShowWelcome(activity);
|
||||||
TrackListActivity trackListActivity = (TrackListActivity) getActivity();
|
TrackListActivity trackListActivity = (TrackListActivity) activity;
|
||||||
trackListActivity.showStartupDialogs();
|
trackListActivity.showStartupDialogs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user