From 2bb76de736a9fbd68699ff0829c15b94836121ed Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Wed, 7 Nov 2012 13:33:58 -0800 Subject: [PATCH] - Show the Google Play services update dialog after the EULA and welcome dialogs. - Handle canceling the Google Play services update dialog. --- .../apps/mytracks/TrackListActivity.java | 39 +++++++-- .../fragments/CheckUnitsDialogFragment.java | 81 ------------------- 2 files changed, 31 insertions(+), 89 deletions(-) delete mode 100644 MyTracks/src/com/google/android/apps/mytracks/fragments/CheckUnitsDialogFragment.java diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java index 24c0a9ce9..03737be99 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java @@ -47,6 +47,7 @@ import com.google.android.maps.mytracks.R; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -86,6 +87,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac private static final String TAG = TrackListActivity.class.getSimpleName(); private static final String START_GPS_KEY = "start_gps_key"; + private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0; private static final String[] PROJECTION = new String[] { TracksColumns._ID, TracksColumns.NAME, TracksColumns.DESCRIPTION, TracksColumns.CATEGORY, TracksColumns.STARTTIME, TracksColumns.TOTALDISTANCE, TracksColumns.TOTALTIME, TracksColumns.ICON }; @@ -434,15 +436,8 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac updateMenuItems(isRecording); resourceCursorAdapter.notifyDataSetChanged(); trackController.update(isRecording, recordingTrackPaused); - - // Check Google Play Services - int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); - if (code != ConnectionResult.SUCCESS) { - Dialog dialog = GooglePlayServicesUtil.getErrorDialog(code, this, 0); - dialog.show(); - } } - + @Override protected void onPause() { super.onPause(); @@ -474,6 +469,15 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac outState.putBoolean(START_GPS_KEY, startGps); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == GOOGLE_PLAY_SERVICES_REQUEST_CODE) { + checkGooglePlayServices(); + } else { + super.onActivityResult(requestCode, resultCode, data); + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.track_list, menu); @@ -601,6 +605,25 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac * doesn't show through. */ findViewById(R.id.track_list_empty_view).setVisibility(View.VISIBLE); + + checkGooglePlayServices(); + } + } + + private void checkGooglePlayServices() { + int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); + if (code != ConnectionResult.SUCCESS) { + Dialog dialog = GooglePlayServicesUtil.getErrorDialog( + code, this, GOOGLE_PLAY_SERVICES_REQUEST_CODE, new DialogInterface.OnCancelListener() { + + @Override + public void onCancel(DialogInterface dialogInterface) { + finish(); + } + }); + if (dialog != null) { + dialog.show(); + } } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/CheckUnitsDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/CheckUnitsDialogFragment.java deleted file mode 100644 index 3d9b9addd..000000000 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/CheckUnitsDialogFragment.java +++ /dev/null @@ -1,81 +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.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.AlertDialog; -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 java.util.Locale; - -/** - * A DialogFragment to check preferred units. - * - * @author Jimmy Shih - */ -public class CheckUnitsDialogFragment extends DialogFragment { - - public static final String CHECK_UNITS_DIALOG_TAG = "checkUnitsDialog"; - - private FragmentActivity activity; - - @Override - public void onCancel(DialogInterface arg0) { - onDone(); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - activity = getActivity(); - - Locale defaultLocale = Locale.getDefault(); - boolean defaultMetric = !defaultLocale.equals(Locale.US) && !defaultLocale.equals(Locale.UK); - PreferencesUtils.setBoolean(activity, R.string.metric_units_key, defaultMetric); - final String metric = getString(R.string.settings_stats_units_metric); - final String imperial = getString(R.string.settings_stats_units_imperial); - final CharSequence[] items = defaultMetric ? new CharSequence[] { metric, imperial } - : new CharSequence[] { imperial, metric }; - return new AlertDialog.Builder(activity).setPositiveButton( - R.string.generic_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); - PreferencesUtils.setBoolean( - activity, R.string.metric_units_key, items[position].equals(metric)); - onDone(); - } - }).setSingleChoiceItems(items, 0, null).setTitle(R.string.settings_stats_units_title) - .create(); - } - - /** - * Tasks to perform when done. - */ - private void onDone() { - EulaUtils.setShowCheckUnits(activity); - TrackListActivity trackListActivity = (TrackListActivity) activity; - trackListActivity.showStartupDialogs(); - } -} \ No newline at end of file