summaryrefslogtreecommitdiffstats
path: root/tests/DumpRenderTree2/src
diff options
context:
space:
mode:
authorMaksymilian Osowski <maxosowski@google.com>2010-07-09 12:33:43 +0100
committerMaksymilian Osowski <maxosowski@google.com>2010-07-12 13:14:43 +0100
commitcc483d25b96dc2e394473e63cac29d06f1e96261 (patch)
tree51c2b45ddf2d8af9d0c2bbd891cb00bba4a718f6 /tests/DumpRenderTree2/src
parent2707d6026240bcca6f0e35e2e1138958882e90ce (diff)
downloadframeworks_base-cc483d25b96dc2e394473e63cac29d06f1e96261.zip
frameworks_base-cc483d25b96dc2e394473e63cac29d06f1e96261.tar.gz
frameworks_base-cc483d25b96dc2e394473e63cac29d06f1e96261.tar.bz2
Added dialogs to the DirListActivity.
- A run/abort dialog on long click on directory - A delayed progress dialog for directories that take long to load Change-Id: I2fda245a48cb09faf8228809f7b091a7d2383589
Diffstat (limited to 'tests/DumpRenderTree2/src')
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java146
1 files changed, 141 insertions, 5 deletions
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java
index 97a81ce..d8509c1 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java
@@ -20,10 +20,16 @@ import com.android.dumprendertree2.FileFilter;
import com.android.dumprendertree2.R;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
import android.app.ListActivity;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
+import android.os.Handler;
+import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -50,7 +56,19 @@ public class DirListActivity extends ListActivity {
File.separator + "LayoutTests";
/** TODO: This is just a guess - think of a better way to achieve it */
- private static final int MEAN_TITLE_CHAR_SIZE = 12;
+ private static final int MEAN_TITLE_CHAR_SIZE = 13;
+
+ private static final int PROGRESS_DIALOG_DELAY_MS = 200;
+
+ /** Code for the dialog, used in showDialog and onCreateDialog */
+ private static final int DIALOG_RUN_ABORT_DIR = 0;
+
+ /** Messages codes */
+ private static final int MSG_LOADED_ITEMS = 0;
+ private static final int MSG_SHOW_PROGRESS_DIALOG = 1;
+
+ /** Initialized lazily before first sProgressDialog.show() */
+ private static ProgressDialog sProgressDialog;
private ListView mListView;
@@ -63,6 +81,28 @@ public class DirListActivity extends ListActivity {
private String mRootDirPath = ROOT_DIR_PATH;
/**
+ * A thread responsible for loading the contents of the directory from sd card
+ * and sending them via Message to main thread that then loads them into
+ * ListView
+ */
+ private class LoadListItemsThread extends Thread {
+ private Handler mHandler;
+ private String mRelativePath;
+
+ public LoadListItemsThread(String relativePath, Handler handler) {
+ mRelativePath = relativePath;
+ mHandler = handler;
+ }
+
+ @Override
+ public void run() {
+ Message msg = mHandler.obtainMessage(MSG_LOADED_ITEMS);
+ msg.obj = getDirList(mRelativePath);
+ mHandler.sendMessage(msg);
+ }
+ }
+
+ /**
* Very simple object to use inside ListView as an item.
*/
private static class ListItem implements Comparable<ListItem> {
@@ -149,8 +189,9 @@ public class DirListActivity extends ListActivity {
mListView = getListView();
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
- ListItem item = (ListItem) adapterView.getItemAtPosition(position);
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ ListItem item = (ListItem) parent.getItemAtPosition(position);
if (item.isDirectory()) {
showDir(item.getRelativePath());
@@ -160,6 +201,24 @@ public class DirListActivity extends ListActivity {
}
});
+ mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ ListItem item = (ListItem) parent.getItemAtPosition(position);
+
+ if (item.isDirectory()) {
+ Bundle arguments = new Bundle(1);
+ arguments.putString("name", item.getName());
+ arguments.putString("relativePath", item.getRelativePath());
+ showDialog(DIALOG_RUN_ABORT_DIR, arguments);
+ } else {
+ /** TODO: Maybe show some info about a test? */
+ }
+
+ return true;
+ }
+ });
+
/** All the paths are relative to test root dir where possible */
showDir("");
}
@@ -189,6 +248,48 @@ public class DirListActivity extends ListActivity {
setTitle(shortenTitle(mCurrentDirPath));
}
+ @Override
+ protected Dialog onCreateDialog(int id, Bundle args) {
+ Dialog dialog = null;
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+
+ switch (id) {
+ case DIALOG_RUN_ABORT_DIR:
+ builder.setTitle(getText(R.string.dialog_run_abort_dir_title_prefix) + " " +
+ args.getString("name"));
+ builder.setMessage(R.string.dialog_run_abort_dir_msg);
+ builder.setCancelable(true);
+
+ builder.setPositiveButton(R.string.dialog_run_abort_dir_ok_button,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ /** TODO: Run tests from the dir */
+ removeDialog(DIALOG_RUN_ABORT_DIR);
+ }
+ });
+
+ builder.setNegativeButton(R.string.dialog_run_abort_dir_abort_button,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ removeDialog(DIALOG_RUN_ABORT_DIR);
+ }
+ });
+
+ dialog = builder.create();
+ dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ removeDialog(DIALOG_RUN_ABORT_DIR);
+ }
+ });
+ break;
+ }
+
+ return dialog;
+ }
+
/**
* Loads the contents of dir into the list view.
*
@@ -197,8 +298,41 @@ public class DirListActivity extends ListActivity {
*/
private void showDir(String dirPath) {
mCurrentDirPath = dirPath;
- setTitle(shortenTitle(dirPath));
- setListAdapter(new DirListAdapter(this, getDirList(dirPath)));
+
+ /** Show progress dialog with a delay */
+ final Handler delayedDialogHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.what == MSG_SHOW_PROGRESS_DIALOG) {
+ if (sProgressDialog == null) {
+ sProgressDialog = new ProgressDialog(DirListActivity.this);
+ sProgressDialog.setCancelable(false);
+ sProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ sProgressDialog.setTitle(R.string.dialog_progress_title);
+ sProgressDialog.setMessage(getText(R.string.dialog_progress_msg));
+ }
+ sProgressDialog.show();
+ }
+ }
+ };
+ Message msgShowDialog = delayedDialogHandler.obtainMessage(MSG_SHOW_PROGRESS_DIALOG);
+ delayedDialogHandler.sendMessageDelayed(msgShowDialog, PROGRESS_DIALOG_DELAY_MS);
+
+ /** Delegate loading contents from SD card to a new thread */
+ new LoadListItemsThread(mCurrentDirPath, new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.what == MSG_LOADED_ITEMS) {
+ setListAdapter(new DirListAdapter(DirListActivity.this,
+ (ListItem[])msg.obj));
+ delayedDialogHandler.removeMessages(MSG_SHOW_PROGRESS_DIALOG);
+ setTitle(shortenTitle(mCurrentDirPath));
+ if (sProgressDialog != null) {
+ sProgressDialog.dismiss();
+ }
+ }
+ }
+ }).start();
}
/**
@@ -222,6 +356,8 @@ public class DirListActivity extends ListActivity {
* Return the array with contents of the given directory.
* First it contains the subfolders, then the files. Both sorted
* alphabetically.
+ *
+ * The dirPath is relative.
*/
private ListItem[] getDirList(String dirPath) {
File dir = new File(mRootDirPath, dirPath);