mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
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"
|
||||
style="@style/ScrollView" >
|
||||
<RadioGroup
|
||||
android:id="@+id/export_type_options"
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp" >
|
||||
<RadioButton
|
||||
android:id="@+id/export_google_drive"
|
||||
android:text="@string/export_google_drive"
|
||||
style="@style/TextMedium" />
|
||||
<RadioButton
|
||||
android:id="@+id/export_google_maps"
|
||||
android:text="@string/export_google_maps"
|
||||
style="@style/TextMedium" />
|
||||
<Spinner
|
||||
android:id="@+id/export_type_options"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent" />
|
||||
<RadioGroup
|
||||
android:id="@+id/export_google_maps_options"
|
||||
style="@style/ExportRadioGroup" >
|
||||
@@ -41,10 +37,6 @@ limitations under the License.
|
||||
android:text="@string/export_google_maps_unlisted"
|
||||
style="@style/TextMedium" />
|
||||
</RadioGroup>
|
||||
<RadioButton
|
||||
android:id="@+id/export_google_fusion_tables"
|
||||
android:text="@string/export_google_fusion_tables"
|
||||
style="@style/TextMedium" />
|
||||
<RadioGroup
|
||||
android:id="@+id/export_google_fusion_tables_options"
|
||||
style="@style/ExportRadioGroup" >
|
||||
@@ -57,14 +49,6 @@ limitations under the License.
|
||||
android:text="@string/export_google_fusion_tables_private"
|
||||
style="@style/TextMedium" />
|
||||
</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
|
||||
android:id="@+id/export_external_storage_options"
|
||||
style="@style/ExportRadioGroup" >
|
||||
@@ -81,5 +65,10 @@ limitations under the License.
|
||||
android:id="@+id/export_external_storage_tcx"
|
||||
style="@style/TextMedium" />
|
||||
</RadioGroup>
|
||||
</RadioGroup>
|
||||
<Spinner
|
||||
android:id="@+id/export_account"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_width="wrap_content" />
|
||||
</LinearLayout>
|
||||
</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.ConfirmSyncDialogFragment;
|
||||
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.ShareTrackDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment.ShareTrackCaller;
|
||||
@@ -158,20 +159,45 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
*/
|
||||
protected void shareTrack(long trackId) {
|
||||
AnalyticsUtils.sendPageViews(this, AnalyticsUtils.ACTION_SHARE_DRIVE);
|
||||
sendRequest = new SendRequest(trackId);
|
||||
sendRequest.setSendDrive(true);
|
||||
ShareTrackDialogFragment.newInstance(sendRequest.getTrackId())
|
||||
ShareTrackDialogFragment.newInstance(trackId)
|
||||
.show(getSupportFragmentManager(), ShareTrackDialogFragment.SHARE_TRACK_DIALOG_TAG);
|
||||
}
|
||||
|
||||
@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.setDriveShareEmails(emails);
|
||||
sendRequest.setAccount(account);
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -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.io.file.TrackFileFormat;
|
||||
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.settings.SettingsActivity;
|
||||
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.maps.mytracks.R;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -486,36 +486,17 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExportDone(ExportType exportType, TrackFileFormat trackFileFormat) {
|
||||
public void onExportDone(
|
||||
ExportType exportType, TrackFileFormat trackFileFormat, Account account) {
|
||||
if (exportType == ExportType.EXTERNAL_STORAGE) {
|
||||
AnalyticsUtils.sendPageViews(this,
|
||||
AnalyticsUtils.ACTION_EXPORT_PREFIX + trackFileFormat.getExtension());
|
||||
AnalyticsUtils.sendPageViews(
|
||||
this, AnalyticsUtils.ACTION_EXPORT_PREFIX + trackFileFormat.getExtension());
|
||||
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
|
||||
.putExtra(SaveActivity.EXTRA_TRACK_IDS, new long[] { trackId })
|
||||
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
SendRequest 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);
|
||||
sendToGoogle(sendRequest);
|
||||
exportTrackToGoogle(trackId, exportType, account);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+113
-79
@@ -16,11 +16,15 @@
|
||||
|
||||
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.util.AccountUtils;
|
||||
import com.google.android.apps.mytracks.util.FileUtils;
|
||||
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.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@@ -28,9 +32,13 @@ import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.RadioGroup.OnCheckedChangeListener;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A DialogFragment to export a track.
|
||||
@@ -45,7 +53,16 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @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";
|
||||
@@ -75,10 +97,15 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
}
|
||||
|
||||
private ExportCaller caller;
|
||||
private RadioGroup exportTypeOptions;
|
||||
private Account[] accounts;
|
||||
private ArrayList<ExportType> exportTypeOptionsList;
|
||||
|
||||
// UI elements
|
||||
private Spinner exportTypeOptions;
|
||||
private RadioGroup exportGoogleMapsOptions;
|
||||
private RadioGroup exportGoogleFusionTablesOptions;
|
||||
private RadioGroup exportExternalStorageOptions;
|
||||
private Spinner accountSpinner;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
@@ -94,48 +121,28 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
@Override
|
||||
protected Dialog createDialog() {
|
||||
FragmentActivity fragmentActivity = getActivity();
|
||||
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;
|
||||
}
|
||||
accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
|
||||
// Get views
|
||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.export, null);
|
||||
exportTypeOptions = (RadioGroup) view.findViewById(R.id.export_type_options);
|
||||
RadioButton exportGoogleDrive = (RadioButton) view.findViewById(R.id.export_google_drive);
|
||||
exportTypeOptions = (Spinner) view.findViewById(R.id.export_type_options);
|
||||
exportGoogleMapsOptions = (RadioGroup) view.findViewById(R.id.export_google_maps_options);
|
||||
exportGoogleFusionTablesOptions = (RadioGroup) view.findViewById(
|
||||
R.id.export_google_fusion_tables_options);
|
||||
exportExternalStorageOptions = (RadioGroup) view.findViewById(
|
||||
R.id.export_external_storage_options);
|
||||
accountSpinner = (Spinner) view.findViewById(R.id.export_account);
|
||||
|
||||
// Setup exportTypeOptions
|
||||
setupExportTypeOptions(fragmentActivity);
|
||||
|
||||
// exportTypeOptions
|
||||
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
|
||||
// Setup exportGoogleMapsOptions
|
||||
boolean exportGoogleMapsPublic = PreferencesUtils.getBoolean(fragmentActivity,
|
||||
R.string.export_google_maps_public_key, PreferencesUtils.EXPORT_GOOGLE_MAPS_PUBLIC_DEFAULT);
|
||||
exportGoogleMapsOptions.check(
|
||||
exportGoogleMapsPublic ? R.id.export_google_maps_public : R.id.export_google_maps_unlisted);
|
||||
|
||||
// exportGoogleFusionTablesOptions
|
||||
// Setup exportGoogleFusionTablesOptions
|
||||
boolean exportGoogleFusionTablesPublic = PreferencesUtils.getBoolean(fragmentActivity,
|
||||
R.string.export_google_fusion_tables_public_key,
|
||||
PreferencesUtils.EXPORT_GOOGLE_FUSION_TABLES_PUBLIC_DEFAULT);
|
||||
@@ -143,7 +150,7 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
exportGoogleFusionTablesPublic ? R.id.export_google_fusion_tables_public
|
||||
: R.id.export_google_fusion_tables_private);
|
||||
|
||||
// exportExternalStorageOptions
|
||||
// Setup exportExternalStorageOptions
|
||||
setExternalStorageOption(
|
||||
(RadioButton) view.findViewById(R.id.export_external_storage_kml), TrackFileFormat.KML);
|
||||
setExternalStorageOption(
|
||||
@@ -157,35 +164,102 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
PreferencesUtils.EXPORT_EXTERNAL_STORAGE_FORMAT_DEFAULT));
|
||||
exportExternalStorageOptions.check(getExternalStorageFormatId(trackFileFormat));
|
||||
|
||||
// Setup accountSpinner
|
||||
AccountUtils.setupAccountSpinner(fragmentActivity, accountSpinner, accounts);
|
||||
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||
R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.menu_export, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FragmentActivity context = getActivity();
|
||||
int id = exportTypeOptions.getCheckedRadioButtonId();
|
||||
ExportType type = getExportType(id);
|
||||
ExportType type = exportTypeOptionsList.get(
|
||||
exportTypeOptions.getSelectedItemPosition());
|
||||
TrackFileFormat format = null;
|
||||
|
||||
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,
|
||||
exportGoogleMapsOptions.getCheckedRadioButtonId()
|
||||
== 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,
|
||||
exportGoogleFusionTablesOptions.getCheckedRadioButtonId()
|
||||
== 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());
|
||||
PreferencesUtils.setString(
|
||||
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();
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
@@ -232,44 +306,4 @@ public class ExportDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
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;
|
||||
|
||||
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.maps.mytracks.R;
|
||||
|
||||
@@ -33,7 +34,6 @@ import android.provider.ContactsContract;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.widget.SimpleCursorAdapter;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
@@ -59,11 +59,12 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
/**
|
||||
* Called when share track is done.
|
||||
*
|
||||
* @param trackId the track id
|
||||
* @param makePublic true to make the track public
|
||||
* @param emails the emails to share the track with
|
||||
* @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";
|
||||
@@ -80,7 +81,6 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
}
|
||||
|
||||
private ShareTrackCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
private Account[] accounts;
|
||||
|
||||
// UI elements
|
||||
@@ -102,7 +102,7 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
|
||||
@Override
|
||||
protected Dialog createDialog() {
|
||||
fragmentActivity = getActivity();
|
||||
FragmentActivity fragmentActivity = getActivity();
|
||||
accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
|
||||
if (accounts.length == 0) {
|
||||
@@ -137,7 +137,7 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
||||
|
||||
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 },
|
||||
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
|
||||
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
|
||||
@@ -150,41 +150,41 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
||||
@Override
|
||||
public Cursor runQuery(CharSequence constraint) {
|
||||
return getAutoCompleteCursor(constraint);
|
||||
return getAutoCompleteCursor(getActivity(), constraint);
|
||||
}
|
||||
});
|
||||
multiAutoCompleteTextView.setAdapter(adapter);
|
||||
|
||||
// Setup accountSpinner
|
||||
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(
|
||||
R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FragmentActivity context = getActivity();
|
||||
if (!publicCheckBox.isChecked() && !inviteCheckBox.isChecked()) {
|
||||
Toast.makeText(fragmentActivity, R.string.share_track_no_selection, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
Toast.makeText(context, R.string.share_track_no_selection, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
String acl = multiAutoCompleteTextView.getText().toString().trim();
|
||||
if (!publicCheckBox.isChecked() && acl.equals("")) {
|
||||
Toast.makeText(fragmentActivity, R.string.share_track_no_emails, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
Toast.makeText(context, R.string.share_track_no_emails, Toast.LENGTH_LONG).show();
|
||||
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
|
||||
.getSelectedItemPosition()]
|
||||
: accounts[0];
|
||||
PreferencesUtils.setBoolean(
|
||||
fragmentActivity, R.string.share_track_public_key, publicCheckBox.isChecked());
|
||||
PreferencesUtils.setBoolean(
|
||||
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);
|
||||
AccountUtils.updateShareTrackAccountPreference(context, account);
|
||||
caller.onShareTrackDone(
|
||||
getArguments().getLong(KEY_TRACK_ID), publicCheckBox.isChecked(), acl, account);
|
||||
}
|
||||
}).setTitle(R.string.share_track_title).setView(view).create();
|
||||
}
|
||||
@@ -194,7 +194,7 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
*
|
||||
* @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 selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
|
||||
if (constraint != null) {
|
||||
@@ -207,26 +207,4 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
|
||||
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