List of usage examples for android.app Activity obtainStyledAttributes
public final TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException
From source file:com.miz.utils.ViewUtils.java
/** * Update the Toolbar background color and title. * @param activity//from w w w . j ava2s.c o m * @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); } }
From source file:com.emartynov.android.app.urlsetter.android.ui.fragment.PlaceholderFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.PlaceholderFragment); fragmentLayout = a.getResourceId(R.styleable.PlaceholderFragment_fragment_layout, -1); a.recycle();/* w w w . j ava2 s. c om*/ }
From source file:com.emartynov.android.app.urlsetter.android.ui.fragment.UrlListFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.PlaceholderFragment); int keys = a.getResourceId(R.styleable.PlaceholderFragment_list_fragment_keys, -1); if (keys != -1) { keyIds = keys;/* ww w .j a va2 s .c o m*/ } int values = a.getResourceId(R.styleable.PlaceholderFragment_list_fragment_values, -1); if (values != -1) { valuesIds = values; } a.recycle(); }
From source file:com.aaa.activity.main.BaseFragment.java
protected int getActionBarSize() { Activity activity = getActivity(); if (activity == null) { return 0; }//from w ww. j ava 2 s . co m TypedValue typedValue = new TypedValue(); int[] textSizeAttr = new int[] { R.attr.actionBarSize }; int indexOfAttrTextSize = 0; TypedArray a = activity.obtainStyledAttributes(typedValue.data, textSizeAttr); int actionBarSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1); a.recycle(); return actionBarSize; }
From source file:com.limewoodmedia.nsdroid.fragments.WACouncilFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.WACouncilFragment); legend = a.getResourceId(R.styleable.WACouncilFragment_legend, -1); a.recycle();//from ww w .ja v a 2 s. co m }
From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java
@Override public void onInflate(Activity a, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(a, attrs, savedInstanceState); TypedArray array = a.obtainStyledAttributes(attrs, R.styleable.SprocketsPreferenceFragment); Bundle args = Fragments.arguments(this); args.putInt(PREFS, array.getResourceId(R.styleable.SprocketsPreferenceFragment_preferences, 0)); args.putBoolean(TRACK_CHANGES,/*from w w w . j a v a2 s . com*/ array.getBoolean(R.styleable.SprocketsPreferenceFragment_trackChanges, false)); array.recycle(); }
From source file:com.eutectoid.dosomething.picker.FriendPickerFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_friend_picker_fragment); setMultiSelect(a.getBoolean(R.styleable.picker_friend_picker_fragment_multi_select, multiSelect)); a.recycle();/*from w ww . ja va 2s .co m*/ }
From source file:com.eutectoid.dosomething.picker.PlacePickerFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_place_picker_fragment); setRadiusInMeters(a.getInt(R.styleable.picker_place_picker_fragment_radius_in_meters, radiusInMeters)); setResultsLimit(a.getInt(R.styleable.picker_place_picker_fragment_results_limit, resultsLimit)); if (a.hasValue(R.styleable.picker_place_picker_fragment_results_limit)) { setSearchText(a.getString(R.styleable.picker_place_picker_fragment_search_text)); }//from w w w .j a v a2 s . c om showSearchBox = a.getBoolean(R.styleable.picker_place_picker_fragment_show_search_box, showSearchBox); a.recycle(); }
From source file:com.fimagena.filepicker.FilePickerFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_PARAMS)) { mParams = (BitSet) savedInstanceState.getSerializable(KEY_PARAMS); mStartPath = new File(savedInstanceState.getString(KEY_CURRENT_PATH)); } else {/*from w w w .j a va2 s . c o m*/ // read xml custom-attributes TypedArray attrArray = activity.obtainStyledAttributes(attrs, R.styleable.FilePickerFragment); mParams = new BitSet(4); mParams.set(SELECT_FILE, attrArray.getBoolean(R.styleable.FilePickerFragment_select_file, false)); mParams.set(SELECT_DIR, attrArray.getBoolean(R.styleable.FilePickerFragment_select_dir, false)); mParams.set(ALLOW_CREATE_DIR, attrArray.getBoolean(R.styleable.FilePickerFragment_allow_dir_create, false)); mParams.set(ALLOW_MULTIPLE_SELECT, attrArray.getBoolean(R.styleable.FilePickerFragment_allow_multiple, false)); if (!mParams.get(SELECT_FILE) && !mParams.get(SELECT_DIR)) mParams.set(SELECT_FILE, true); if (attrArray.hasValue(R.styleable.FilePickerFragment_start_path)) mStartPath = new File(attrArray.getText(R.styleable.FilePickerFragment_start_path).toString()); else mStartPath = Environment.getExternalStorageDirectory(); attrArray.recycle(); } }
From source file:com.chao.facebookzc.widget.PickerFragment.java
@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)); }//from w ww .j a v a 2 s . co m 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(); }