forked from upstream-mirrors/OpenTracks
Use a DialogFragment for ChooseUploadService.
This commit is contained in:
@@ -205,7 +205,6 @@ limitations under the License.
|
|||||||
<activity android:name="com.google.android.apps.mytracks.io.maps.SendMapsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.io.maps.SendMapsActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.AccountChooserActivity" />
|
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.AccountChooserActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
|
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActivity" />
|
|
||||||
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.settings.ChartSettingsActivity" />
|
||||||
<activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" />
|
<activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" />
|
||||||
|
|||||||
+12
-12
@@ -25,24 +25,24 @@ limitations under the License.
|
|||||||
<ImageView
|
<ImageView
|
||||||
android:contentDescription="@string/send_google_maps"
|
android:contentDescription="@string/send_google_maps"
|
||||||
android:src="@drawable/google_maps_icon"
|
android:src="@drawable/google_maps_icon"
|
||||||
style="@style/UploadServiceChooserImageView" />
|
style="@style/ChooseUploadServiceImageView" />
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/send_google_maps"
|
android:id="@+id/choose_upload_service_maps"
|
||||||
android:text="@string/send_google_maps"
|
android:text="@string/send_google_maps"
|
||||||
style="@style/UploadServiceChooserCheckBox" />
|
style="@style/ChooseUploadServiceCheckBox" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow android:id="@+id/send_google_maps_option_row" >
|
<TableRow android:id="@+id/choose_upload_service_maps_options" >
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:layout_column="1"
|
android:layout_column="1"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_width="0dp" >
|
android:layout_width="0dp" >
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/send_google_new_map"
|
android:id="@+id/choose_upload_service_new_map"
|
||||||
android:text="@string/send_google_new_map"
|
android:text="@string/send_google_new_map"
|
||||||
style="@style/TextMedium" />
|
style="@style/TextMedium" />
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/send_google_existing_map"
|
android:id="@+id/choose_upload_service_existing_map"
|
||||||
android:text="@string/send_google_existing_map"
|
android:text="@string/send_google_existing_map"
|
||||||
style="@style/TextMedium" />
|
style="@style/TextMedium" />
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
@@ -51,21 +51,21 @@ limitations under the License.
|
|||||||
<ImageView
|
<ImageView
|
||||||
android:contentDescription="@string/send_google_fusion_tables"
|
android:contentDescription="@string/send_google_fusion_tables"
|
||||||
android:src="@drawable/google_fusion_tables_icon"
|
android:src="@drawable/google_fusion_tables_icon"
|
||||||
style="@style/UploadServiceChooserImageView" />
|
style="@style/ChooseUploadServiceImageView" />
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/send_google_fusion_tables"
|
android:id="@+id/choose_upload_service_fusion_tables"
|
||||||
android:text="@string/send_google_fusion_tables"
|
android:text="@string/send_google_fusion_tables"
|
||||||
style="@style/UploadServiceChooserCheckBox" />
|
style="@style/ChooseUploadServiceCheckBox" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:contentDescription="@string/send_google_docs"
|
android:contentDescription="@string/send_google_docs"
|
||||||
android:src="@drawable/google_docs_icon"
|
android:src="@drawable/google_docs_icon"
|
||||||
style="@style/UploadServiceChooserImageView" />
|
style="@style/ChooseUploadServiceImageView" />
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/send_google_docs"
|
android:id="@+id/choose_upload_service_docs"
|
||||||
android:text="@string/send_google_docs"
|
android:text="@string/send_google_docs"
|
||||||
style="@style/UploadServiceChooserCheckBox" />
|
style="@style/ChooseUploadServiceCheckBox" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -31,6 +31,17 @@ limitations under the License.
|
|||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">fill_parent</item>
|
||||||
<item name="android:orientation">horizontal</item>
|
<item name="android:orientation">horizontal</item>
|
||||||
</style>
|
</style>
|
||||||
|
<!-- The style for choose upload service check box -->
|
||||||
|
<style name="ChooseUploadServiceCheckBox" parent="@style/TextMedium">
|
||||||
|
<item name="android:layout_gravity">center_vertical</item>
|
||||||
|
<item name="android:layout_marginLeft">8dp</item>
|
||||||
|
<item name="android:layout_width">0dp</item>
|
||||||
|
</style>
|
||||||
|
<!-- The style for choose upload service image view -->
|
||||||
|
<style name="ChooseUploadServiceImageView">
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:layout_width">wrap_content</item>
|
||||||
|
</style>
|
||||||
<!-- The style for the edit category -->
|
<!-- The style for the edit category -->
|
||||||
<style name="EditCategory" parent="@style/TextMedium">
|
<style name="EditCategory" parent="@style/TextMedium">
|
||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">fill_parent</item>
|
||||||
@@ -150,15 +161,4 @@ limitations under the License.
|
|||||||
<style name="TrackWidgetValue" parent="@style/TextSmall">
|
<style name="TrackWidgetValue" parent="@style/TextSmall">
|
||||||
<item name="android:width">100dp</item>
|
<item name="android:width">100dp</item>
|
||||||
</style>
|
</style>
|
||||||
<!-- The style for upload service chooser check box -->
|
|
||||||
<style name="UploadServiceChooserCheckBox" parent="@style/TextMedium">
|
|
||||||
<item name="android:layout_gravity">center_vertical</item>
|
|
||||||
<item name="android:layout_marginLeft">8dp</item>
|
|
||||||
<item name="android:layout_width">0dp</item>
|
|
||||||
</style>
|
|
||||||
<!-- The style for upload service chooser image view -->
|
|
||||||
<style name="UploadServiceChooserImageView">
|
|
||||||
<item name="android:layout_height">wrap_content</item>
|
|
||||||
<item name="android:layout_width">wrap_content</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.content.Waypoint;
|
|||||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||||
import com.google.android.apps.mytracks.fragments.ChartFragment;
|
import com.google.android.apps.mytracks.fragments.ChartFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment;
|
import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment;
|
||||||
|
import com.google.android.apps.mytracks.fragments.ChooseUploadServiceDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
|
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
|
||||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
|
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
|
||||||
import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
|
import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
|
||||||
@@ -32,7 +33,6 @@ import com.google.android.apps.mytracks.fragments.StatsFragment;
|
|||||||
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActivity;
|
|
||||||
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;
|
||||||
@@ -289,9 +289,9 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
|
|||||||
.show(getSupportFragmentManager(), FrequencyDialogFragment.FREQUENCY_DIALOG_TAG);
|
.show(getSupportFragmentManager(), FrequencyDialogFragment.FREQUENCY_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_send_google:
|
case R.id.track_detail_send_google:
|
||||||
intent = IntentUtils.newIntent(this, UploadServiceChooserActivity.class)
|
ChooseUploadServiceDialogFragment.newInstance(new SendRequest(trackId)).show(
|
||||||
.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(trackId));
|
getSupportFragmentManager(),
|
||||||
startActivity(intent);
|
ChooseUploadServiceDialogFragment.CHOOSE_UPLOAD_SERVICE_DIALOG_TAG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_save_gpx:
|
case R.id.track_detail_save_gpx:
|
||||||
startSaveActivity(TrackFileFormat.GPX);
|
startSaveActivity(TrackFileFormat.GPX);
|
||||||
|
|||||||
+172
@@ -0,0 +1,172 @@
|
|||||||
|
/*
|
||||||
|
* 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.AnalyticsUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A DialogFragment to choose upload service.
|
||||||
|
*
|
||||||
|
* @author Jimmy Shih
|
||||||
|
*/
|
||||||
|
public class ChooseUploadServiceDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
public static final String CHOOSE_UPLOAD_SERVICE_DIALOG_TAG = "chooseUploadService";
|
||||||
|
|
||||||
|
private static final String KEY_SEND_REQUEST = "sendRequest";
|
||||||
|
|
||||||
|
public static ChooseUploadServiceDialogFragment newInstance(SendRequest sendRequest) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(KEY_SEND_REQUEST, sendRequest);
|
||||||
|
|
||||||
|
ChooseUploadServiceDialogFragment chooseUploadServiceDialogFragment =
|
||||||
|
new ChooseUploadServiceDialogFragment();
|
||||||
|
chooseUploadServiceDialogFragment.setArguments(bundle);
|
||||||
|
return chooseUploadServiceDialogFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SendRequest sendRequest;
|
||||||
|
|
||||||
|
private CheckBox mapsCheckBox;
|
||||||
|
private CheckBox fusionTablesCheckBox;
|
||||||
|
private CheckBox docsCheckBox;
|
||||||
|
|
||||||
|
private TableRow mapsOptionTableRow;
|
||||||
|
private RadioButton existingMapRadioButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
sendRequest = getArguments().getParcelable(KEY_SEND_REQUEST);
|
||||||
|
View view = getActivity().getLayoutInflater().inflate(R.layout.choose_upload_service, null);
|
||||||
|
|
||||||
|
mapsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_maps);
|
||||||
|
fusionTablesCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_fusion_tables);
|
||||||
|
docsCheckBox = (CheckBox) view.findViewById(R.id.choose_upload_service_docs);
|
||||||
|
|
||||||
|
mapsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
|
getActivity(), R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
||||||
|
fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
|
getActivity(), R.string.send_to_fusion_tables_key,
|
||||||
|
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
|
||||||
|
docsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
|
getActivity(), R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
|
||||||
|
|
||||||
|
mapsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
|
public void onCheckedChanged(CompoundButton button, boolean checked) {
|
||||||
|
updateMapsOption();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mapsOptionTableRow = (TableRow) view.findViewById(R.id.choose_upload_service_maps_options);
|
||||||
|
RadioButton newMapRadioButton = (RadioButton) view.findViewById(
|
||||||
|
R.id.choose_upload_service_new_map);
|
||||||
|
existingMapRadioButton = (RadioButton) view.findViewById(
|
||||||
|
R.id.choose_upload_service_existing_map);
|
||||||
|
|
||||||
|
updateMapsOption();
|
||||||
|
if (PreferencesUtils.getBoolean(getActivity(), R.string.pick_existing_map_key,
|
||||||
|
PreferencesUtils.PICK_EXISTING_MAP_DEFAULT)) {
|
||||||
|
existingMapRadioButton.setChecked(true);
|
||||||
|
} else {
|
||||||
|
newMapRadioButton.setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
|
||||||
|
.setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
PreferencesUtils.setBoolean(
|
||||||
|
getActivity(), R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
|
||||||
|
PreferencesUtils.setBoolean(
|
||||||
|
getActivity(), R.string.send_to_maps_key, mapsCheckBox.isChecked());
|
||||||
|
PreferencesUtils.setBoolean(getActivity(), R.string.send_to_fusion_tables_key,
|
||||||
|
fusionTablesCheckBox.isChecked());
|
||||||
|
PreferencesUtils.setBoolean(
|
||||||
|
getActivity(), R.string.send_to_docs_key, docsCheckBox.isChecked());
|
||||||
|
if (mapsCheckBox.isChecked() || fusionTablesCheckBox.isChecked()
|
||||||
|
|| docsCheckBox.isChecked()) {
|
||||||
|
startNextActivity();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(
|
||||||
|
getActivity(), R.string.send_google_no_service_selected, Toast.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setTitle(R.string.send_google_title)
|
||||||
|
.setView(view)
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates map option.
|
||||||
|
*/
|
||||||
|
private void updateMapsOption() {
|
||||||
|
mapsOptionTableRow.setVisibility(mapsCheckBox.isChecked() ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the next activity, {@link AccountChooserActivity}.
|
||||||
|
*/
|
||||||
|
private void startNextActivity() {
|
||||||
|
sendStats();
|
||||||
|
sendRequest.setSendMaps(mapsCheckBox.isChecked());
|
||||||
|
sendRequest.setSendFusionTables(fusionTablesCheckBox.isChecked());
|
||||||
|
sendRequest.setSendDocs(docsCheckBox.isChecked());
|
||||||
|
sendRequest.setNewMap(!existingMapRadioButton.isChecked());
|
||||||
|
Intent intent = IntentUtils.newIntent(getActivity(), AccountChooserActivity.class)
|
||||||
|
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends stats to Google Analytics.
|
||||||
|
*/
|
||||||
|
private void sendStats() {
|
||||||
|
ArrayList<String> pages = new ArrayList<String>();
|
||||||
|
if (sendRequest.isSendMaps()) {
|
||||||
|
pages.add("/send/maps");
|
||||||
|
}
|
||||||
|
if (sendRequest.isSendFusionTables()) {
|
||||||
|
pages.add("/send/fusion_tables");
|
||||||
|
}
|
||||||
|
if (sendRequest.isSendDocs()) {
|
||||||
|
pages.add("/send/docs");
|
||||||
|
}
|
||||||
|
AnalyticsUtils.sendPageViews(getActivity(), pages.toArray(new String[pages.size()]));
|
||||||
|
}
|
||||||
|
}
|
||||||
-237
@@ -1,237 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.io.sendtogoogle;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.util.AnalyticsUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
|
||||||
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.view.View;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.TableRow;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A chooser to select the Google services to upload a track to.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public class UploadServiceChooserActivity extends Activity {
|
|
||||||
|
|
||||||
private static final int DIALOG_CHOOSER_ID = 0;
|
|
||||||
|
|
||||||
private SendRequest sendRequest;
|
|
||||||
private AlertDialog alertDialog;
|
|
||||||
|
|
||||||
private CheckBox mapsCheckBox;
|
|
||||||
private CheckBox fusionTablesCheckBox;
|
|
||||||
private CheckBox docsCheckBox;
|
|
||||||
|
|
||||||
private TableRow mapsOptionTableRow;
|
|
||||||
private RadioButton newMapRadioButton;
|
|
||||||
private RadioButton existingMapRadioButton;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
showDialog(DIALOG_CHOOSER_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Dialog onCreateDialog(int id) {
|
|
||||||
if (id != DIALOG_CHOOSER_ID) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
View view = getLayoutInflater().inflate(R.layout.upload_service_chooser, null);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
mapsOptionTableRow = (TableRow) view.findViewById(R.id.send_google_maps_option_row);
|
|
||||||
newMapRadioButton = (RadioButton) view.findViewById(R.id.send_google_new_map);
|
|
||||||
existingMapRadioButton = (RadioButton) view.findViewById(R.id.send_google_existing_map);
|
|
||||||
|
|
||||||
// Setup checkboxes
|
|
||||||
OnCheckedChangeListener checkBoxListener = new OnCheckedChangeListener() {
|
|
||||||
public void onCheckedChanged(CompoundButton button, boolean checked) {
|
|
||||||
updateStateBySelection();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mapsCheckBox.setOnCheckedChangeListener(checkBoxListener);
|
|
||||||
fusionTablesCheckBox.setOnCheckedChangeListener(checkBoxListener);
|
|
||||||
docsCheckBox.setOnCheckedChangeListener(checkBoxListener);
|
|
||||||
|
|
||||||
// Setup initial state
|
|
||||||
initState();
|
|
||||||
|
|
||||||
// Update state based on current selection
|
|
||||||
updateStateBySelection();
|
|
||||||
|
|
||||||
alertDialog = new AlertDialog.Builder(this)
|
|
||||||
.setCancelable(true)
|
|
||||||
.setNegativeButton(R.string.generic_cancel, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
||||||
@Override
|
|
||||||
public void onCancel(DialogInterface d) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
saveState();
|
|
||||||
if (sendMaps() || sendFusionTables() || sendDocs()) {
|
|
||||||
startNextActivity();
|
|
||||||
} else {
|
|
||||||
Toast.makeText(UploadServiceChooserActivity.this,
|
|
||||||
R.string.send_google_no_service_selected, Toast.LENGTH_LONG).show();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setTitle(R.string.send_google_title)
|
|
||||||
.setView(view)
|
|
||||||
.create();
|
|
||||||
return alertDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the UI state based on the shared preferences.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void initState() {
|
|
||||||
boolean pickExistingMap = PreferencesUtils.getBoolean(
|
|
||||||
this, R.string.pick_existing_map_key, PreferencesUtils.PICK_EXISTING_MAP_DEFAULT);
|
|
||||||
|
|
||||||
newMapRadioButton.setChecked(!pickExistingMap);
|
|
||||||
existingMapRadioButton.setChecked(pickExistingMap);
|
|
||||||
|
|
||||||
mapsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
|
||||||
this, R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
|
||||||
fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
|
|
||||||
this, R.string.send_to_fusion_tables_key, PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
|
|
||||||
docsCheckBox.setChecked(PreferencesUtils.getBoolean(
|
|
||||||
this, R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the UI state based on the current selection.
|
|
||||||
*/
|
|
||||||
private void updateStateBySelection() {
|
|
||||||
mapsOptionTableRow.setVisibility(sendMaps() ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the UI state to the shared preferences.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void saveState() {
|
|
||||||
PreferencesUtils.setBoolean(
|
|
||||||
this, R.string.pick_existing_map_key, existingMapRadioButton.isChecked());
|
|
||||||
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 mapsCheckBox.isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true to send to Google Fusion Tables.
|
|
||||||
*/
|
|
||||||
private boolean sendFusionTables() {
|
|
||||||
return fusionTablesCheckBox.isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true to send to Google Docs.
|
|
||||||
*/
|
|
||||||
private boolean sendDocs() {
|
|
||||||
return docsCheckBox.isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the next activity, {@link AccountChooserActivity}.
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
protected void startNextActivity() {
|
|
||||||
sendStats();
|
|
||||||
sendRequest.setSendMaps(sendMaps());
|
|
||||||
sendRequest.setSendFusionTables(sendFusionTables());
|
|
||||||
sendRequest.setSendDocs(sendDocs());
|
|
||||||
sendRequest.setNewMap(!existingMapRadioButton.isChecked());
|
|
||||||
Intent intent = IntentUtils.newIntent(this, AccountChooserActivity.class)
|
|
||||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends stats to Google Analytics.
|
|
||||||
*/
|
|
||||||
private void sendStats() {
|
|
||||||
ArrayList<String> pages = new ArrayList<String>();
|
|
||||||
if (sendRequest.isSendMaps()) {
|
|
||||||
pages.add("/send/maps");
|
|
||||||
}
|
|
||||||
if (sendRequest.isSendFusionTables()) {
|
|
||||||
pages.add("/send/fusion_tables");
|
|
||||||
}
|
|
||||||
if (sendRequest.isSendDocs()) {
|
|
||||||
pages.add("/send/docs");
|
|
||||||
}
|
|
||||||
AnalyticsUtils.sendPageViews(this, pages.toArray(new String[pages.size()]));
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
AlertDialog getAlertDialog() {
|
|
||||||
return alertDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
SendRequest getSendRequest() {
|
|
||||||
return sendRequest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-219
@@ -1,219 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.io.sendtogoogle;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the {@link UploadServiceChooserActivity}.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
public class UploadServiceChooserActivityTest extends
|
|
||||||
ActivityInstrumentationTestCase2<UploadServiceChooserActivity> {
|
|
||||||
|
|
||||||
private Instrumentation instrumentation;
|
|
||||||
private UploadServiceChooserActivity uploadServiceChooserActivity;
|
|
||||||
|
|
||||||
public UploadServiceChooserActivityTest() {
|
|
||||||
super(UploadServiceChooserActivity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
instrumentation = getInstrumentation();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the logic to display all options.
|
|
||||||
*/
|
|
||||||
public void testOnCreateDialog_displayAll() {
|
|
||||||
// Initials activity to display all send items.
|
|
||||||
initialActivity();
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
assertTrue(getMapsCheckBox().isShown());
|
|
||||||
assertTrue(getFusionTablesCheckBox().isShown());
|
|
||||||
assertTrue(getDocsCheckBox().isShown());
|
|
||||||
|
|
||||||
// Clicks to disable all send items.
|
|
||||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (getMapsCheckBox().isChecked()) {
|
|
||||||
getMapsCheckBox().performClick();
|
|
||||||
}
|
|
||||||
if (getFusionTablesCheckBox().isChecked()) {
|
|
||||||
getFusionTablesCheckBox().performClick();
|
|
||||||
}
|
|
||||||
if (getDocsCheckBox().isChecked()) {
|
|
||||||
getDocsCheckBox().performClick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
assertTrue(getMapsCheckBox().isShown());
|
|
||||||
assertTrue(getFusionTablesCheckBox().isShown());
|
|
||||||
assertTrue(getDocsCheckBox().isShown());
|
|
||||||
|
|
||||||
assertFalse(getNewMapRadioButton().isShown());
|
|
||||||
assertFalse(getExistingMapRadioButton().isShown());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the logic to initial state of check box to unchecked. This test cover
|
|
||||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog(int)},
|
|
||||||
* {@link UploadServiceChooserActivity#initState()}.
|
|
||||||
*/
|
|
||||||
public void testOnCreateDialog_initStateUnchecked() {
|
|
||||||
initialActivity();
|
|
||||||
// Initial all values to false in SharedPreferences.
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, false);
|
|
||||||
PreferencesUtils.setBoolean(
|
|
||||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, false);
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, false);
|
|
||||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
uploadServiceChooserActivity.initState();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
assertFalse(getMapsCheckBox().isChecked());
|
|
||||||
assertFalse(getFusionTablesCheckBox().isChecked());
|
|
||||||
assertFalse(getDocsCheckBox().isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the logic to initial state of check box to checked. This test cover
|
|
||||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog(int)},
|
|
||||||
* {@link UploadServiceChooserActivity#initState()}.
|
|
||||||
*/
|
|
||||||
public void testOnCreateDialog_initStateChecked() {
|
|
||||||
initialActivity();
|
|
||||||
// Initial all values to true in SharedPreferences.
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.pick_existing_map_key, true);
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
|
|
||||||
PreferencesUtils.setBoolean(
|
|
||||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, true);
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
|
|
||||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
uploadServiceChooserActivity.initState();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
assertTrue(getMapsCheckBox().isChecked());
|
|
||||||
assertTrue(getFusionTablesCheckBox().isChecked());
|
|
||||||
assertTrue(getDocsCheckBox().isChecked());
|
|
||||||
assertTrue(getExistingMapRadioButton().isChecked());
|
|
||||||
|
|
||||||
assertFalse(getNewMapRadioButton().isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the logic of saveState when click send button. This test cover code
|
|
||||||
* in method {@link UploadServiceChooserActivity#initState()} and
|
|
||||||
* {@link UploadServiceChooserActivity#saveState()},
|
|
||||||
*/
|
|
||||||
public void testOnCreateDialog_saveState() {
|
|
||||||
initialActivity();
|
|
||||||
// Initial all values to true in SharedPreferences.
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
|
|
||||||
PreferencesUtils.setBoolean(
|
|
||||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, true);
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
|
|
||||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
uploadServiceChooserActivity.initState();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
uploadServiceChooserActivity.saveState();
|
|
||||||
// All values in SharedPreferences must be changed.
|
|
||||||
assertTrue(PreferencesUtils.getBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key,
|
|
||||||
PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
|
||||||
assertTrue(PreferencesUtils.getBoolean(
|
|
||||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key,
|
|
||||||
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
|
|
||||||
assertTrue(PreferencesUtils.getBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key,
|
|
||||||
PreferencesUtils.SEND_TO_DOCS_DEFAULT));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the logic of startNextActivity when click send button. This test
|
|
||||||
* cover code in method {@link UploadServiceChooserActivity#initState()} and
|
|
||||||
* {@link UploadServiceChooserActivity#startNextActivity()}.
|
|
||||||
*/
|
|
||||||
public void testOnCreateDialog_startNextActivity() {
|
|
||||||
initialActivity();
|
|
||||||
// Initial all values to true or false in SharedPreferences.
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
|
|
||||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
|
|
||||||
PreferencesUtils.setBoolean(
|
|
||||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, false);
|
|
||||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
uploadServiceChooserActivity.initState();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instrumentation.waitForIdleSync();
|
|
||||||
uploadServiceChooserActivity.startNextActivity();
|
|
||||||
// All values in SendRequest must be same as set above.
|
|
||||||
assertTrue(uploadServiceChooserActivity.getSendRequest().isSendMaps());
|
|
||||||
assertTrue(uploadServiceChooserActivity.getSendRequest().isSendDocs());
|
|
||||||
|
|
||||||
assertFalse(uploadServiceChooserActivity.getSendRequest().isSendFusionTables());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initials a activity to be tested.
|
|
||||||
*/
|
|
||||||
private void initialActivity() {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(1L));
|
|
||||||
setActivityIntent(intent);
|
|
||||||
uploadServiceChooserActivity = this.getActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CheckBox getMapsCheckBox() {
|
|
||||||
return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(R.id.send_google_maps);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CheckBox getFusionTablesCheckBox() {
|
|
||||||
return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(
|
|
||||||
R.id.send_google_fusion_tables);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CheckBox getDocsCheckBox() {
|
|
||||||
return (CheckBox) uploadServiceChooserActivity.getAlertDialog().findViewById(R.id.send_google_docs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RadioButton getNewMapRadioButton() {
|
|
||||||
return (RadioButton) uploadServiceChooserActivity.getAlertDialog().findViewById(
|
|
||||||
R.id.send_google_new_map);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RadioButton getExistingMapRadioButton() {
|
|
||||||
return (RadioButton) uploadServiceChooserActivity.getAlertDialog().findViewById(
|
|
||||||
R.id.send_google_existing_map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user