Add a UploadResultActivity to better support

screen rotation.
This commit is contained in:
Jimmy Shih
2012-01-13 13:09:56 -08:00
parent feac34ca32
commit d3216b0520
10 changed files with 378 additions and 730 deletions
@@ -1,130 +0,0 @@
/*
* Copyright 2011 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.MyTracks;
import com.google.android.maps.mytracks.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
/**
* Tests {@link ResultDialogFactory}.
*
* @author Matthew Simmons
*/
public class ResultDialogFactoryTest extends ActivityInstrumentationTestCase2<MyTracks> {
public ResultDialogFactoryTest() {
super(MyTracks.class);
}
private List<SendResult> makeResults(SendResult... results) {
List<SendResult> resultsList = new ArrayList<SendResult>();
for (SendResult result : results) {
resultsList.add(result);
}
return resultsList;
}
private DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
};
private MyTracks myTracks;
protected void setUp() throws Exception {
super.setUp();
myTracks = getActivity();
};
public void testSuccess_noShare() {
List<SendResult> results = makeResults(new SendResult(SendType.MAPS, true),
new SendResult(SendType.DOCS, true));
AlertDialog dialog = ResultDialogFactory.makeDialog(
myTracks, results, clickListener, null, null);
dialog.show();
ListView listView = (ListView) dialog.findViewById(R.id.send_to_google_result_list);
ListAdapter listAdapter = listView.getAdapter();
assertEquals(2, listAdapter.getCount());
assertEquals(SendType.MAPS, ((SendResult) listAdapter.getItem(0)).getType());
assertEquals(SendType.DOCS, ((SendResult) listAdapter.getItem(1)).getType());
// Checking the return code of Dialog#getButton doesn't appear to be
// sufficient, as a Button will be returned even if it doesn't appear in
// the rendered dialog.
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
assertEquals(View.GONE, dialog.getButton(AlertDialog.BUTTON_NEUTRAL).getVisibility());
assertEquals(View.VISIBLE,
dialog.findViewById(R.id.send_to_google_result_comment).getVisibility());
assertEquals(View.GONE,
dialog.findViewById(R.id.send_to_google_result_error).getVisibility());
// TODO: Test correct listener invocation. Neither TouchUtils#clickView
// nor Button#performClick appear to cause listener invocation. This
// might be Android bug
// http://code.google.com/p/android/issues/detail?id=6564
}
public void testSuccess_share() {
List<SendResult> results = makeResults(
new SendResult(SendType.MAPS, true), new SendResult(SendType.DOCS, true));
AlertDialog dialog = ResultDialogFactory.makeDialog(
myTracks, results, clickListener, clickListener, null);
dialog.show();
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_NEGATIVE).getVisibility());
}
public void testFailure_noShare() {
List<SendResult> results = makeResults(new SendResult(SendType.MAPS, true),
new SendResult(SendType.DOCS, false));
AlertDialog dialog = ResultDialogFactory.makeDialog(
myTracks, results, clickListener, null, null);
dialog.show();
assertEquals(View.GONE,
dialog.findViewById(R.id.send_to_google_result_comment).getVisibility());
assertEquals(View.VISIBLE,
dialog.findViewById(R.id.send_to_google_result_error).getVisibility());
}
public void testFailure_share() {
List<SendResult> results = makeResults(new SendResult(SendType.MAPS, true),
new SendResult(SendType.DOCS, false));
AlertDialog dialog = ResultDialogFactory.makeDialog(
myTracks, results, clickListener, clickListener, null);
dialog.show();
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_NEGATIVE).getVisibility());
}
}
@@ -1,117 +0,0 @@
/*
* Copyright 2011 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.maps.mytracks.R;
import android.content.Context;
import android.test.AndroidTestCase;
import android.view.LayoutInflater;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
/**
* Tests {@link ResultListAdapter}.
*
* @author Matthew Simmons
*/
public class ResultListAdapterTest extends AndroidTestCase {
private static class TestResultListAdapter extends ResultListAdapter {
public View contentView;
public int drawableId;
public int nameId;
public int urlId;
public TestResultListAdapter(Context context, List<SendResult> results) {
super(context, 0, results);
}
@Override
protected void setImage(View content, int drawableId) {
saveContentView(content);
this.drawableId = drawableId;
}
@Override
protected void setName(View content, int nameId) {
saveContentView(content);
this.nameId = nameId;
}
@Override
protected void setUrl(View content, int urlId) {
saveContentView(content);
this.urlId = urlId;
}
@SuppressWarnings("hiding")
private void saveContentView(View contentView) {
if (this.contentView == null) {
this.contentView = contentView;
} else {
AndroidTestCase.assertEquals(this.contentView, contentView);
}
}
}
private final SendType sendType = SendType.MAPS;
private View inflateContentView(int viewId) {
LayoutInflater layoutInflater
= (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return layoutInflater.inflate(viewId, null);
}
private List<SendResult> makeResult(SendType type, boolean success) {
List<SendResult> results = new ArrayList<SendResult>();
results.add(new SendResult(type, success));
return results;
}
public void testSuccess_createsNewView() {
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
makeResult(sendType, true));
adapter.getView(0, null, null);
assertEquals(R.drawable.success, adapter.drawableId);
assertEquals(sendType.getServiceName(), adapter.nameId);
assertEquals(sendType.getServiceUrl(), adapter.urlId);
}
public void testSuccess_reusesView() {
View contentView = inflateContentView(R.layout.send_to_google_result_list_item);
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
makeResult(sendType, true));
adapter.getView(0, contentView, null);
assertEquals(contentView, adapter.contentView);
assertEquals(R.drawable.success, adapter.drawableId);
assertEquals(sendType.getServiceName(), adapter.nameId);
assertEquals(sendType.getServiceUrl(), adapter.urlId);
}
public void testFailure() {
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
makeResult(sendType, false));
adapter.getView(0, null, null);
assertEquals(R.drawable.failure, adapter.drawableId);
assertEquals(sendType.getServiceName(), adapter.nameId);
assertEquals(sendType.getServiceUrl(), adapter.urlId);
}
}