- Switch Account
- Sync Google Drive
- New maps public

under the Google settings.
This commit is contained in:
Jimmy Shih
2013-01-15 14:33:22 -08:00
parent ae5bedc3bd
commit 8b92bd7367
16 changed files with 249 additions and 185 deletions
+1
View File
@@ -210,6 +210,7 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" /> <activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.GoogleSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" /> <activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" />
@@ -160,7 +160,7 @@ limitations under the License.
<item>5000</item> <item>5000</item>
</string-array> </string-array>
<string-array name="sensor_type_all_options"> <string-array name="sensor_type_all_options">
<item>@string/settings_sensor_type_none</item> <item>@string/value_none</item>
<item>@string/settings_sensor_type_ant</item> <item>@string/settings_sensor_type_ant</item>
<item>@string/settings_sensor_type_polar</item> <item>@string/settings_sensor_type_polar</item>
<item>@string/settings_sensor_type_zephyr</item> <item>@string/settings_sensor_type_zephyr</item>
@@ -172,7 +172,7 @@ limitations under the License.
<item>@string/sensor_type_value_zephyr</item> <item>@string/sensor_type_value_zephyr</item>
</string-array> </string-array>
<string-array name="sensor_type_bluetooth_options"> <string-array name="sensor_type_bluetooth_options">
<item>@string/settings_sensor_type_none</item> <item>@string/value_none</item>
<item>@string/settings_sensor_type_polar</item> <item>@string/settings_sensor_type_polar</item>
<item>@string/settings_sensor_type_zephyr</item> <item>@string/settings_sensor_type_zephyr</item>
</string-array> </string-array>
+4 -2
View File
@@ -30,8 +30,9 @@ limitations under the License.
<string name="chart_show_power_key">chartShowPower</string> <string name="chart_show_power_key">chartShowPower</string>
<string name="chart_show_speed_key">chartShowSpeed</string> <string name="chart_show_speed_key">chartShowSpeed</string>
<string name="default_activity_key">defaultActivity</string> <string name="default_activity_key">defaultActivity</string>
<string name="default_map_public_key">defaultMapPublic</string> <string name="google_settings_account_key">googleSettingsAccount</string>
<string name="google_account_key">googleAccount</string> <string name="google_settings_drive_sync_key">googleSettingsDriveSync</string>
<string name="google_settings_maps_public_key">googleSettingsMapsPublic</string>
<string name="max_recording_distance_key">maxRecordingDistance</string> <string name="max_recording_distance_key">maxRecordingDistance</string>
<string name="metric_units_key">metricUnits</string> <string name="metric_units_key">metricUnits</string>
<string name="min_recording_distance_key">minRecordingDistance</string> <string name="min_recording_distance_key">minRecordingDistance</string>
@@ -68,6 +69,7 @@ limitations under the License.
<string name="selected_track_id_key">selectedTrackId</string> <string name="selected_track_id_key">selectedTrackId</string>
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. --> <!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
<string name="google_settings_key">googleSettings</string>
<string name="settings_backup_key">settingsBackup</string> <string name="settings_backup_key">settingsBackup</string>
<string name="settings_backup_now_key">settingsBackupNow</string> <string name="settings_backup_now_key">settingsBackupNow</string>
<string name="settings_backup_restore_key">settingsBackupRestore</string> <string name="settings_backup_restore_key">settingsBackupRestore</string>
+59 -39
View File
@@ -719,6 +719,61 @@ limitations under the License.
Success Success
</string> </string>
<!-- Google Settings -->
<string name="google_settings_title"
translation_description="In the 'Settings' page, the option to change the Google settings.
Character limit: ~23 (1 line)">
Google
</string>
<string name="google_settings_account_title"
translation_description="In the 'Google' settings, the option to switch Google account.
Character limit: ~23 (1 line)">
Switch account
</string>
<string name="google_settings_drive_sync_title"
translation_description="In the 'Google' settings, the checkbox to sync tracks with Google
Drive.
Character limit: ~23 (1 line)">
Sync Google Drive
</string>
<string name="google_settings_drive_sync_summary_on"
translation_description="In the 'Google' settings, the summary for the 'Sync Google Drive'
checkbox when it is checked explaining that all tracks will be synced to a Google Drive
account.
%1$s account name. E.g., 'foo@foo.com'.">
All tracks will be synced to %1$s Google Drive
</string>
<string name="google_settings_maps_public_title"
translation_description="In the 'Google' settings, the checkbox to make new maps created in
Google Maps public instead of unlisted. See
http://support.google.com/maps/bin/answer.py?answer=144365 for public versus unlisted.
Character limit: ~23 (1 line)">
New maps public
</string>
<string name="google_settings_maps_public_summary_off"
translation_description="In the 'Google' settings, the summary for the 'New maps public'
checkbox when it is unchecked explaining that new maps created in Google Maps will be
unlisted, instead of public. See http://support.google.com/maps/bin/answer.py?answer=144365
for public versus unlisted.
%1$s url. E.g., 'support.google.com/maps/bin/answer.py?answer=144365'.">
New maps created in Google Maps will be unlisted, instead of public. See %1$s for more info.
</string>
<string name="google_settings_maps_public_summary_on"
translation_description="In the 'Google' settings, the summary for the 'New maps public'
checkbox when it is checked explaining that new maps created in Google Maps will be public,
instead of unlisted. See http://support.google.com/maps/bin/answer.py?answer=144365 for public
versus unlisted.
%1$s url. E.g., 'support.google.com/maps/bin/answer.py?answer=144365'.">
New maps created in Google Maps will be public, instead of unlisted. See %1$s for more info.
</string>
<!-- Gps --> <!-- Gps -->
<string name="gps_google_location_settings" <string name="gps_google_location_settings"
translation_description="In Android, the Google location settings to modify location settings translation_description="In Android, the Google location settings to modify location settings
@@ -1593,12 +1648,6 @@ limitations under the License.
Character limit: ~26 (1 line)"> Character limit: ~26 (1 line)">
Show Show
</string> </string>
<string name="settings_switch_account"
translation_description="In the 'Settings' page, the option to switch account.
Character limit: ~26 (1 line)">
Switch account
</string>
<!-- Settings Backup --> <!-- Settings Backup -->
<string name="settings_backup" <string name="settings_backup"
@@ -2029,13 +2078,6 @@ limitations under the License.
Character limit: ~20 (1 line)"> Character limit: ~20 (1 line)">
ANT+ ANT+
</string> </string>
<string name="settings_sensor_type_none"
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
not connect to any sensor.
Character limit: ~20 (1 line)">
None
</string>
<string name="settings_sensor_type_polar" <string name="settings_sensor_type_polar"
translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to translation_description="In the 'Sensor' settings, for the 'Sensor type' dropdown, the option to
connect to a Polar bluetooth sensor. Do not translate Polar, the company name, but can connect to a Polar bluetooth sensor. Do not translate Polar, the company name, but can
@@ -2093,32 +2135,6 @@ limitations under the License.
Tracks data."> Tracks data.">
Other apps can read, write, start/stop recording My Tracks data. Other apps can read, write, start/stop recording My Tracks data.
</string> </string>
<string name="settings_sharing_new_map_public"
translation_description="In the 'Sharing' settings, the checkbox option to make new maps created
in Google Maps public, instead of unlisted. See
http://support.google.com/maps/bin/answer.py?answer=144365 for public versus unlisted.
Character limit: ~23 (1 line)">
New maps public
</string>
<string name="settings_sharing_new_map_public_summary_off"
translation_description="In the 'Sharing' settings, the summary for the 'New maps public'
checkbox option when it is unchecked explaining that new maps created in Google Maps will be
unlisted, instead of public. See
http://support.google.com/maps/bin/answer.py?answer=144365 for public versus unlisted.
%1$s url. E.g., 'support.google.com/maps/bin/answer.py?answer=144365'.">
New maps created in Google Maps will be unlisted, instead of public. See %1$s for more info.
</string>
<string name="settings_sharing_new_map_public_summary_on"
translation_description="In the 'Sharing' settings, the summary for the 'New maps public'
checkbox option when it is checked explaining that new maps created in Google Maps will be
public, instead of unlisted. See
http://support.google.com/maps/bin/answer.py?answer=144365 for public versus unlisted.
%1$s url. E.g., 'support.google.com/maps/bin/answer.py?answer=144365'.">
New maps created in Google Maps will be public, instead of unlisted. See %1$s for more info.
</string>
<!-- Settings Stats --> <!-- Settings Stats -->
<string name="settings_stats_coordinate" <string name="settings_stats_coordinate"
@@ -2632,6 +2648,10 @@ limitations under the License.
translation_description="In a setting picker, the value to never use the feature."> translation_description="In a setting picker, the value to never use the feature.">
Never Never
</string> </string>
<string name="value_none"
translation_description="In a setting picker, the value to pick none of the options.">
None
</string>
<string name="value_off" <string name="value_off"
translation_description="In a setting picker, the value to turn off the feature."> translation_description="In a setting picker, the value to turn off the feature.">
Off Off
+31
View File
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2013 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/google_settings_title" >
<ListPreference
android:defaultValue=""
android:key="@string/google_settings_account_key"
android:title="@string/google_settings_account_title" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/google_settings_drive_sync_key"
android:title="@string/google_settings_drive_sync_title" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/google_settings_maps_public_key"
android:title="@string/google_settings_maps_public_title" />
</PreferenceScreen>
+4 -4
View File
@@ -16,6 +16,10 @@ limitations under the License.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/menu_settings" > android:title="@string/menu_settings" >
<Preference
android:key="@string/google_settings_key"
android:persistent="false"
android:title="@string/google_settings_title" />
<Preference <Preference
android:key="@string/settings_map_key" android:key="@string/settings_map_key"
android:persistent="false" android:persistent="false"
@@ -44,10 +48,6 @@ limitations under the License.
android:key="@string/settings_backup_key" android:key="@string/settings_backup_key"
android:persistent="false" android:persistent="false"
android:title="@string/settings_backup" /> android:title="@string/settings_backup" />
<ListPreference
android:defaultValue=""
android:key="@string/google_account_key"
android:title="@string/settings_switch_account" />
<Preference <Preference
android:key="@string/settings_reset_key" android:key="@string/settings_reset_key"
android:persistent="false" android:persistent="false"
-4
View File
@@ -16,10 +16,6 @@ limitations under the License.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/settings_sharing" > android:title="@string/settings_sharing" >
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/default_map_public_key"
android:title="@string/settings_sharing_new_map_public" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/allow_access_key" android:key="@string/allow_access_key"
@@ -98,7 +98,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(activity, boolean defaultMapPublic = PreferencesUtils.getBoolean(activity,
R.string.default_map_public_key, PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT); R.string.google_settings_maps_public_key, PreferencesUtils.GOOGLE_SETTINGS_MAPS_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);
@@ -223,7 +223,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
return true; return true;
} else { } else {
boolean defaultMapPublic = PreferencesUtils.getBoolean( boolean defaultMapPublic = PreferencesUtils.getBoolean(
context, R.string.default_map_public_key, PreferencesUtils.DEFAULT_MAP_PUBLIC_DEFAULT); context, R.string.google_settings_maps_public_key, PreferencesUtils.GOOGLE_SETTINGS_MAPS_PUBLIC_DEFAULT);
try { try {
String description = track.getCategory() + "\n" + track.getDescription() + "\n" String description = track.getCategory() + "\n" + track.getDescription() + "\n"
+ context.getString(R.string.send_google_by_my_tracks, "", ""); + context.getString(R.string.send_google_by_my_tracks, "", "");
@@ -91,13 +91,13 @@ public class AccountChooserActivity extends Activity {
if (accounts.length == 1) { if (accounts.length == 1) {
sendRequest.setAccount(accounts[0]); sendRequest.setAccount(accounts[0]);
PreferencesUtils.setString(this, R.string.google_account_key, accounts[0].name); PreferencesUtils.setString(this, R.string.google_settings_account_key, accounts[0].name);
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback); getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
return; return;
} }
String googleAccount = PreferencesUtils.getString(this, R.string.google_account_key, String googleAccount = PreferencesUtils.getString(this, R.string.google_settings_account_key,
PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT); PreferencesUtils.GOOGLE_SETTINGS_ACCOUNT_DEFAULT);
for (int i = 0; i < accounts.length; i++) { for (int i = 0; i < accounts.length; i++) {
if (accounts[i].name.equals(googleAccount)) { if (accounts[i].name.equals(googleAccount)) {
sendRequest.setAccount(accounts[i]); sendRequest.setAccount(accounts[i]);
@@ -161,7 +161,7 @@ public class AccountChooserActivity extends Activity {
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
Account account = accounts[position]; Account account = accounts[position];
PreferencesUtils.setString( PreferencesUtils.setString(
AccountChooserActivity.this, R.string.google_account_key, account.name); AccountChooserActivity.this, R.string.google_settings_account_key, account.name);
sendRequest.setAccount(account); sendRequest.setAccount(account);
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback); getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
} }
@@ -99,7 +99,7 @@ public class SensorUtils {
public static String getStateAsString(Sensor.SensorState state, Context c) { public static String getStateAsString(Sensor.SensorState state, Context c) {
switch (state) { switch (state) {
case NONE: case NONE:
return c.getString(R.string.settings_sensor_type_none); return c.getString(R.string.value_none);
case CONNECTING: case CONNECTING:
return c.getString(R.string.sensor_state_connecting); return c.getString(R.string.sensor_state_connecting);
case CONNECTED: case CONNECTED:
@@ -0,0 +1,106 @@
/*
* Copyright 2013 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.settings;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import java.util.ArrayList;
import java.util.List;
/**
* An activity for accessing the Google settings.
*
* @author Jimmy Shih
*/
public class GoogleSettingsActivity extends AbstractSettingsActivity {
private ListPreference googleSettingsAccount;
private CheckBoxPreference settingsGoogleDriveSync;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.google_settings);
googleSettingsAccount = (ListPreference) findPreference(
getString(R.string.google_settings_account_key));
List<String> entries = new ArrayList<String>();
List<String> entryValues = new ArrayList<String>();
Account[] accounts = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE);
for (Account account : accounts) {
entries.add(account.name);
entryValues.add(account.name);
}
entries.add(getString(R.string.value_none));
entryValues.add(PreferencesUtils.GOOGLE_SETTINGS_ACCOUNT_DEFAULT);
googleSettingsAccount.setEntries(entries.toArray(new CharSequence[entries.size()]));
googleSettingsAccount.setEntryValues(entryValues.toArray(new CharSequence[entries.size()]));
googleSettingsAccount.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
updateUi((String) newValue, true);
return true;
}
});
settingsGoogleDriveSync = (CheckBoxPreference) findPreference(
getString(R.string.google_settings_drive_sync_key));
CheckBoxPreference settingsGoogleMapsPublic = (CheckBoxPreference) findPreference(
getString(R.string.google_settings_maps_public_key));
settingsGoogleMapsPublic.setSummaryOn(getString(R.string.google_settings_maps_public_summary_on,
getString(R.string.maps_public_unlisted_url)));
settingsGoogleMapsPublic.setSummaryOff(getString(
R.string.google_settings_maps_public_summary_off,
getString(R.string.maps_public_unlisted_url)));
String account = PreferencesUtils.getString(this, R.string.google_settings_account_key,
PreferencesUtils.GOOGLE_SETTINGS_ACCOUNT_DEFAULT);
updateUi(account, false);
}
/**
* Updates the UI.
*
* @param account the account
* @param uncheckDriveSync true to uncheck drive sync
*/
private void updateUi(String account, boolean uncheckDriveSync) {
googleSettingsAccount.setSummary(PreferencesUtils.GOOGLE_SETTINGS_ACCOUNT_DEFAULT.equals(
account) ? getString(R.string.value_unknown)
: account);
boolean hasAccount = !PreferencesUtils.GOOGLE_SETTINGS_ACCOUNT_DEFAULT.equals(account);
settingsGoogleDriveSync.setEnabled(hasAccount);
settingsGoogleDriveSync.setSummaryOn(
getString(R.string.google_settings_drive_sync_summary_on, account));
if (uncheckDriveSync) {
settingsGoogleDriveSync.setChecked(false);
}
}
}
@@ -22,24 +22,17 @@ import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
/** /**
* An activity for accessing settings. * An activity for accessing settings.
* *
@@ -51,7 +44,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
private static final String TAG = SettingsActivity.class.getSimpleName(); private static final String TAG = SettingsActivity.class.getSimpleName();
private static final int DIALOG_CONFIRM_RESET_ID = 0; private static final int DIALOG_CONFIRM_RESET_ID = 0;
private ListPreference googleAccountListPreference;
private Preference resetPreference; private Preference resetPreference;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -60,99 +52,14 @@ public class SettingsActivity extends AbstractSettingsActivity {
super.onCreate(bundle); super.onCreate(bundle);
addPreferencesFromResource(R.xml.settings); addPreferencesFromResource(R.xml.settings);
Preference mapPreference = findPreference(getString(R.string.settings_map_key)); configPreference(R.string.google_settings_key, GoogleSettingsActivity.class);
mapPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { configPreference(R.string.settings_map_key, MapSettingsActivity.class);
@Override configPreference(R.string.settings_chart_key, ChartSettingsActivity.class);
public boolean onPreferenceClick(Preference preference) { configPreference(R.string.settings_stats_key, StatsSettingsActivity.class);
Intent intent = IntentUtils.newIntent(SettingsActivity.this, MapSettingsActivity.class); configPreference(R.string.settings_recording_key, RecordingSettingsActivity.class);
startActivity(intent); configPreference(R.string.settings_sharing_key, SharingSettingsActivity.class);
return true; configPreference(R.string.settings_sensor_key, SensorSettingsActivity.class);
} configPreference(R.string.settings_backup_key, BackupSettingsActivity.class);
});
Preference chartPreference = findPreference(getString(R.string.settings_chart_key));
chartPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, ChartSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference statsPreference = findPreference(getString(R.string.settings_stats_key));
statsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, StatsSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference recordingPreference = findPreference(getString(R.string.settings_recording_key));
recordingPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(
SettingsActivity.this, RecordingSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference sharingPreference = findPreference(getString(R.string.settings_sharing_key));
sharingPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, SharingSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference sensorPreference = findPreference(getString(R.string.settings_sensor_key));
sensorPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, SensorSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference backupPreference = findPreference(getString(R.string.settings_backup_key));
backupPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, BackupSettingsActivity.class);
startActivity(intent);
return true;
}
});
googleAccountListPreference = (ListPreference) findPreference(getString(R.string.google_account_key));
List<String> entries = new ArrayList<String>();
Account[] accounts = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE);
for (Account account : accounts) {
entries.add(account.name);
}
googleAccountListPreference.setEntries(entries.toArray(new CharSequence[entries.size()]));
googleAccountListPreference.setEntryValues(entries.toArray(
new CharSequence[entries.size()]));
if (entries.size() == 1) {
googleAccountListPreference.setValueIndex(0);
}
String googleAccount = PreferencesUtils.getString(this, R.string.google_account_key,
PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
updateSwitchAccountSummary(googleAccount);
googleAccountListPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
updateSwitchAccountSummary((String) newValue);
return true;
}
});
resetPreference = findPreference(getString(R.string.settings_reset_key)); resetPreference = findPreference(getString(R.string.settings_reset_key));
resetPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { resetPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -164,6 +71,24 @@ public class SettingsActivity extends AbstractSettingsActivity {
}); });
} }
/**
* Configures a preference by starting a new activity when it is clicked.
*
* @param key the preference key
* @param cl the class to start the new activity
*/
private void configPreference(int key, final Class<?> cl) {
Preference preference = findPreference(getString(key));
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, cl);
startActivity(intent);
return true;
}
});
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@@ -174,17 +99,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
: R.string.settings_reset_summary); : R.string.settings_reset_summary);
} }
/**
* Updates the switch account summary.
*
* @param value the value
*/
private void updateSwitchAccountSummary(String value) {
googleAccountListPreference.setSummary(
PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT.equals(value) ? getString(R.string.value_unknown)
: value);
}
@Override @Override
protected Dialog onCreateDialog(int id) { protected Dialog onCreateDialog(int id) {
if (id != DIALOG_CONFIRM_RESET_ID) { if (id != DIALOG_CONFIRM_RESET_ID) {
@@ -35,7 +35,6 @@ public class SharingSettingsActivity extends AbstractSettingsActivity {
private static final int DIALOG_CONFIRM_ALLOW_ACCESS_ID = 0; private static final int DIALOG_CONFIRM_ALLOW_ACCESS_ID = 0;
private CheckBoxPreference defaultMapPublicCheckBoxPreference;
private CheckBoxPreference allowAccessCheckBoxPreference; private CheckBoxPreference allowAccessCheckBoxPreference;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@@ -44,15 +43,6 @@ public class SharingSettingsActivity extends AbstractSettingsActivity {
super.onCreate(bundle); super.onCreate(bundle);
addPreferencesFromResource(R.xml.sharing_settings); addPreferencesFromResource(R.xml.sharing_settings);
defaultMapPublicCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.default_map_public_key));
defaultMapPublicCheckBoxPreference.setSummaryOn(getString(
R.string.settings_sharing_new_map_public_summary_on,
getString(R.string.maps_public_unlisted_url)));
defaultMapPublicCheckBoxPreference.setSummaryOff(getString(
R.string.settings_sharing_new_map_public_summary_off,
getString(R.string.maps_public_unlisted_url)));
allowAccessCheckBoxPreference = (CheckBoxPreference) findPreference( allowAccessCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.allow_access_key)); getString(R.string.allow_access_key));
allowAccessCheckBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { allowAccessCheckBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@@ -50,9 +50,13 @@ public class PreferencesUtils {
public static final boolean CHART_SHOW_SPEED_DEFAULT = true; public static final boolean CHART_SHOW_SPEED_DEFAULT = true;
public static final String DEFAULT_ACTIVITY_DEFAULT = ""; public static final String DEFAULT_ACTIVITY_DEFAULT = "";
public static final boolean DEFAULT_MAP_PUBLIC_DEFAULT = false;
public static final int FREQUENCY_OFF = 0; public static final int FREQUENCY_OFF = 0;
public static final String GOOGLE_ACCOUNT_DEFAULT = "";
public static final String GOOGLE_SETTINGS_ACCOUNT_DEFAULT = "";
public static final boolean GOOGLE_SETTINGS_DRIVE_SYNC_DEFAULT = false;
public static final boolean GOOGLE_SETTINGS_MAPS_PUBLIC_DEFAULT = false;
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200; public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
public static final boolean METRIC_UNITS_DEFAULT = true; public static final boolean METRIC_UNITS_DEFAULT = true;
public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5; public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5;
@@ -198,7 +198,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
.findViewById(viewID)); .findViewById(viewID));
assertNotNull(sensorValueText); assertNotNull(sensorValueText);
String realValue = sensorValueText.getText().toString(); String realValue = sensorValueText.getText().toString();
String noneValue = trackListActivity.getString(R.string.settings_sensor_type_none); String noneValue = trackListActivity.getString(R.string.value_none);
assertNotSame(realValue, noneValue); assertNotSame(realValue, noneValue);
} }