Same the same confirmation dialog fragment for all action confirmation.

This commit is contained in:
Jimmy Shih
2013-01-29 15:59:31 -08:00
parent 707985a081
commit f9bd84dba0
7 changed files with 123 additions and 219 deletions
@@ -24,7 +24,7 @@ import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.fragments.ChartFragment;
import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment;
import com.google.android.apps.mytracks.fragments.ChooseUploadServiceDialogFragment;
import com.google.android.apps.mytracks.fragments.ConfirmPlayDialogFragment;
import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
@@ -39,6 +39,7 @@ import com.google.android.apps.mytracks.settings.SettingsActivity;
import com.google.android.apps.mytracks.util.AnalyticsUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
import com.google.android.maps.mytracks.R;
@@ -311,6 +312,25 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
return super.onPrepareOptionsMenu(menu);
}
public void onConfirmDialogDone(int id) {
switch (id) {
case R.string.show_confirm_play_earth_dialog_key:
AnalyticsUtils.sendPageViews(this, "/action/play");
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
.putExtra(SaveActivity.EXTRA_TRACK_ID, trackId)
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML)
.putExtra(SaveActivity.EXTRA_PLAY_TRACK, true);
startActivity(intent);
break;
case R.string.show_confirm_sharing_dialog_key:
AnalyticsUtils.sendPageViews(this, "/action/share");
ChooseActivityDialogFragment.newInstance(trackId, null).show(
getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG);
break;
default:
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
@@ -323,17 +343,21 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
return true;
case R.id.track_detail_play:
if (isEarthInstalled()) {
ConfirmPlayDialogFragment.newInstance(trackId)
.show(getSupportFragmentManager(), ConfirmPlayDialogFragment.CONFIRM_PLAY_DIALOG_TAG);
ConfirmDialogFragment.newInstance(R.string.show_confirm_play_earth_dialog_key,
PreferencesUtils.SHOW_CONFIRM_PLAY_DIALOG_DEFAULT,
getString(R.string.track_detail_play_confirm_message))
.show(getSupportFragmentManager(), ConfirmDialogFragment.CONFIRM_DIALOG_TAG);
} else {
new InstallEarthDialogFragment().show(
getSupportFragmentManager(), InstallEarthDialogFragment.INSTALL_EARTH_DIALOG_TAG);
}
return true;
case R.id.track_detail_share:
AnalyticsUtils.sendPageViews(this, "/action/share");
ChooseActivityDialogFragment.newInstance(trackId, null).show(
getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG);
ConfirmDialogFragment.newInstance(R.string.show_confirm_sharing_dialog_key,
PreferencesUtils.SHOW_CONFIRM_SHARING_DIALOG_DEFAULT,
StringUtils.getHtml(
this, R.string.share_track_confirm_message, R.string.maps_public_unlisted_url))
.show(getSupportFragmentManager(), ConfirmDialogFragment.CONFIRM_DIALOG_TAG);
return true;
case R.id.track_detail_markers:
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
@@ -16,7 +16,7 @@
package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.io.sendtogoogle.ConfirmSharingActivity;
import com.google.android.apps.mytracks.io.sendtogoogle.AccountChooserActivity;
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.maps.mytracks.R;
@@ -120,7 +120,7 @@ public class ChooseActivityDialogFragment extends DialogFragment {
sendRequest.setNewMap(true);
sendRequest.setSharingAppPackageName(packageName);
sendRequest.setSharingAppClassName(className);
Intent intent = IntentUtils.newIntent(activity, ConfirmSharingActivity.class)
Intent intent = IntentUtils.newIntent(activity, AccountChooserActivity.class)
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
startActivity(intent);
dismiss();
@@ -0,0 +1,89 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.TrackDetailActivity;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
/**
* A DialogFragment to confirm an action.
*
* @author Jimmy Shih
*/
public class ConfirmDialogFragment extends DialogFragment {
public static final String CONFIRM_DIALOG_TAG = "confirmDialog";
private static final String KEY_CONFIRM_ID = "confirmId";
private static final String KEY_DEFAULT_VALUE = "defaultValue";
private static final String KEY_MESSAGE = "message";
private CheckBox checkBox;
public static ConfirmDialogFragment newInstance(
int confirmId, boolean defaultValue, CharSequence message) {
Bundle bundle = new Bundle();
bundle.putInt(KEY_CONFIRM_ID, confirmId);
bundle.putBoolean(KEY_DEFAULT_VALUE, defaultValue);
bundle.putCharSequence(KEY_MESSAGE, message);
ConfirmDialogFragment confirmDialogFragment = new ConfirmDialogFragment();
confirmDialogFragment.setArguments(bundle);
return confirmDialogFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int confirmId = getArguments().getInt(KEY_CONFIRM_ID);
boolean defaultValue = getArguments().getBoolean(KEY_DEFAULT_VALUE);
if (!PreferencesUtils.getBoolean(getActivity(), confirmId, defaultValue)) {
dismiss();
TrackDetailActivity trackDetailActivity = (TrackDetailActivity) getActivity();
trackDetailActivity.onConfirmDialogDone(confirmId);
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = getActivity().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)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int confirmId = getArguments().getInt(KEY_CONFIRM_ID);
PreferencesUtils.setBoolean(getActivity(), confirmId, !checkBox.isChecked());
TrackDetailActivity trackDetailActivity = (TrackDetailActivity) getActivity();
trackDetailActivity.onConfirmDialogDone(confirmId);
}
}).setTitle(R.string.generic_confirm_title).setView(view).create();
}
}
@@ -1,102 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.io.file.SaveActivity;
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
import com.google.android.apps.mytracks.util.AnalyticsUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
/**
* A DialogFragment to confirm play in Google Earth.
*
* @author Jimmy Shih
*/
public class ConfirmPlayDialogFragment extends DialogFragment {
public static final String CONFIRM_PLAY_DIALOG_TAG = "confirmPlayDialog";
private static final String KEY_TRACK_ID = "trackId";
private FragmentActivity activity;
private CheckBox checkBox;
public static ConfirmPlayDialogFragment newInstance(long trackId) {
Bundle bundle = new Bundle();
bundle.putLong(KEY_TRACK_ID, trackId);
ConfirmPlayDialogFragment confirmPlayDialogFragment = new ConfirmPlayDialogFragment();
confirmPlayDialogFragment.setArguments(bundle);
return confirmPlayDialogFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = getActivity();
if (!PreferencesUtils.getBoolean(getActivity(), R.string.show_confirm_play_earth_dialog_key,
PreferencesUtils.SHOW_CONFIRM_PLAY_DIALOG_DEFAULT)) {
dismiss();
playTrack();
}
}
private void playTrack() {
long trackId = getArguments().getLong(KEY_TRACK_ID);
AnalyticsUtils.sendPageViews(activity, "/action/play");
Intent intent = IntentUtils.newIntent(activity, SaveActivity.class)
.putExtra(SaveActivity.EXTRA_TRACK_ID, trackId)
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) TrackFileFormat.KML)
.putExtra(SaveActivity.EXTRA_PLAY_TRACK, true);
startActivity(intent);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = activity.getLayoutInflater().inflate(R.layout.confirm_dialog, null);
TextView textView = (TextView) view.findViewById(R.id.confirm_dialog_message);
textView.setText(R.string.track_detail_play_confirm_message);
checkBox = (CheckBox) view.findViewById(R.id.confirm_dialog_check_box);
return new AlertDialog.Builder(activity)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PreferencesUtils.setBoolean(
activity, R.string.show_confirm_play_earth_dialog_key, !checkBox.isChecked());
playTrack();
}
})
.setTitle(R.string.generic_confirm_title)
.setView(view)
.create();
}
}
@@ -1,106 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.io.sendtogoogle;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
/**
* An interstitial to confirm sharing with friends.
*
* @author Jimmy Shih
*/
public class ConfirmSharingActivity extends Activity {
private static final int DIALOG_ID = 0;
private SendRequest sendRequest;
private CheckBox checkBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
if (PreferencesUtils.getBoolean(this, R.string.show_confirm_sharing_dialog_key,
PreferencesUtils.SHOW_CONFIRM_SHARING_DIALOG_DEFAULT)) {
showDialog(DIALOG_ID);
} else {
startNextActivity();
}
}
@Override
protected Dialog onCreateDialog(int id) {
if (id != DIALOG_ID) {
return null;
}
View view = getLayoutInflater().inflate(R.layout.confirm_dialog, null);
TextView textView = (TextView) view.findViewById(R.id.confirm_dialog_message);
textView.setText(StringUtils.getHtml(
this, R.string.share_track_confirm_message, R.string.maps_public_unlisted_url));
checkBox = (CheckBox) view.findViewById(R.id.confirm_dialog_check_box);
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int button) {
PreferencesUtils.setBoolean(ConfirmSharingActivity.this,
R.string.show_confirm_sharing_dialog_key, !checkBox.isChecked());
startNextActivity();
}
};
DialogInterface.OnClickListener cancelListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int button) {
finish();
}
};
Dialog dialog = DialogUtils.createConfirmationDialog(
this, -1, view, okListener, cancelListener);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
finish();
}
});
return dialog;
}
/**
* Starts the next activity for sharing with friends and finishes this
* activity.
*/
private void startNextActivity() {
Intent intent = IntentUtils.newIntent(this, AccountChooserActivity.class)
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
startActivity(intent);
finish();
}
}