Java Code Examples for android.content.res.TypedArray#getIndex()
The following examples show how to use
android.content.res.TypedArray#getIndex() .
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: CustomFontTextView.java From FriendlyDemo with Apache License 2.0 | 6 votes |
@SuppressWarnings({"PMD.UnusedFormalParameter", "PMD.ConstructorCallsOverridableMethod"}) public CustomFontTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs); setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); String fontName = null; TypedArray appearance = context.obtainStyledAttributes(attrs, R.styleable.CustomFontTextView); if (appearance != null) { int indexCount = appearance.getIndexCount(); for (int i = 0; i < indexCount; i++) { int attr = appearance.getIndex(i); if (attr == R.styleable.CustomFontTextView_font) { fontName = appearance.getString(attr); } } appearance.recycle(); } setTypeface(fontName); }
Example 2
Source File: DateTimeView.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public DateTimeView(Context context, AttributeSet attrs) { super(context, attrs); final TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.DateTimeView, 0, 0); final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.DateTimeView_showRelative: boolean relative = a.getBoolean(i, false); setShowRelativeTime(relative); break; } } a.recycle(); }
Example 3
Source File: VDVideoControlPanelContainer.java From NewsMe with Apache License 2.0 | 6 votes |
public VDVideoControlPanelContainer(Context context, AttributeSet attrs) { super(context, attrs); int level = -1; TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.VDVideoControlPanelContainer); for (int i = 0; i < typedArray.getIndexCount(); i++) { if (typedArray.getIndex(i) == R.styleable.VDVideoControlPanelContainer_gestureLevel) { level = typedArray.getInt(i, -1); } } typedArray.recycle(); // if (level == -1) { // level = (GESTURELEVELVERTICALSCROLL | GESTURELEVELHORIZONSCROLL // | GESTURELEVELDOUBLETAP | GESTURELEVELSINGLETAP // | GESTURELEVELHORIZONSCROLLLIGHTING | // GESTURELEVELHORIZONSCROLLSOUND); // } init(context, level); }
Example 4
Source File: WeekView.java From CalendarView with Apache License 2.0 | 6 votes |
private void initAttrs(AttributeSet attrs) { String weekStr = null; TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.WeekView); for (int i = 0; i < ta.getIndexCount(); i++) { int attr = ta.getIndex(i); if (attr == R.styleable.WeekView_week_color) { weekColor = ta.getColor(R.styleable.WeekView_week_color, weekColor); } else if (attr == R.styleable.WeekView_week_size) { weekSize = ta.getInteger(R.styleable.WeekView_week_size, weekSize); } else if (attr == R.styleable.WeekView_week_str) { weekStr = ta.getString(R.styleable.WeekView_week_str); } } ta.recycle(); if (!TextUtils.isEmpty(weekStr)) { String[] weeks = weekStr.split("\\."); if (weeks.length != 7) { return; } System.arraycopy(weeks, 0, weekArray, 0, 7); } weekSize = CalendarUtil.getTextSize1(context, weekSize); }
Example 5
Source File: TwoWayLayoutManager.java From UltimateAndroid with Apache License 2.0 | 6 votes |
public TwoWayLayoutManager(Context context, AttributeSet attrs, int defStyle) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.twowayview_TwoWayLayoutManager, defStyle, 0); final int indexCount = a.getIndexCount(); for (int i = 0; i < indexCount; i++) { final int attr = a.getIndex(i); if (attr == R.styleable.twowayview_TwoWayLayoutManager_android_orientation) { final int orientation = a.getInt(attr, -1); if (orientation >= 0) { setOrientation(Orientation.values()[orientation]); } } } a.recycle(); }
Example 6
Source File: TypefaceManager.java From Android-Font-Library with The Unlicense | 6 votes |
/** * Fetches the font attributes from the given typed array and overrides all properties in the * given data holder that are present in the typed array. * * @param a A TypedArray from which the attributes will be fetched. It will be recycled if not * null. * @param data The data holder in which all read properties are stored. */ private static void getAttributes(final TypedArray a, final ExtraFontData data) { if (a == null) { return; } try { // Iterate over all attributes in 'Android-style' // (similar to the implementation of the TextView constructor) int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); if (attr == R.styleable.Fonts_flFont) { data.font = a.getString(attr); } else if (attr == R.styleable.Fonts_android_textStyle) { data.style = a.getInt(attr, Typeface.NORMAL); } else if (attr == R.styleable.Fonts_flBorderWidth) { data.borderWidth = a.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.Fonts_flBorderColor) { data.borderColor = a.getColor(attr, Color.BLACK); } } } finally { a.recycle(); } }
Example 7
Source File: CheckBox.java From Carbon with Apache License 2.0 | 6 votes |
public void initCheckBox(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CheckBox, defStyleAttr, defStyleRes); setButtonDrawable(Carbon.getDrawable(this, a, R.styleable.CheckBox_android_button, R.drawable.carbon_checkbox_anim)); for (int i = 0; i < a.getIndexCount(); i++) { int attr = a.getIndex(i); if (attr == R.styleable.CheckBox_android_drawablePadding) { drawablePadding = a.getDimension(attr, 0); } else if (attr == R.styleable.CheckBox_android_checked) { setChecked(a.getBoolean(attr, false)); } else if (attr == R.styleable.CheckBox_carbon_buttonGravity) { buttonGravity = ButtonGravity.values()[a.getInt(attr, 0)]; } } a.recycle(); }
Example 8
Source File: ViewPager.java From Carbon with Apache License 2.0 | 6 votes |
private void initViewPager(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { super.setOnPageChangeListener(internalOnPageChangeListener); final ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ViewPager, defStyleAttr, defStyleRes); for (int i = 0; i < a.getIndexCount(); i++) { int attr = a.getIndex(i); if (attr == R.styleable.ViewPager_carbon_overScroll) { setOverScrollMode(a.getInt(attr, OVER_SCROLL_ALWAYS)); } else if (attr == R.styleable.ViewPager_carbon_swipeEnabled) { setSwipeEnabled(a.getBoolean(attr, true)); } } Carbon.initTint(this, a, tintIds); a.recycle(); setWillNotDraw(false); }
Example 9
Source File: VDVideoLockScreenView.java From NewsMe with Apache License 2.0 | 5 votes |
public VDVideoLockScreenView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray typedArr = context.obtainStyledAttributes(attrs, R.styleable.VDVideoLockScreenView); if (typedArr != null) { for (int i = 0; i < typedArr.getIndexCount(); i++) { int resID = -1; if (typedArr.getIndex(i) == R.styleable.VDVideoLockScreenView_LockOpenImg) { resID = typedArr.getResourceId( R.styleable.VDVideoLockScreenView_LockOpenImg, -1); if (resID != -1) { mBackGroundOpenID = resID; } } else if (typedArr.getIndex(i) == R.styleable.VDVideoLockScreenView_LockCloseImg) { resID = typedArr.getResourceId( R.styleable.VDVideoLockScreenView_LockCloseImg, -1); if (resID != -1) { mBackgroundCloseID = resID; } } else if (typedArr.getIndex(i) == R.styleable.VDVideoLockScreenView_orientation) { int flag = typedArr.getInt(i, -1); if (flag != -1) { mOrientation = flag; } } } typedArr.recycle(); } setBackground(); init(context); }
Example 10
Source File: DSListView.java From direct-select-android with MIT License | 5 votes |
public DSListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.DSListView); final int count = styledAttrs.getIndexCount(); for (int i = 0; i < count; ++i) { int attr = styledAttrs.getIndex(i); if (attr == R.styleable.DSListView_cell_font_size) { this.cellTextSize = styledAttrs.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.DSListView_data_array) { String[] arr = getResources().getStringArray(styledAttrs.getResourceId(attr, 0)); this.dataFromAttributes = new ArrayList<>(Arrays.asList(arr)); } else if (attr == R.styleable.DSListView_scale_animations) { this.selectorAnimationsEnabled = styledAttrs.getBoolean(attr, true); } else if (attr == R.styleable.DSListView_selected_index) { this.selectedItem = styledAttrs.getInt(attr, 0); } else if (attr == R.styleable.DSListView_picker_box_view) { this.pickerBoxResId = styledAttrs.getResourceId(attr, 0); } else if (attr == R.styleable.DSListView_scale_animations_factor) { this.scaleFactorDelta = styledAttrs.getFloat(attr, 1.3f) - 1f; } else if (attr == R.styleable.DSListView_scale_animations_pivot_center) { this.selectorAnimationCenterPivot = styledAttrs.getBoolean(attr, false); } else if (attr == R.styleable.DSListView_selector_background) { try { this.selectorBgColor = styledAttrs.getColor(attr, Color.parseColor("#116b2b66")); } catch (Exception e) { this.selectorBgDrawable = styledAttrs.getResourceId(attr, 0); } } } styledAttrs.recycle(); initPicker(context); }
Example 11
Source File: GradientTextView.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
private void applyAttributes(AttributeSet attrs) { TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.GradientTextView); for (int i = 0; i < array.getIndexCount(); i++) { int type = array.getIndex(i); if (type == R.styleable.GradientTextView_gFontPath) { setFont(array.getString(R.styleable.GradientTextView_gFontPath)); } if (type == R.styleable.GradientTextView_text_html) { applyHtmlText(array.getString(R.styleable.GradientTextView_text_html)); } if (type == R.styleable.GradientTextView_linear_gradient) { // Set the flag mApplyLinearGradient = true; String orientation = array.getString(R.styleable.GradientTextView_linear_gradient); if (orientation.toLowerCase().equalsIgnoreCase("vertical")) { mGradientOrientation = LG_VERTICAL; } else if (orientation.toLowerCase().equalsIgnoreCase("horizontal")) { mGradientOrientation = LG_HORIZONTAL; } } if (type == R.styleable.GradientTextView_start_color) { // Set the flag mApplyLinearGradient = true; mStartColor = array.getColor(R.styleable.GradientTextView_start_color, Color.BLACK); } if (type == R.styleable.GradientTextView_end_color) { // Set the flag mApplyLinearGradient = true; mEndColor = array.getColor(R.styleable.GradientTextView_end_color, Color.BLACK); } } array.recycle(); }
Example 12
Source File: DrawableRatingBar.java From ProjectX with Apache License 2.0 | 4 votes |
private void initView(Context context, AttributeSet attrs, int defStyleAttr) { final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS, defStyleAttr, 0); int n = a.getIndexCount(); Drawable drawable = null; int drawablePadding = 0; for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case 0: drawable = a.getDrawable(attr); break; case 1: drawablePadding = a.getDimensionPixelSize(attr, drawablePadding); break; } } a.recycle(); Drawable selected = null; Drawable normal = null; if (drawable instanceof LayerDrawable) { LayerDrawable layerDrawable = (LayerDrawable) drawable; selected = layerDrawable.findDrawableByLayerId(android.R.id.progress); normal = layerDrawable.findDrawableByLayerId(android.R.id.secondaryProgress); } int max = DEFAULT_MAX; int min = 0; int rating = 0; boolean manually; boolean onlyItemTouchable; int gravity = Compat.START; TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.DrawableRatingBar); if (custom.hasValue(R.styleable.DrawableRatingBar_drbProgressDrawable)) selected = custom.getDrawable(R.styleable.DrawableRatingBar_drbProgressDrawable); if (custom.hasValue(R.styleable.DrawableRatingBar_drbSecondaryProgress)) normal = custom.getDrawable(R.styleable.DrawableRatingBar_drbSecondaryProgress); drawablePadding = custom.getDimensionPixelSize( R.styleable.DrawableRatingBar_drbDrawablePadding, drawablePadding); max = custom.getInteger(R.styleable.DrawableRatingBar_drbMax, max); min = custom.getInteger(R.styleable.DrawableRatingBar_drbMin, min); rating = custom.getInteger(R.styleable.DrawableRatingBar_drbRating, rating); manually = custom.getBoolean(R.styleable.DrawableRatingBar_drbManually, false); onlyItemTouchable = custom.getBoolean( R.styleable.DrawableRatingBar_drbOnlyItemTouchable, false); gravity = a.getInteger(R.styleable.DrawableRatingBar_drbGravity, gravity); custom.recycle(); setRatingDrawable(selected, normal); setDrawablePadding(drawablePadding); setGravity(gravity); setMax(max <= 0 ? DEFAULT_MAX : max); setMin(min < 0 ? 0 : min); setRating(rating); setManually(manually); setOnlyItemTouchable(onlyItemTouchable); }
Example 13
Source File: TextDrawable.java From QiQuYing with Apache License 2.0 | 4 votes |
public TextDrawable(Context context) { super(); //Used to load and scale resource items mResources = context.getResources(); //Definition of this drawables size mTextBounds = new Rect(); //Paint to use for the text mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.density = mResources.getDisplayMetrics().density; mTextPaint.setDither(true); int textSize = 15; ColorStateList textColor = null; int styleIndex = -1; int typefaceIndex = -1; //Set default parameters from the current theme TypedArray a = context.getTheme().obtainStyledAttributes(themeAttributes); int appearanceId = a.getResourceId(0, -1); a.recycle(); TypedArray ap = null; if (appearanceId != -1) { ap = context.obtainStyledAttributes(appearanceId, appearanceAttributes); } if (ap != null) { for (int i=0; i < ap.getIndexCount(); i++) { int attr = ap.getIndex(i); switch (attr) { case 0: //Text Size textSize = a.getDimensionPixelSize(attr, textSize); break; case 1: //Typeface typefaceIndex = a.getInt(attr, typefaceIndex); break; case 2: //Text Style styleIndex = a.getInt(attr, styleIndex); break; case 3: //Text Color textColor = a.getColorStateList(attr); break; default: break; } } ap.recycle(); } setTextColor(textColor != null ? textColor : ColorStateList.valueOf(0xFF000000)); setRawTextSize(textSize); Typeface tf = null; switch (typefaceIndex) { case SANS: tf = Typeface.SANS_SERIF; break; case SERIF: tf = Typeface.SERIF; break; case MONOSPACE: tf = Typeface.MONOSPACE; break; } setTypeface(tf, styleIndex); }
Example 14
Source File: PullButton.java From AnkiDroid-Wear with GNU General Public License v2.0 | 4 votes |
public PullButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.pull_button, this); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); display.getSize(displaySize); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullButton); final int N = a.getIndexCount(); icon = (ImageButton) findViewById(R.id.icon); textView = (TextView) findViewById(R.id.textView); easeTextView = (TextView) findViewById(R.id.ease_text); for (int i = 0; i < N; ++i) { int attr = a.getIndex(i); switch (attr) { case R.styleable.PullButton_icon: imageResId = a.getResourceId(attr, R.drawable.close_button); break; case R.styleable.PullButton_text: String text = a.getString(attr); textView.setText(text); break; case R.styleable.PullButton_upsideDown: upsideDown = a.getBoolean(attr, false); break; case R.styleable.PullButton_ease_text: easeTextView.setText(a.getString(attr)); break; } } a.recycle(); ViewTreeObserver vto = getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (upsideDown) { textView.setY(0); icon.setY(textView.getHeight()); icon.setRotation(180); easeTextView.setY(easeTextView.getY() + textView.getHeight()); } if (upsideDown) { homePosition = 0 - textView.getHeight(); extendedPosition = 0; exitY = displaySize.y + 10; } else { homePosition = displaySize.y - icon.getHeight(); extendedPosition = displaySize.y - getHeight(); exitY = -getHeight() - 10; } setY(homePosition); ViewTreeObserver obs = getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); if (imageResId != -1) { icon.setImageResource(imageResId); } minMovementDistance = displaySize.y / 2; setAlpha(homeAlpha); this.animate().setInterpolator(new LinearInterpolator()); this.setOnTouchListener(new SwipeTouchListener()); }
Example 15
Source File: NumberPickerView.java From SmartChart with Apache License 2.0 | 4 votes |
private void initAttr(Context context, AttributeSet attrs){ if (attrs == null) { return; } TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerView); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); if(attr == R.styleable.NumberPickerView_npv_ShowCount){ mShowCount = a.getInt(attr, DEFAULT_SHOW_COUNT); }else if(attr == R.styleable.NumberPickerView_npv_DividerColor){ mDividerColor = a.getColor(attr, DEFAULT_DIVIDER_COLOR); }else if(attr == R.styleable.NumberPickerView_npv_DividerHeight){ mDividerHeight = a.getDimensionPixelSize(attr, DEFAULT_DIVIDER_HEIGHT); }else if(attr == R.styleable.NumberPickerView_npv_DividerMarginLeft){ mDividerMarginL = a.getDimensionPixelSize(attr, DEFAULT_DIVIDER_MARGIN_HORIZONTAL); }else if(attr == R.styleable.NumberPickerView_npv_DividerMarginRight){ mDividerMarginR = a.getDimensionPixelSize(attr, DEFAULT_DIVIDER_MARGIN_HORIZONTAL); }else if(attr == R.styleable.NumberPickerView_npv_TextArray){ mDisplayedValues = convertCharSequenceArrayToStringArray(a.getTextArray(attr)); }else if(attr == R.styleable.NumberPickerView_npv_TextColorNormal){ mTextColorNormal = a.getColor(attr, DEFAULT_TEXT_COLOR_NORMAL); }else if(attr == R.styleable.NumberPickerView_npv_TextColorSelected){ mTextColorSelected = a.getColor(attr, DEFAULT_TEXT_COLOR_SELECTED); }else if(attr == R.styleable.NumberPickerView_npv_TextColorHint){ mTextColorHint = a.getColor(attr, DEFAULT_TEXT_COLOR_SELECTED); }else if(attr == R.styleable.NumberPickerView_npv_TextSizeNormal){ mTextSizeNormal = a.getDimensionPixelSize(attr, sp2px(context, DEFAULT_TEXT_SIZE_NORMAL_SP)); }else if(attr == R.styleable.NumberPickerView_npv_TextSizeSelected){ mTextSizeSelected = a.getDimensionPixelSize(attr, sp2px(context, DEFAULT_TEXT_SIZE_SELECTED_SP)); }else if(attr == R.styleable.NumberPickerView_npv_TextSizeHint){ mTextSizeHint = a.getDimensionPixelSize(attr, sp2px(context, DEFAULT_TEXT_SIZE_HINT_SP)); }else if(attr == R.styleable.NumberPickerView_npv_MinValue){ mMinShowIndex = a.getInteger(attr, 0); }else if(attr == R.styleable.NumberPickerView_npv_MaxValue){ mMaxShowIndex = a.getInteger(attr, 0); }else if(attr == R.styleable.NumberPickerView_npv_WrapSelectorWheel){ mWrapSelectorWheel = a.getBoolean(attr, DEFAULT_WRAP_SELECTOR_WHEEL); }else if(attr == R.styleable.NumberPickerView_npv_ShowDivider){ mShowDivider = a.getBoolean(attr, DEFAULT_SHOW_DIVIDER); }else if(attr == R.styleable.NumberPickerView_npv_HintText){ mHintText = a.getString(attr); }else if(attr == R.styleable.NumberPickerView_npv_AlternativeHint){ mAlterHint = a.getString(attr); }else if(attr == R.styleable.NumberPickerView_npv_EmptyItemHint){ mEmptyItemHint = a.getString(attr); }else if(attr == R.styleable.NumberPickerView_npv_MarginStartOfHint){ mMarginStartOfHint = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_MARGIN_START_OF_HINT_DP)); }else if(attr == R.styleable.NumberPickerView_npv_MarginEndOfHint){ mMarginEndOfHint = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_MARGIN_END_OF_HINT_DP)); }else if(attr == R.styleable.NumberPickerView_npv_ItemPaddingVertical){ mItemPaddingVertical = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_ITEM_PADDING_DP_V)); }else if(attr == R.styleable.NumberPickerView_npv_ItemPaddingHorizontal){ mItemPaddingHorizontal = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_ITEM_PADDING_DP_H)); }else if(attr == R.styleable.NumberPickerView_npv_AlternativeTextArrayWithMeasureHint){ mAlterTextArrayWithMeasureHint = a.getTextArray(attr); }else if(attr == R.styleable.NumberPickerView_npv_AlternativeTextArrayWithoutMeasureHint){ mAlterTextArrayWithoutMeasureHint = a.getTextArray(attr); }else if(attr == R.styleable.NumberPickerView_npv_RespondChangeOnDetached){ mRespondChangeOnDetach = a.getBoolean(attr, DEFAULT_RESPOND_CHANGE_ON_DETACH); }else if(attr == R.styleable.NumberPickerView_npv_RespondChangeInMainThread){ mRespondChangeInMainThread = a.getBoolean(attr, DEFAULT_RESPOND_CHANGE_IN_MAIN_THREAD); }else if (attr == R.styleable.NumberPickerView_npv_TextEllipsize) { mTextEllipsize = a.getString(attr); } } a.recycle(); }
Example 16
Source File: LatinKeyboardView.java From hackerskeyboard with Apache License 2.0 | 4 votes |
public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO(klausw): migrate attribute styles to LatinKeyboardView? TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.LatinKeyboardBaseView, defStyle, R.style.LatinKeyboardBaseView); LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); int previewLayout = 0; int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.LatinKeyboardBaseView_keyPreviewLayout: previewLayout = a.getResourceId(attr, 0); if (previewLayout == R.layout.null_layout) previewLayout = 0; break; case R.styleable.LatinKeyboardBaseView_keyPreviewOffset: mPreviewOffset = a.getDimensionPixelOffset(attr, 0); break; case R.styleable.LatinKeyboardBaseView_keyPreviewHeight: mPreviewHeight = a.getDimensionPixelSize(attr, 80); break; case R.styleable.LatinKeyboardBaseView_popupLayout: mPopupLayout = a.getResourceId(attr, 0); if (mPopupLayout == R.layout.null_layout) mPopupLayout = 0; break; } } final Resources res = getResources(); // If true, popups are forced to remain inside the keyboard area. If false, // they can extend above it. Enable clipping just for Android P since drawing // outside the keyboard area doesn't work on that version. boolean clippingEnabled = (Build.VERSION.SDK_INT >= 28 /* Build.VERSION_CODES.P */); if (previewLayout != 0) { mPreviewPopup = new PopupWindow(context); if (!isInEditMode()) Log.i(TAG, "new mPreviewPopup " + mPreviewPopup + " from " + this); mPreviewText = (TextView) inflate.inflate(previewLayout, null); mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large); mPreviewPopup.setContentView(mPreviewText); mPreviewPopup.setBackgroundDrawable(null); mPreviewPopup.setTouchable(false); mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation); mPreviewPopup.setClippingEnabled(clippingEnabled); } else { mShowPreview = false; } if (mPopupLayout != 0) { mMiniKeyboardParent = this; mMiniKeyboardPopup = new PopupWindow(context); if (!isInEditMode()) Log.i(TAG, "new mMiniKeyboardPopup " + mMiniKeyboardPopup + " from " + this); mMiniKeyboardPopup.setBackgroundDrawable(null); mMiniKeyboardPopup.setAnimationStyle(R.style.MiniKeyboardAnimation); mMiniKeyboardPopup.setClippingEnabled(clippingEnabled); mMiniKeyboardVisible = false; } }
Example 17
Source File: OverMenuLayout.java From OverlayMenu with Apache License 2.0 | 4 votes |
private void initialize(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.OverMenuLayout, defStyleAttr, defStyleRes); int textAppearance = R.style.TextAppearance_AppCompat; int selectedTextAppearance = textAppearance; int itemsGap = 0; int textGravity = Gravity.CENTER; int textPadding = 0; int selectedTextBackground = R.drawable.overmenu_selectedtext_background; final int N = array.getIndexCount(); for (int i = 0; i < N; i++) { int attr = array.getIndex(i); if (attr == R.styleable.OverMenuLayout_overmenu_textAppearance) { textAppearance = array.getResourceId(attr, 0); } else if (attr == R.styleable.OverMenuLayout_overmenu_selectedTextAppearance) { selectedTextAppearance = array.getResourceId(attr, 0); } else if (attr == R.styleable.OverMenuLayout_overmenu_selectedTextBackground) { selectedTextBackground = array.getResourceId(attr, R.drawable.overmenu_selectedtext_background); } else if (attr == R.styleable.OverMenuLayout_android_background) { mMenuBackground = array.getResourceId(attr, 0); } else if (attr == R.styleable.OverMenuLayout_android_padding) { paddingLeft = array.getDimensionPixelSize(attr, 0); paddingRight = paddingLeft; paddingTop = paddingLeft; paddingBottom = paddingTop; } else if (attr == R.styleable.OverMenuLayout_android_paddingLeft) { paddingLeft = array.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.OverMenuLayout_android_paddingRight) { paddingRight = array.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.OverMenuLayout_android_paddingTop) { paddingTop = array.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.OverMenuLayout_android_paddingBottom) { paddingBottom = array.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.OverMenuLayout_android_verticalGap) { itemsGap = array.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.OverMenuLayout_overmenu_textGravity) { textGravity = array.getInt(attr, Gravity.CENTER); } else if (attr == R.styleable.OverMenuLayout_overmenu_textPaddingHorizontal) { textPadding = array.getDimensionPixelSize(attr, 0); } else if (attr == R.styleable.OverMenuLayout_overmenu_selectedPosition) { mDefaultPosition = array.getInteger(attr, -1); } else if (attr == R.styleable.OverMenuLayout_android_inAnimation) { mTextSwitcherInAnimation = array.getResourceId(attr, R.anim.overmenu_textswitcher_in); } else if (attr == R.styleable.OverMenuLayout_android_outAnimation) { mTextSwitcherOutAnimation = array.getResourceId(attr, R.anim.overmenu_textswitcher_out); } else if (attr == R.styleable.OverMenuLayout_overmenu_animateItems) { mAnimateItems = array.getBoolean(attr, true); } } array.recycle(); setMenuTextPadding(textPadding); setMenuTextGravity(textGravity); setMenuTextAppearance(textAppearance); setSelectedTextAppearance(selectedTextAppearance); setSelectedTextBackground(selectedTextBackground); setItemsGap(itemsGap); initializeMenu(context); setWillNotDraw(true); }
Example 18
Source File: CountDownProgressBar.java From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 | 4 votes |
private void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CountDownProgressBar, defStyleAttr, 0); int indexCount = typedArray.getIndexCount(); for (int i = 0; i < indexCount; i++) { int attr = typedArray.getIndex(i); switch (attr) { case R.styleable.CountDownProgressBar_maxProress: mMaxProgress = typedArray.getInt(attr, 100); break; case R.styleable.CountDownProgressBar_circleColor: mCircleColor = typedArray.getColor(attr, 0xff0000); break; case R.styleable.CountDownProgressBar_textColor: mTextColor = typedArray.getColor(attr, 0xff0000); break; case R.styleable.CountDownProgressBar_circleWidth: mCircleWidth = typedArray.getDimensionPixelSize(attr, 3); break; case R.styleable.CountDownProgressBar_backgroundWidth: mBackgroundWidth = typedArray.getDimensionPixelSize(attr, 10); break; case R.styleable.CountDownProgressBar_currentProgress: mCurrentProgress = typedArray.getInt(attr, 0); break; case R.styleable.CountDownProgressBar_backgroundColor: mBackgroundColor = typedArray.getColor(attr, 0xcfcfcf); break; case R.styleable.CountDownProgressBar_textSize: mTextSize = typedArray.getDimensionPixelSize(attr, 40); break; } } typedArray.recycle(); mBgPaint = new Paint(); mBgPaint.setColor(mBackgroundColor); mBgPaint.setStyle(Paint.Style.FILL); mBgPaint.setAntiAlias(true); mBgPaint.setStrokeWidth(mBackgroundWidth / 2); mProgressPaint = new Paint(); mProgressPaint.setColor(mCircleColor); mProgressPaint.setStyle(Paint.Style.STROKE); mProgressPaint.setAntiAlias(true); mProgressPaint.setStrokeWidth(mCircleWidth); mTextPaint = new Paint(); mTextPaint.setColor(mTextColor); mTextPaint.setTextSize(mTextSize); mTextPaint.setTypeface(Typeface.DEFAULT); mTextPaint.setTextAlign(Paint.Align.LEFT); mTextRect = new Rect(); mTextPaint.getTextBounds(content, 0, content.length(), mTextRect); mTextY = mTextPaint.descent() - mTextPaint.ascent(); rectF = new RectF(5, 5, mBackgroundWidth - 5, mBackgroundWidth - 5); mStartAngel = mCurrentProgress * 360 / 100 - 90; }
Example 19
Source File: RelativeLayout.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); TypedArray a = c.obtainStyledAttributes(attrs, com.android.internal.R.styleable.RelativeLayout_Layout); final int targetSdkVersion = c.getApplicationInfo().targetSdkVersion; mIsRtlCompatibilityMode = (targetSdkVersion < JELLY_BEAN_MR1 || !c.getApplicationInfo().hasRtlSupport()); final int[] rules = mRules; //noinspection MismatchedReadAndWriteOfArray final int[] initialRules = mInitialRules; final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); switch (attr) { case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignWithParentIfMissing: alignWithParent = a.getBoolean(attr, false); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_toLeftOf: rules[LEFT_OF] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_toRightOf: rules[RIGHT_OF] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_above: rules[ABOVE] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_below: rules[BELOW] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignBaseline: rules[ALIGN_BASELINE] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignLeft: rules[ALIGN_LEFT] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignTop: rules[ALIGN_TOP] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignRight: rules[ALIGN_RIGHT] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignBottom: rules[ALIGN_BOTTOM] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignParentLeft: rules[ALIGN_PARENT_LEFT] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignParentTop: rules[ALIGN_PARENT_TOP] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignParentRight: rules[ALIGN_PARENT_RIGHT] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignParentBottom: rules[ALIGN_PARENT_BOTTOM] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_centerInParent: rules[CENTER_IN_PARENT] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_centerHorizontal: rules[CENTER_HORIZONTAL] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_centerVertical: rules[CENTER_VERTICAL] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_toStartOf: rules[START_OF] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_toEndOf: rules[END_OF] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignStart: rules[ALIGN_START] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignEnd: rules[ALIGN_END] = a.getResourceId(attr, 0); break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignParentStart: rules[ALIGN_PARENT_START] = a.getBoolean(attr, false) ? TRUE : 0; break; case com.android.internal.R.styleable.RelativeLayout_Layout_layout_alignParentEnd: rules[ALIGN_PARENT_END] = a.getBoolean(attr, false) ? TRUE : 0; break; } } mRulesChanged = true; System.arraycopy(rules, LEFT_OF, initialRules, LEFT_OF, VERB_COUNT); a.recycle(); }
Example 20
Source File: CanRefreshLayout.java From CanRefresh with Apache License 2.0 | 2 votes |
public CanRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = context.obtainStyledAttributes(attrs, com.canyinghao.canrefresh.R.styleable.CanRefreshLayout, defStyleAttr, 0); try { final int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_enabled_up) { setRefreshEnabled(a.getBoolean(attr, true)); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_enabled_down) { setLoadMoreEnabled(a.getBoolean(attr, true)); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_style_up) { mHeadStyle = a.getInt(attr, CLASSIC); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_style_down) { mFootStyle = a.getInt(attr, CLASSIC); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_friction) { setFriction(a.getFloat(attr, DEFAULT_FRICTION)); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_duration) { mDuration = a.getInt(attr, DEFAULT_DURATION); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_smooth_duration) { mSmoothDuration = a.getInt(attr, DEFAULT_SMOOTH_DURATION); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_smooth_length) { mSmoothLength = a.getInt(attr, DEFAULT_SMOOTH_LENGTH); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_bg_up) { mRefreshBackgroundResource = a.getResourceId(attr, android.R.color.transparent); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_bg_down) { mLoadMoreBackgroundResource = a.getResourceId(attr, android.R.color.transparent); } else if (attr == com.canyinghao.canrefresh.R.styleable.CanRefreshLayout_can_is_coo) { mIsCoo = a.getBoolean(attr, false); } } } finally { a.recycle(); } }