List of usage examples for android.app Activity getTheme
@Override
public Resources.Theme getTheme()
From source file:Main.java
public static int getActionBarHeight(Activity activity) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics()); }//w w w . j av a2s . c om return 0; }
From source file:Main.java
public static int getActionBarSize(Activity activity) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics()); }/*from w w w . j av a 2 s . c om*/ return 0; }
From source file:Main.java
public static int getSystemUiActionBarHeight(Activity activity) { final TypedValue typedValue = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { return TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics()); }/*from ww w. ja va 2s. c o m*/ return -1; }
From source file:com.yixia.zi.utils.UIUtils.java
public static TypedValue getAttrValue(Activity activity, int attrId) { TypedValue typedValue = new TypedValue(); activity.getTheme().resolveAttribute(attrId, typedValue, true); return typedValue; }
From source file:Main.java
public static int getColor(Activity activity, String attr, int fallbackColor) { TypedValue color = new TypedValue(); try {/*w w w . j av a2 s . c o m*/ int colorId = activity.getResources().getIdentifier(attr, "attr", activity.getPackageName()); if (activity.getTheme().resolveAttribute(colorId, color, true)) { return color.data; } } catch (Exception ignored) { } return activity.getResources().getColor(fallbackColor); }
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public static void setBackground(Activity activity, int background) { activity.getActionBar()/*from w ww . ja va2s. c o m*/ .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent))); Drawable draw; if (android.os.Build.VERSION.SDK_INT >= 21) { draw = activity.getResources().getDrawable(background, activity.getTheme()); activity.getActionBar().setBackgroundDrawable(draw); } else { draw = activity.getResources().getDrawable(background); activity.getActionBar().setBackgroundDrawable(draw); } }
From source file:com.poloure.simplerss.Constants.java
@TargetApi(Build.VERSION_CODES.KITKAT) static void setTopOffset(Activity activity, View view) { if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) { if (!ViewConfiguration.get(activity).hasPermanentMenuKey()) { TypedValue value = new TypedValue(); Resources.Theme theme = activity.getTheme(); theme.resolveAttribute(android.R.attr.actionBarSize, value, true); int actionBar = s_resources.getDimensionPixelSize(value.resourceId); int resourceId = s_resources.getIdentifier("status_bar_height", "dimen", "android"); int statusBar = s_resources.getDimensionPixelSize(resourceId); view.setPadding(0, actionBar + statusBar, 0, 0); }//w ww . ja v a 2 s . c o m } }
From source file:com.docd.purefm.utils.BookmarksHelper.java
@NonNull public static List<BookmarkItem> getAllBookmarks(@NonNull final Activity activity) { final List<BookmarkItem> items = new ArrayList<>(); int internalCount = 0; int externalCount = 0; int usbCount = 0; final Resources.Theme theme = activity.getTheme(); final Drawable iconStorage = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_storage); final Drawable iconSdcard = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_sdcard); final Drawable iconUsb = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_usb); final Drawable iconUser = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_bookmark); for (final StorageHelper.StorageVolume v : Environment.getStorageVolumes()) { final BookmarkItem item = new BookmarkItem(); switch (v.getType()) { case EXTERNAL: externalCount++;//from ww w. j av a2 s . co m item.mIcon = iconSdcard; item.mDisplayName = activity.getText(R.string.storage_sdcard); if (externalCount > 1) { item.mDisplayName = TextUtils.concat(item.mDisplayName, " (" + externalCount + ")"); } break; case USB: usbCount++; item.mIcon = iconUsb; item.mDisplayName = activity.getText(R.string.storage_usb); if (usbCount > 1) { item.mDisplayName = TextUtils.concat(item.mDisplayName, " (" + usbCount + ")"); } break; case INTERNAL: default: internalCount++; item.mIcon = iconStorage; item.mDisplayName = activity.getText(R.string.storage_internal); if (internalCount > 1) { item.mDisplayName = TextUtils.concat(item.mDisplayName, " (" + internalCount + ")"); } break; } item.mDisplayPath = v.file.getAbsolutePath(); items.add(item); } for (final String bookmark : Settings.getInstance(activity).getBookmarks()) { final BookmarkItem item = new BookmarkItem(); item.mDisplayName = FilenameUtils.getName(bookmark); if (item.mDisplayName.equals(Environment.sRootDirectory.getAbsolutePath())) { item.mDisplayName = activity.getText(R.string.root); } item.mDisplayPath = bookmark; item.mIcon = iconUser; items.add(item); } return items; }
From source file:Main.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") public static void setActionBar(Activity activity, int background) { // Action Bar Icon activity.getActionBar()//from w ww .j ava 2 s.co m .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent))); // Action Bar Background Drawable draw; if (android.os.Build.VERSION.SDK_INT >= 21) { draw = activity.getResources().getDrawable(background, activity.getTheme()); activity.getActionBar().setBackgroundDrawable(draw); } else { draw = activity.getResources().getDrawable(background); activity.getActionBar().setBackgroundDrawable(draw); } }
From source file:Main.java
/** * @see "http://blog.peterkuterna.net/2011/09/simple-crossfade-on-imageview.html" * with modifications by Thomas Suarez./*from w ww . j a v a 2s.c o m*/ */ public static void setImageDrawableWithFade(final Activity context, final ImageView imageView, final String drawableName, final int durationMillis) { int resId = getDrawableId(context, drawableName); // get new drawable resource Drawable drawable; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { drawable = context.getResources().getDrawable(resId, context.getTheme()); } else { drawable = context.getResources().getDrawable(resId); // this is deprecated starting in Android 5.0 Lollipop } final Drawable currentDrawable = imageView.getDrawable(); final Drawable newDrawable = drawable; Runnable r = new Runnable() { @Override public void run() { if (currentDrawable != null) { Drawable[] arrayDrawable = new Drawable[2]; arrayDrawable[0] = currentDrawable; arrayDrawable[1] = newDrawable; TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable); transitionDrawable.setCrossFadeEnabled(true); imageView.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(durationMillis); } else { imageView.setImageDrawable(newDrawable); } } }; context.runOnUiThread(r); }