forked from upstream-mirrors/OpenTracks
Modify the sharing flow to first show a list of applications.
Store preferred account as a sharing setting. Remove share url only option. Apply share url only if twitter is selected.
This commit is contained in:
@@ -22,6 +22,7 @@ import com.google.android.apps.mytracks.content.TrackDataHub;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.fragments.ChartFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
|
||||
import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
|
||||
@@ -212,15 +213,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
|
||||
menu.findItem(R.id.track_detail_save_tcx)
|
||||
.setTitle(getString(R.string.menu_save_format, fileTypes[3]));
|
||||
|
||||
menu.findItem(R.id.track_detail_share_gpx)
|
||||
.setTitle(getString(R.string.menu_share_file, fileTypes[0]));
|
||||
menu.findItem(R.id.track_detail_share_kml)
|
||||
.setTitle(getString(R.string.menu_share_file, fileTypes[1]));
|
||||
menu.findItem(R.id.track_detail_share_csv)
|
||||
.setTitle(getString(R.string.menu_share_file, fileTypes[2]));
|
||||
menu.findItem(R.id.track_detail_share_tcx)
|
||||
.setTitle(getString(R.string.menu_share_file, fileTypes[3]));
|
||||
|
||||
stopRecordingMenuItem = menu.findItem(R.id.track_detail_stop_recording);
|
||||
insertMarkerMenuItem = menu.findItem(R.id.track_detail_insert_marker);
|
||||
playMenuItem = menu.findItem(R.id.track_detail_play);
|
||||
@@ -276,27 +268,9 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
|
||||
getSupportFragmentManager(), InstallEarthDialogFragment.INSTALL_EARTH_DIALOG_TAG);
|
||||
}
|
||||
return true;
|
||||
case R.id.track_detail_share_map_url:
|
||||
intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, false, false));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_detail_share_fusion_table_url:
|
||||
intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, false, true, false));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_detail_share_gpx:
|
||||
startSaveActivity(TrackFileFormat.GPX, true);
|
||||
return true;
|
||||
case R.id.track_detail_share_kml:
|
||||
startSaveActivity(TrackFileFormat.KML, true);
|
||||
return true;
|
||||
case R.id.track_detail_share_csv:
|
||||
startSaveActivity(TrackFileFormat.CSV, true);
|
||||
return true;
|
||||
case R.id.track_detail_share_tcx:
|
||||
startSaveActivity(TrackFileFormat.TCX, true);
|
||||
case R.id.track_detail_share:
|
||||
ChooseActivityDialogFragment.newInstance(trackId, null).show(
|
||||
getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG);
|
||||
return true;
|
||||
case R.id.track_detail_markers:
|
||||
intent = IntentUtils.newIntent(this, MarkerListActivity.class)
|
||||
@@ -316,20 +290,20 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
|
||||
return true;
|
||||
case R.id.track_detail_send_google:
|
||||
intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId, true, true, true));
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_detail_save_gpx:
|
||||
startSaveActivity(TrackFileFormat.GPX, false);
|
||||
startSaveActivity(TrackFileFormat.GPX);
|
||||
return true;
|
||||
case R.id.track_detail_save_kml:
|
||||
startSaveActivity(TrackFileFormat.KML, false);
|
||||
startSaveActivity(TrackFileFormat.KML);
|
||||
return true;
|
||||
case R.id.track_detail_save_csv:
|
||||
startSaveActivity(TrackFileFormat.CSV, false);
|
||||
startSaveActivity(TrackFileFormat.CSV);
|
||||
return true;
|
||||
case R.id.track_detail_save_tcx:
|
||||
startSaveActivity(TrackFileFormat.TCX, false);
|
||||
startSaveActivity(TrackFileFormat.TCX);
|
||||
return true;
|
||||
case R.id.track_detail_edit:
|
||||
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
|
||||
@@ -480,13 +454,11 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
|
||||
* Starts the {@link SaveActivity} to save a track.
|
||||
*
|
||||
* @param trackFileFormat the track file format
|
||||
* @param shareTrack true to share the track after saving
|
||||
*/
|
||||
private void startSaveActivity(TrackFileFormat trackFileFormat, boolean shareTrack) {
|
||||
private void startSaveActivity(TrackFileFormat trackFileFormat) {
|
||||
Intent intent = IntentUtils.newIntent(this, SaveActivity.class)
|
||||
.putExtra(SaveActivity.EXTRA_TRACK_ID, trackId)
|
||||
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat)
|
||||
.putExtra(SaveActivity.EXTRA_SHARE_TRACK, shareTrack);
|
||||
.putExtra(SaveActivity.EXTRA_TRACK_FILE_FORMAT, (Parcelable) trackFileFormat);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,11 +132,11 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
return view;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
ViewGroup layout = (ViewGroup) getActivity().findViewById(R.id.chart_view_layout);
|
||||
@SuppressWarnings("deprecation")
|
||||
LayoutParams layoutParams = new LayoutParams(
|
||||
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
|
||||
layout.addView(chartView, layoutParams);
|
||||
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright 2012 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.fragments;
|
||||
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.AccountChooserActivity;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.ShareCompat;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A DialogFragment to choose an activity.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class ChooseActivityDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String CHOOSE_ACTIVITY_DIALOG_TAG = "chooseActivityDialog";
|
||||
|
||||
private static final String KEY_TRACK_ID = "trackId";
|
||||
private static final String KEY_TRACK_URL = "trackUrl";
|
||||
|
||||
private PackageManager packageManager;
|
||||
|
||||
public static ChooseActivityDialogFragment newInstance(long trackId, String trackUrl) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(KEY_TRACK_ID, trackId);
|
||||
bundle.putString(KEY_TRACK_URL, trackUrl);
|
||||
|
||||
ChooseActivityDialogFragment chooseActivityDialogFragment = new ChooseActivityDialogFragment();
|
||||
chooseActivityDialogFragment.setArguments(bundle);
|
||||
return chooseActivityDialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
packageManager = getActivity().getPackageManager();
|
||||
List<DisplayInfo> displayInfos = getDisplayInfos();
|
||||
|
||||
ArrayAdapter<DisplayInfo> arrayAdapter = new ArrayAdapter<DisplayInfo>(getActivity(),
|
||||
R.layout.choose_activity_list_item, R.id.choose_activity_list_item_text1, displayInfos) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view;
|
||||
if (convertView == null) {
|
||||
view = getActivity()
|
||||
.getLayoutInflater().inflate(R.layout.choose_activity_list_item, parent, false);
|
||||
} else {
|
||||
view = convertView;
|
||||
}
|
||||
DisplayInfo displayInfo = getItem(position);
|
||||
TextView text1 = (TextView) view.findViewById(R.id.choose_activity_list_item_text1);
|
||||
TextView text2 = (TextView) view.findViewById(R.id.choose_activity_list_item_text2);
|
||||
ImageView icon = (ImageView) view.findViewById(R.id.choose_activity_list_item_icon);
|
||||
text1.setText(displayInfo.primaryLabel);
|
||||
if (displayInfo.secondaryLabel != null) {
|
||||
text2.setVisibility(View.VISIBLE);
|
||||
text2.setText(displayInfo.secondaryLabel);
|
||||
} else {
|
||||
text2.setVisibility(View.GONE);
|
||||
}
|
||||
icon.setImageDrawable(displayInfo.icon);
|
||||
return view;
|
||||
}
|
||||
};
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setSingleChoiceItems(arrayAdapter, 0, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AlertDialog alertDialog = (AlertDialog) dialog;
|
||||
DisplayInfo displayInfo = (DisplayInfo) alertDialog.getListView()
|
||||
.getItemAtPosition(which);
|
||||
ActivityInfo activityInfo = displayInfo.resolveInfo.activityInfo;
|
||||
String packageName = activityInfo.applicationInfo.packageName;
|
||||
String className = activityInfo.name;
|
||||
|
||||
String trackUrl = getArguments().getString(KEY_TRACK_URL);
|
||||
if (trackUrl == null) {
|
||||
SendRequest sendRequest = new SendRequest(getArguments().getLong(KEY_TRACK_ID));
|
||||
sendRequest.setSendMaps(true);
|
||||
sendRequest.setNewMap(true);
|
||||
sendRequest.setSharingAppPackageName(packageName);
|
||||
sendRequest.setSharingAppClassName(className);
|
||||
Intent intent = IntentUtils.newIntent(getActivity(), AccountChooserActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
dismiss();
|
||||
} else {
|
||||
Intent intent = IntentUtils.newShareUrlIntent(
|
||||
getActivity(), trackUrl, packageName, className);
|
||||
startActivity(intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setTitle(R.string.share_track_picker_title)
|
||||
.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display info.
|
||||
*/
|
||||
private List<DisplayInfo> getDisplayInfos() {
|
||||
List<DisplayInfo> displayInfos = new ArrayList<DisplayInfo>();
|
||||
Intent intent = ShareCompat.IntentBuilder.from(getActivity())
|
||||
.setType(IntentUtils.TEXT_PLAIN_TYPE).getIntent();
|
||||
List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(
|
||||
intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
if (resolveInfos != null && resolveInfos.size() > 0) {
|
||||
int size = resolveInfos.size();
|
||||
ResolveInfo firstResolveInfo = resolveInfos.get(0);
|
||||
for (int i = 1; i < size; i++) {
|
||||
ResolveInfo resolveInfo = resolveInfos.get(i);
|
||||
if (firstResolveInfo.priority != resolveInfo.priority
|
||||
|| firstResolveInfo.isDefault != resolveInfo.isDefault) {
|
||||
while (i < size) {
|
||||
resolveInfos.remove(i);
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (size > 1) {
|
||||
ResolveInfo.DisplayNameComparator displayNameComparator = new ResolveInfo.DisplayNameComparator(
|
||||
packageManager);
|
||||
Collections.sort(resolveInfos, displayNameComparator);
|
||||
}
|
||||
|
||||
firstResolveInfo = resolveInfos.get(0);
|
||||
int start = 0;
|
||||
CharSequence firstLabel = firstResolveInfo.loadLabel(packageManager);
|
||||
for (int i = 1; i < size; i++) {
|
||||
if (firstLabel == null) {
|
||||
firstLabel = firstResolveInfo.activityInfo.packageName;
|
||||
}
|
||||
ResolveInfo resolveInfo = resolveInfos.get(i);
|
||||
CharSequence label = resolveInfo.loadLabel(packageManager);
|
||||
if (label == null) {
|
||||
label = resolveInfo.activityInfo.packageName;
|
||||
}
|
||||
if (label.equals(firstLabel)) {
|
||||
continue;
|
||||
}
|
||||
processGroup(resolveInfos, displayInfos, start, i - 1);
|
||||
firstResolveInfo = resolveInfo;
|
||||
firstLabel = label;
|
||||
start = i;
|
||||
}
|
||||
// Process last group
|
||||
processGroup(resolveInfos, displayInfos, start, size - 1);
|
||||
}
|
||||
return displayInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains display info.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
private final class DisplayInfo {
|
||||
private ResolveInfo resolveInfo;
|
||||
private CharSequence primaryLabel;
|
||||
private CharSequence secondaryLabel;
|
||||
private Drawable icon;
|
||||
|
||||
public DisplayInfo(ResolveInfo resolveInfo, CharSequence primaryLabel,
|
||||
CharSequence secondaryLabel, Drawable icon) {
|
||||
this.resolveInfo = resolveInfo;
|
||||
this.primaryLabel = primaryLabel;
|
||||
this.secondaryLabel = secondaryLabel;
|
||||
this.icon = icon;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a group of items with the same label.
|
||||
*
|
||||
* @param resolveInfos list of resolve infos
|
||||
* @param displayInfos list of display infos
|
||||
* @param start start index
|
||||
* @param end end index
|
||||
*/
|
||||
private void processGroup(
|
||||
List<ResolveInfo> resolveInfos, List<DisplayInfo> displayInfos, int start, int end) {
|
||||
ResolveInfo startResolveInfo = resolveInfos.get(start);
|
||||
CharSequence primaryLabel = startResolveInfo.loadLabel(packageManager);
|
||||
Drawable icon = startResolveInfo.loadIcon(packageManager);
|
||||
|
||||
int num = end - start + 1;
|
||||
if (num == 1) {
|
||||
// Only one, set the secondary label to null
|
||||
displayInfos.add(new DisplayInfo(startResolveInfo, primaryLabel, null, icon));
|
||||
} else {
|
||||
// Decide package name or application name for the secondary label
|
||||
boolean usePackageName = false;
|
||||
CharSequence appName = startResolveInfo.activityInfo.applicationInfo.loadLabel(
|
||||
packageManager);
|
||||
if (appName == null) {
|
||||
usePackageName = true;
|
||||
} else {
|
||||
// Use HashSet to track duplicates
|
||||
HashSet<CharSequence> duplicates = new HashSet<CharSequence>();
|
||||
duplicates.add(appName);
|
||||
for (int i = start + 1; i <= end; i++) {
|
||||
ResolveInfo resolveInfo = resolveInfos.get(i);
|
||||
CharSequence name = resolveInfo.activityInfo.applicationInfo.loadLabel(packageManager);
|
||||
if ((name == null) || (duplicates.contains(name))) {
|
||||
usePackageName = true;
|
||||
break;
|
||||
} else {
|
||||
duplicates.add(name);
|
||||
}
|
||||
}
|
||||
// Clear HashSet for later use
|
||||
duplicates.clear();
|
||||
}
|
||||
for (int i = start; i <= end; i++) {
|
||||
ResolveInfo resolveInfo = resolveInfos.get(i);
|
||||
CharSequence secondaryLabel = usePackageName ? resolveInfo.activityInfo.packageName
|
||||
: resolveInfo.activityInfo.applicationInfo.loadLabel(packageManager);
|
||||
displayInfos.add(new DisplayInfo(resolveInfo, primaryLabel, secondaryLabel, icon));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -80,9 +80,6 @@ public abstract class AbstractSendAsyncTask extends AsyncTask<Void, Integer, Boo
|
||||
return performTask();
|
||||
} finally {
|
||||
closeConnection();
|
||||
if (success) {
|
||||
saveResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +94,9 @@ public abstract class AbstractSendAsyncTask extends AsyncTask<Void, Integer, Boo
|
||||
protected void onPostExecute(Boolean result) {
|
||||
success = result;
|
||||
completed = true;
|
||||
if (success) {
|
||||
saveResult();
|
||||
}
|
||||
if (activity != null) {
|
||||
activity.onAsyncTaskCompleted(success);
|
||||
}
|
||||
|
||||
+11
-18
@@ -76,7 +76,6 @@ public class AccountChooserActivity extends Activity {
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private Account[] accounts;
|
||||
private int selectedAccountIndex;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -91,19 +90,18 @@ public class AccountChooserActivity extends Activity {
|
||||
|
||||
if (accounts.length == 1) {
|
||||
sendRequest.setAccount(accounts[0]);
|
||||
PreferencesUtils.setString(this, R.string.preferred_account_key, accounts[0].name);
|
||||
PreferencesUtils.setString(this, R.string.sharing_account_key, accounts[0].name);
|
||||
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||
return;
|
||||
}
|
||||
|
||||
String preferredAccount = PreferencesUtils.getString(this, R.string.preferred_account_key,
|
||||
PreferencesUtils.PREFERRED_ACCOUNT_DEFAULT);
|
||||
|
||||
selectedAccountIndex = 0;
|
||||
String sharingAccount = PreferencesUtils.getString(this, R.string.sharing_account_key,
|
||||
PreferencesUtils.SHARING_ACCOUNT_DEFAULT);
|
||||
for (int i = 0; i < accounts.length; i++) {
|
||||
if (accounts[i].name.equals(preferredAccount)) {
|
||||
selectedAccountIndex = i;
|
||||
break;
|
||||
if (accounts[i].name.equals(sharingAccount)) {
|
||||
sendRequest.setAccount(accounts[i]);
|
||||
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
showDialog(DIALOG_CHOOSER_ID);
|
||||
@@ -159,20 +157,15 @@ public class AccountChooserActivity extends Activity {
|
||||
})
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Account account = accounts[selectedAccountIndex];
|
||||
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
|
||||
Account account = accounts[position];
|
||||
PreferencesUtils.setString(
|
||||
AccountChooserActivity.this, R.string.preferred_account_key, account.name);
|
||||
AccountChooserActivity.this, R.string.sharing_account_key, account.name);
|
||||
sendRequest.setAccount(account);
|
||||
getPermission(MapsConstants.SERVICE_NAME, sendRequest.isSendMaps(), mapsCallback);
|
||||
}
|
||||
})
|
||||
.setSingleChoiceItems(
|
||||
choices, selectedAccountIndex, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
selectedAccountIndex = which;
|
||||
}
|
||||
})
|
||||
.setSingleChoiceItems(choices, 0, null)
|
||||
.setTitle(R.string.send_google_choose_account_title)
|
||||
.create();
|
||||
}
|
||||
|
||||
@@ -31,9 +31,8 @@ public class SendRequest implements Parcelable {
|
||||
public static final String SEND_REQUEST_KEY = "sendRequest";
|
||||
|
||||
private long trackId = -1L;
|
||||
private boolean showMaps = false;
|
||||
private boolean showFusionTables = false;
|
||||
private boolean showDocs = false;
|
||||
private String sharingAppPackageName = null;
|
||||
private String sharingAppClassName = null;
|
||||
private boolean sendMaps = false;
|
||||
private boolean sendFusionTables = false;
|
||||
private boolean sendDocs = false;
|
||||
@@ -48,15 +47,9 @@ public class SendRequest implements Parcelable {
|
||||
* Creates a new send request.
|
||||
*
|
||||
* @param trackId the track id
|
||||
* @param showMaps true to show the Google Maps option
|
||||
* @param showFusionTables true to show the Google Fusion Tables option
|
||||
* @param showDocs true to show the Google Docs option
|
||||
*/
|
||||
public SendRequest(long trackId, boolean showMaps, boolean showFusionTables, boolean showDocs) {
|
||||
public SendRequest(long trackId) {
|
||||
this.trackId = trackId;
|
||||
this.showMaps = showMaps;
|
||||
this.showFusionTables = showFusionTables;
|
||||
this.showDocs = showDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,31 +60,35 @@ public class SendRequest implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing the send to Google Maps option.
|
||||
* Gets the sharing app package name.
|
||||
*/
|
||||
public boolean isShowMaps() {
|
||||
return showMaps;
|
||||
public String getSharingAppPackageName() {
|
||||
return sharingAppPackageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing the send to Google Fusion Tables option.
|
||||
* Sets the sharing app package name.
|
||||
*
|
||||
* @param sharingAppPackageName the sharing app package name
|
||||
*/
|
||||
public boolean isShowFusionTables() {
|
||||
return showFusionTables;
|
||||
public void setSharingAppPackageName(String sharingAppPackageName) {
|
||||
this.sharingAppPackageName = sharingAppPackageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing the send to Google Docs option.
|
||||
* Gets the sharing app class name.
|
||||
*/
|
||||
public boolean isShowDocs() {
|
||||
return showDocs;
|
||||
public String getSharingAppClassName() {
|
||||
return sharingAppClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if showing all the send options.
|
||||
* Sets the sharing app class name.
|
||||
*
|
||||
* @param sharingAppClassName the sharing app class name
|
||||
*/
|
||||
public boolean isShowAll() {
|
||||
return showMaps && showFusionTables && showDocs;
|
||||
public void setSharingAppClassName(String sharingAppClassName) {
|
||||
this.sharingAppClassName = sharingAppClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,9 +242,8 @@ public class SendRequest implements Parcelable {
|
||||
|
||||
private SendRequest(Parcel in) {
|
||||
trackId = in.readLong();
|
||||
showMaps = in.readByte() == 1;
|
||||
showFusionTables = in.readByte() == 1;
|
||||
showDocs = in.readByte() == 1;
|
||||
sharingAppPackageName = in.readString();
|
||||
sharingAppClassName = in.readString();
|
||||
sendMaps = in.readByte() == 1;
|
||||
sendFusionTables = in.readByte() == 1;
|
||||
sendDocs = in.readByte() == 1;
|
||||
@@ -267,9 +263,8 @@ public class SendRequest implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeLong(trackId);
|
||||
out.writeByte((byte) (showMaps ? 1 : 0));
|
||||
out.writeByte((byte) (showFusionTables ? 1 : 0));
|
||||
out.writeByte((byte) (showDocs ? 1 : 0));
|
||||
out.writeString(sharingAppPackageName);
|
||||
out.writeString(sharingAppClassName);
|
||||
out.writeByte((byte) (sendMaps ? 1 : 0));
|
||||
out.writeByte((byte) (sendFusionTables ? 1 : 0));
|
||||
out.writeByte((byte) (sendDocs ? 1 : 0));
|
||||
|
||||
+25
-41
@@ -17,18 +17,19 @@ package com.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment;
|
||||
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils;
|
||||
import com.google.android.apps.mytracks.io.maps.SendMapsUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -36,33 +37,40 @@ import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* A dialog to show the result of uploading to Google services.
|
||||
*
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class UploadResultActivity extends Activity {
|
||||
public class UploadResultActivity extends FragmentActivity {
|
||||
|
||||
private static final String TEXT_PLAIN_TYPE = "text/plain";
|
||||
private static final int DIALOG_RESULT_ID = 0;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private Track track;
|
||||
private String shareUrl;
|
||||
private Dialog resultDialog;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
track = null;
|
||||
shareUrl = null;
|
||||
|
||||
|
||||
if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) {
|
||||
shareUrl = SendMapsUtils.getMapUrl(getTrack());
|
||||
if (sendRequest.getSharingAppPackageName() != null) {
|
||||
Intent intent = IntentUtils.newShareUrlIntent(this, shareUrl,
|
||||
sendRequest.getSharingAppPackageName(), sendRequest.getSharingAppClassName());
|
||||
startActivity(intent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (shareUrl == null && sendRequest.isSendFusionTables()
|
||||
&& sendRequest.isFusionTablesSuccess()) {
|
||||
shareUrl = SendFusionTablesUtils.getMapUrl(getTrack());
|
||||
}
|
||||
showDialog(DIALOG_RESULT_ID);
|
||||
}
|
||||
|
||||
private Track getTrack() {
|
||||
@@ -72,17 +80,11 @@ public class UploadResultActivity extends Activity {
|
||||
return track;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
showDialog(DIALOG_RESULT_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
if (id != DIALOG_RESULT_ID) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
View view = getLayoutInflater().inflate(R.layout.upload_result, null);
|
||||
|
||||
LinearLayout mapsResult = (LinearLayout) view.findViewById(R.id.upload_result_maps_result);
|
||||
@@ -139,31 +141,29 @@ public class UploadResultActivity extends Activity {
|
||||
.setCancelable(true)
|
||||
.setIcon(hasError ? android.R.drawable.ic_dialog_alert : android.R.drawable.ic_dialog_info)
|
||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (!sendRequest.isShowAll() && shareUrl != null) {
|
||||
startShareUrlActivity(shareUrl);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setTitle(hasError ? R.string.generic_error_title : R.string.generic_success_title)
|
||||
.setView(view);
|
||||
|
||||
// Add a Share URL button if showing all the options and a shareUrl exists
|
||||
if (sendRequest.isShowAll() && shareUrl != null) {
|
||||
// Add a Share URL button if shareUrl exists
|
||||
if (shareUrl != null) {
|
||||
builder.setNegativeButton(
|
||||
R.string.send_google_result_share_url, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
R.string.share_track_share_url, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
startShareUrlActivity(shareUrl);
|
||||
finish();
|
||||
ChooseActivityDialogFragment.newInstance(sendRequest.getTrackId(), shareUrl).show(
|
||||
getSupportFragmentManager(),
|
||||
ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -171,22 +171,6 @@ public class UploadResultActivity extends Activity {
|
||||
return resultDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an activity to share the url.
|
||||
*
|
||||
* @param url the url
|
||||
*/
|
||||
private void startShareUrlActivity(String url) {
|
||||
boolean shareUrlOnly = PreferencesUtils.getBoolean(
|
||||
this, R.string.share_url_only_key, PreferencesUtils.SHARE_URL_ONLY_DEFAULT);
|
||||
Intent intent = new Intent(Intent.ACTION_SEND)
|
||||
.setType(TEXT_PLAIN_TYPE)
|
||||
.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_track_subject))
|
||||
.putExtra(Intent.EXTRA_TEXT,
|
||||
shareUrlOnly ? url : getString(R.string.share_track_url_body_format, url));
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Dialog getDialog() {
|
||||
return resultDialog;
|
||||
|
||||
+6
-37
@@ -49,10 +49,6 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
private SendRequest sendRequest;
|
||||
private AlertDialog alertDialog;
|
||||
|
||||
private TableRow mapsTableRow;
|
||||
private TableRow fusionTablesTableRow;
|
||||
private TableRow docsTableRow;
|
||||
|
||||
private CheckBox mapsCheckBox;
|
||||
private CheckBox fusionTablesCheckBox;
|
||||
private CheckBox docsCheckBox;
|
||||
@@ -80,10 +76,6 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
}
|
||||
View view = getLayoutInflater().inflate(R.layout.upload_service_chooser, null);
|
||||
|
||||
mapsTableRow = (TableRow) view.findViewById(R.id.send_google_maps_row);
|
||||
fusionTablesTableRow = (TableRow) view.findViewById(R.id.send_google_fusion_tables_row);
|
||||
docsTableRow = (TableRow) view.findViewById(R.id.send_google_docs_row);
|
||||
|
||||
mapsCheckBox = (CheckBox) view.findViewById(R.id.send_google_maps);
|
||||
fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.send_google_fusion_tables);
|
||||
docsCheckBox = (CheckBox) view.findViewById(R.id.send_google_docs);
|
||||
@@ -105,9 +97,6 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
// Setup initial state
|
||||
initState();
|
||||
|
||||
// Update state based on sendRequest
|
||||
updateStateBySendRequest();
|
||||
|
||||
// Update state based on current selection
|
||||
updateStateBySelection();
|
||||
|
||||
@@ -163,24 +152,6 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
this, R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI state based on sendRequest.
|
||||
*/
|
||||
private void updateStateBySendRequest() {
|
||||
if (!sendRequest.isShowAll()) {
|
||||
if (sendRequest.isShowMaps()) {
|
||||
mapsCheckBox.setChecked(true);
|
||||
} else if (sendRequest.isShowFusionTables()) {
|
||||
fusionTablesCheckBox.setChecked(true);
|
||||
} else if (sendRequest.isShowDocs()) {
|
||||
docsCheckBox.setChecked(true);
|
||||
}
|
||||
}
|
||||
mapsTableRow.setVisibility(sendRequest.isShowMaps() ? View.VISIBLE : View.GONE);
|
||||
fusionTablesTableRow.setVisibility(sendRequest.isShowFusionTables() ? View.VISIBLE : View.GONE);
|
||||
docsTableRow.setVisibility(sendRequest.isShowDocs() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI state based on the current selection.
|
||||
*/
|
||||
@@ -195,32 +166,30 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
void saveState() {
|
||||
PreferencesUtils.setBoolean(
|
||||
this, R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
|
||||
if (sendRequest.isShowAll()) {
|
||||
PreferencesUtils.setBoolean(this, R.string.send_to_maps_key, sendMaps());
|
||||
PreferencesUtils.setBoolean(this, R.string.send_to_fusion_tables_key, sendFusionTables());
|
||||
PreferencesUtils.setBoolean(this, R.string.send_to_docs_key, sendDocs());
|
||||
}
|
||||
PreferencesUtils.setBoolean(this, R.string.send_to_maps_key, sendMaps());
|
||||
PreferencesUtils.setBoolean(this, R.string.send_to_fusion_tables_key, sendFusionTables());
|
||||
PreferencesUtils.setBoolean(this, R.string.send_to_docs_key, sendDocs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to send to Google Maps.
|
||||
*/
|
||||
private boolean sendMaps() {
|
||||
return sendRequest.isShowMaps() && mapsCheckBox.isChecked();
|
||||
return mapsCheckBox.isChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to send to Google Fusion Tables.
|
||||
*/
|
||||
private boolean sendFusionTables() {
|
||||
return sendRequest.isShowFusionTables() && fusionTablesCheckBox.isChecked();
|
||||
return fusionTablesCheckBox.isChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true to send to Google Docs.
|
||||
*/
|
||||
private boolean sendDocs() {
|
||||
return sendRequest.isShowDocs() && docsCheckBox.isChecked();
|
||||
return docsCheckBox.isChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -36,13 +36,13 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
||||
|
||||
private BackupPreferencesListener backupPreferencesListener;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
||||
ApiAdapterFactory.getApiAdapter().configureActionBarHomeAsUp(this);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
PreferenceManager preferenceManager = getPreferenceManager();
|
||||
preferenceManager.setSharedPreferencesName(Constants.SETTINGS_NAME);
|
||||
preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);
|
||||
@@ -63,10 +63,10 @@ public class AbstractSettingsActivity extends PreferenceActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
@SuppressWarnings("deprecation")
|
||||
PreferenceManager preferenceManager = getPreferenceManager();
|
||||
preferenceManager.getSharedPreferences()
|
||||
.unregisterOnSharedPreferenceChangeListener(backupPreferencesListener);
|
||||
|
||||
@@ -120,8 +120,8 @@ public class SensorSettingsActivity extends AbstractSettingsActivity {
|
||||
/**
|
||||
* Updates the bluetooth sensor list preference.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateBluetoothSensorListPreference() {
|
||||
@SuppressWarnings("deprecation")
|
||||
ListPreference bluetoothSensorListPreference = (ListPreference) findPreference(
|
||||
getString(R.string.bluetooth_sensor_key));
|
||||
List<String> entries = new ArrayList<String>();
|
||||
|
||||
@@ -16,16 +16,23 @@
|
||||
|
||||
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.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.
|
||||
*
|
||||
@@ -56,6 +63,21 @@ 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
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
@@ -26,6 +29,9 @@ import android.content.Intent;
|
||||
*/
|
||||
public class IntentUtils {
|
||||
|
||||
public static final String TEXT_PLAIN_TYPE = "text/plain";
|
||||
private static final String TWITTER_PACKAGE_NAME = "com.twitter.android";
|
||||
|
||||
private IntentUtils() {}
|
||||
|
||||
/**
|
||||
@@ -39,4 +45,23 @@ public class IntentUtils {
|
||||
return new Intent(context, cls).addFlags(
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an intent to share a url with a sharing app.
|
||||
*
|
||||
* @param context the context
|
||||
* @param url the url
|
||||
* @param packageName the sharing app package name
|
||||
* @param className the sharing app class name
|
||||
*/
|
||||
public static final Intent newShareUrlIntent(
|
||||
Context context, String url, String packageName, String className) {
|
||||
return new Intent(Intent.ACTION_SEND)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP)
|
||||
.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share_track_subject))
|
||||
.putExtra(Intent.EXTRA_TEXT, TWITTER_PACKAGE_NAME.equals(packageName)
|
||||
? url : context.getString(R.string.share_track_url_body_format, url))
|
||||
.setComponent(new ComponentName(packageName, className))
|
||||
.setType(TEXT_PLAIN_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,14 +66,13 @@ public class PreferencesUtils {
|
||||
public static final int MIN_REQUIRED_ACCURACY_POOR = 5000;
|
||||
|
||||
public static final boolean PICK_EXISTING_MAP_DEFAULT = false;
|
||||
public static final String PREFERRED_ACCOUNT_DEFAULT = "";
|
||||
public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
|
||||
public static final boolean REPORT_SPEED_DEFAULT = true;
|
||||
public static final long SELECTED_TRACK_ID_DEFAULT = -1L;
|
||||
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 boolean SHARE_URL_ONLY_DEFAULT = false;
|
||||
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