下面列出了怎么用android.view.ContextThemeWrapper的API类实例代码及写法,或者点击链接到github查看源代码。
private static boolean isDialogBelongActivity(Context dialogContext, Context activityContext) {
int limit = 0;
while (true) {
if (dialogContext == activityContext) {
return true;
}
if (!(dialogContext instanceof ContextThemeWrapper)) {
return false;
}
//防止极端情况
if (limit++ > 10) {
return false;
}
dialogContext = ((ContextThemeWrapper) dialogContext).getBaseContext();
}
}
private void showLocalAppDialog() {
ContextThemeWrapper wrapper = new ContextThemeWrapper(getContext(), R.style.DialogBaseTheme);
final PaneledChoiceDialog chooseApp = new PaneledChoiceDialog(wrapper,
Localization.get("install.choose.local.app"));
DialogChoiceItem[] items = new DialogChoiceItem[mLocalApps.size()];
int count = 0;
for (final MicroNode.AppManifest app : mLocalApps) {
DialogChoiceItem item = new DialogChoiceItem(app.getName(), -1, v -> {
Activity currentActivity = getActivity();
if (currentActivity instanceof CommCareSetupActivity) {
((CommCareSetupActivity)currentActivity).onURLChosen(app.getLocalUrl());
}
((CommCareActivity)getActivity()).dismissAlertDialog();
});
items[count] = item;
count++;
}
chooseApp.setChoiceItems(items);
((CommCareActivity)getActivity()).showAlertDialog(chooseApp);
}
private void init() {
setOrientation(LinearLayout.VERTICAL);
nodeContainer = new RelativeLayout(getContext());
nodeContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
nodeContainer.setId(R.id.node_header);
ContextThemeWrapper newContext = new ContextThemeWrapper(getContext(), containerStyle);
nodeItemsContainer = new LinearLayout(newContext, null, containerStyle);
nodeItemsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
nodeItemsContainer.setId(R.id.node_items);
nodeItemsContainer.setOrientation(LinearLayout.VERTICAL);
nodeItemsContainer.setVisibility(View.GONE);
addView(nodeContainer);
addView(nodeItemsContainer);
}
/**
* Updates the add note button for {@link TextNoteFragment} and {@link GalleryNoteFragment} when
* a recording starts/stops.
*/
public void attachAddButton(FloatingActionButton button) {
recordingStatus
.takeUntil(RxView.detaches(button))
.subscribe(
status -> {
Theme theme = button.getContext().getTheme();
if (status.state.shouldShowStopButton()) {
theme = new ContextThemeWrapper(
button.getContext(), R.style.RecordingProgressBarColor).getTheme();
}
button.setImageDrawable(
ResourcesCompat.getDrawable(
button.getResources(), R.drawable.ic_send_24dp, theme));
TypedValue iconColor = new TypedValue();
theme.resolveAttribute(R.attr.icon_color, iconColor, true);
TypedValue iconBackground = new TypedValue();
theme.resolveAttribute(R.attr.icon_background, iconBackground, true);
button.setBackgroundTintList(ColorStateList.valueOf(
button.getResources().getColor(iconBackground.resourceId)));
button.setRippleColor(button.getResources().getColor(iconColor.resourceId));
});
}
CardViewHolder(ImageCardView view, Context context) {
super(view);
mContext = context;
Context wrapper = new ContextThemeWrapper(mContext, R.style.MyPopupMenu);
mPopupMenu = new PopupMenu(wrapper, view);
mPopupMenu.inflate(R.menu.popup_menu);
mPopupMenu.setOnMenuItemClickListener(this);
view.setOnLongClickListener(this);
mOwner = (LifecycleOwner) mContext;
mDefaultBackground = mContext.getResources().getDrawable(R.drawable.no_cache_no_internet, null);
mDefaultPlaceHolder = new RequestOptions().
placeholder(mDefaultBackground);
mCardView = (ImageCardView) CardViewHolder.this.view;
Resources resources = mCardView.getContext().getResources();
mCardView.setMainImageDimensions(Math.round(
resources.getDimensionPixelSize(R.dimen.card_width)),
resources.getDimensionPixelSize(R.dimen.card_height));
mFragmentActivity = (FragmentActivity) context;
mViewModel = ViewModelProviders.of(mFragmentActivity).get(VideosViewModel.class);
}
private void init() {
setOrientation(LinearLayout.VERTICAL);
nodeContainer = new RelativeLayout(getContext());
nodeContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
nodeContainer.setId(R.id.node_header);
ContextThemeWrapper newContext = new ContextThemeWrapper(getContext(), containerStyle);
nodeItemsContainer = new LinearLayout(newContext, null, containerStyle);
nodeItemsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
nodeItemsContainer.setId(R.id.node_items);
nodeItemsContainer.setOrientation(LinearLayout.VERTICAL);
nodeItemsContainer.setVisibility(View.GONE);
addView(nodeContainer);
addView(nodeItemsContainer);
}
private void displayFinishDialog(String outcome) {
setGameButtonsEnabled(false);
resetButton.setEnabled(true);
AlertDialog.Builder gameOverBuilder =
new AlertDialog.Builder(
new ContextThemeWrapper(context, R.style.SetupGuideAlertDialogStyle));
gameOverBuilder.setTitle(outcome);
gameOverBuilder.setMessage(context.getString(R.string.game_outcome_body_text));
gameOverBuilder.setNegativeButton(
context.getString(R.string.game_outcome_negative_response),
(dialogInterface, viewId) -> {
((Activity) context).recreate();
KeyAssignmentUtils.clearAllKeyPrefs(context);
dialogInterface.cancel();
});
gameOverBuilder.setPositiveButton(
context.getString(R.string.game_outcome_positive_response),
(dialogInterface, viewId) -> dialogInterface.cancel());
AlertDialog gameOverDialog = gameOverBuilder.create();
gameOverDialog.show();
}
private void showPopup() {
int menu_res_id = R.menu.popup_post;
String currentLoggedInUser = HaprampPreferenceManager.getInstance().getCurrentSteemUsername();
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this, R.style.PopupMenuOverlapAnchor);
PopupMenu popup = new PopupMenu(contextThemeWrapper, overflowBtn);
//customize menu items
//add Share
popup.getMenu().add(PostMenu.Share);
popup.getMenu().add(PostMenu.Repost);
popup.getMenuInflater().inflate(menu_res_id, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getTitle().equals(PostMenu.Share)) {
ShareUtils.shareMixedContent(DetailedActivity.this, post);
return true;
} else if (item.getTitle().equals(PostMenu.Repost)) {
showAlertDialogForRepost();
}
return false;
}
});
popup.show();
}
public void setTheme(Theme.ThemeDescriptor theme) {
mThemeTitle.setText(theme.getName(getContext()));
Context themedContext = new ContextThemeWrapper(getContext(), theme.getTheme());
setCardBackgroundColor(Utils.getThemeColor(themedContext, R.attr.colorPrimary));
int accentColor = Utils.getThemeColor(themedContext, R.attr.colorAccent);
setStrokeColor(accentColor);
mThemeTitle.setTextColor(accentColor);
if (Utils.apiIsAtLeast(Build.VERSION_CODES.M)) {
setRippleColor(themedContext.getColorStateList(R.color.selector_theme_card_ripple));
}
mThemeMessage.setTextColor(Utils.getThemeColor(themedContext, android.R.attr.textColorPrimary));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.OSTheme);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
View view = localInflater.inflate(R.layout.fragment_os, container, false);
unbinder = ButterKnife.bind(this, view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.dark_blue));
window.setNavigationBarColor(getResources().getColor(R.color.dark_blue));
}
/*
View view = inflater.inflate(R.layout.fragment_os, container, false);
unbinder = ButterKnife.bind(this, view);
*/
return view;
}
/**
* Inflates the layout.
*
* @param tabsOnly
* True, if only the tabs should be inflated, false otherwise
*/
public final void inflateLayout(final boolean tabsOnly) {
int themeResourceId = style.getThemeHelper().getThemeResourceId(tabSwitcher.getLayout());
LayoutInflater inflater =
LayoutInflater.from(new ContextThemeWrapper(getContext(), themeResourceId));
onInflateLayout(inflater, tabsOnly);
registerEventHandlerCallbacks();
adaptDecorator();
adaptLogLevel();
if (!tabsOnly) {
adaptToolbarVisibility();
adaptToolbarTitle();
adaptToolbarNavigationIcon();
inflateToolbarMenu();
}
}
private void initDropDown(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DropDown, defStyleAttr, defStyleRes);
int theme = a.getResourceId(R.styleable.DropDown_carbon_popupTheme, -1);
dropDownMenu = new DropDownMenu(new ContextThemeWrapper(getContext(), theme));
dropDownMenu.setOnDismissListener(() -> isShowingPopup = false);
dropDownMenu.setPopupMode(PopupMode.values()[a.getInt(R.styleable.DropDown_carbon_popupMode, PopupMode.Over.ordinal())]);
setMode(Mode.values()[a.getInt(R.styleable.DropDown_carbon_mode, Mode.SingleSelect.ordinal())]);
dropDownMenu.setOnItemClickedListener(onItemClickedListener);
setButtonDrawable(Carbon.getDrawable(this, a, R.styleable.DropDown_android_button, R.drawable.carbon_dropdown));
for (int i = 0; i < a.getIndexCount(); i++) {
int attr = a.getIndex(i);
if (attr == R.styleable.DropDown_android_drawablePadding) {
drawablePadding = a.getDimension(attr, 0);
} else if (attr == R.styleable.DropDown_carbon_buttonGravity) {
buttonGravity = ButtonGravity.values()[a.getInt(attr, 0)];
}
}
a.recycle();
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedState)
{
ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext())); // hack: contextWrapper required because base theme is not properly applied
dialogContent = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_worldmap, parent, false);
initLocale(getContext());
initViews(getContext(), dialogContent);
if (savedState != null)
{
Log.d(LOGTAG, "WorldMapDialog onCreate (restoreState)");
worldmap.loadSettings(getContext(), savedState);
}
themeViews(dialogContent.getContext());
return dialogContent;
}
/**
* 初始化
*
* @param context 上下文
*/
private void init(ContextThemeWrapper context) {
initResources(context);
initBitmap();
initPaint();
mLeafFactory = new LeafFactory();
mLeafInfos = mLeafFactory.generateLeafs();
mFan = new FanFactory().generateFan();
}
public Object createService(ContextImpl ctx) {
final Context outerContext = ctx.getOuterContext();
return new NotificationManager(
new ContextThemeWrapper(outerContext,
Resources.selectSystemTheme(0,
outerContext.getApplicationInfo().targetSdkVersion,
com.android.internal.R.style.Theme_Dialog,
com.android.internal.R.style.Theme_Holo_Dialog,
com.android.internal.R.style.Theme_DeviceDefault_Dialog)),
ctx.mMainThread.getHandler());
}
/**
* LoadingDialog
*/
public AlertDialog getLoadingDialog(String text) {
final AlertDialog dlg = new AlertDialog
.Builder(new ContextThemeWrapper(mContext, R.style.lib_pub_dialog_style))
.create();
if (mContext instanceof Activity && !((Activity) mContext).isFinishing()) {
dlg.show();
}
dlg.setContentView(R.layout.lib_pub_dialog_loading);
TextView tips = (TextView) dlg.findViewById(R.id.tv_tips);
if (text != null) {
tips.setText(text);
}
return dlg;
}
public static void applyThemeToSudokuBoardViewFromContext(String theme, SudokuBoardView board, Context context) {
if (theme.equals("custom") || theme.equals("custom_light")) {
applyCustomThemeToSudokuBoardViewFromContext(board, context);
} else {
ContextThemeWrapper themeWrapper = new ContextThemeWrapper(context, getThemeResourceIdFromString(theme));
int[] attributes = {
R.attr.lineColor,
R.attr.sectorLineColor,
R.attr.textColor,
R.attr.textColorReadOnly,
R.attr.textColorNote,
R.attr.backgroundColor,
R.attr.backgroundColorSecondary,
R.attr.backgroundColorReadOnly,
R.attr.backgroundColorTouched,
R.attr.backgroundColorSelected,
R.attr.backgroundColorHighlighted
};
TypedArray themeColors = themeWrapper.getTheme().obtainStyledAttributes(attributes);
board.setLineColor(themeColors.getColor(0, R.color.default_lineColor));
board.setSectorLineColor(themeColors.getColor(1, R.color.default_sectorLineColor));
board.setTextColor(themeColors.getColor(2, R.color.default_textColor));
board.setTextColorReadOnly(themeColors.getColor(3, R.color.default_textColorReadOnly));
board.setTextColorNote(themeColors.getColor(4, R.color.default_textColorNote));
board.setBackgroundColor(themeColors.getColor(5, R.color.default_backgroundColor));
board.setBackgroundColorSecondary(themeColors.getColor(6, R.color.default_backgroundColorSecondary));
board.setBackgroundColorReadOnly(themeColors.getColor(7, R.color.default_backgroundColorReadOnly));
board.setBackgroundColorTouched(themeColors.getColor(8, R.color.default_backgroundColorTouched));
board.setBackgroundColorSelected(themeColors.getColor(9, R.color.default_backgroundColorSelected));
board.setBackgroundColorHighlighted(themeColors.getColor(10, R.color.default_backgroundColorHighlighted));
}
board.invalidate();
}
public Object createService(ContextImpl ctx) {
final Context outerContext = ctx.getOuterContext();
return new NotificationManager(
new ContextThemeWrapper(outerContext,
Resources.selectSystemTheme(0,
outerContext.getApplicationInfo().targetSdkVersion,
com.android.internal.R.style.Theme_Dialog,
com.android.internal.R.style.Theme_Holo_Dialog,
com.android.internal.R.style.Theme_DeviceDefault_Dialog)),
ctx.mMainThread.getHandler());
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context layoutContext = new ContextThemeWrapper(getActivity(),
android.R.style.Theme_DeviceDefault_Light_Dialog);
LayoutInflater layoutInflater = LayoutInflater.from(layoutContext);
View rootView = layoutInflater.inflate(R.layout.dialog_weather_location_chooser, null);
TextView searchView = (TextView) rootView.findViewById(R.id.location_query);
searchView.addTextChangedListener(this);
// Set up apps
mSearchResultsList = (ListView) rootView.findViewById(android.R.id.list);
mSearchResultsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long itemId) {
String value = mSearchResultsAdapter.getPrefValueAt(position);
if (value == null || "".equals(value)) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);
}
}
mPreference.setValue(value);
dismiss();
}
});
tryBindList();
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setView(rootView)
.create();
dialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
return dialog;
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedState)
{
ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext())); // hack: contextWrapper required because base theme is not properly applied
View dialogContent = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_about, parent, false);
if (savedState != null)
{
param_iconID = savedState.getInt(KEY_ICONID, param_iconID);
param_appName = savedState.getInt(KEY_APPNAME, param_appName);
}
initViews(getActivity(), dialogContent);
return dialogContent;
}
public static void allFields() throws HackAssertionException {
ActivityThread_mInstrumentation = ActivityThread.field("mInstrumentation").ofType(Instrumentation.class);
ActivityThread_mAllApplications = ActivityThread.field("mAllApplications").ofGenericType(ArrayList.class);
ActivityThread_mInitialApplication = ActivityThread.field("mInitialApplication").ofType(Application.class);
ActivityThread_mPackages = ActivityThread.field("mPackages").ofGenericType(Map.class);
ActivityThread_sPackageManager = ActivityThread.staticField("sPackageManager").ofType(IPackageManager.getmClass());
LoadedApk_mApplication = LoadedApk.field("mApplication").ofType(Application.class);
LoadedApk_mResources = LoadedApk.field("mResources").ofType(Resources.class);
LoadedApk_mResDir = LoadedApk.field("mResDir").ofType(String.class);
LoadedApk_mClassLoader = LoadedApk.field("mClassLoader").ofType(ClassLoader.class);
LoadedApk_mBaseClassLoader = LoadedApk.field("mBaseClassLoader").ofType(ClassLoader.class);
LoadedApk_mAppDir = LoadedApk.field("mAppDir").ofType(String.class);
ContextImpl_mResources = ContextImpl.field("mResources").ofType(Resources.class);
ContextImpl_mTheme = ContextImpl.field("mTheme").ofType(Theme.class);
sIsIgnoreFailure = true;
ContextThemeWrapper_mBase = ContextThemeWrapper.field("mBase").ofType(Context.class);
sIsIgnoreFailure = false;
ContextThemeWrapper_mTheme = ContextThemeWrapper.field("mTheme").ofType(Theme.class);
try {
if (VERSION.SDK_INT >= 17 && ContextThemeWrapper.getmClass().getDeclaredField("mResources") != null) {
ContextThemeWrapper_mResources = ContextThemeWrapper.field("mResources").ofType(Resources.class);
}
} catch (NoSuchFieldException e) {
log.warn("Not found ContextThemeWrapper.mResources on VERSION " + VERSION.SDK_INT);
}
ContextWrapper_mBase = ContextWrapper.field("mBase").ofType(Context.class);
Resources_mAssets = Resources.field("mAssets");
}
@SuppressLint("ObsoleteSdkInt")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setTitle(R.string.prefs_about_chrome);
PreferenceUtils.addPreferencesFromResource(this, R.xml.about_chrome_preferences);
// TODO(crbug.com/635567): Fix this properly.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
ChromeBasePreference deprecationWarning = new ChromeBasePreference(
new ContextThemeWrapper(getActivity(),
R.style.DeprecationWarningPreferenceTheme));
deprecationWarning.setOrder(-1);
deprecationWarning.setTitle(R.string.deprecation_warning);
deprecationWarning.setIcon(R.drawable.exclamation_triangle);
getPreferenceScreen().addPreference(deprecationWarning);
}
PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();
AboutVersionStrings versionStrings = prefServiceBridge.getAboutVersionStrings();
Preference p = findPreference(PREF_APPLICATION_VERSION);
p.setSummary(getApplicationVersion(getActivity(), versionStrings.getApplicationVersion()));
p = findPreference(PREF_OS_VERSION);
p.setSummary(versionStrings.getOSVersion());
p = findPreference(PREF_LEGAL_INFORMATION);
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
p.setSummary(getString(R.string.legal_information_summary, currentYear));
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (mTheme > 0) {
Context newContext = new ContextThemeWrapper(inflater.getContext(), mTheme);
inflater = inflater.cloneInContext(newContext);
}
mInflater = inflater;
mView = inflater.inflate(R.layout.mnd_list, container, false);
mListView = (ListView) mView.findViewById(R.id.mnd_list);
mPinnedContainer = (ViewGroup) mView.findViewById(R.id.mnd_section_pinned);
mPinnedDivider = mView.findViewById(R.id.mnd_divider_pinned);
return mView;
}
private static Context createPresentationContext(
Context outerContext, Display display, int theme) {
if (outerContext == null) {
throw new IllegalArgumentException("outerContext must not be null");
}
if (display == null) {
throw new IllegalArgumentException("display must not be null");
}
Context displayContext = outerContext.createDisplayContext(display);
if (theme == 0) {
TypedValue outValue = new TypedValue();
displayContext.getTheme().resolveAttribute(
com.android.internal.R.attr.presentationTheme, outValue, true);
theme = outValue.resourceId;
}
// Derive the display's window manager from the outer window manager.
// We do this because the outer window manager have some extra information
// such as the parent window, which is important if the presentation uses
// an application window type.
final WindowManagerImpl outerWindowManager =
(WindowManagerImpl)outerContext.getSystemService(WINDOW_SERVICE);
final WindowManagerImpl displayWindowManager =
outerWindowManager.createPresentationWindowManager(displayContext);
return new ContextThemeWrapper(displayContext, theme) {
@Override
public Object getSystemService(String name) {
if (WINDOW_SERVICE.equals(name)) {
return displayWindowManager;
}
return super.getSystemService(name);
}
};
}
/**
* Sets the {@link Resources.Theme} against which drop-down views are
* inflated.
* <p>
* By default, drop-down views are inflated against the theme of the
* {@link Context} passed to the adapter's constructor.
*
* @param theme the theme against which to inflate drop-down views or
* {@code null} to use the theme from the adapter's context
* @see #getDropDownView(int, View, ViewGroup)
*/
@Override
public void setDropDownViewTheme(@Nullable Resources.Theme theme) {
if (theme == null) {
mDropDownInflater = null;
} else if (theme == mInflater.getContext().getTheme()) {
mDropDownInflater = mInflater;
} else {
final Context context = new ContextThemeWrapper(mContext, theme);
mDropDownInflater = LayoutInflater.from(context);
}
}
/**
* 初始化资源
*
* @param context 上下文
*/
private void initResources(ContextThemeWrapper context) {
mResources = getResources();
mLeafFloatTime = LEAF_FLOAT_TIME;
mLeafRotateTime = LEAF_ROTATE_TIME;
mDefaultWidth = UiUtils.dip2px(context, mDefaultWidth);
mDefaultHeight = UiUtils.dip2px(context, mDefaultHeight);
}
/**
* Sets the {@link android.content.res.Resources.Theme} against which drop-down views are
* inflated.
* <p>
* By default, drop-down views are inflated against the theme of the
* {@link Context} passed to the adapter's constructor.
*
* @param theme the theme against which to inflate drop-down views or
* {@code null} to use the theme from the adapter's context
* @see #getDropDownView(int, View, ViewGroup)
*/
@Override
public void setDropDownViewTheme(Resources.Theme theme) {
if (theme == null) {
mDropDownInflater = null;
} else if (theme == mInflater.getContext().getTheme()) {
mDropDownInflater = mInflater;
} else {
final Context context = new ContextThemeWrapper(mInflater.getContext(), theme);
mDropDownInflater = LayoutInflater.from(context);
}
}
public static ContextThemeWrapper createThemeWrapper(Context context,
int parentStyleAttr, int parentDefaultStyle, int childStyleAttr,
int childDefaultStyle) {
final TypedArray forParent = context.obtainStyledAttributes(
new int[]{parentStyleAttr});
int parentStyle = forParent.getResourceId(0, parentDefaultStyle);
forParent.recycle();
TypedArray forChild = context.obtainStyledAttributes(parentStyle,
new int[]{childStyleAttr});
int childStyleId = forChild.getResourceId(0, childDefaultStyle);
forChild.recycle();
return new ContextThemeWrapper(context, childStyleId);
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedState)
{
ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext())); // hack: contextWrapper required because base theme is not properly applied
View dialogContent = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_date1, parent, false);
initViews(getContext(), dialogContent);
if (savedState != null) {
loadSettings(savedState);
} else {
loadSettings(getActivity());
}
return dialogContent;
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState)
{
ContextThemeWrapper contextWrapper = new ContextThemeWrapper(getActivity(), AppSettings.loadTheme(getContext())); // hack: contextWrapper required because base theme is not properly applied
View view = inflater.cloneInContext(contextWrapper).inflate(R.layout.layout_dialog_location, parent, false);
final FragmentActivity myParent = getActivity();
dialogContent = (LocationConfigView) view.findViewById(R.id.locationConfig);
dialogContent.setHideTitle(hideTitle);
dialogContent.setHideMode(hideMode);
dialogContent.init(myParent, false);
Button btn_cancel = (Button) view.findViewById(R.id.dialog_button_cancel);
btn_cancel.setOnClickListener(onDialogCancelClick);
Button btn_accept = (Button) view.findViewById(R.id.dialog_button_accept);
btn_accept.setOnClickListener(onDialogAcceptClick);
if (savedInstanceState != null) {
loadSettings(savedInstanceState);
} else if (presetData != null) {
dialogContent.loadSettings(myParent, presetData);
} else if (presetLocation != null) {
setLocation(getContext(), presetLocation);
}
return view;
}