List of usage examples for android.app Activity getTheme
@Override
public Resources.Theme getTheme()
From source file:android_network.hetnet.vpn_service.AdapterRule.java
public AdapterRule(Activity context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); this.context = context; this.inflater = LayoutInflater.from(context); if (prefs.getBoolean("dark_theme", false)) colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY)); else/*from w w w. j a v a 2s . c o m*/ colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY), Color.blue(Color.LTGRAY)); TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary }); try { colorText = ta.getColor(0, 0); } finally { ta.recycle(); } TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); colorOn = tv.data; context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed); iconSize = Util.dips2pixels(48, context); }
From source file:eu.faircode.netguard.AdapterRule.java
public AdapterRule(Activity context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); this.context = context; if (prefs.getBoolean("dark_theme", false)) colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY)); else// www .j a v a 2 s . c o m colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY), Color.blue(Color.LTGRAY)); TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary }); try { colorText = ta.getColor(0, 0); } finally { ta.recycle(); } TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); colorOn = tv.data; context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed); iconSize = Util.dips2pixels(48, context); }
From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java
private void resolveTheme() { // Look up the guidedStepTheme in the currently specified theme. If it exists, // replace the theme with its value. Activity activity = getActivity(); int theme = onProvideTheme(); if (theme == -1 && !isGuidedStepTheme(activity)) { // Look up the guidedStepTheme in the activity's currently specified theme. If it // exists, replace the theme with its value. int resId = android.support.v17.leanback.R.attr.guidedStepTheme; TypedValue typedValue = new TypedValue(); boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true); if (DEBUG) Log.v(TAG, "Found guided step theme reference? " + found); if (found) { ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId); if (isGuidedStepTheme(themeWrapper)) { mThemeWrapper = themeWrapper; } else { found = false;// w ww .j av a 2 s . co m mThemeWrapper = null; } } if (!found) { Log.e(TAG, "GuidedStepListFragment does not have an appropriate theme set."); } } else if (theme != -1) { mThemeWrapper = new ContextThemeWrapper(activity, theme); } }
From source file:android.support.v17.leanback.app.GuidedStepFragment.java
private void resolveTheme() { // Look up the guidedStepTheme in the currently specified theme. If it exists, // replace the theme with its value. Activity activity = getActivity(); if (mTheme == -1 && !isGuidedStepTheme(activity)) { // Look up the guidedStepTheme in the activity's currently specified theme. If it // exists, replace the theme with its value. int resId = R.attr.guidedStepTheme; TypedValue typedValue = new TypedValue(); boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true); if (DEBUG) Log.v(TAG, "Found guided step theme reference? " + found); if (found) { ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId); if (isGuidedStepTheme(themeWrapper)) { mTheme = typedValue.resourceId; mThemeWrapper = themeWrapper; } else { found = false;// ww w .j a v a 2s . co m mThemeWrapper = null; } } if (!found) { Log.e(TAG, "GuidedStepFragment does not have an appropriate theme set."); } } else if (mTheme != -1) { mThemeWrapper = new ContextThemeWrapper(activity, mTheme); } }
From source file:com.rbware.github.androidcouchpotato.app.GuidedStepFragment.java
private void resolveTheme() { // Look up the guidedStepTheme in the currently specified theme. If it exists, // replace the theme with its value. Activity activity = getActivity(); int theme = onProvideTheme(); if (theme == -1 && !isGuidedStepTheme(activity)) { // Look up the guidedStepTheme in the activity's currently specified theme. If it // exists, replace the theme with its value. int resId = R.attr.guidedStepTheme; TypedValue typedValue = new TypedValue(); boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true); if (DEBUG) Log.v(TAG, "Found guided step theme reference? " + found); if (found) { ContextThemeWrapper themeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId); if (isGuidedStepTheme(themeWrapper)) { mThemeWrapper = themeWrapper; } else { found = false;// w ww . j av a 2 s.co m mThemeWrapper = null; } } if (!found) { Log.e(TAG, "GuidedStepFragment does not have an appropriate theme set."); } } else if (theme != -1) { mThemeWrapper = new ContextThemeWrapper(activity, theme); } }
From source file:android.support.v17.leanback.app.BackgroundManager.java
private BackgroundManager(Activity activity, boolean isSupportFragmentActivity) { mContext = activity;//from w ww. j a v a 2 s . c o m mService = BackgroundContinuityService.getInstance(); mHeightPx = mContext.getResources().getDisplayMetrics().heightPixels; mWidthPx = mContext.getResources().getDisplayMetrics().widthPixels; mHandler = new Handler(); Interpolator defaultInterpolator = new FastOutLinearInInterpolator(); mAccelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.accelerate_interpolator); mDecelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.decelerate_interpolator); mAnimator = ValueAnimator.ofInt(0, FULL_ALPHA); mAnimator.addListener(mAnimationListener); mAnimator.addUpdateListener(mAnimationUpdateListener); mAnimator.setInterpolator(defaultInterpolator); mDimAnimator = new ValueAnimator(); mDimAnimator.addUpdateListener(mDimUpdateListener); TypedArray ta = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); mThemeDrawableResourceId = ta.getResourceId(0, -1); if (mThemeDrawableResourceId < 0) { if (DEBUG) Log.v(TAG, "BackgroundManager no window background resource!"); } ta.recycle(); if (isSupportFragmentActivity) { createSupportFragment((FragmentActivity) activity); } else { createFragment(activity); } }
From source file:com.example.ray.firstapp.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }// w w w . j av a2 s . c o m if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }/* ww w .j a va 2s .c om*/ if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset, bottomBar.isShy(), bottomBar.mIsTabletMode)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:com.sabaibrowser.UI.java
public UI(Activity browser, UiController controller) { mActivity = browser;/*from w w w.j a v a 2 s . c o m*/ mUiController = controller; mTabControl = controller.getTabControl(); Resources res = mActivity.getResources(); mInputManager = (InputMethodManager) browser.getSystemService(Activity.INPUT_METHOD_SERVICE); FrameLayout frameLayout = (FrameLayout) mActivity.getWindow().getDecorView() .findViewById(android.R.id.content); LayoutInflater.from(mActivity).inflate(R.layout.custom_screen, frameLayout); mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(R.id.fixed_titlebar_container); mContentView = (FrameLayout) frameLayout.findViewById(R.id.main_content); mCustomViewContainer = (FrameLayout) frameLayout.findViewById(R.id.fullscreen_custom_content); mBlockedElementsContainer = (FrameLayout) frameLayout.findViewById(R.id.blocked_dialog_container); mBubbleMenu = (BubbleMenu) frameLayout.findViewById(R.id.bubble_menu); setImmersiveFullscreen(false); mTitleBar = new TitleBar(mActivity, mUiController, this, mContentView); mTitleBar.setProgress(100); mNavigationBar = mTitleBar.getNavigationBar(); mUrlBarAutoShowManager = new UrlBarAutoShowManager(this); mSwipeContainer = (SwipeRefreshLayout) frameLayout.findViewById(R.id.swipe_container); mSwipeContainer.setColorSchemeColors(browser.getResources().getColor(R.color.primary)); mSwipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mUiController.getCurrentTopWebView().reload(); mSwipeContainer.setRefreshing(false); } }); mSwipeContainer.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (getWebView() == null) return; int scrollY = getWebView().getScrollY(); // workaround for swipetorefresh not "stealing" the scrolling if (scrollY == 0) { mSwipeContainer.setEnabled(true); } else { mSwipeContainer.setEnabled(false); } if (mLastWebViewScrollY < scrollY && mLastWebViewScrollY != 0 && !mTitleBar.isShrank()) { mTitleBar.shrink(); } else if (mLastWebViewScrollY > scrollY && scrollY != 0 && mTitleBar.isShrank()) { mTitleBar.unShrink(); } mLastWebViewScrollY = scrollY; } }); mNavigationBar = mTitleBar.getNavigationBar(); mNavigationBar.setFabMenu(mBubbleMenu); initBubbleMenu(); TypedValue heightValue = new TypedValue(); browser.getTheme().resolveAttribute(android.R.attr.actionBarSize, heightValue, true); mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data, browser.getResources().getDisplayMetrics()); MainThreadBus.get().register(this); }