forked from upstream-mirrors/OpenTracks
- Show the Google Play services update dialog after the EULA and welcome dialogs.
- Handle canceling the Google Play services update dialog.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user