androidx.appcompat.view.ContextThemeWrapper Java Examples
The following examples show how to use
androidx.appcompat.view.ContextThemeWrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarshmallowEditText.java From Carbon with Apache License 2.0 | 6 votes |
private void createMenu(Menu menu) { TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(R.attr.carbon_editMenuTheme, outValue, true); int theme = outValue.resourceId; Context themedContext = new ContextThemeWrapper(getContext(), theme); popupMenu = new EditTextMenu(themedContext); popupMenu.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { isShowingPopup = false; } }); popupMenu.initCopy(menu.findItem(ID_COPY)); popupMenu.initCut(menu.findItem(ID_CUT)); popupMenu.initPaste(menu.findItem(ID_PASTE)); popupMenu.initSelectAll(menu.findItem(ID_SELECT_ALL)); //menu.clear(); /*try { mIgnoreActionUpEventField.set(editor, true); } catch (IllegalAccessException e) { e.printStackTrace(); }*/ }
Example #2
Source File: BaseFragment.java From onpc with GNU General Public License v3.0 | 6 votes |
AppCompatImageButton createButton( @DrawableRes int imageId, @StringRes int descriptionId, final ISCPMessage msg, Object tag, int leftMargin, int rightMargin, int verticalMargin) { ContextThemeWrapper wrappedContext = new ContextThemeWrapper(activity, R.style.ImageButtonPrimaryStyle); final AppCompatImageButton b = new AppCompatImageButton(wrappedContext, null, 0); final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(buttonSize, buttonSize); lp.setMargins(leftMargin, verticalMargin, rightMargin, verticalMargin); b.setLayoutParams(lp); b.setTag(tag); prepareButton(b, msg, imageId, descriptionId); return b; }
Example #3
Source File: BaseFragment.java From onpc with GNU General Public License v3.0 | 6 votes |
AppCompatButton createButton(@StringRes int descriptionId, final ISCPMessage msg, Object tag, final ButtonListener listener) { ContextThemeWrapper wrappedContext = new ContextThemeWrapper(activity, R.style.TextButtonStyle); final AppCompatButton b = new AppCompatButton(wrappedContext, null, 0); final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, buttonSize); lp.setMargins(buttonMarginHorizontal, 0, buttonMarginHorizontal, 0); b.setLayoutParams(lp); b.setText(descriptionId); b.setTag(tag); prepareButtonListeners(b, msg, listener); return b; }
Example #4
Source File: ShapeThemingDemoFragment.java From material-components-android with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView( LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { this.wrappedContext = new ContextThemeWrapper(getContext(), getShapeTheme()); LayoutInflater layoutInflaterWithThemedContext = layoutInflater.cloneInContext(wrappedContext); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getActivity().getWindow(); statusBarColor = window.getStatusBarColor(); final TypedValue value = new TypedValue(); wrappedContext .getTheme() .resolveAttribute(R.attr.colorPrimaryDark, value, true); window.setStatusBarColor(value.data); } return super.onCreateView(layoutInflaterWithThemedContext, viewGroup, bundle); }
Example #5
Source File: ManageStoreFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); getFragmentComponent(savedInstanceState).inject(this); currentModel = Parcels.unwrap(getArguments().getParcelable(EXTRA_STORE_MODEL)); goToHome = getArguments().getBoolean(EXTRA_GO_TO_HOME, true); dialogFragment = new ImagePickerDialog.Builder(new ContextThemeWrapper(getContext(), themeManager.getAttributeForTheme(R.attr.dialogsTheme).resourceId), themeManager).setViewRes(ImagePickerDialog.LAYOUT) .setTitle(R.string.upload_dialog_title) .setNegativeButton(R.string.cancel) .setCameraButton(R.id.button_camera) .setGalleryButton(R.id.button_gallery) .build(); imagePickerErrorHandler = new ImagePickerErrorHandler(getContext(), themeManager); }
Example #6
Source File: UTest.java From Taskbar with Apache License 2.0 | 6 votes |
@Test public void testWrapContext() { SharedPreferences prefs = U.getSharedPreferences(context); prefs.edit().putString(PREF_THEME, "light").apply(); Context newContext = U.wrapContext(context); Integer themeResource = ReflectionHelpers.getField(newContext, "mThemeResource"); assertNotNull(themeResource); assertEquals(R.style.Taskbar, (int) themeResource); prefs.edit().putString(PREF_THEME, "dark").apply(); newContext = U.wrapContext(context); themeResource = ReflectionHelpers.getField(newContext, "mThemeResource"); assertNotNull(themeResource); assertEquals(R.style.Taskbar_Dark, (int) themeResource); prefs.edit().putString(PREF_THEME, "non-support").apply(); newContext = U.wrapContext(context); assertTrue(newContext instanceof ContextThemeWrapper); prefs.edit().remove(PREF_THEME).apply(); newContext = U.wrapContext(context); themeResource = ReflectionHelpers.getField(newContext, "mThemeResource"); assertNotNull(themeResource); assertEquals(R.style.Taskbar, (int) themeResource); }
Example #7
Source File: CommonUtil.java From GSYVideoPlayer with Apache License 2.0 | 5 votes |
/** * Get AppCompatActivity from context * * @param context * @return AppCompatActivity if it's not null */ public static AppCompatActivity getAppCompActivity(Context context) { if (context == null) return null; if (context instanceof AppCompatActivity) { return (AppCompatActivity) context; } else if (context instanceof ContextThemeWrapper) { return getAppCompActivity(((ContextThemeWrapper) context).getBaseContext()); } return null; }
Example #8
Source File: SupportDialogFragment.java From ui with Apache License 2.0 | 5 votes |
void showlistdialog(String title) { final String[] items = {"Remove Walls", "Add Walls", "Add/Remove Objects", "Add/Remove Score"}; AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.ThemeOverlay_AppCompat_Dialog)); builder.setTitle("Choose Type:"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { dialog.dismiss(); //the dismiss is needed here or the dialog stays showing. displaylog(items[item]); } }); builder.show(); }
Example #9
Source File: Carbon.java From Carbon with Apache License 2.0 | 5 votes |
public static Context getThemedContext(Context context, AttributeSet attributeSet, int[] attrs, @AttrRes int defStyleAttr, int attr) { TypedArray a = context.obtainStyledAttributes(attributeSet, attrs, defStyleAttr, 0); if (a.hasValue(attr)) { int themeId = a.getResourceId(attr, 0); a.recycle(); return new ContextThemeWrapper(context, themeId); } return context; }
Example #10
Source File: NavFloatingActionButtonTest.java From materialistic with Apache License 2.0 | 5 votes |
@Before public void setUp() { button = new NavFloatingActionButton(new ContextThemeWrapper(RuntimeEnvironment.application, R.style.AppTheme)); shadowOf(button).getOnTouchListener().onTouch(button, MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0)); gestureListener = (GestureDetector.SimpleOnGestureListener) shadowOf(ShadowGestureDetector.getLastActiveDetector()).getListener(); navigable = mock(Navigable.class); button.setNavigable(navigable); assertTrue(gestureListener.onDown(null)); }
Example #11
Source File: MaterialThemeOverlayTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void wrap_doesNotWrapTwice_withSameAttributeSet() { AttributeSet attributes = Robolectric.buildAttributeSet() .addAttribute(R.attr.materialThemeOverlay, "@style/ThemeOverlayColorAccentRed") .build(); Context themedContext = MaterialThemeOverlay.wrap(context, attributes, 0, 0); Context themedContext2 = MaterialThemeOverlay .wrap(themedContext, attributes, 0, 0); assertThat(themedContext).isInstanceOf(ContextThemeWrapper.class); assertThat(themedContext).isSameInstanceAs(themedContext2); }
Example #12
Source File: MaterialThemeOverlay.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Uses the materialThemeOverlay attribute to create a themed context. This allows us to use * MaterialThemeOverlay with a default style, and gives us some protection against losing our * ThemeOverlay by clients who set android:theme or app:theme. If android:theme or app:theme is * specified by the client, any attributes defined there will take precedence over attributes * defined in materialThemeOverlay. */ @NonNull public static Context wrap( @NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { int materialThemeOverlayId = obtainMaterialThemeOverlayId(context, attrs, defStyleAttr, defStyleRes); boolean contextHasOverlay = context instanceof ContextThemeWrapper && ((ContextThemeWrapper) context).getThemeResId() == materialThemeOverlayId; if (materialThemeOverlayId == 0 || contextHasOverlay) { return context; } Context contextThemeWrapper = new ContextThemeWrapper(context, materialThemeOverlayId); // We want values set in android:theme or app:theme to always override values supplied by // materialThemeOverlay, so we'll wrap the context again if either of those are set. int androidThemeOverlayId = obtainAndroidThemeOverlayId(context, attrs); if (androidThemeOverlayId != 0) { contextThemeWrapper.getTheme().applyStyle(androidThemeOverlayId, true); } return contextThemeWrapper; }
Example #13
Source File: MaterialAlertDialogBuilder.java From material-components-android with Apache License 2.0 | 5 votes |
private static Context createMaterialAlertDialogThemedContext(@NonNull Context context) { int themeOverlayId = getMaterialAlertDialogThemeOverlay(context); Context themedContext = wrap(context, null, DEF_STYLE_ATTR, DEF_STYLE_RES); if (themeOverlayId == 0) { return themedContext; } return new ContextThemeWrapper(themedContext, themeOverlayId); }
Example #14
Source File: ManageUserFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); getFragmentComponent(savedInstanceState).inject(this); Context context = getContext(); if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_USER_MODEL)) { currentModel = Parcels.unwrap(savedInstanceState.getParcelable(EXTRA_USER_MODEL)); } else { currentModel = new ViewModel(); } Bundle args = getArguments(); isEditProfile = args != null && args.getBoolean(EXTRA_IS_EDIT, false); imagePickerErrorHandler = new ImagePickerErrorHandler(context, themeManager); dialogFragment = new ImagePickerDialog.Builder(new ContextThemeWrapper(getContext(), themeManager.getAttributeForTheme(R.attr.dialogsTheme).resourceId), themeManager).setViewRes(ImagePickerDialog.LAYOUT) .setTitle(R.string.upload_dialog_title) .setNegativeButton(R.string.cancel) .setCameraButton(R.id.button_camera) .setGalleryButton(R.id.button_gallery) .build(); uploadWaitDialog = GenericDialogs.createGenericPleaseWaitDialog(context, themeManager.getAttributeForTheme(R.attr.dialogsTheme).resourceId, context.getString(R.string.please_wait_upload)); }
Example #15
Source File: U.java From Taskbar with Apache License 2.0 | 5 votes |
public static Context wrapContext(Context context) { int theme; if(isDarkTheme(context)) theme = R.style.Taskbar_Dark; else theme = R.style.Taskbar; return new ContextThemeWrapper(context, theme); }
Example #16
Source File: ContextHelper.java From candybar with Apache License 2.0 | 5 votes |
@NonNull static Context getBaseContext(@NonNull View view) { Context context = view.getContext(); if (context instanceof ContextThemeWrapper) { context = ((ContextThemeWrapper) view.getContext()).getBaseContext(); } else if (context instanceof ViewPumpContextWrapper) { context = ((ViewPumpContextWrapper) view.getContext()).getBaseContext(); } return context; }
Example #17
Source File: NotificationsFragment.java From green_android with GNU General Public License v3.0 | 5 votes |
@Override public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) { super.onCreatePreferences(savedInstanceState, rootKey); Context activityContext = getActivity(); final PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(activityContext); setPreferenceScreen(preferenceScreen); final TypedValue themeTypedValue = new TypedValue(); activityContext.getTheme().resolveAttribute(R.attr.preferenceTheme, themeTypedValue, true); mContextThemeWrapper = new ContextThemeWrapper(activityContext, themeTypedValue.resourceId); mEmptyNotifications = new PreferenceCategory(mContextThemeWrapper); mEmptyNotifications.setTitle(R.string.id_your_notifications_will_be); }
Example #18
Source File: MessagesActivity.java From android with MIT License | 5 votes |
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (item.getGroupId() == R.id.apps) { selectAppIdOnDrawerClose = id; startLoading(); toolbar.setSubtitle(item.getTitle()); } else if (id == R.id.nav_all_messages) { selectAppIdOnDrawerClose = MessageState.ALL_MESSAGES; startLoading(); toolbar.setSubtitle(""); } else if (id == R.id.logout) { new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AppTheme_Dialog)) .setTitle(R.string.logout) .setMessage(getString(R.string.logout_confirm)) .setPositiveButton(R.string.yes, this::doLogout) .setNegativeButton(R.string.cancel, (a, b) -> {}) .show(); } else if (id == R.id.nav_logs) { startActivity(new Intent(this, LogsActivity.class)); } else if (id == R.id.settings) { startActivity(new Intent(this, SettingsActivity.class)); } drawer.closeDrawer(GravityCompat.START); return true; }
Example #19
Source File: LoginActivity.java From android with MIT License | 5 votes |
private void newClientDialog(ApiClient client) { EditText clientName = new EditText(this); clientName.setText(Build.MODEL); new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AppTheme_Dialog)) .setTitle(R.string.create_client_title) .setMessage(R.string.create_client_message) .setView(clientName) .setPositiveButton(R.string.create, doCreateClient(client, clientName)) .setNegativeButton(R.string.cancel, this::onCancelClientDialog) .show(); }
Example #20
Source File: LoginActivity.java From android with MIT License | 5 votes |
public void showHttpWarning() { new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AppTheme_Dialog)) .setTitle(R.string.warning) .setCancelable(true) .setMessage(R.string.http_warning) .setPositiveButton(R.string.i_understand, (a, b) -> {}) .show(); }
Example #21
Source File: DeviceList.java From onpc with GNU General Public License v3.0 | 5 votes |
private void updateRadioGroup(final Map<String, DeviceInfo> devices) { if (dialogList != null) { dialogList.removeAllViews(); for (DeviceInfo deviceInfo : devices.values()) { deviceInfo.selected = false; if (deviceInfo.responses > 0) { final ContextThemeWrapper wrappedContext = new ContextThemeWrapper(context, R.style.RadioButtonStyle); final AppCompatRadioButton b = new AppCompatRadioButton(wrappedContext, null, 0); final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); b.setLayoutParams(lp); b.setText(deviceInfo.message.getDescription()); b.setTextColor(Utils.getThemeColorAttr(context, android.R.attr.textColor)); b.setOnClickListener(v -> { deviceInfo.selected = true; stop(); }); dialogList.addView(b); } } dialogList.invalidate(); } }
Example #22
Source File: SingleRecipientNotificationBuilder.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public SingleRecipientNotificationBuilder(@NonNull Context context, @NonNull NotificationPrivacyPreference privacy) { super(new ContextThemeWrapper(context, R.style.TextSecure_LightTheme), privacy); setSmallIcon(R.drawable.ic_notification); setColor(context.getResources().getColor(R.color.core_ultramarine)); setCategory(NotificationCompat.CATEGORY_MESSAGE); if (!NotificationChannels.supported()) { setPriority(TextSecurePreferences.getNotificationPriority(context)); } }
Example #23
Source File: ViewHelper.java From candybar with Apache License 2.0 | 5 votes |
public static void setFastScrollColor(@Nullable RecyclerFastScroller fastScroll) { if (fastScroll == null) return; Context context = fastScroll.getContext(); if (context instanceof ContextThemeWrapper) { context = ((ContextThemeWrapper) context).getBaseContext(); } int accent = ColorHelper.getAttributeColor(context, R.attr.colorAccent); fastScroll.setBarColor(ColorHelper.setColorAlpha(accent, 0.8f)); fastScroll.setHandleNormalColor(accent); fastScroll.setHandlePressedColor(ColorHelper.getDarkerColor(accent, 0.7f)); }
Example #24
Source File: SettingsFragment.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 4 votes |
@Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.settings); SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH); if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) { getPreferenceScreen().removePreference(forceEnglish); } else { forceEnglish.setOnPreferenceChangeListener(this); } /* if (Utils.hideStartActivity()) { ((PreferenceCategory) findPreference(KEY_USER_INTERFACE)) .removePreference(findPreference(KEY_MATERIAL_ICON)); } else { findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this); } */ findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this); findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this); findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this); findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this); findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this); findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this); findPreference(KEY_PRIMARY_COLOR).setOnPreferenceClickListener(this); findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this); findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this); findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this); findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this); if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) { findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this); } else { ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference( findPreference(KEY_LAST_KMSG)); } findPreference(KEY_DMESG).setOnPreferenceClickListener(this); findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this); findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) { ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference( findPreference(KEY_FINGERPRINT)); } else { mFingerprint = findPreference(KEY_FINGERPRINT); mFingerprint.setEnabled(!AppSettings.getPassword(getActivity()).isEmpty()); } NavigationActivity activity = (NavigationActivity) getActivity(); PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS); for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) { Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass; int id = navigationFragment.mId; if (fragmentClass != null && fragmentClass != SettingsFragment.class) { SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat( new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material)); switchPreference.setSummary(getString(id)); switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled"); switchPreference.setChecked(AppSettings.isFragmentEnabled(fragmentClass, getActivity())); switchPreference.setOnPreferenceChangeListener(this); switchPreference.setPersistent(true); sectionsCategory.addPreference(switchPreference); } } }
Example #25
Source File: ThemeUtil.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
public static LayoutInflater getThemedInflater(@NonNull Context context, @NonNull LayoutInflater inflater, @StyleRes int theme) { Context contextThemeWrapper = new ContextThemeWrapper(context, theme); return inflater.cloneInContext(contextThemeWrapper); }
Example #26
Source File: DirectShareService.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private Bitmap getFallbackDrawable(@NonNull Recipient recipient) { Context themedContext = new ContextThemeWrapper(this, R.style.TextSecure_LightTheme); return BitmapUtil.createFromDrawable(recipient.getFallbackContactPhotoDrawable(themedContext, false), getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height)); }