forked from upstream-mirrors/OpenTracks
Inline account chooser in export dialog
This commit is contained in:
@@ -16,19 +16,15 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
style="@style/ScrollView" >
|
style="@style/ScrollView" >
|
||||||
<RadioGroup
|
<LinearLayout
|
||||||
android:id="@+id/export_type_options"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
android:padding="8dp" >
|
android:padding="8dp" >
|
||||||
<RadioButton
|
<Spinner
|
||||||
android:id="@+id/export_google_drive"
|
android:id="@+id/export_type_options"
|
||||||
android:text="@string/export_google_drive"
|
android:layout_height="wrap_content"
|
||||||
style="@style/TextMedium" />
|
android:layout_width="match_parent" />
|
||||||
<RadioButton
|
|
||||||
android:id="@+id/export_google_maps"
|
|
||||||
android:text="@string/export_google_maps"
|
|
||||||
style="@style/TextMedium" />
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:id="@+id/export_google_maps_options"
|
android:id="@+id/export_google_maps_options"
|
||||||
style="@style/ExportRadioGroup" >
|
style="@style/ExportRadioGroup" >
|
||||||
@@ -41,10 +37,6 @@ limitations under the License.
|
|||||||
android:text="@string/export_google_maps_unlisted"
|
android:text="@string/export_google_maps_unlisted"
|
||||||
style="@style/TextMedium" />
|
style="@style/TextMedium" />
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
<RadioButton
|
|
||||||
android:id="@+id/export_google_fusion_tables"
|
|
||||||
android:text="@string/export_google_fusion_tables"
|
|
||||||
style="@style/TextMedium" />
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:id="@+id/export_google_fusion_tables_options"
|
android:id="@+id/export_google_fusion_tables_options"
|
||||||
style="@style/ExportRadioGroup" >
|
style="@style/ExportRadioGroup" >
|
||||||
@@ -57,14 +49,6 @@ limitations under the License.
|
|||||||
android:text="@string/export_google_fusion_tables_private"
|
android:text="@string/export_google_fusion_tables_private"
|
||||||
style="@style/TextMedium" />
|
style="@style/TextMedium" />
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
<RadioButton
|
|
||||||
android:id="@+id/export_google_spreadsheets"
|
|
||||||
android:text="@string/export_google_spreadsheets"
|
|
||||||
style="@style/TextMedium" />
|
|
||||||
<RadioButton
|
|
||||||
android:id="@+id/export_external_storage"
|
|
||||||
android:text="@string/export_external_storage"
|
|
||||||
style="@style/TextMedium" />
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:id="@+id/export_external_storage_options"
|
android:id="@+id/export_external_storage_options"
|
||||||
style="@style/ExportRadioGroup" >
|
style="@style/ExportRadioGroup" >
|
||||||
@@ -81,5 +65,10 @@ limitations under the License.
|
|||||||
android:id="@+id/export_external_storage_tcx"
|
android:id="@+id/export_external_storage_tcx"
|
||||||
style="@style/TextMedium" />
|
style="@style/TextMedium" />
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
</RadioGroup>
|
<Spinner
|
||||||
|
android:id="@+id/export_account"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_width="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -22,6 +22,7 @@ import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment;
|
|||||||
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment.ConfirmDeleteCaller;
|
import com.google.android.apps.mytracks.fragments.ConfirmDeleteDialogFragment.ConfirmDeleteCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment.ConfirmSyncCaller;
|
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment.ConfirmSyncCaller;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType;
|
||||||
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
|
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment.ShareTrackCaller;
|
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment.ShareTrackCaller;
|
||||||
@@ -158,20 +159,45 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
|||||||
*/
|
*/
|
||||||
protected void shareTrack(long trackId) {
|
protected void shareTrack(long trackId) {
|
||||||
AnalyticsUtils.sendPageViews(this, AnalyticsUtils.ACTION_SHARE_DRIVE);
|
AnalyticsUtils.sendPageViews(this, AnalyticsUtils.ACTION_SHARE_DRIVE);
|
||||||
sendRequest = new SendRequest(trackId);
|
ShareTrackDialogFragment.newInstance(trackId)
|
||||||
sendRequest.setSendDrive(true);
|
|
||||||
ShareTrackDialogFragment.newInstance(sendRequest.getTrackId())
|
|
||||||
.show(getSupportFragmentManager(), ShareTrackDialogFragment.SHARE_TRACK_DIALOG_TAG);
|
.show(getSupportFragmentManager(), ShareTrackDialogFragment.SHARE_TRACK_DIALOG_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShareTrackDone(boolean makePublic, String emails, Account account) {
|
public void onShareTrackDone(long trackId, boolean makePublic, String emails, Account account) {
|
||||||
|
sendRequest = new SendRequest(trackId);
|
||||||
|
sendRequest.setSendDrive(true);
|
||||||
sendRequest.setDriveSharePublic(makePublic);
|
sendRequest.setDriveSharePublic(makePublic);
|
||||||
sendRequest.setDriveShareEmails(emails);
|
sendRequest.setDriveShareEmails(emails);
|
||||||
sendRequest.setAccount(account);
|
sendRequest.setAccount(account);
|
||||||
onConfirmSyncDone(true);
|
onConfirmSyncDone(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void exportTrackToGoogle(long trackId, ExportType exportType, Account account) {
|
||||||
|
sendRequest = new SendRequest(trackId);
|
||||||
|
String pageView;
|
||||||
|
switch (exportType) {
|
||||||
|
case GOOGLE_DRIVE:
|
||||||
|
pageView = AnalyticsUtils.ACTION_EXPORT_DRIVE;
|
||||||
|
sendRequest.setSendDrive(true);
|
||||||
|
break;
|
||||||
|
case GOOGLE_MAPS:
|
||||||
|
pageView = AnalyticsUtils.ACTION_EXPORT_MAPS;
|
||||||
|
sendRequest.setSendMaps(true);
|
||||||
|
break;
|
||||||
|
case GOOGLE_FUSION_TABLES:
|
||||||
|
pageView = AnalyticsUtils.ACTION_EXPORT_FUSION_TABLES;
|
||||||
|
sendRequest.setSendFusionTables(true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
pageView = AnalyticsUtils.ACTION_EXPORT_SPREADSHEETS;
|
||||||
|
sendRequest.setSendSpreadsheets(true);
|
||||||
|
}
|
||||||
|
AnalyticsUtils.sendPageViews(this, pageView);
|
||||||
|
sendRequest.setAccount(account);
|
||||||
|
onConfirmSyncDone(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a request to Google.
|
* Sends a request to Google.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import com.google.android.apps.mytracks.fragments.PlayMultipleDialogFragment.Pla
|
|||||||
import com.google.android.apps.mytracks.fragments.StatsFragment;
|
import com.google.android.apps.mytracks.fragments.StatsFragment;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||||
import com.google.android.apps.mytracks.io.file.exporter.SaveActivity;
|
import com.google.android.apps.mytracks.io.file.exporter.SaveActivity;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
|
||||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||||
import com.google.android.apps.mytracks.settings.SettingsActivity;
|
import com.google.android.apps.mytracks.settings.SettingsActivity;
|
||||||
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
||||||
@@ -51,6 +50,7 @@ import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtil
|
|||||||
import com.google.android.apps.mytracks.util.TrackUtils;
|
import com.google.android.apps.mytracks.util.TrackUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@@ -486,36 +486,17 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onExportDone(ExportType exportType, TrackFileFormat trackFileFormat) {
|
public void onExportDone(
|
||||||
|
ExportType exportType, TrackFileFormat trackFileFormat, Account account) {
|
||||||
if (exportType == ExportType.EXTERNAL_STORAGE) {
|
if (exportType == ExportType.EXTERNAL_STORAGE) {
|
||||||
AnalyticsUtils.sendPageViews(this,
|
AnalyticsUtils.sendPageViews(
|
||||||
AnalyticsUtils.ACTION_EXPORT_PREFIX + trackFileFormat.getExtension());
|
this, AnalyticsUtils.ACTION_EXPORT_PREFIX + trackFileFormat.getExtension());
|
||||||
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
|
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
|
||||||
.putExtra(SaveActivity.EXTRA_TRACK_IDS, new long[] { trackId })
|
.putExtra(SaveActivity.EXTRA_TRACK_IDS, new long[] { trackId })
|
||||||
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
SendRequest sendRequest = new SendRequest(trackId);
|
exportTrackToGoogle(trackId, exportType, account);
|
||||||
String pageView;
|
|
||||||
switch (exportType) {
|
|
||||||
case GOOGLE_DRIVE:
|
|
||||||
pageView = AnalyticsUtils.ACTION_EXPORT_DRIVE;
|
|
||||||
sendRequest.setSendDrive(true);
|
|
||||||
break;
|
|
||||||
case GOOGLE_MAPS:
|
|
||||||
pageView = AnalyticsUtils.ACTION_EXPORT_MAPS;
|
|
||||||
sendRequest.setSendMaps(true);
|
|
||||||
break;
|
|
||||||
case GOOGLE_FUSION_TABLES:
|
|
||||||
pageView = AnalyticsUtils.ACTION_EXPORT_FUSION_TABLES;
|
|
||||||
sendRequest.setSendFusionTables(true);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pageView = AnalyticsUtils.ACTION_EXPORT_SPREADSHEETS;
|
|
||||||
sendRequest.setSendSpreadsheets(true);
|
|
||||||
}
|
|
||||||
AnalyticsUtils.sendPageViews(this, pageView);
|
|
||||||
sendToGoogle(sendRequest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+113
-79
@@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.fragments;
|
package com.google.android.apps.mytracks.fragments;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||||
|
import com.google.android.apps.mytracks.util.AccountUtils;
|
||||||
import com.google.android.apps.mytracks.util.FileUtils;
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
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.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
@@ -28,9 +32,13 @@ import android.content.DialogInterface;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.RadioGroup.OnCheckedChangeListener;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DialogFragment to export a track.
|
* A DialogFragment to export a track.
|
||||||
@@ -45,7 +53,16 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public enum ExportType {
|
public enum ExportType {
|
||||||
GOOGLE_DRIVE, GOOGLE_MAPS, GOOGLE_FUSION_TABLES, GOOGLE_SPREADSHEET, EXTERNAL_STORAGE
|
GOOGLE_DRIVE(R.string.export_google_drive),
|
||||||
|
GOOGLE_MAPS(R.string.export_google_maps),
|
||||||
|
GOOGLE_FUSION_TABLES(R.string.export_google_fusion_tables),
|
||||||
|
GOOGLE_SPREADSHEET(R.string.export_google_spreadsheets),
|
||||||
|
EXTERNAL_STORAGE(R.string.export_external_storage);
|
||||||
|
final int resId;
|
||||||
|
|
||||||
|
ExportType(int resId) {
|
||||||
|
this.resId = resId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,8 +74,13 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when export is done.
|
* Called when export is done.
|
||||||
|
*
|
||||||
|
* @param exportType the export type
|
||||||
|
* @param trackFileFormat the track file format
|
||||||
|
* @param account the account
|
||||||
*/
|
*/
|
||||||
public void onExportDone(ExportType exportType, TrackFileFormat trackFileFormat);
|
public void onExportDone(
|
||||||
|
ExportType exportType, TrackFileFormat trackFileFormat, Account account);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String EXPORT_DIALOG_TAG = "export";
|
public static final String EXPORT_DIALOG_TAG = "export";
|
||||||
@@ -75,10 +97,15 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ExportCaller caller;
|
private ExportCaller caller;
|
||||||
private RadioGroup exportTypeOptions;
|
private Account[] accounts;
|
||||||
|
private ArrayList<ExportType> exportTypeOptionsList;
|
||||||
|
|
||||||
|
// UI elements
|
||||||
|
private Spinner exportTypeOptions;
|
||||||
private RadioGroup exportGoogleMapsOptions;
|
private RadioGroup exportGoogleMapsOptions;
|
||||||
private RadioGroup exportGoogleFusionTablesOptions;
|
private RadioGroup exportGoogleFusionTablesOptions;
|
||||||
private RadioGroup exportExternalStorageOptions;
|
private RadioGroup exportExternalStorageOptions;
|
||||||
|
private Spinner accountSpinner;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
@@ -94,48 +121,28 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected Dialog createDialog() {
|
protected Dialog createDialog() {
|
||||||
FragmentActivity fragmentActivity = getActivity();
|
FragmentActivity fragmentActivity = getActivity();
|
||||||
boolean hideDrive = getArguments().getBoolean(KEY_HIDE_DRIVE);
|
accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||||
ExportType exportType = ExportType.valueOf(PreferencesUtils.getString(
|
|
||||||
fragmentActivity, R.string.export_type_key, PreferencesUtils.EXPORT_TYPE_DEFAULT));
|
|
||||||
|
|
||||||
if (hideDrive && exportType == ExportType.GOOGLE_DRIVE) {
|
|
||||||
exportType = ExportType.GOOGLE_MAPS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get views
|
// Get views
|
||||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.export, null);
|
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.export, null);
|
||||||
exportTypeOptions = (RadioGroup) view.findViewById(R.id.export_type_options);
|
exportTypeOptions = (Spinner) view.findViewById(R.id.export_type_options);
|
||||||
RadioButton exportGoogleDrive = (RadioButton) view.findViewById(R.id.export_google_drive);
|
|
||||||
exportGoogleMapsOptions = (RadioGroup) view.findViewById(R.id.export_google_maps_options);
|
exportGoogleMapsOptions = (RadioGroup) view.findViewById(R.id.export_google_maps_options);
|
||||||
exportGoogleFusionTablesOptions = (RadioGroup) view.findViewById(
|
exportGoogleFusionTablesOptions = (RadioGroup) view.findViewById(
|
||||||
R.id.export_google_fusion_tables_options);
|
R.id.export_google_fusion_tables_options);
|
||||||
exportExternalStorageOptions = (RadioGroup) view.findViewById(
|
exportExternalStorageOptions = (RadioGroup) view.findViewById(
|
||||||
R.id.export_external_storage_options);
|
R.id.export_external_storage_options);
|
||||||
|
accountSpinner = (Spinner) view.findViewById(R.id.export_account);
|
||||||
|
|
||||||
|
// Setup exportTypeOptions
|
||||||
|
setupExportTypeOptions(fragmentActivity);
|
||||||
|
|
||||||
// exportTypeOptions
|
// Setup exportGoogleMapsOptions
|
||||||
exportTypeOptions.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
|
||||||
exportGoogleMapsOptions.setVisibility(
|
|
||||||
checkedId == R.id.export_google_maps ? View.VISIBLE : View.GONE);
|
|
||||||
exportGoogleFusionTablesOptions.setVisibility(
|
|
||||||
checkedId == R.id.export_google_fusion_tables ? View.VISIBLE : View.GONE);
|
|
||||||
exportExternalStorageOptions.setVisibility(
|
|
||||||
checkedId == R.id.export_external_storage ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
exportTypeOptions.check(getExportTypeId(exportType));
|
|
||||||
|
|
||||||
// exportGoogleDrive
|
|
||||||
exportGoogleDrive.setVisibility(hideDrive ? View.GONE : View.VISIBLE);
|
|
||||||
|
|
||||||
// exportGoogleMapsOptions
|
|
||||||
boolean exportGoogleMapsPublic = PreferencesUtils.getBoolean(fragmentActivity,
|
boolean exportGoogleMapsPublic = PreferencesUtils.getBoolean(fragmentActivity,
|
||||||
R.string.export_google_maps_public_key, PreferencesUtils.EXPORT_GOOGLE_MAPS_PUBLIC_DEFAULT);
|
R.string.export_google_maps_public_key, PreferencesUtils.EXPORT_GOOGLE_MAPS_PUBLIC_DEFAULT);
|
||||||
exportGoogleMapsOptions.check(
|
exportGoogleMapsOptions.check(
|
||||||
exportGoogleMapsPublic ? R.id.export_google_maps_public : R.id.export_google_maps_unlisted);
|
exportGoogleMapsPublic ? R.id.export_google_maps_public : R.id.export_google_maps_unlisted);
|
||||||
|
|
||||||
// exportGoogleFusionTablesOptions
|
// Setup exportGoogleFusionTablesOptions
|
||||||
boolean exportGoogleFusionTablesPublic = PreferencesUtils.getBoolean(fragmentActivity,
|
boolean exportGoogleFusionTablesPublic = PreferencesUtils.getBoolean(fragmentActivity,
|
||||||
R.string.export_google_fusion_tables_public_key,
|
R.string.export_google_fusion_tables_public_key,
|
||||||
PreferencesUtils.EXPORT_GOOGLE_FUSION_TABLES_PUBLIC_DEFAULT);
|
PreferencesUtils.EXPORT_GOOGLE_FUSION_TABLES_PUBLIC_DEFAULT);
|
||||||
@@ -143,7 +150,7 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
exportGoogleFusionTablesPublic ? R.id.export_google_fusion_tables_public
|
exportGoogleFusionTablesPublic ? R.id.export_google_fusion_tables_public
|
||||||
: R.id.export_google_fusion_tables_private);
|
: R.id.export_google_fusion_tables_private);
|
||||||
|
|
||||||
// exportExternalStorageOptions
|
// Setup exportExternalStorageOptions
|
||||||
setExternalStorageOption(
|
setExternalStorageOption(
|
||||||
(RadioButton) view.findViewById(R.id.export_external_storage_kml), TrackFileFormat.KML);
|
(RadioButton) view.findViewById(R.id.export_external_storage_kml), TrackFileFormat.KML);
|
||||||
setExternalStorageOption(
|
setExternalStorageOption(
|
||||||
@@ -157,35 +164,102 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
PreferencesUtils.EXPORT_EXTERNAL_STORAGE_FORMAT_DEFAULT));
|
PreferencesUtils.EXPORT_EXTERNAL_STORAGE_FORMAT_DEFAULT));
|
||||||
exportExternalStorageOptions.check(getExternalStorageFormatId(trackFileFormat));
|
exportExternalStorageOptions.check(getExternalStorageFormatId(trackFileFormat));
|
||||||
|
|
||||||
|
// Setup accountSpinner
|
||||||
|
AccountUtils.setupAccountSpinner(fragmentActivity, accountSpinner, accounts);
|
||||||
|
|
||||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||||
R.string.generic_cancel, null)
|
R.string.generic_cancel, null)
|
||||||
.setPositiveButton(R.string.menu_export, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.menu_export, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
FragmentActivity context = getActivity();
|
FragmentActivity context = getActivity();
|
||||||
int id = exportTypeOptions.getCheckedRadioButtonId();
|
ExportType type = exportTypeOptionsList.get(
|
||||||
ExportType type = getExportType(id);
|
exportTypeOptions.getSelectedItemPosition());
|
||||||
TrackFileFormat format = null;
|
TrackFileFormat format = null;
|
||||||
|
|
||||||
PreferencesUtils.setString(context, R.string.export_type_key, type.name());
|
PreferencesUtils.setString(context, R.string.export_type_key, type.name());
|
||||||
if (id == R.id.export_google_maps) {
|
if (type == ExportType.GOOGLE_MAPS) {
|
||||||
PreferencesUtils.setBoolean(context, R.string.export_google_maps_public_key,
|
PreferencesUtils.setBoolean(context, R.string.export_google_maps_public_key,
|
||||||
exportGoogleMapsOptions.getCheckedRadioButtonId()
|
exportGoogleMapsOptions.getCheckedRadioButtonId()
|
||||||
== R.id.export_google_maps_public);
|
== R.id.export_google_maps_public);
|
||||||
} else if (id == R.id.export_google_fusion_tables) {
|
} else if (type == ExportType.GOOGLE_FUSION_TABLES) {
|
||||||
PreferencesUtils.setBoolean(context, R.string.export_google_fusion_tables_public_key,
|
PreferencesUtils.setBoolean(context, R.string.export_google_fusion_tables_public_key,
|
||||||
exportGoogleFusionTablesOptions.getCheckedRadioButtonId()
|
exportGoogleFusionTablesOptions.getCheckedRadioButtonId()
|
||||||
== R.id.export_google_fusion_tables_public);
|
== R.id.export_google_fusion_tables_public);
|
||||||
} else if (id == R.id.export_external_storage) {
|
} else if (type == ExportType.EXTERNAL_STORAGE) {
|
||||||
format = getTrackFileFormat(exportExternalStorageOptions.getCheckedRadioButtonId());
|
format = getTrackFileFormat(exportExternalStorageOptions.getCheckedRadioButtonId());
|
||||||
PreferencesUtils.setString(
|
PreferencesUtils.setString(
|
||||||
context, R.string.export_external_storage_format_key, format.name());
|
context, R.string.export_external_storage_format_key, format.name());
|
||||||
}
|
}
|
||||||
caller.onExportDone(type, format);
|
Account account;
|
||||||
|
if (accounts.length == 0) {
|
||||||
|
account = null;
|
||||||
|
} else if (accounts.length == 1) {
|
||||||
|
account = accounts[0];
|
||||||
|
} else {
|
||||||
|
account = accounts[accountSpinner.getSelectedItemPosition()];
|
||||||
|
}
|
||||||
|
AccountUtils.updateShareTrackAccountPreference(context, account);
|
||||||
|
caller.onExportDone(type, format, account);
|
||||||
}
|
}
|
||||||
}).setTitle(R.string.export_title).setView(view).create();
|
}).setTitle(R.string.export_title).setView(view).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupExportTypeOptions(FragmentActivity fragmentActivity) {
|
||||||
|
boolean hideDrive = getArguments().getBoolean(KEY_HIDE_DRIVE);
|
||||||
|
ExportType exportType = ExportType.valueOf(PreferencesUtils.getString(
|
||||||
|
fragmentActivity, R.string.export_type_key, PreferencesUtils.EXPORT_TYPE_DEFAULT));
|
||||||
|
|
||||||
|
if (hideDrive && exportType == ExportType.GOOGLE_DRIVE) {
|
||||||
|
exportType = ExportType.GOOGLE_MAPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
exportTypeOptionsList = new ArrayList<ExportDialogFragment.ExportType>();
|
||||||
|
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
|
||||||
|
getActivity(), android.R.layout.simple_spinner_item);
|
||||||
|
if (accounts.length > 0) {
|
||||||
|
if (!hideDrive) {
|
||||||
|
exportTypeOptionsList.add(ExportType.GOOGLE_DRIVE);
|
||||||
|
}
|
||||||
|
exportTypeOptionsList.add(ExportType.GOOGLE_MAPS);
|
||||||
|
exportTypeOptionsList.add(ExportType.GOOGLE_FUSION_TABLES);
|
||||||
|
exportTypeOptionsList.add(ExportType.GOOGLE_SPREADSHEET);
|
||||||
|
}
|
||||||
|
exportTypeOptionsList.add(ExportType.EXTERNAL_STORAGE);
|
||||||
|
|
||||||
|
int selection = 0;
|
||||||
|
for (int i = 0; i < exportTypeOptionsList.size(); i++) {
|
||||||
|
ExportType type = exportTypeOptionsList.get(i);
|
||||||
|
adapter.add(getString(type.resId));
|
||||||
|
if (type == exportType) {
|
||||||
|
selection = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
exportTypeOptions.setAdapter(adapter);
|
||||||
|
exportTypeOptions.setSelection(selection);
|
||||||
|
exportTypeOptions.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
ExportType type = exportTypeOptionsList.get(position);
|
||||||
|
exportGoogleMapsOptions.setVisibility(
|
||||||
|
type == ExportType.GOOGLE_MAPS ? View.VISIBLE : View.GONE);
|
||||||
|
exportGoogleFusionTablesOptions.setVisibility(
|
||||||
|
type == ExportType.GOOGLE_FUSION_TABLES ? View.VISIBLE : View.GONE);
|
||||||
|
exportExternalStorageOptions.setVisibility(
|
||||||
|
type == ExportType.EXTERNAL_STORAGE ? View.VISIBLE : View.GONE);
|
||||||
|
accountSpinner.setVisibility(
|
||||||
|
accounts.length > 1 && type != ExportType.EXTERNAL_STORAGE ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
// Safely ignore
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an external storage option.
|
* Sets an external storage option.
|
||||||
*
|
*
|
||||||
@@ -232,44 +306,4 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
return TrackFileFormat.TCX;
|
return TrackFileFormat.TCX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the export type id from an export type.
|
|
||||||
*
|
|
||||||
* @param exportType the export type
|
|
||||||
*/
|
|
||||||
private int getExportTypeId(ExportType exportType) {
|
|
||||||
switch (exportType) {
|
|
||||||
case GOOGLE_DRIVE:
|
|
||||||
return R.id.export_google_drive;
|
|
||||||
case GOOGLE_MAPS:
|
|
||||||
return R.id.export_google_maps;
|
|
||||||
case GOOGLE_FUSION_TABLES:
|
|
||||||
return R.id.export_google_fusion_tables;
|
|
||||||
case GOOGLE_SPREADSHEET:
|
|
||||||
return R.id.export_google_spreadsheets;
|
|
||||||
default:
|
|
||||||
return R.id.export_external_storage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the export type from an export type id.
|
|
||||||
*
|
|
||||||
* @param exportTypeId the export type id
|
|
||||||
*/
|
|
||||||
private ExportType getExportType(int exportTypeId) {
|
|
||||||
switch (exportTypeId) {
|
|
||||||
case R.id.export_google_drive:
|
|
||||||
return ExportType.GOOGLE_DRIVE;
|
|
||||||
case R.id.export_google_maps:
|
|
||||||
return ExportType.GOOGLE_MAPS;
|
|
||||||
case R.id.export_google_fusion_tables:
|
|
||||||
return ExportType.GOOGLE_FUSION_TABLES;
|
|
||||||
case R.id.export_google_spreadsheets:
|
|
||||||
return ExportType.GOOGLE_SPREADSHEET;
|
|
||||||
default:
|
|
||||||
return ExportType.EXTERNAL_STORAGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-42
@@ -17,6 +17,7 @@
|
|||||||
package com.google.android.apps.mytracks.fragments;
|
package com.google.android.apps.mytracks.fragments;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
|
import com.google.android.apps.mytracks.util.AccountUtils;
|
||||||
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;
|
||||||
|
|
||||||
@@ -33,7 +34,6 @@ import android.provider.ContactsContract;
|
|||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.widget.SimpleCursorAdapter;
|
import android.support.v4.widget.SimpleCursorAdapter;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
@@ -59,11 +59,12 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
/**
|
/**
|
||||||
* Called when share track is done.
|
* Called when share track is done.
|
||||||
*
|
*
|
||||||
|
* @param trackId the track id
|
||||||
* @param makePublic true to make the track public
|
* @param makePublic true to make the track public
|
||||||
* @param emails the emails to share the track with
|
* @param emails the emails to share the track with
|
||||||
* @param account the google drive account
|
* @param account the google drive account
|
||||||
*/
|
*/
|
||||||
public void onShareTrackDone(boolean makePublic, String emails, Account account);
|
public void onShareTrackDone(long trackId, boolean makePublic, String emails, Account account);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String SHARE_TRACK_DIALOG_TAG = "shareTrackDialog";
|
public static final String SHARE_TRACK_DIALOG_TAG = "shareTrackDialog";
|
||||||
@@ -80,7 +81,6 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ShareTrackCaller caller;
|
private ShareTrackCaller caller;
|
||||||
private FragmentActivity fragmentActivity;
|
|
||||||
private Account[] accounts;
|
private Account[] accounts;
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
@@ -102,7 +102,7 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog createDialog() {
|
protected Dialog createDialog() {
|
||||||
fragmentActivity = getActivity();
|
FragmentActivity fragmentActivity = getActivity();
|
||||||
accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);
|
accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||||
|
|
||||||
if (accounts.length == 0) {
|
if (accounts.length == 0) {
|
||||||
@@ -137,7 +137,7 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
||||||
|
|
||||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity,
|
SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity,
|
||||||
R.layout.add_emails_item, getAutoCompleteCursor(null), new String[] {
|
R.layout.add_emails_item, getAutoCompleteCursor(fragmentActivity, null), new String[] {
|
||||||
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA },
|
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA },
|
||||||
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
|
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
|
||||||
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
|
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
|
||||||
@@ -150,41 +150,41 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
||||||
@Override
|
@Override
|
||||||
public Cursor runQuery(CharSequence constraint) {
|
public Cursor runQuery(CharSequence constraint) {
|
||||||
return getAutoCompleteCursor(constraint);
|
return getAutoCompleteCursor(getActivity(), constraint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
multiAutoCompleteTextView.setAdapter(adapter);
|
multiAutoCompleteTextView.setAdapter(adapter);
|
||||||
|
|
||||||
// Setup accountSpinner
|
// Setup accountSpinner
|
||||||
accountSpinner = (Spinner) view.findViewById(R.id.share_track_account);
|
accountSpinner = (Spinner) view.findViewById(R.id.share_track_account);
|
||||||
setupAccountSpinner(accountSpinner);
|
accountSpinner.setVisibility(accounts.length > 1 ? View.VISIBLE : View.GONE);
|
||||||
|
AccountUtils.setupAccountSpinner(fragmentActivity, accountSpinner, accounts);
|
||||||
|
|
||||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||||
R.string.generic_cancel, null)
|
R.string.generic_cancel, null)
|
||||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
FragmentActivity context = getActivity();
|
||||||
if (!publicCheckBox.isChecked() && !inviteCheckBox.isChecked()) {
|
if (!publicCheckBox.isChecked() && !inviteCheckBox.isChecked()) {
|
||||||
Toast.makeText(fragmentActivity, R.string.share_track_no_selection, Toast.LENGTH_LONG)
|
Toast.makeText(context, R.string.share_track_no_selection, Toast.LENGTH_LONG).show();
|
||||||
.show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String acl = multiAutoCompleteTextView.getText().toString().trim();
|
String acl = multiAutoCompleteTextView.getText().toString().trim();
|
||||||
if (!publicCheckBox.isChecked() && acl.equals("")) {
|
if (!publicCheckBox.isChecked() && acl.equals("")) {
|
||||||
Toast.makeText(fragmentActivity, R.string.share_track_no_emails, Toast.LENGTH_LONG)
|
Toast.makeText(context, R.string.share_track_no_emails, Toast.LENGTH_LONG).show();
|
||||||
.show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
PreferencesUtils.setBoolean(
|
||||||
|
context, R.string.share_track_public_key, publicCheckBox.isChecked());
|
||||||
|
PreferencesUtils.setBoolean(
|
||||||
|
context, R.string.share_track_invite_key, inviteCheckBox.isChecked());
|
||||||
Account account = accounts.length > 1 ? accounts[accountSpinner
|
Account account = accounts.length > 1 ? accounts[accountSpinner
|
||||||
.getSelectedItemPosition()]
|
.getSelectedItemPosition()]
|
||||||
: accounts[0];
|
: accounts[0];
|
||||||
PreferencesUtils.setBoolean(
|
AccountUtils.updateShareTrackAccountPreference(context, account);
|
||||||
fragmentActivity, R.string.share_track_public_key, publicCheckBox.isChecked());
|
caller.onShareTrackDone(
|
||||||
PreferencesUtils.setBoolean(
|
getArguments().getLong(KEY_TRACK_ID), publicCheckBox.isChecked(), acl, account);
|
||||||
fragmentActivity, R.string.share_track_invite_key, inviteCheckBox.isChecked());
|
|
||||||
PreferencesUtils.setString(
|
|
||||||
fragmentActivity, R.string.share_track_account_key, account.name);
|
|
||||||
caller.onShareTrackDone(publicCheckBox.isChecked(), acl, account);
|
|
||||||
}
|
}
|
||||||
}).setTitle(R.string.share_track_title).setView(view).create();
|
}).setTitle(R.string.share_track_title).setView(view).create();
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
*
|
*
|
||||||
* @param constraint the constraint
|
* @param constraint the constraint
|
||||||
*/
|
*/
|
||||||
private Cursor getAutoCompleteCursor(CharSequence constraint) {
|
private Cursor getAutoCompleteCursor(FragmentActivity fragmentActivity, CharSequence constraint) {
|
||||||
String order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
|
String order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
|
||||||
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
|
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
|
||||||
if (constraint != null) {
|
if (constraint != null) {
|
||||||
@@ -207,26 +207,4 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
|
Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
|
||||||
return fragmentActivity.getContentResolver().query(uri, projection, selection, null, order);
|
return fragmentActivity.getContentResolver().query(uri, projection, selection, null, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupAccountSpinner(Spinner spinner) {
|
|
||||||
boolean hasMultiple = accounts.length > 1;
|
|
||||||
spinner.setVisibility(hasMultiple ? View.VISIBLE : View.GONE);
|
|
||||||
if (hasMultiple) {
|
|
||||||
String shareTrackAccount = PreferencesUtils.getString(fragmentActivity,
|
|
||||||
R.string.share_track_account_key, PreferencesUtils.SHARE_TRACK_ACCOUNT_DEFAULT);
|
|
||||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
|
|
||||||
fragmentActivity, R.layout.account_spinner_item);
|
|
||||||
int selection = 0;
|
|
||||||
for (int i = 0; i < accounts.length; i++) {
|
|
||||||
String name = accounts[i].name;
|
|
||||||
adapter.add(name);
|
|
||||||
if (name.equals(shareTrackAccount)) {
|
|
||||||
selection = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
adapter.setDropDownViewResource(R.layout.account_spinner_dropdown_item);
|
|
||||||
spinner.setAdapter(adapter);
|
|
||||||
spinner.setSelection(selection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* 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.util;
|
||||||
|
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for account.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public class AccountUtils {
|
||||||
|
|
||||||
|
private AccountUtils() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up account spinner.
|
||||||
|
*
|
||||||
|
* @param fragmentActivity tyhe fragment activity
|
||||||
|
* @param spinner the spinner
|
||||||
|
* @param accounts the accounts
|
||||||
|
*/
|
||||||
|
public static void setupAccountSpinner(
|
||||||
|
FragmentActivity fragmentActivity, Spinner spinner, Account[] accounts) {
|
||||||
|
if (accounts.length > 1) {
|
||||||
|
String shareTrackAccount = PreferencesUtils.getString(fragmentActivity,
|
||||||
|
R.string.share_track_account_key, PreferencesUtils.SHARE_TRACK_ACCOUNT_DEFAULT);
|
||||||
|
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
|
||||||
|
fragmentActivity, R.layout.account_spinner_item);
|
||||||
|
int selection = 0;
|
||||||
|
for (int i = 0; i < accounts.length; i++) {
|
||||||
|
String name = accounts[i].name;
|
||||||
|
adapter.add(name);
|
||||||
|
if (name.equals(shareTrackAccount)) {
|
||||||
|
selection = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adapter.setDropDownViewResource(R.layout.account_spinner_dropdown_item);
|
||||||
|
spinner.setAdapter(adapter);
|
||||||
|
spinner.setSelection(selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the share track account preference.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param account the account
|
||||||
|
*/
|
||||||
|
public static void updateShareTrackAccountPreference(Context context, Account account) {
|
||||||
|
if (account != null) {
|
||||||
|
PreferencesUtils.setString(context, R.string.share_track_account_key, account.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user