Added AlertDialog.Builder#getContext
Change-Id: Ic3033a4eff67f507aa39dacfc4c8984a9ee142c1
diff --git a/core/java/android/app/AlertDialog.java b/core/java/android/app/AlertDialog.java
index 92cedc4..f0477e5 100644
--- a/core/java/android/app/AlertDialog.java
+++ b/core/java/android/app/AlertDialog.java
@@ -16,6 +16,8 @@
package android.app;
+import com.android.internal.app.AlertController;
+
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
@@ -23,6 +25,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
+import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
@@ -31,8 +34,6 @@
import android.widget.ListAdapter;
import android.widget.ListView;
-import com.android.internal.app.AlertController;
-
/**
* A subclass of Dialog that can display one, two or three buttons. If you only want to
* display a String in this dialog box, use the setMessage() method. If you
@@ -273,6 +274,7 @@
public static class Builder {
private final AlertController.AlertParams P;
private int mTheme;
+ private Context mWrappedContext;
/**
* Constructor using a context for this builder and the {@link AlertDialog} it creates.
@@ -294,6 +296,21 @@
}
/**
+ * Returns a {@link Context} with the appropriate theme for dialogs created by this Builder.
+ * Applications should use this Context for obtaining LayoutInflaters for inflating views
+ * that will be used in the resulting dialogs, as it will cause views to be inflated with
+ * the correct theme.
+ *
+ * @return A Context for built Dialogs.
+ */
+ public Context getContext() {
+ if (mWrappedContext == null) {
+ mWrappedContext = new ContextThemeWrapper(P.mContext, mTheme);
+ }
+ return mWrappedContext;
+ }
+
+ /**
* Set the title using the given resource id.
*
* @return This Builder object to allow for chaining of calls to set methods
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index 04735bf..a178c04 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -177,7 +177,7 @@
/**
* Retrieve the Context this Dialog is running in.
*
- * @return Context The Context that was supplied to the constructor.
+ * @return Context The Context used by the Dialog.
*/
public final Context getContext() {
return mContext;