forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010 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;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks with the user if he prefers the metric units or the imperial units.
|
|
||||||
*
|
|
||||||
* @author Sandor Dornbush
|
|
||||||
*/
|
|
||||||
class CheckUnits {
|
|
||||||
private static final String CHECK_UNITS_PREFERENCE_FILE = "checkunits";
|
|
||||||
private static final String CHECK_UNITS_PREFERENCE_KEY = "checkunits.checked";
|
|
||||||
private static boolean metric = true;
|
|
||||||
|
|
||||||
public static void check(final Context context) {
|
|
||||||
final SharedPreferences checkUnitsSharedPreferences = context.getSharedPreferences(
|
|
||||||
CHECK_UNITS_PREFERENCE_FILE, Context.MODE_PRIVATE);
|
|
||||||
if (checkUnitsSharedPreferences.getBoolean(CHECK_UNITS_PREFERENCE_KEY, false)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(context.getString(R.string.preferred_units_title));
|
|
||||||
CharSequence[] items = { context.getString(R.string.preferred_units_metric),
|
|
||||||
context.getString(R.string.preferred_units_imperial) };
|
|
||||||
builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
if (which == 0) {
|
|
||||||
metric = true;
|
|
||||||
} else {
|
|
||||||
metric = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setCancelable(true);
|
|
||||||
builder.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
recordCheckPerformed(checkUnitsSharedPreferences);
|
|
||||||
SharedPreferences useMetricPreferences = context.getSharedPreferences(
|
|
||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = useMetricPreferences.edit();
|
|
||||||
String key = context.getString(R.string.metric_units_key);
|
|
||||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor.putBoolean(key, metric));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
||||||
public void onCancel(DialogInterface dialog) {
|
|
||||||
recordCheckPerformed(checkUnitsSharedPreferences);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void recordCheckPerformed(SharedPreferences preferences) {
|
|
||||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(
|
|
||||||
preferences.edit().putBoolean(CHECK_UNITS_PREFERENCE_KEY, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
private CheckUnits() {}
|
|
||||||
}
|
|
||||||
@@ -70,7 +70,10 @@ import android.widget.Toast;
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class MyTracks extends TabActivity implements OnTouchListener {
|
public class MyTracks extends TabActivity implements OnTouchListener {
|
||||||
private static final int DIALOG_EULA_ID = 0;
|
private static final int DIALOG_EULA_ID = 0;
|
||||||
|
private static final int DIALOG_CHECK_UNITS_ID = 1;
|
||||||
|
private static final String CHECK_UNITS_PREFERENCE_FILE = "checkunits";
|
||||||
|
private static final String CHECK_UNITS_PREFERENCE_KEY = "checkunits.checked";
|
||||||
|
|
||||||
private TrackDataHub dataHub;
|
private TrackDataHub dataHub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,31 +265,59 @@ public class MyTracks extends TabActivity implements OnTouchListener {
|
|||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case DIALOG_EULA_ID:
|
case DIALOG_EULA_ID:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
return new AlertDialog.Builder(this)
|
||||||
builder.setTitle(R.string.eula_title);
|
.setCancelable(true)
|
||||||
builder.setMessage(EulaUtils.getEulaMessage(this));
|
.setMessage(EulaUtils.getEulaMessage(this))
|
||||||
builder.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
|
.setNegativeButton(R.string.eula_decline, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EulaUtils.setEulaValue(MyTracks.this);
|
finish();
|
||||||
Intent startIntent = new Intent(MyTracks.this, WelcomeActivity.class);
|
}
|
||||||
startActivityForResult(startIntent, Constants.WELCOME);
|
})
|
||||||
}
|
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
});
|
@Override
|
||||||
builder.setNegativeButton(R.string.eula_decline, new DialogInterface.OnClickListener() {
|
public void onCancel(DialogInterface dialog) {
|
||||||
@Override
|
finish();
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
}
|
||||||
finish();
|
})
|
||||||
}
|
.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
|
||||||
});
|
@Override
|
||||||
builder.setCancelable(true);
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
EulaUtils.setEulaValue(MyTracks.this);
|
||||||
@Override
|
Intent startIntent = new Intent(MyTracks.this, WelcomeActivity.class);
|
||||||
public void onCancel(DialogInterface dialog) {
|
startActivityForResult(startIntent, Constants.WELCOME);
|
||||||
finish();
|
}
|
||||||
}
|
})
|
||||||
});
|
.setTitle(R.string.eula_title)
|
||||||
return builder.create();
|
.create();
|
||||||
|
case DIALOG_CHECK_UNITS_ID:
|
||||||
|
return new AlertDialog.Builder(this)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
SharedPreferences sharedPreferences = getSharedPreferences(
|
||||||
|
CHECK_UNITS_PREFERENCE_FILE, Context.MODE_PRIVATE);
|
||||||
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(
|
||||||
|
sharedPreferences.edit().putBoolean(CHECK_UNITS_PREFERENCE_KEY, true));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
SharedPreferences sharedPreferences = getSharedPreferences(
|
||||||
|
CHECK_UNITS_PREFERENCE_FILE, Context.MODE_PRIVATE);
|
||||||
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(
|
||||||
|
sharedPreferences.edit().putBoolean(CHECK_UNITS_PREFERENCE_KEY, true));
|
||||||
|
|
||||||
|
int position = ((AlertDialog) dialog).getListView().getSelectedItemPosition();
|
||||||
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(
|
||||||
|
editor.putBoolean(getString(R.string.metric_units_key), position == 0));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setSingleChoiceItems(new CharSequence[] { getString(R.string.preferred_units_metric),
|
||||||
|
getString(R.string.preferred_units_imperial) }, 0, null)
|
||||||
|
.setTitle(R.string.preferred_units_title)
|
||||||
|
.create();
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -380,7 +411,11 @@ public class MyTracks extends TabActivity implements OnTouchListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Constants.WELCOME: {
|
case Constants.WELCOME: {
|
||||||
CheckUnits.check(this);
|
SharedPreferences sharedPreferences = getSharedPreferences(
|
||||||
|
CHECK_UNITS_PREFERENCE_FILE, Context.MODE_PRIVATE);
|
||||||
|
if (!sharedPreferences.getBoolean(CHECK_UNITS_PREFERENCE_KEY, false)) {
|
||||||
|
showDialog(DIALOG_CHECK_UNITS_ID);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
|||||||
import com.google.android.apps.mytracks.content.WaypointsColumns;
|
import com.google.android.apps.mytracks.content.WaypointsColumns;
|
||||||
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
||||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||||
|
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||||
import com.google.android.apps.mytracks.util.StringUtils;
|
import com.google.android.apps.mytracks.util.StringUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.Dialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@@ -57,9 +58,10 @@ import android.widget.Toast;
|
|||||||
*
|
*
|
||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class WaypointsList extends ListActivity
|
public class WaypointsList extends ListActivity implements View.OnClickListener {
|
||||||
implements View.OnClickListener {
|
|
||||||
|
|
||||||
|
private static final int DIALOG_DELETE_CURRENT_ID = 0;
|
||||||
|
|
||||||
private int contextPosition = -1;
|
private int contextPosition = -1;
|
||||||
private long trackId = -1;
|
private long trackId = -1;
|
||||||
private long selectedWaypointId = -1;
|
private long selectedWaypointId = -1;
|
||||||
@@ -119,7 +121,7 @@ public class WaypointsList extends ListActivity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case Constants.MENU_DELETE: {
|
case Constants.MENU_DELETE: {
|
||||||
deleteWaypoint(selectedWaypointId);
|
showDialog(DIALOG_DELETE_CURRENT_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,6 +201,24 @@ public class WaypointsList extends ListActivity
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dialog onCreateDialog(int id) {
|
||||||
|
switch (id) {
|
||||||
|
case DIALOG_DELETE_CURRENT_ID:
|
||||||
|
return DialogUtils.createConfirmationDialog(this,
|
||||||
|
R.string.marker_list_delete_marker_confirm_message,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
providerUtils.deleteWaypoint(
|
||||||
|
selectedWaypointId, new DescriptionGeneratorImpl(WaypointsList.this));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.search_only, menu);
|
getMenuInflater().inflate(R.menu.search_only, menu);
|
||||||
@@ -303,34 +323,4 @@ public class WaypointsList extends ListActivity
|
|||||||
});
|
});
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the way point with the given id.
|
|
||||||
* Prompts the user if he want to really delete it.
|
|
||||||
*/
|
|
||||||
public void deleteWaypoint(final long waypointId) {
|
|
||||||
AlertDialog dialog = null;
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
builder.setMessage(getString(R.string.marker_list_delete_marker_confirm_message));
|
|
||||||
builder.setTitle(getString(R.string.generic_confirm_title));
|
|
||||||
builder.setIcon(android.R.drawable.ic_dialog_alert);
|
|
||||||
builder.setPositiveButton(getString(R.string.generic_yes),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
dialogInterface.dismiss();
|
|
||||||
providerUtils.deleteWaypoint(waypointId,
|
|
||||||
new DescriptionGeneratorImpl(WaypointsList.this));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(getString(R.string.generic_no),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
dialogInterface.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dialog = builder.create();
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user