mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Move "Switch Account" to the top level settings.
This commit is contained in:
@@ -31,6 +31,7 @@ limitations under the License.
|
||||
<string name="chart_show_speed_key">chartShowSpeed</string>
|
||||
<string name="default_activity_key">defaultActivity</string>
|
||||
<string name="default_map_public_key">defaultMapPublic</string>
|
||||
<string name="google_account_key">googleAccount</string>
|
||||
<string name="max_recording_distance_key">maxRecordingDistance</string>
|
||||
<string name="metric_units_key">metricUnits</string>
|
||||
<string name="min_recording_distance_key">minRecordingDistance</string>
|
||||
@@ -44,7 +45,6 @@ limitations under the License.
|
||||
<string name="send_to_fusion_tables_key">sendToFusionTables</string>
|
||||
<string name="send_to_maps_key">sendToMaps</string>
|
||||
<string name="sensor_type_key">sensorType</string>
|
||||
<string name="sharing_account_key">sharingAccount</string>
|
||||
<string name="show_check_units_dialog_key">showCheckUnitsDialog</string>
|
||||
<string name="show_welcome_dialog_key">showWelcomeDialog</string>
|
||||
<string name="split_frequency_key">splitFrequency</string>
|
||||
|
||||
@@ -1800,14 +1800,6 @@ limitations under the License.
|
||||
Character limit: ~26 (1 line)">
|
||||
Sharing
|
||||
</string>
|
||||
<string name="settings_sharing_account"
|
||||
translation_description="In the 'Sharing' settings, the option to switch account.">
|
||||
Switch account
|
||||
</string>
|
||||
<string name="settings_sharing_account_summary"
|
||||
translation_description="In the 'Sharing' settings, the summary for 'Switch account'.">
|
||||
Account used when sending a track to Google.
|
||||
</string>
|
||||
<string name="settings_sharing_allow_access"
|
||||
translation_description="In the 'Sharing' settings, the checkbox option to allow third party
|
||||
apps access to the My Tracks data.
|
||||
@@ -1912,6 +1904,12 @@ limitations under the License.
|
||||
Preferred units
|
||||
</string>
|
||||
|
||||
<!-- Settings Switch Account -->
|
||||
<string name="settings_switch_account"
|
||||
translation_description="In the 'Settings' page, the option to switch account.">
|
||||
Switch account
|
||||
</string>
|
||||
|
||||
<!-- Settings Voice -->
|
||||
<string name="settings_voice_frequency_title"
|
||||
translation_description="The title of the 'Voice frequency' dialog.">
|
||||
|
||||
@@ -44,6 +44,10 @@ limitations under the License.
|
||||
android:key="@string/settings_backup_key"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_backup" />
|
||||
<ListPreference
|
||||
android:defaultValue=""
|
||||
android:key="@string/google_account_key"
|
||||
android:title="@string/settings_switch_account" />
|
||||
<Preference
|
||||
android:key="@string/settings_reset_key"
|
||||
android:persistent="false"
|
||||
|
||||
@@ -16,11 +16,6 @@ limitations under the License.
|
||||
-->
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/settings_sharing" >
|
||||
<ListPreference
|
||||
android:defaultValue=""
|
||||
android:key="@string/sharing_account_key"
|
||||
android:summary="@string/settings_sharing_account_summary"
|
||||
android:title="@string/settings_sharing_account" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/default_map_public_key"
|
||||
|
||||
+5
-5
@@ -90,15 +90,15 @@ public class AccountChooserActivity extends Activity {
|
||||
|
||||
if (accounts.length == 1) {
|
||||
sendRequest.setAccount(accounts[0]);
|
||||
PreferencesUtils.setString(this, R.string.sharing_account_key, accounts[0].name);
|
||||
PreferencesUtils.setString(this, R.string.google_account_key, accounts[0].name);
|
||||
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||
return;
|
||||
}
|
||||
|
||||
String sharingAccount = PreferencesUtils.getString(this, R.string.sharing_account_key,
|
||||
PreferencesUtils.SHARING_ACCOUNT_DEFAULT);
|
||||
String googleAccount = PreferencesUtils.getString(this, R.string.google_account_key,
|
||||
PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
if (accounts[i].name.equals(sharingAccount)) {
|
||||
if (accounts[i].name.equals(googleAccount)) {
|
||||
sendRequest.setAccount(accounts[i]);
|
||||
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||
return;
|
||||
@@ -160,7 +160,7 @@ public class AccountChooserActivity extends Activity {
|
||||
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||
Account account = accounts[position];
|
||||
PreferencesUtils.setString(
|
||||
AccountChooserActivity.this, R.string.sharing_account_key, account.name);
|
||||
AccountChooserActivity.this, R.string.google_account_key, account.name);
|
||||
sendRequest.setAccount(account);
|
||||
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||
}
|
||||
|
||||
@@ -22,17 +22,24 @@ 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.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An activity for accessing settings.
|
||||
*
|
||||
@@ -44,6 +51,7 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||
private static final String TAG = SettingsActivity.class.getSimpleName();
|
||||
private static final int DIALOG_CONFIRM_RESET_ID = 0;
|
||||
|
||||
private ListPreference googleAccountListPreference;
|
||||
private Preference resetPreference;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -123,6 +131,29 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||
}
|
||||
});
|
||||
|
||||
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.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
@@ -143,6 +174,17 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||
: 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
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
if (id != DIALOG_CONFIRM_RESET_ID) {
|
||||
|
||||
+1
-23
@@ -16,24 +16,17 @@
|
||||
|
||||
package com.google.android.apps.mytracks.settings;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||
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.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
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 sharing settings.
|
||||
*
|
||||
@@ -79,21 +72,6 @@ public class SharingSettingsActivity extends AbstractSettingsActivity {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ListPreference sharingAccountListPreference = (ListPreference) findPreference(
|
||||
getString(R.string.sharing_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);
|
||||
}
|
||||
|
||||
sharingAccountListPreference.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
||||
sharingAccountListPreference.setEntryValues(entries.toArray(
|
||||
new CharSequence[entries.size()]));
|
||||
if (entries.size() == 1) {
|
||||
sharingAccountListPreference.setValueIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,7 +88,7 @@ public class SharingSettingsActivity extends AbstractSettingsActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the title for the default map public check box preference.
|
||||
*
|
||||
|
||||
@@ -53,6 +53,7 @@ public class PreferencesUtils {
|
||||
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 String GOOGLE_ACCOUNT_DEFAULT = "";
|
||||
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
|
||||
public static final boolean METRIC_UNITS_DEFAULT = true;
|
||||
public static final int MIN_RECORDING_DISTANCE_DEFAULT = 5;
|
||||
@@ -72,7 +73,6 @@ public class PreferencesUtils {
|
||||
public static final boolean SEND_TO_DOCS_DEFAULT = true;
|
||||
public static final boolean SEND_TO_FUSION_TABLES_DEFAULT = true;
|
||||
public static final boolean SEND_TO_MAPS_DEFAULT = true;
|
||||
public static final String SHARING_ACCOUNT_DEFAULT = "";
|
||||
public static final boolean SHOW_CHECK_UNITS_DIALOG_DEFAULT = true;
|
||||
public static final boolean SHOW_WELCOME_DIALOG_DEFAULT = true;
|
||||
public static final int SPLIT_FREQUENCY_DEFAULT = 0;
|
||||
|
||||
Reference in New Issue
Block a user