mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-06 19:43:06 +02:00
Move "Switch Account" to the top level settings.
This commit is contained in:
+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