summaryrefslogtreecommitdiffstats
path: root/packages/DocumentsUI/src/com/android
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-10-08 17:09:18 -0700
committerJeff Sharkey <jsharkey@android.com>2013-10-08 17:11:49 -0700
commit78b137030864c028920046a38b5a040f5920fddf (patch)
tree8133ce422893e95d0524c7235ade8d7fe33cc7b2 /packages/DocumentsUI/src/com/android
parenta6af40cda29837fb68507f431ee5a179db93de28 (diff)
downloadframeworks_base-78b137030864c028920046a38b5a040f5920fddf.zip
frameworks_base-78b137030864c028920046a38b5a040f5920fddf.tar.gz
frameworks_base-78b137030864c028920046a38b5a040f5920fddf.tar.bz2
Grab Activity reference before leaving fragment.
When creating a new directory, we spawn an AsyncTask and finish the fragment. This change keeps an Activity reference to report the result back to. Bug: 11137561 Change-Id: Icfccc5e50e8f53a50dced589e1564d64457e0ed0
Diffstat (limited to 'packages/DocumentsUI/src/com/android')
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java24
1 files changed, 12 insertions, 12 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java
index 22dd6e4..90be197 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/CreateDirectoryFragment.java
@@ -73,7 +73,7 @@ public class CreateDirectoryFragment extends DialogFragment {
final DocumentsActivity activity = (DocumentsActivity) getActivity();
final DocumentInfo cwd = activity.getCurrentDirectory();
- new CreateDirectoryTask(displayName).executeOnExecutor(
+ new CreateDirectoryTask(activity, cwd, displayName).executeOnExecutor(
ProviderExecutor.forAuthority(cwd.authority));
}
});
@@ -83,25 +83,26 @@ public class CreateDirectoryFragment extends DialogFragment {
}
private class CreateDirectoryTask extends AsyncTask<Void, Void, DocumentInfo> {
+ private final DocumentsActivity mActivity;
+ private final DocumentInfo mCwd;
private final String mDisplayName;
- public CreateDirectoryTask(String displayName) {
+ public CreateDirectoryTask(
+ DocumentsActivity activity, DocumentInfo cwd, String displayName) {
+ mActivity = activity;
+ mCwd = cwd;
mDisplayName = displayName;
}
@Override
protected DocumentInfo doInBackground(Void... params) {
- final DocumentsActivity activity = (DocumentsActivity) getActivity();
- final ContentResolver resolver = activity.getContentResolver();
-
- final DocumentInfo cwd = activity.getCurrentDirectory();
-
+ final ContentResolver resolver = mActivity.getContentResolver();
ContentProviderClient client = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(
- resolver, cwd.derivedUri.getAuthority());
+ resolver, mCwd.derivedUri.getAuthority());
final Uri childUri = DocumentsContract.createDocument(
- client, cwd.derivedUri, Document.MIME_TYPE_DIR, mDisplayName);
+ client, mCwd.derivedUri, Document.MIME_TYPE_DIR, mDisplayName);
return DocumentInfo.fromUri(resolver, childUri);
} catch (Exception e) {
Log.w(TAG, "Failed to create directory", e);
@@ -113,12 +114,11 @@ public class CreateDirectoryFragment extends DialogFragment {
@Override
protected void onPostExecute(DocumentInfo result) {
- final DocumentsActivity activity = (DocumentsActivity) getActivity();
if (result != null) {
// Navigate into newly created child
- activity.onDocumentPicked(result);
+ mActivity.onDocumentPicked(result);
} else {
- Toast.makeText(activity, R.string.create_error, Toast.LENGTH_SHORT).show();
+ Toast.makeText(mActivity, R.string.create_error, Toast.LENGTH_SHORT).show();
}
}
}