Java Code Examples for android.app.Activity#obtainStyledAttributes()
The following examples show how to use
android.app.Activity#obtainStyledAttributes() .
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: ViewUtils.java From Mizuu with Apache License 2.0 | 6 votes |
/** * Update the Toolbar background color and title. * @param activity * @param toolbar * @param alpha * @param title * @param color */ public static void updateToolbarBackground(Activity activity, Toolbar toolbar, int alpha, String title, int color) { if (defaultTitleTextColor == -1) { int[] textColorAttr = new int[]{R.attr.actionMenuTextColor}; TypedValue typedValue = new TypedValue(); int indexOfAttrTextColor = 0; TypedArray a = activity.obtainStyledAttributes(typedValue.data, textColorAttr); defaultTitleTextColor = a.getColor(indexOfAttrTextColor, -1); a.recycle(); } toolbar.setTitle(title); toolbar.setTitleTextColor(adjustAlpha(defaultTitleTextColor, alpha)); int toolbarColor = adjustAlpha(color, alpha); if (MizLib.hasJellyBean()) { int topColor = darkenColor(color, alpha / 255f); topColor = adjustAlpha(topColor, Math.max(125, alpha)); int[] colors = {topColor, toolbarColor}; toolbar.setBackground(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors)); } else { toolbar.setBackgroundColor(toolbarColor); } }
Example 2
Source File: OutlayTheme.java From outlay with Apache License 2.0 | 6 votes |
public OutlayTheme( Activity context, int themeId ) { int[] textSizeAttr = new int[]{ R.attr.activeIconColor, R.attr.textColorPrimary, R.attr.inactiveIconColor, R.attr.textColorSecondary, R.attr.backgroundDarkColor, R.attr.backgroundColor }; TypedArray a = context.obtainStyledAttributes(themeId, textSizeAttr); activeIconColor = a.getColor(0, -1); primaryTextColor = a.getColor(1, -1); inactiveIconColor = a.getColor(2, -1); secondaryTextColor = a.getColor(3, -1); backgroundDarkColor = a.getColor(4, -1); backgroundColor = a.getColor(5, -1); a.recycle(); }
Example 3
Source File: PickerFragment.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 6 votes |
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_picker_fragment); setShowPictures(a.getBoolean(R.styleable.com_facebook_picker_fragment_show_pictures, showPictures)); String extraFieldsString = a.getString(R.styleable.com_facebook_picker_fragment_extra_fields); if (extraFieldsString != null) { String[] strings = extraFieldsString.split(","); setExtraFields(Arrays.asList(strings)); } showTitleBar = a.getBoolean(R.styleable.com_facebook_picker_fragment_show_title_bar, showTitleBar); titleText = a.getString(R.styleable.com_facebook_picker_fragment_title_text); doneButtonText = a.getString(R.styleable.com_facebook_picker_fragment_done_button_text); titleBarBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_title_bar_background); doneButtonBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_done_button_background); a.recycle(); }
Example 4
Source File: ThemeUtility.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public static int getDimensionPixelSize(Activity activity, int attr, int defaultValue) { int[] attrs = new int[]{ attr }; TypedArray ta = activity.obtainStyledAttributes(attrs); int value = ta.getDimensionPixelSize(0, defaultValue); ta.recycle(); return value; }
Example 5
Source File: FriendPickerFragment.java From platform-friends-android with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_friend_picker_fragment); setMultiSelect(a.getBoolean(R.styleable.com_facebook_friend_picker_fragment_multi_select, multiSelect)); a.recycle(); }
Example 6
Source File: PlacePickerFragment.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 5 votes |
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_place_picker_fragment); setRadiusInMeters(a.getInt(R.styleable.com_facebook_place_picker_fragment_radius_in_meters, radiusInMeters)); setResultsLimit(a.getInt(R.styleable.com_facebook_place_picker_fragment_results_limit, resultsLimit)); if (a.hasValue(R.styleable.com_facebook_place_picker_fragment_results_limit)) { setSearchText(a.getString(R.styleable.com_facebook_place_picker_fragment_search_text)); } showSearchBox = a.getBoolean(R.styleable.com_facebook_place_picker_fragment_show_search_box, showSearchBox); a.recycle(); }
Example 7
Source File: FragmentArgumentsSupport.java From V.FlyoutTest with MIT License | 5 votes |
/** * Parse attributes during inflation from a view hierarchy into the * arguments we handle. */ @Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.FragmentArguments); mLabel = a.getText(R.styleable.FragmentArguments_android_label); a.recycle(); }
Example 8
Source File: SuperToastManagerImpl.java From pandroid with Apache License 2.0 | 5 votes |
protected void applyStyle(SuperActivityToast toast, Activity activity, int style) { if (style == 0) { style = R.style.Toast; } TypedArray attributes = activity.obtainStyledAttributes(style, R.styleable.ToastAppearance); int textColor = attributes.getColor(R.styleable.ToastAppearance_toastTextColor, ContextCompat.getColor(activity, R.color.white)); int backgroundColor = attributes.getColor(R.styleable.ToastAppearance_toastBackground, ContextCompat.getColor(activity, R.color.pandroid_green)); toast.setColor(backgroundColor); toast.setTextColor(textColor); attributes.recycle(); }
Example 9
Source File: DuoDrawerToggleHoneycomb.java From duo-navigation-drawer with Apache License 2.0 | 4 votes |
public static Drawable getThemeUpIndicator(Activity activity) { final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS); final Drawable result = a.getDrawable(0); a.recycle(); return result; }
Example 10
Source File: SystemBarTintManager.java From quickmark with MIT License | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(19) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 11
Source File: SystemBarTintManager.java From Android-SpeedyViewSelector with Apache License 2.0 | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(Build.VERSION_CODES.KITKAT) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } View childRoot = decorViewGroup.getChildAt(0); decorViewGroup.removeView(childRoot); LinearLayout rootView = new LinearLayout(activity); rootView.setOrientation(LinearLayout.VERTICAL); if (mStatusBarAvailable) { setupStatusBarView(activity, rootView); } rootView.addView(childRoot,generateLayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0,1.0f)); if (mNavBarAvailable) { setupNavBarView(activity, rootView); } decorViewGroup.addView(rootView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
Example 12
Source File: SystemBarTintManager.java From MaterialHome with Apache License 2.0 | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(19) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 13
Source File: SystemBarTintManager.java From SweetMusicPlayer with Apache License 2.0 | 4 votes |
/** * @param activity The host activity. */ @TargetApi(19) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus,android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 14
Source File: ActionBarHelperNative.java From WayHoo with Apache License 2.0 | 4 votes |
public static Drawable getThemeUpIndicator(Object info, Activity activity) { final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS); final Drawable result = a.getDrawable(0); a.recycle(); return result; }
Example 15
Source File: SystemBarTintManager.java From LLApp with Apache License 2.0 | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(19) @SuppressWarnings("ResourceType") public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 16
Source File: TopicInfoFragment.java From tindroid with Apache License 2.0 | 4 votes |
private void notifyContentChanged() { final Activity activity = getActivity(); if (activity == null || activity.isFinishing() || activity.isDestroyed()) { return; } final AppCompatImageView avatar = activity.findViewById(R.id.imageAvatar); final TextView title = activity.findViewById(R.id.topicTitle); final TextView subtitle = activity.findViewById(R.id.topicSubtitle); VxCard pub = mTopic.getPub(); if (pub != null && !TextUtils.isEmpty(pub.fn)) { title.setText(pub.fn); title.setTypeface(null, Typeface.NORMAL); title.setTextIsSelectable(true); } else { title.setText(R.string.placeholder_contact_title); title.setTypeface(null, Typeface.ITALIC); title.setTextIsSelectable(false); } final Bitmap bmp = pub != null ? pub.getBitmap() : null; if (bmp != null) { avatar.setImageDrawable(new RoundImageDrawable(getResources(), bmp)); } else { avatar.setImageDrawable( new LetterTileDrawable(requireContext()) .setIsCircular(true) .setContactTypeAndColor( mTopic.getTopicType() == Topic.TopicType.P2P ? LetterTileDrawable.ContactType.PERSON : LetterTileDrawable.ContactType.GROUP) .setLetterAndColor(pub != null ? pub.fn : null, mTopic.getName())); } PrivateType priv = mTopic.getPriv(); if (priv != null && !TextUtils.isEmpty(priv.getComment())) { subtitle.setText(priv.getComment()); subtitle.setTypeface(null, Typeface.NORMAL); TypedValue typedValue = new TypedValue(); Resources.Theme theme = getActivity().getTheme(); theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true); TypedArray arr = activity.obtainStyledAttributes(typedValue.data, new int[]{android.R.attr.textColorSecondary}); subtitle.setTextColor(arr.getColor(0, -1)); arr.recycle(); subtitle.setTextIsSelectable(true); } else { subtitle.setText(R.string.placeholder_private); subtitle.setTypeface(null, Typeface.ITALIC); subtitle.setTextColor(getResources().getColor(R.color.colorTextPlaceholder)); subtitle.setTextIsSelectable(false); } ((Switch) activity.findViewById(R.id.switchMuted)).setChecked(mTopic.isMuted()); ((Switch) activity.findViewById(R.id.switchArchived)).setChecked(mTopic.isArchived()); Acs acs = mTopic.getAccessMode(); ((TextView) activity.findViewById(R.id.permissionsSingle)).setText(acs == null ? "" : acs.getMode()); }
Example 17
Source File: ActionBarDrawerToggleHoneycomb.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public static Drawable getThemeUpIndicator(Activity activity) { final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS); final Drawable result = a.getDrawable(0); a.recycle(); return result; }
Example 18
Source File: SystemBarTintManager.java From LiuAGeAndroid with MIT License | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(19) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 19
Source File: ActionBarDrawerToggleHoneycomb.java From V.FlyoutTest with MIT License | 4 votes |
public static Drawable getThemeUpIndicator(Activity activity) { final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS); final Drawable result = a.getDrawable(0); a.recycle(); return result; }
Example 20
Source File: SystemBarTintManager.java From MissZzzReader with Apache License 2.0 | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(19) @SuppressWarnings("ResourceType") public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }