List of usage examples for android.content.res TypedArray getIndexCount
public int getIndexCount()
From source file:com.albedinsky.android.ui.widget.ViewPagerWidget.java
/** * Called from one of constructors of this view to perform its initialization. * <p>// www .j av a 2 s . c o m * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view 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) { this.ensureDecorator(); mDecorator.processAttributes(context, attrs, defStyleAttr, defStyleRes); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ViewPager, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_ViewPager_android_background) { int resID = typedArray.getResourceId(index, -1); if (resID != -1) { setBackgroundResource(resID); } else { setBackgroundColor(typedArray.getColor(0, Color.TRANSPARENT)); } } else if (index == R.styleable.Ui_ViewPager_uiPageMargin) { setPageMargin(typedArray.getDimensionPixelSize(index, 0)); } else if (index == R.styleable.Ui_ViewPager_uiPageMarginDrawable) { setPageMarginDrawable(typedArray.getDrawable(index)); } else if (index == R.styleable.Ui_ViewPager_uiPageSwipingEnabled) { mDecorator.updatePrivateFlags(PFLAG_PAGE_SWIPING_ENABLED, typedArray.getBoolean(index, true)); } else if (index == R.styleable.Ui_ViewPager_uiPageFlingSwipingEnabled) { mDecorator.updatePrivateFlags(PFLAG_PAGE_FLING_SWIPING_ENABLED, typedArray.getBoolean(index, false)); } else if (index == R.styleable.Ui_ViewPager_uiPageFlingSwipingSensitivity) { this.mPageFlingSwipingSensitivity = Math.max(0, typedArray.getFloat(index, mPageFlingSwipingSensitivity)); } else if (index == R.styleable.Ui_ViewPager_uiCurrentPage) { this.mCurrentPage = typedArray.getInteger(index, 0); } else if (index == R.styleable.Ui_ViewPager_uiOffScreenPageLimit) { setOffscreenPageLimit(typedArray.getInt(index, getOffscreenPageLimit())); } else if (index == R.styleable.Ui_ViewPager_uiPageScrollDuration) { this.mPageScrollDuration = typedArray.getInteger(index, mPageScrollDuration); } else if (index == R.styleable.Ui_ViewPager_uiPageScrollRelativeDurationEnabled) { mDecorator.updatePrivateFlags(PFLAG_PAGE_SCROLL_RELATIVE_DURATION_ENABLED, typedArray.getBoolean(index, false)); } else if (index == R.styleable.Ui_ViewPager_uiPullEnabled) { setPullEnabled(typedArray.getBoolean(index, false)); } } typedArray.recycle(); } // Override default scroller so we can use custom durations for scroll if requested. setScroller(new WidgetScroller(context, SCROLLER_INTERPOLATOR)); }
From source file:com.canyinghao.canrefresh.CanRefreshLayout.java
public CanRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CanRefreshLayout, defStyleAttr, 0); try {//w w w . j ava2 s.c o m final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); if (attr == R.styleable.CanRefreshLayout_can_enabled_up) { setRefreshEnabled(a.getBoolean(attr, true)); } else if (attr == R.styleable.CanRefreshLayout_can_enabled_down) { setLoadMoreEnabled(a.getBoolean(attr, true)); } else if (attr == R.styleable.CanRefreshLayout_can_style_up) { mHeadStyle = a.getInt(attr, CLASSIC); } else if (attr == R.styleable.CanRefreshLayout_can_style_down) { mFootStyle = a.getInt(attr, CLASSIC); } else if (attr == R.styleable.CanRefreshLayout_can_friction) { setFriction(a.getFloat(attr, DEFAULT_FRICTION)); } else if (attr == R.styleable.CanRefreshLayout_can_duration) { mDuration = a.getInt(attr, DEFAULT_DURATION); } else if (attr == R.styleable.CanRefreshLayout_can_smooth_duration) { mSmoothDuration = a.getInt(attr, DEFAULT_SMOOTH_DURATION); } else if (attr == R.styleable.CanRefreshLayout_can_smooth_length) { mSmoothLength = a.getInt(attr, DEFAULT_SMOOTH_LENGTH); } } } finally { a.recycle(); } }
From source file:com.albedinsky.android.support.ui.widget.ViewPagerWidget.java
/** * Creates a new instance of ViewPagerWidget 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 a v a 2 s. co m*/ public ViewPagerWidget(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs); /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ViewPager, defStyleAttr, 0); if (typedArray != null) { this.ensurePullController(); mPullController.setUpFromAttrs(context, attrs, defStyleAttr); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_Widget_ViewPager_android_background) { int resID = typedArray.getResourceId(index, -1); if (resID != -1) { setBackgroundResource(resID); } else { setBackgroundColor(typedArray.getColor(0, Color.TRANSPARENT)); } } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageMargin) { setPageMargin(typedArray.getDimensionPixelSize(index, 0)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageMarginDrawable) { setPageMarginDrawable(typedArray.getDrawable(index)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageSwipingEnabled) { updatePrivateFlags(PFLAG_PAGE_SWIPING_ENABLED, typedArray.getBoolean(index, true)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageFlingSwipingEnabled) { updatePrivateFlags(PFLAG_PAGE_FLING_SWIPING_ENABLED, typedArray.getBoolean(index, false)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageFlingSwipingSensitivity) { this.mPageFlingSwipingSensitivity = Math.max(0, typedArray.getFloat(index, mPageFlingSwipingSensitivity)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiCurrentPage) { this.mCurrentPage = typedArray.getInteger(index, 0); } else if (index == R.styleable.Ui_Widget_ViewPager_uiOffScreenPageLimit) { setOffscreenPageLimit(typedArray.getInt(index, getOffscreenPageLimit())); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageScrollDuration) { this.mPageScrollDuration = typedArray.getInteger(index, mPageScrollDuration); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageScrollRelativeDurationEnabled) { updatePrivateFlags(PFLAG_PAGE_SCROLL_RELATIVE_DURATION_ENABLED, typedArray.getBoolean(index, false)); } else if (index == R.styleable.Ui_Widget_ViewPager_uiPullEnabled) { setPullEnabled(typedArray.getBoolean(index, false)); } } } // Override default scroller so we can use custom durations for scroll if requested. this.mScroller = new WidgetScroller(context, SCROLLER_INTERPOLATOR); }
From source file:com.wit.and.dialog.LoginDialog.java
/** * // w w w.ja v a 2 s .c o m */ @Override protected void onStyleDialog(View dialogView, TypedArray parsedArray) { final Context context = getActivity(); final int loginDialogStyle = parsedArray.getResourceId(R.styleable.And_Theme_Dialog_loginDialogStyle, R.style.And_Dialog_LoginDialog); final TypedArray dialogArray = context.obtainStyledAttributes(loginDialogStyle, R.styleable.And_Theme_Dialog_LoginDialog); if (dialogArray != null) { final int n = dialogArray.getIndexCount(); for (int i = 0; i < n; i++) { int attr = dialogArray.getIndex(i); /** * Obtain login dialog sub-dialog style. */ if (attr == R.styleable.And_Theme_Dialog_LoginDialog_dialogStyle) { /** * Let super to process login dialog sub-dialog style. */ super.onStyleDialog(dialogView, dialogArray.getResourceId(attr, R.style.And_Dialog_Dialog)); } // Set up login dialog edit texts divider style. else if (attr == R.styleable.And_Theme_Dialog_LoginDialog_dialogDividerStyle) { final DialogDivider divider = (DialogDivider) findViewByID( R.id.And_Dialog_Divider_LoginDialog_EditTexts); if (divider != null) { DIVIDER_STYLER.performStyling( dialogArray.getResourceId(attr, R.style.And_Dialog_Divider_EditText), divider); // Remove any custom orientation, only horizontal divider is allowed. divider.setOrientation(DialogDivider.HORIZONTAL); } } /** * Set up login dialog edit style. */ else if (attr == R.styleable.And_Theme_Dialog_LoginDialog_android_editTextStyle) { final int editStyle = dialogArray.getResourceId(attr, R.style.And_Dialog_EditText); EDIT_STYLER.performStyling(editStyle, mUsername); EDIT_STYLER.performStyling(editStyle, mPassword); } /** * Set up empty circle progress bar style. */ else if (attr == R.styleable.And_Theme_Dialog_LoginDialog_android_progressBarStyle) { final ProgressBar progressBar = (ProgressBar) findViewByID(R.id.And_Dialog_ProgressBar); if (progressBar != null) { PROGRESS_STYLER.performStyling( dialogArray.getResourceId(attr, R.style.And_Dialog_ProgressBar), progressBar); } } } dialogArray.recycle(); } /** * Set type face to text views. */ Typeface typeface = obtainTypeface(loginDialogStyle); if (typeface != null) { applyTypeface(typeface, mUsername); applyTypeface(typeface, mPassword); } }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
public IndicatorTabStrip(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setItemClickable(true);// w ww .j a v a2s . c o m setClickSmoothScroll(true); final float density = getResources().getDisplayMetrics().density; mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTextAlign(Align.CENTER); if (Build.VERSION.SDK_INT > 4) { updateTextPaintDensity(); } mTagLocation = new TagLocation(TagLocation.LOCATION_EDGE); final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); int n = a.getIndexCount(); int textSize = (int) (DEFAULT_TEXT_SIZE * density); ColorStateList textColors = null; Drawable divider = null; for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case 0: textSize = a.getDimensionPixelSize(attr, textSize); break; case 1: textColors = a.getColorStateList(attr); break; case 2: divider = a.getDrawable(attr); break; } } a.recycle(); float scale = 1; Drawable itemBackground = null; ColorStateList gradient = null; Drawable indicator = null; int indicatorWidthMode = INDICATOR_WIDTH_MODE_SET; int indicatorPadding = 0; int indicatorWidth = INDICATOR_WIDTH_BY_DRAWABLE; int indicatorHeight = INDICATOR_HEIGHT_BY_DRAWABLE; Drawable interval = null; int minItemWidth = (int) (DEFAULT_ITEM_WIDTH * density); int minItemHeight = (int) (DEFAULT_ITEM_HEIGHT * density); int tagTextSize = (int) (DEFAULT_TAG_TEXT_SIZE * density); int tagTextColor = DEFAULT_TAG_TEXT_COLOR; Drawable tagBackground = getDefaultTagBackground(); int tagMinSizeMode = TAG_MIN_SIZE_MODE_HAS_TEXT; int tagMinWidth = (int) (DEFAULT_TAG_MIN_SIZE * density); int tagMinHeight = (int) (DEFAULT_TAG_MIN_SIZE * density); int tagPaddingLeft = 0; int tagPaddingTop = 0; int tagPaddingRight = 0; int tagPaddingBottom = 0; int tagMarginLeft = 0; int tagMarginTop = 0; int tagMarginRight = 0; int tagMarginBottom = 0; TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.IndicatorTabStrip); textSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTextSize, textSize); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTextColor)) textColors = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsTextColor); scale = custom.getFloat(R.styleable.IndicatorTabStrip_ttsTextScale, scale); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsBackground)) itemBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsBackground); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsGradient)) gradient = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsGradient); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsDivider)) divider = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsDivider); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsIndicator)) indicator = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsIndicator); indicatorWidthMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsIndicatorWidthMode, indicatorWidthMode); indicatorPadding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorPadding, indicatorPadding); indicatorWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorWidth, indicatorWidth); indicatorHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorHeight, indicatorHeight); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsInterval)) interval = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsInterval); minItemWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemWidth, minItemWidth); minItemHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemHeight, minItemHeight); tagTextSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTagTextSize, tagTextSize); tagTextColor = custom.getColor(R.styleable.IndicatorTabStrip_ttsTagTextColor, tagTextColor); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagBackground)) tagBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsTagBackground); tagMinSizeMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsTagMinSizeMode, tagMinSizeMode); tagMinWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinWidth, tagMinWidth); tagMinHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinHeight, tagMinHeight); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagPadding)) { final int padding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPadding, 0); tagPaddingLeft = padding; tagPaddingTop = padding; tagPaddingRight = padding; tagPaddingBottom = padding; } tagPaddingLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingLeft, tagPaddingLeft); tagPaddingTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingTop, tagPaddingTop); tagPaddingRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingRight, tagPaddingRight); tagPaddingBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingBottom, tagPaddingBottom); if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagMargin)) { final int margin = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMargin, 0); tagMarginLeft = margin; tagMarginTop = margin; tagMarginRight = margin; tagMarginBottom = margin; } tagMarginLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginLeft, tagMarginLeft); tagMarginTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginTop, tagMarginTop); tagMarginRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginRight, tagMarginRight); tagMarginBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginBottom, tagMarginBottom); custom.recycle(); setTextSize(textSize); if (textColors != null) { setTextColor(textColors); } else { setTextColor(DEFAULT_TEXT_COLOR); } setTextScale(scale); setItemBackground(itemBackground); setGradient(gradient); setDivider(divider); setIndicator(indicator); setIndicatorWidthMode(indicatorWidthMode); setIndicatorPadding(indicatorPadding); setIndicatorWidth(indicatorWidth); setIndicatorHeight(indicatorHeight); setInterval(interval); setMinItemWidth(minItemWidth); setMinItemHeight(minItemHeight); setTagTextSize(tagTextSize); setTagTextColor(tagTextColor); setTagBackground(tagBackground); setTagMinSizeMode(tagMinSizeMode); setTagMinWidth(tagMinWidth); setTagMinHeight(tagMinHeight); setTagPadding(tagPaddingLeft, tagPaddingTop, tagPaddingRight, tagPaddingBottom); setTagMargin(tagMarginLeft, tagMarginTop, tagMarginRight, tagMarginBottom); }
From source file:com.albedinsky.android.ui.widget.SearchView.java
/** * Called from one of constructors of this view to perform its initialization. * <p>//from ww w. j a va 2 s .c om * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view 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>. */ @SuppressWarnings("ResourceType") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.mContext = context; setOrientation(HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); this.inflateHierarchy(context, R.layout.ui_search_view); this.mProgressBarAnimator = createProgressBarAnimator(); this.mDefaultRevealAnimationHandler = createRevealAnimationHandler(); ColorStateList tintList = null; PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN; /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SearchView, defStyleAttr, defStyleRes); if (typedArray != null) { final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_SearchView_android_queryHint) { setQueryHint(typedArray.getText(index)); } else if (index == R.styleable.Ui_SearchView_uiTint) { tintList = typedArray.getColorStateList(index); } else if (index == R.styleable.Ui_SearchView_uiTintMode) { tintMode = TintManager.parseTintMode(typedArray.getInt(R.styleable.Ui_SearchView_uiTintMode, 0), tintList != null ? PorterDuff.Mode.SRC_IN : null); } else if (index == R.styleable.Ui_SearchView_uiRevealDuration) { mDefaultRevealAnimationHandler.revealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiConcealDuration) { mDefaultRevealAnimationHandler.concealDuration = typedArray.getInt(index, 0); } else if (index == R.styleable.Ui_SearchView_uiRevealInterpolator) { final int resId = typedArray.getResourceId(index, 0); if (resId != 0) { mDefaultRevealAnimationHandler.interpolator = AnimationUtils.loadInterpolator(context, resId); } } } typedArray.recycle(); } if (tintList != null || tintMode != null) { this.mTintInfo = new SearchTintInfo(); this.mTintInfo.tintList = tintList; this.mTintInfo.hasTintList = tintList != null; this.mTintInfo.tintMode = tintMode; this.mTintInfo.hasTintMode = tintMode != null; } final Resources.Theme theme = context.getTheme(); final TypedValue typedValue = new TypedValue(); if (theme.resolveAttribute(R.attr.uiSearchSelectHandleColor, typedValue, true)) { if (mTintInfo == null) { this.mTintInfo = new SearchTintInfo(); } if (typedValue.resourceId > 0) { mTintInfo.textSelectHandleTintList = ResourceUtils.getColorStateList(getResources(), typedValue.resourceId, theme); } else { mTintInfo.textSelectHandleTintList = ColorStateList.valueOf(typedValue.data); } mTintInfo.hasTextSelectHandleTintList = mTintInfo.textSelectHandleTintList != null; } this.applyTint(); this.mRevealAnimationHandler = mDefaultRevealAnimationHandler; }
From source file:org.kde.necessitas.ministro.ExtractStyle.java
public void extractViewInformations(String styleName, int styleId, JSONObject json, String qtClassName, AttributeSet attribSet) { try {/*from w w w . j a v a 2 s . c o m*/ int[] viewAttrs; viewAttrs = (int[]) styleableClass.getDeclaredField("View").get(null); TypedArray a = m_theme.obtainStyledAttributes(attribSet, viewAttrs, styleId, 0); if (null != qtClassName) json.put("qtClass", qtClassName); final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); if (attr == View_background) json.put("View_background", getDrawable(a.getDrawable(attr), styleName + "_View_background")); else if (attr == View_padding) json.put("View_padding", a.getDimensionPixelSize(attr, -1)); else if (attr == View_paddingLeft) json.put("View_paddingLeft", a.getDimensionPixelSize(attr, -1)); else if (attr == View_paddingTop) json.put("View_paddingTop", a.getDimensionPixelSize(attr, -1)); else if (attr == View_paddingRight) json.put("View_paddingRight", a.getDimensionPixelSize(attr, -1)); else if (attr == View_paddingBottom) json.put("View_paddingBottom", a.getDimensionPixelSize(attr, -1)); else if (attr == View_scrollX) json.put("View_paddingBottom", a.getDimensionPixelOffset(attr, 0)); else if (attr == View_scrollY) json.put("View_scrollY", a.getDimensionPixelOffset(attr, 0)); else if (attr == View_id) json.put("View_id", a.getResourceId(attr, -1)); else if (attr == View_tag) json.put("View_tag", a.getText(attr)); else if (attr == View_fitsSystemWindows) json.put("View_fitsSystemWindows", a.getBoolean(attr, false)); else if (attr == View_focusable) json.put("View_focusable", a.getBoolean(attr, false)); else if (attr == View_focusableInTouchMode) json.put("View_focusableInTouchMode", a.getBoolean(attr, false)); else if (attr == View_clickable) json.put("View_clickable", a.getBoolean(attr, false)); else if (attr == View_longClickable) json.put("View_longClickable", a.getBoolean(attr, false)); else if (attr == View_saveEnabled) json.put("View_saveEnabled", a.getBoolean(attr, true)); else if (attr == View_duplicateParentState) json.put("View_duplicateParentState", a.getBoolean(attr, false)); else if (attr == View_visibility) json.put("View_visibility", a.getInt(attr, 0)); else if (attr == View_drawingCacheQuality) json.put("View_drawingCacheQuality", a.getInt(attr, 0)); else if (attr == View_drawingCacheQuality) json.put("View_contentDescription", a.getString(attr)); else if (attr == View_soundEffectsEnabled) json.put("View_soundEffectsEnabled", a.getBoolean(attr, true)); else if (attr == View_hapticFeedbackEnabled) json.put("View_hapticFeedbackEnabled", a.getBoolean(attr, true)); else if (attr == View_scrollbars) json.put("View_scrollbars", a.getInt(attr, 0)); else if (attr == View_fadingEdge) json.put("View_fadingEdge", a.getInt(attr, 0)); else if (attr == View_scrollbarStyle) json.put("View_scrollbarStyle", a.getInt(attr, 0)); else if (attr == View_isScrollContainer) json.put("View_isScrollContainer", a.getBoolean(attr, false)); else if (attr == View_keepScreenOn) json.put("View_keepScreenOn", a.getBoolean(attr, false)); else if (attr == View_filterTouchesWhenObscured) json.put("View_filterTouchesWhenObscured", a.getBoolean(attr, false)); else if (attr == View_nextFocusLeft) json.put("View_nextFocusLeft", a.getResourceId(attr, -1)); else if (attr == View_nextFocusRight) json.put("View_nextFocusRight", a.getResourceId(attr, -1)); else if (attr == View_nextFocusUp) json.put("View_nextFocusUp", a.getResourceId(attr, -1)); else if (attr == View_nextFocusDown) json.put("View_nextFocusDown", a.getResourceId(attr, -1)); else if (attr == View_minWidth) json.put("View_minWidth", a.getDimensionPixelSize(attr, 0)); else if (attr == View_minHeight) json.put("View_minHeight", a.getDimensionPixelSize(attr, 0)); else if (attr == View_onClick) json.put("View_onClick", a.getString(attr)); else if (attr == View_overScrollMode) json.put("View_overScrollMode", a.getInt(attr, 1)); } a.recycle(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.alice.jack_blog.widget.refreshContainer.CanRefreshLayout.java
public CanRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CanRefreshLayout, defStyleAttr, 0); try {//from w w w . j av a 2 s .com final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); if (attr == R.styleable.CanRefreshLayout_can_enabled_up) { setRefreshEnabled(a.getBoolean(attr, true)); } else if (attr == R.styleable.CanRefreshLayout_can_enabled_down) { setLoadMoreEnabled(a.getBoolean(attr, true)); } else if (attr == R.styleable.CanRefreshLayout_can_style_up) { mHeadStyle = a.getInt(attr, CLASSIC); } else if (attr == R.styleable.CanRefreshLayout_can_style_down) { mFootStyle = a.getInt(attr, CLASSIC); } else if (attr == R.styleable.CanRefreshLayout_can_friction) { setFriction(a.getFloat(attr, DEFAULT_FRICTION)); } else if (attr == R.styleable.CanRefreshLayout_can_duration) { mDuration = a.getInt(attr, DEFAULT_DURATION); } else if (attr == R.styleable.CanRefreshLayout_can_smooth_duration) { mSmoothDuration = a.getInt(attr, DEFAULT_SMOOTH_DURATION); } else if (attr == R.styleable.CanRefreshLayout_can_smooth_length) { mSmoothLength = a.getInt(attr, DEFAULT_SMOOTH_LENGTH); } else if (attr == R.styleable.CanRefreshLayout_can_bg_up) { mRefreshBackgroundResource = a.getResourceId(attr, android.R.color.transparent); } else if (attr == R.styleable.CanRefreshLayout_can_bg_down) { mLoadMoreBackgroundResource = a.getResourceId(attr, android.R.color.transparent); } else if (attr == R.styleable.CanRefreshLayout_can_is_coo) { mIsCoo = a.getBoolean(attr, false); } } } finally { a.recycle(); } }
From source file:net.toload.main.hd.candidate.CandidateView.java
public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext = context;// ww w. j a v a2s . co m mCandidateView = this; embeddedComposing = null; // Jeremy '15,6,4 for embedded composing view in candidateView when floating candidateView (not fixed) mLIMEPref = new LIMEPreferenceManager(context); //Jeremy '16,7,24 get themed objects TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.LIMECandidateView, defStyle, R.style.LIMECandidateView); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.LIMECandidateView_suggestHighlight: mDrawableSuggestHighlight = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_voiceInputIcon: mDrawableVoiceInput = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_ExpandButtonIcon: mDrawableExpandButton = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_closeButtonIcon: mDrawableCloseButton = a.getDrawable(attr); break; case R.styleable.LIMECandidateView_candidateBackground: mColorBackground = a.getColor(attr, ContextCompat.getColor(context, R.color.third_background_light)); break; case R.styleable.LIMECandidateView_composingTextColor: mColorComposingText = a.getColor(attr, ContextCompat.getColor(context, R.color.second_foreground_light)); break; case R.styleable.LIMECandidateView_composingBackgroundColor: mColorComposingBackground = a.getColor(attr, ContextCompat.getColor(context, R.color.composing_background_light)); break; case R.styleable.LIMECandidateView_candidateNormalTextColor: mColorNormalText = a.getColor(attr, ContextCompat.getColor(context, R.color.foreground_light)); break; case R.styleable.LIMECandidateView_candidateNormalTextHighlightColor: mColorNormalTextHighlight = a.getColor(attr, ContextCompat.getColor(context, R.color.foreground_light)); break; case R.styleable.LIMECandidateView_composingCodeColor: mColorComposingCode = a.getColor(attr, ContextCompat.getColor(context, R.color.color_common_green_hl)); break; case R.styleable.LIMECandidateView_composingCodeHighlightColor: mColorComposingCodeHighlight = a.getColor(attr, ContextCompat.getColor(context, R.color.third_background_light)); break; case R.styleable.LIMECandidateView_spacerColor: mColorSpacer = a.getColor(attr, ContextCompat.getColor(context, R.color.candidate_spacer)); break; case R.styleable.LIMECandidateView_selKeyColor: mColorSelKey = a.getColor(attr, ContextCompat.getColor(context, R.color.candidate_selection_keys)); break; case R.styleable.LIMECandidateView_selKeyShiftedColor: mColorSelKeyShifted = a.getColor(attr, ContextCompat.getColor(context, R.color.color_common_green_hl)); break; } } a.recycle(); final Resources r = context.getResources(); Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Point screenSize = new Point(); display.getSize(screenSize); mScreenWidth = screenSize.x; mScreenHeight = screenSize.y; mVerticalPadding = (int) (r.getDimensionPixelSize(R.dimen.candidate_vertical_padding) * mLIMEPref.getFontSize()); configHeight = (int) (r.getDimensionPixelSize(R.dimen.candidate_stripe_height) * mLIMEPref.getFontSize()); mHeight = configHeight + mVerticalPadding; mExpandButtonWidth = r.getDimensionPixelSize(R.dimen.candidate_expand_button_width);// *mLIMEPref.getFontSize()); mCandidatePaint = new Paint(); mCandidatePaint.setColor(mColorNormalText); mCandidatePaint.setAntiAlias(true); mCandidatePaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_size) * mLIMEPref.getFontSize()); mCandidatePaint.setStrokeWidth(0); mSelKeyPaint = new Paint(); mSelKeyPaint.setColor(mColorSelKey); mSelKeyPaint.setAntiAlias(true); mSelKeyPaint .setTextSize(r.getDimensionPixelSize(R.dimen.candidate_number_font_size) * mLIMEPref.getFontSize()); mSelKeyPaint.setStyle(Paint.Style.FILL_AND_STROKE); //final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); //Jeremy '12,4,23 add mContext parameter. The constructor without context is deprecated mGestureDetector = new GestureDetector(mContext, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (DEBUG) Log.i(TAG, "onScroll(): distanceX = " + distanceX + "; distanceY = " + distanceY); //Jeremy '12,4,8 filter out small scroll which is actually candidate selection. if (Math.abs(distanceX) < mHeight / 5 && Math.abs(distanceY) < mHeight / 5) return true; mScrolled = true; // Update full candidate list before scroll checkHasMoreRecords(); int sx = getScrollX(); sx += distanceX; if (sx < 0) { sx = 0; } if (sx + getWidth() > mTotalWidth) { sx -= distanceX; } if (mLIMEPref.getParameterBoolean("candidate_switch", false)) { hasSlide = true; mTargetScrollX = sx; scrollTo(sx, getScrollY()); currentX = getScrollX(); //Jeremy '12,7,6 set currentX to the left edge of current scrollview after scrolled } else { hasSlide = false; if (distanceX < 0) { goLeft = true; goRight = false; } else if (distanceX > 0) { goLeft = false; goRight = true; } else { mTargetScrollX = sx; } } return true; } }); }
From source file:com.albedinsky.android.ui.widget.BaseProgressBar.java
/** * Called from one of constructors of this view to perform its initialization. * <p>/*from w ww . j a v a2 s. co m*/ * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for * this view specific data from it that can be used to configure this new view 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>. */ @SuppressLint("NewApi") private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { this.mUiThreadId = Thread.currentThread().getId(); // Use software layer that is required for proper drawing work of progress drawables. if (ProgressDrawable.REQUIRES_SOFTWARE_LAYER) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } onAttachDrawable(); if (mDrawable == null) { throw new IllegalArgumentException("No progress drawable has been attached."); } /** * Process attributes. */ final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_ProgressBar, defStyleAttr, defStyleRes); if (typedArray != null) { this.processTintValues(context, typedArray); final int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++) { final int index = typedArray.getIndex(i); if (index == R.styleable.Ui_ProgressBar_android_max) { setMax(typedArray.getInt(index, getMax())); } else if (index == R.styleable.Ui_ProgressBar_android_progress) { setProgress(typedArray.getInt(index, mProgress)); } else if (index == R.styleable.Ui_ProgressBar_uiColorProgress) { mDrawable.setColor(typedArray.getColor(index, mDrawable.getColor())); } else if (index == R.styleable.Ui_ProgressBar_uiColorsProgress) { final int colorsResId = typedArray.getResourceId(index, -1); if (colorsResId > 0 && !isInEditMode()) { mDrawable.setColors(context.getResources().getIntArray(colorsResId)); } } else if (index == R.styleable.Ui_ProgressBar_uiMultiColored) { mDrawable.setMultiColored(typedArray.getBoolean(index, mDrawable.isMultiColored())); } else if (index == R.styleable.Ui_ProgressBar_uiColorProgressBackground) { mDrawable.setBackgroundColor(typedArray.getInt(index, Color.TRANSPARENT)); } else if (index == R.styleable.Ui_ProgressBar_android_thickness) { mDrawable.setThickness(typedArray.getDimensionPixelSize(index, 0)); } else if (index == R.styleable.Ui_ProgressBar_uiRounded) { mDrawable.setRounded(!isInEditMode() && typedArray.getBoolean(index, mDrawable.isRounded())); } else if (index == R.styleable.Ui_ProgressBar_uiIndeterminateSpeed) { mDrawable.setIndeterminateSpeed(typedArray.getFloat(index, 1)); } } } mDrawable.setInEditMode(isInEditMode()); this.applyProgressTint(); this.applyIndeterminateTint(); this.applyProgressBackgroundTint(); }