summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan <adnan@cyngn.com>2014-08-26 18:31:33 -0700
committerAdnan <adnan@cyngn.com>2014-08-27 09:06:43 -0700
commit2ef0f2fc6d08a3e077e4425754c867e7cf3140c3 (patch)
tree90ef6f5553181fac4cebff30c3ccd68b056af593
parent5d1d0f24bae61ad1b5ecf31d340b379a52a423b3 (diff)
downloadandroid_packages_providers_DownloadProvider-2ef0f2fc6d08a3e077e4425754c867e7cf3140c3.zip
android_packages_providers_DownloadProvider-2ef0f2fc6d08a3e077e4425754c867e7cf3140c3.tar.gz
android_packages_providers_DownloadProvider-2ef0f2fc6d08a3e077e4425754c867e7cf3140c3.tar.bz2
DownloadProvider: Create and implement DialogDismissListener.
- Better way to dismiss a host activity then explicitly calling getActivity() finish(). Change-Id: I121fb63d2d57c6c4b22abac2389d5c3d5ccad6e4
-rw-r--r--ui/src/com/android/providers/downloads/ui/DialogDismissListener.java21
-rwxr-xr-xui/src/com/android/providers/downloads/ui/TrampolineActivity.java33
2 files changed, 49 insertions, 5 deletions
diff --git a/ui/src/com/android/providers/downloads/ui/DialogDismissListener.java b/ui/src/com/android/providers/downloads/ui/DialogDismissListener.java
new file mode 100644
index 0000000..e55caa8
--- /dev/null
+++ b/ui/src/com/android/providers/downloads/ui/DialogDismissListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2014 The CyanogenMod Project
+ *
+ * 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.android.providers.downloads.ui;
+
+interface DialogDismissListener {
+ public void onDialogDismiss();
+}
diff --git a/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java b/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
index 8ada01b..b4f2698 100755
--- a/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
+++ b/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
@@ -41,7 +41,7 @@ import libcore.io.IoUtils;
* Intercept all download clicks to provide special behavior. For example,
* PackageInstaller really wants raw file paths.
*/
-public class TrampolineActivity extends Activity {
+public class TrampolineActivity extends Activity implements DialogDismissListener {
private static final String TAG_PAUSED = "paused";
private static final String TAG_FAILED = "failed";
@@ -125,7 +125,14 @@ public class TrampolineActivity extends Activity {
sendBroadcast(intent);
}
+ @Override
+ public void onDialogDismiss() {
+ finish();
+ }
+
public static class PausedDialogFragment extends DialogFragment {
+ private DialogDismissListener mListener;
+
public static void show(FragmentManager fm, long id) {
final PausedDialogFragment dialog = new PausedDialogFragment();
final Bundle args = new Bundle();
@@ -135,8 +142,15 @@ public class TrampolineActivity extends Activity {
}
@Override
+ public void onDetach() {
+ super.onDetach();
+ mListener = null;
+ }
+
+ @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
+ mListener = (DialogDismissListener) getActivity();
final DownloadManager dm = (DownloadManager) context.getSystemService(
Context.DOWNLOAD_SERVICE);
@@ -165,13 +179,15 @@ public class TrampolineActivity extends Activity {
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
- if (getActivity() != null) {
- getActivity().finish();
+ if (mListener != null) {
+ mListener.onDialogDismiss();
}
}
}
public static class FailedDialogFragment extends DialogFragment {
+ private DialogDismissListener mListener;
+
public static void show(FragmentManager fm, long id, int reason) {
final FailedDialogFragment dialog = new FailedDialogFragment();
final Bundle args = new Bundle();
@@ -182,8 +198,15 @@ public class TrampolineActivity extends Activity {
}
@Override
+ public void onDetach() {
+ super.onDetach();
+ mListener = null;
+ }
+
+ @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
+ mListener = (DialogDismissListener) getActivity();
final DownloadManager dm = (DownloadManager) context.getSystemService(
Context.DOWNLOAD_SERVICE);
@@ -236,8 +259,8 @@ public class TrampolineActivity extends Activity {
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
- if (getActivity() != null) {
- getActivity().finish();
+ if (mListener != null) {
+ mListener.onDialogDismiss();
}
}
}