List of usage examples for android.content Context obtainStyledAttributes
public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)
From source file:app.newbee.lib.swipeback.SwipeBackLayout.java
public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mDragHelper = ViewDragHelper.create(this, new ViewDragCallback()); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout, defStyle, R.style.SwipeBackLayout);//ww w .ja v a 2 s . c o m int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1); if (edgeSize > 0) setEdgeSize(edgeSize); int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)]; setEdgeTrackingEnabled(mode); a.recycle(); final float density = getResources().getDisplayMetrics().density; final float minVel = MIN_FLING_VELOCITY * density; mDragHelper.setMinVelocity(minVel); mDragHelper.setMaxVelocity(minVel * 2f); }
From source file:com.albedinsky.android.setting.SettingSelectionDialogPreference.java
/** * Called from one of constructors of this setting preference to perform its initialization. * <p>/*ww w .ja v a2 s.com*/ * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this preference specific data from it that can be used to configure this new preference instance. * The specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default * data from the current theme provided by the specified <var>context</var>. */ private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Settings_SelectionDialogPreference, defStyleAttr, defStyleRes); setEntries(typedArray.getTextArray(R.styleable.Ui_Settings_SelectionDialogPreference_android_entries)); setEntryValues( typedArray.getTextArray(R.styleable.Ui_Settings_SelectionDialogPreference_android_entryValues)); typedArray.recycle(); this.mSummaryTextBuilder = new DefaultSummaryTextBuilder(SUMMARY_ENTRIES_SEPARATOR); }
From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java
public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mDragHelper = ViewDragHelper.create(this, new ViewDragCallback()); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout, defStyle, R.style.SwipeBackLayout);/*from w w w .j a va2 s. c om*/ int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1); if (edgeSize > 0) { setEdgeSize(edgeSize); } int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)]; setEdgeTrackingEnabled(mode); int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, R.drawable.shadow_left); int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, R.drawable.shadow_right); int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, R.drawable.shadow_bottom); setShadow(shadowLeft, EDGE_LEFT); setShadow(shadowRight, EDGE_RIGHT); setShadow(shadowBottom, EDGE_BOTTOM); a.recycle(); final float density = getResources().getDisplayMetrics().density; final float minVel = MIN_FLING_VELOCITY * density; mDragHelper.setMinVelocity(minVel); mDragHelper.setMaxVelocity(minVel * 2f); }
From source file:at.linuxtage.companion.widgets.SlidingTabLayout.java
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);//from w ww . j a v a 2s .co m mTabStrip = new SlidingTabStrip(context); addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout, defStyle, R.style.SlidingTabLayout); mTabStrip.setSelectedIndicatorHeight( a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0)); mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_indicatorColor, 0)); mTextColor = a.getColorStateList(R.styleable.SlidingTabLayout_textColor); if ((mTextColor != null) && a.hasValue(R.styleable.SlidingTabLayout_selectedTextColor)) { setTabTextColors(mTextColor.getDefaultColor(), a.getColor(R.styleable.SlidingTabLayout_selectedTextColor, 0)); } setContentInsetStart(a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, 0)); setDistributeEvenly(a.getBoolean(R.styleable.SlidingTabLayout_distributeEvenly, false)); a.recycle(); }
From source file:com.albedinsky.android.support.ui.widget.ScrollViewWidget.java
/** * Creates a new instance of ScrollViewWidget within the given <var>context</var>. * * @param context Context in which will be this view presented. * @param attrs Set of Xml attributes used to configure the new instance of this view. * @param defStyleAttr An attribute which contains a reference to a default style resource for * this view within a theme of the given context. *//*from w ww .j av a 2 s. c o m*/ public ScrollViewWidget(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ScrollView, defStyleAttr, 0); if (typedArray != null) { this.ensurePullController(); mPullController.setUpFromAttrs(context, attrs, defStyleAttr); this.processTintValues(context, typedArray); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { int index = typedArray.getIndex(i); if (index == R.styleable.Ui_Widget_ScrollView_uiPullEnabled) { setPullEnabled(typedArray.getBoolean(index, false)); } } typedArray.recycle(); } this.applyBackgroundTint(); }
From source file:com.albedinsky.android.support.ui.widget.HorizontalScrollViewWidget.java
/** * Creates a new instance of HorizontalScrollViewWidget within the given <var>context</var>. * * @param context Context in which will be this view presented. * @param attrs Set of Xml attributes used to configure the new instance of this view. * @param defStyleAttr An attribute which contains a reference to a default style resource for * this view within a theme of the given context. *///ww w. j av a 2 s.com public HorizontalScrollViewWidget(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_HorizontalScrollView, defStyleAttr, 0); if (typedArray != null) { this.ensurePullController(); mPullController.setUpFromAttrs(context, attrs, defStyleAttr); this.processTintValues(context, typedArray); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { int index = typedArray.getIndex(i); if (index == R.styleable.Ui_Widget_HorizontalScrollView_uiPullEnabled) { setPullEnabled(typedArray.getBoolean(index, false)); } } typedArray.recycle(); } this.applyBackgroundTint(); }
From source file:be.virtualsushi.gaz.view.ActivityChooserView.java
/** * Create a new instance./* ww w. j ava 2 s . co m*/ * * @param context * The application environment. * @param attrs * A collection of attributes. * @param defStyle * The default style to apply to this view. */ public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView, defStyle, 0); mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount, ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT); Drawable expandActivityOverflowButtonDrawable = attributesArray .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable); attributesArray.recycle(); LayoutInflater inflater = LayoutInflater.from(getContext()); inflater.inflate(R.layout.abc_activity_chooser_view, this, true); mCallbacks = new Callbacks(); mActivityChooserContent = (LinearLayout) findViewById(R.id.activity_chooser_view_content); mActivityChooserContent.setBackgroundDrawable(null); findViewById(R.id.default_activity_button).setVisibility(GONE); mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button); mExpandActivityOverflowButton.setOnClickListener(mCallbacks); mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.findViewById(R.id.image); mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable); mAdapter = new ActivityChooserViewAdapter(); mAdapter.registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { super.onChanged(); updateAppearance(); } }); Resources resources = context.getResources(); mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth)); }
From source file:ch.berta.fabio.fabprogress.FabProgress.java
private void init(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) { mArcWidth = getResources().getDimensionPixelSize(R.dimen.fp_progress_arc_stroke_width); mFabIcon = getDrawable();// w ww. j a v a2 s. c o m mAccentColor = fetchAccentColor(); TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FabProgress, defStyleAttr, 0); try { mArcColor = attr.getColor(R.styleable.FabProgress_fp_arcColor, ContextCompat.getColor(context, R.color.green_500)); mUseRoundedStroke = attr.getBoolean(R.styleable.FabProgress_fp_roundedStroke, false); mCompleteIcon = attr.getDrawable(R.styleable.FabProgress_fp_finalIcon); if (mCompleteIcon == null) { mCompleteIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_done_white_24dp); } mIsReusable = attr.getBoolean(R.styleable.FabProgress_fp_reusable, false); } finally { attr.recycle(); } if (!Utils.isRunningLollipopAndHigher()) { setFakeShadowPadding(context, attrs, defStyleAttr); } setupPaint(); setupAnimations(); }
From source file:com.anjuke.library.uicomponent.photo.EndlessCircleIndicator.java
public EndlessCircleIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;/* w ww . ja va2 s .com*/ //Load defaults from resources final Resources res = getResources(); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EndlessCircleIndicator, defStyle, 0); mCentered = a.getBoolean(R.styleable.EndlessCircleIndicator_centered, true); mOrientation = a.getInt(R.styleable.EndlessCircleIndicator_android_orientation, 0); mPaintPageFill.setStyle(Style.FILL); mPaintPageFill .setColor(a.getColor(R.styleable.EndlessCircleIndicator_pageColor, Color.parseColor("#00000000"))); mPaintStroke.setStyle(Style.STROKE); mPaintStroke.setColor( a.getColor(R.styleable.EndlessCircleIndicator_strokeColor, Color.parseColor("#FFDDDDDD"))); mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.EndlessCircleIndicator_strokeWidth, UIUtils.dipToPx(res.getDisplayMetrics(), 1))); mPaintFill.setStyle(Style.FILL); mPaintFill .setColor(a.getColor(R.styleable.EndlessCircleIndicator_fillColor, Color.parseColor("#FFFFFFFF"))); mRadius = a.getDimension(R.styleable.EndlessCircleIndicator_radius, UIUtils.dipToPx(res.getDisplayMetrics(), 3)); mSnap = a.getBoolean(R.styleable.EndlessCircleIndicator_snap, false); Drawable background = a.getDrawable(R.styleable.EndlessCircleIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java
/** * Construct a new spinner with the given context's theme, the supplied attribute set, * and default style./* w w w . j av a 2 s. c o m*/ * * @param context The Context the view is running in, through which it can * access the current theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the view. * @param defStyle The default style to apply to this view. If 0, no style * will be applied (beyond what is included in the theme). This may * either be an attribute resource, whose value will be retrieved * from the current theme, or an explicit style resource. */ public IcsSpinner(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockSpinner, defStyle, 0); DropdownPopup popup = new DropdownPopup(context, attrs, defStyle); mDropDownWidth = a.getLayoutDimension(R.styleable.SherlockSpinner_android_dropDownWidth, ViewGroup.LayoutParams.WRAP_CONTENT); popup.setBackgroundDrawable(a.getDrawable(R.styleable.SherlockSpinner_android_popupBackground)); final int verticalOffset = a .getDimensionPixelOffset(R.styleable.SherlockSpinner_android_dropDownVerticalOffset, 0); if (verticalOffset != 0) { popup.setVerticalOffset(verticalOffset); } final int horizontalOffset = a .getDimensionPixelOffset(R.styleable.SherlockSpinner_android_dropDownHorizontalOffset, 0); if (horizontalOffset != 0) { popup.setHorizontalOffset(horizontalOffset); } mPopup = popup; mGravity = a.getInt(R.styleable.SherlockSpinner_android_gravity, Gravity.CENTER); mPopup.setPromptText(a.getString(R.styleable.SherlockSpinner_android_prompt)); mDisableChildrenWhenDisabled = true; a.recycle(); // Base constructor can call setAdapter before we initialize mPopup. // Finish setting things up if this happened. if (mTempAdapter != null) { mPopup.setAdapter(mTempAdapter); mTempAdapter = null; } }