List of usage examples for android.content.res TypedArray getTextArray
public CharSequence[] getTextArray(@StyleableRes int index)
From source file:com.bitflake.counter.HorizontalPicker.java
public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // create the selector wheel paint TextPaint paint = new TextPaint(); paint.setAntiAlias(true);// w ww.j a va 2 s .c o m textPaint = paint; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0); CharSequence[] values; int ellipsize = 3; // END default value int sideItems = this.sideItems; try { textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor); if (textColor == null) { textColor = ColorStateList.valueOf(0xFF000000); } values = a.getTextArray(R.styleable.HorizontalPicker_values); ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize); marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit, marqueeRepeatLimit); dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize); sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems); float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1); if (textSize > -1) { setTextSize(textSize); } } finally { a.recycle(); } switch (ellipsize) { case 1: setEllipsize(TextUtils.TruncateAt.START); break; case 2: setEllipsize(TextUtils.TruncateAt.MIDDLE); break; case 3: setEllipsize(TextUtils.TruncateAt.END); break; case 4: setEllipsize(TextUtils.TruncateAt.MARQUEE); break; } Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt(); boringMetrics = new BoringLayout.Metrics(); boringMetrics.ascent = fontMetricsInt.ascent; boringMetrics.bottom = fontMetricsInt.bottom; boringMetrics.descent = fontMetricsInt.descent; boringMetrics.leading = fontMetricsInt.leading; boringMetrics.top = fontMetricsInt.top; boringMetrics.width = itemWidth; setWillNotDraw(false); flingScrollerX = new OverScroller(context); adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f)); // initialize constants ViewConfiguration configuration = ViewConfiguration.get(context); touchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; overscrollDistance = configuration.getScaledOverscrollDistance(); previousScrollerX = Integer.MIN_VALUE; setValues(values); setSideItems(sideItems); touchHelper = new PickerTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, touchHelper); }
From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java
public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // create the selector wheel paint TextPaint paint = new TextPaint(); paint.setAntiAlias(true);//from w w w. j a v a 2 s .c o m mTextPaint = paint; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0); CharSequence[] values; int ellipsize = 3; // END default value int sideItems = mSideItems; try { mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor); if (mTextColor == null) { mTextColor = ColorStateList.valueOf(0xFF000000); } values = a.getTextArray(R.styleable.HorizontalPicker_values); ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize); mMarqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit, mMarqueeRepeatLimit); mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize); sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems); float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1); if (textSize > -1) { setTextSize(textSize); } } finally { a.recycle(); } switch (ellipsize) { case 1: setEllipsize(TextUtils.TruncateAt.START); break; case 2: setEllipsize(TextUtils.TruncateAt.MIDDLE); break; case 3: setEllipsize(TextUtils.TruncateAt.END); break; case 4: setEllipsize(TextUtils.TruncateAt.MARQUEE); break; } Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt(); mBoringMetrics = new BoringLayout.Metrics(); mBoringMetrics.ascent = fontMetricsInt.ascent; mBoringMetrics.bottom = fontMetricsInt.bottom; mBoringMetrics.descent = fontMetricsInt.descent; mBoringMetrics.leading = fontMetricsInt.leading; mBoringMetrics.top = fontMetricsInt.top; mBoringMetrics.width = mItemWidth; setWillNotDraw(false); mFlingScrollerX = new OverScroller(context); mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f)); // initialize constants ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; mOverscrollDistance = configuration.getScaledOverscrollDistance(); mPreviousScrollerX = Integer.MIN_VALUE; setValues(values); setSideItems(sideItems); mTouchHelper = new PickerTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); }
From source file:com.leeon.blank.widget.RangeBarNew.java
private void applyConfig(Context context, AttributeSet attrs) { if (attrs == null) { return;//from w w w.ja v a 2 s . c om } TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RangeBar); indicatorDrawable = a.getDrawable(R.styleable.RangeBar_indicatorDrawable); mLeftCursorBG = a.getDrawable(R.styleable.RangeBar_leftCursorBackground); mRightCursorBG = a.getDrawable(R.styleable.RangeBar_rightCursorBackground); mTextColorNormal = a.getColor(R.styleable.RangeBar_textColorNormal, Color.GRAY); mRangeBarColorNormal = a.getColor(R.styleable.RangeBar_barColorNormal, Color.rgb(218, 215, 215)); mRangeBarColorSelected = a.getColor(R.styleable.RangeBar_barColorSelected, Color.rgb(197, 0, 0)); mRangeBarHeight = (int) a.getDimension(R.styleable.RangeBar_barHeight, 10); mTextSize = (int) a.getDimension(R.styleable.RangeBar_textSize, 14); mMarginBetween = (int) a.getDimension(R.styleable.RangeBar_spaceBetween, 16); isInfinite = a.getBoolean(R.styleable.RangeBar_isInfinite, true); CharSequence[] charArray = a.getTextArray(R.styleable.RangeBar_markTextArray); if (null == charArray || charArray.length <= 1) { throw new IllegalArgumentException("markTextArray should at least have 2 number!"); } mTextArray = new int[isInfinite ? charArray.length + 1 : charArray.length]; for (int i = 0; i < charArray.length; i++) { mTextArray[i] = Integer.parseInt(charArray[i].toString()); if (mTextArray[i] < 0) { throw new IllegalArgumentException("markTextArray must be a positive number array"); } } if (isInfinite) { mTextArray[charArray.length] = -1; } mLeftCursorIndex = 0; mRightCursorIndex = (mTextArray.length - 1) * 5; mRightCursorNextIndex = mRightCursorIndex; a.recycle(); }
From source file:com.grottworkshop.gwsmaterialcalendarview.MaterialCalendarView.java
@SuppressWarnings("deprecation") public MaterialCalendarView(Context context, AttributeSet attrs) { super(context, attrs); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //If we're on good Android versions, turn off clipping for cool effects setClipToPadding(false);//from w w w . j av a 2 s. c o m setClipChildren(false); } else { //Old Android does not like _not_ clipping view pagers, we need to clip setClipChildren(true); setClipToPadding(true); } buttonPast = new DirectionButton(getContext()); title = new TextView(getContext()); buttonFuture = new DirectionButton(getContext()); pager = new ViewPager(getContext()); setupChildren(); title.setOnClickListener(onClickListener); buttonPast.setOnClickListener(onClickListener); buttonFuture.setOnClickListener(onClickListener); titleChanger = new TitleChanger(title); titleChanger.setTitleFormatter(DEFAULT_TITLE_FORMATTER); adapter = new MonthPagerAdapter(); adapter.setTitleFormatter(DEFAULT_TITLE_FORMATTER); pager.setAdapter(adapter); pager.setOnPageChangeListener(pageChangeListener); pager.setPageTransformer(false, new ViewPager.PageTransformer() { @Override public void transformPage(View page, float position) { position = (float) Math.sqrt(1 - Math.abs(position)); page.setAlpha(position); } }); adapter.setCallbacks(monthViewCallbacks); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaterialCalendarView, 0, 0); try { int tileSize = a.getDimensionPixelSize(R.styleable.MaterialCalendarView_mcv_tileSize, -1); if (tileSize > 0) { setTileSize(tileSize); } setArrowColor(a.getColor(R.styleable.MaterialCalendarView_mcv_arrowColor, Color.BLACK)); Drawable leftMask = a.getDrawable(R.styleable.MaterialCalendarView_mcv_leftArrowMask); if (leftMask == null) { //TODO: getDrawable depreciated leftMask = getResources().getDrawable(R.drawable.mcv_action_previous); } setLeftArrowMask(leftMask); Drawable rightMask = a.getDrawable(R.styleable.MaterialCalendarView_mcv_rightArrowMask); if (rightMask == null) { //TODO: getDrawable depreciated rightMask = getResources().getDrawable(R.drawable.mcv_action_next); } setRightArrowMask(rightMask); setSelectionColor( a.getColor(R.styleable.MaterialCalendarView_mcv_selectionColor, getThemeAccentColor(context))); CharSequence[] array = a.getTextArray(R.styleable.MaterialCalendarView_mcv_weekDayLabels); if (array != null) { setWeekDayFormatter(new ArrayWeekDayFormatter(array)); } array = a.getTextArray(R.styleable.MaterialCalendarView_mcv_monthLabels); if (array != null) { setTitleFormatter(new MonthArrayTitleFormatter(array)); } setHeaderTextAppearance(a.getResourceId(R.styleable.MaterialCalendarView_mcv_headerTextAppearance, R.style.TextAppearance_MaterialCalendarWidget_Header)); setWeekDayTextAppearance(a.getResourceId(R.styleable.MaterialCalendarView_mcv_weekDayTextAppearance, R.style.TextAppearance_MaterialCalendarWidget_WeekDay)); setDateTextAppearance(a.getResourceId(R.styleable.MaterialCalendarView_mcv_dateTextAppearance, R.style.TextAppearance_MaterialCalendarWidget_Date)); setShowOtherDates(a.getBoolean(R.styleable.MaterialCalendarView_mcv_showOtherDates, false)); int firstDayOfWeek = a.getInt(R.styleable.MaterialCalendarView_mcv_firstDayOfWeek, -1); if (firstDayOfWeek < 0) { firstDayOfWeek = CalendarUtils.getInstance().getFirstDayOfWeek(); } setFirstDayOfWeek(firstDayOfWeek); } catch (Exception e) { e.printStackTrace(); } finally { a.recycle(); } currentMonth = CalendarDay.today(); setCurrentDate(currentMonth); if (isInEditMode()) { removeView(pager); MonthView monthView = new MonthView(context, currentMonth, getFirstDayOfWeek()); monthView.setSelectionColor(getSelectionColor()); monthView.setDateTextAppearance(adapter.getDateTextAppearance()); monthView.setWeekDayTextAppearance(adapter.getWeekDayTextAppearance()); monthView.setShowOtherDates(getShowOtherDates()); addView(monthView, new LayoutParams(MonthView.DEFAULT_MONTH_TILE_HEIGHT)); } }
From source file:org.bangbang.support.v4.widget.HListView.java
public HListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, /*com.android.internal.*/R.styleable.HListView, defStyle, 0);//from w ww .j a v a 2s . co m CharSequence[] entries = a.getTextArray(/*com.android.internal.*/R.styleable.HListView_entries); if (entries != null) { setAdapter(new ArrayAdapter<CharSequence>(context, /*com.android.internal.*/android.R.layout.simple_list_item_1, entries)); } final Drawable d = a.getDrawable(/*com.android.internal.*/R.styleable.HListView_divider); if (d != null) { // If a divider is specified use its intrinsic height for divider height setDivider(d); } // Use the height specified, zero being the default final int dividerHeight = a .getDimensionPixelSize(/*com.android.internal.*/R.styleable.HListView_dividerWidth, 0); if (dividerHeight != 0) { setDividerHeight(dividerHeight); } setChoiceMode(a.getInt(R.styleable.HListView_choiceMode, CHOICE_MODE_NONE)); mHeaderDividersEnabled = a.getBoolean(R.styleable.HListView_headerDividersEnabled, true); mFooterDividersEnabled = a.getBoolean(R.styleable.HListView_footerDividersEnabled, true); a.recycle(); }
From source file:com.appunite.list.HorizontalListView.java
public HorizontalListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, defStyle, 0); CharSequence[] entries = a.getTextArray(R.styleable.ListView_android_entries); if (entries != null) { setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries)); }//from w ww. j a v a 2 s .c o m final Drawable d = a.getDrawable(R.styleable.ListView_android_divider); if (d != null) { // If a divider is specified use its intrinsic width for divider width setDivider(d); } final Drawable osHeader = a.getDrawable(R.styleable.ListView_overScrollHeader); if (osHeader != null) { setOverscrollHeader(osHeader); } final Drawable osFooter = a.getDrawable(R.styleable.ListView_overScrollFooter); if (osFooter != null) { setOverscrollFooter(osFooter); } // Use the width specified, zero being the default final int dividerHeight = a.getDimensionPixelSize(R.styleable.ListView_android_dividerHeight, 0); if (dividerHeight != 0) { setDividerWidth(dividerHeight); } mHeaderDividersEnabled = a.getBoolean(R.styleable.ListView_headerDividersEnabled, true); mFooterDividersEnabled = a.getBoolean(R.styleable.ListView_footerDividersEnabled, true); a.recycle(); }
From source file:com.common.widget.hzlib.HorizontalListView.java
public HorizontalListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, defStyle, 0); CharSequence[] entries = a.getTextArray(R.styleable.ListView_android_entries); if (entries != null) { setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries)); }//from ww w. j ava 2s . c om final Drawable d = a.getDrawable(R.styleable.ListView_android_divider); if (d != null) { // If a divider is specified use its intrinsic width for divider width setDivider(d); } final Drawable osHeader = a.getDrawable(R.styleable.ListView_overScrollHeader); if (osHeader != null) { setOverscrollHeader(osHeader); } final Drawable osFooter = a.getDrawable(R.styleable.ListView_overScrollFooter); if (osFooter != null) { setOverscrollFooter(osFooter); } // Use the width specified, zero being the default final int dividerHeight = a.getDimensionPixelSize(R.styleable.ListView_dividerHeight, 0); if (dividerHeight != 0) { setDividerWidth(dividerHeight); } mHeaderDividersEnabled = a.getBoolean(R.styleable.ListView_headerDividersEnabled, true); mFooterDividersEnabled = a.getBoolean(R.styleable.ListView_footerDividersEnabled, true); a.recycle(); }
From source file:com.liu.hz.view.HorizontalListView.java
public HorizontalListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, defStyle, 0); CharSequence[] entries = a.getTextArray(R.styleable.ListView_android_entries); if (entries != null) { setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries)); }/* www . j a v a 2 s.c om*/ final Drawable d = a.getDrawable(R.styleable.ListView_divider); if (d != null) { // If a divider is specified use its intrinsic width for divider width setDivider(d); } final Drawable osHeader = a.getDrawable(R.styleable.ListView_overScrollHeader); if (osHeader != null) { setOverscrollHeader(osHeader); } final Drawable osFooter = a.getDrawable(R.styleable.ListView_overScrollFooter); if (osFooter != null) { setOverscrollFooter(osFooter); } // Use the width specified, zero being the default final int dividerHeight = a.getDimensionPixelSize(R.styleable.ListView_dividerHeight, 0); if (dividerHeight != 0) { setDividerWidth(dividerHeight); } mHeaderDividersEnabled = a.getBoolean(R.styleable.ListView_headerDividersEnabled, true); mFooterDividersEnabled = a.getBoolean(R.styleable.ListView_footerDividersEnabled, true); a.recycle(); }
From source file:com.appunite.list.ListView.java
public ListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, defStyle, 0); CharSequence[] entries = a.getTextArray(R.styleable.ListView_android_entries); if (entries != null) { setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries)); }//from www . ja va2 s .c om final Drawable d = a.getDrawable(R.styleable.ListView_android_divider); if (d != null) { // If a divider is specified use its intrinsic width for divider width setDivider(d); } final Drawable osHeader = a.getDrawable(R.styleable.ListView_overScrollHeader); if (osHeader != null) { setOverscrollHeader(osHeader); } final Drawable osFooter = a.getDrawable(R.styleable.ListView_overScrollFooter); if (osFooter != null) { setOverscrollFooter(osFooter); } // Use the width specified, zero being the default final int dividerHeight = a.getDimensionPixelSize(R.styleable.ListView_android_dividerHeight, 0); if (dividerHeight != 0) { setDividerHeight(dividerHeight); } mHeaderDividersEnabled = a.getBoolean(R.styleable.ListView_headerDividersEnabled, true); mFooterDividersEnabled = a.getBoolean(R.styleable.ListView_footerDividersEnabled, true); a.recycle(); }
From source file:com.common.widget.hzlib.ListView.java
public ListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, defStyle, 0); CharSequence[] entries = a.getTextArray(R.styleable.ListView_android_entries); if (entries != null) { setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries)); }//w ww . ja v a2 s .co m final Drawable d = a.getDrawable(R.styleable.ListView_android_divider); if (d != null) { // If a divider is specified use its intrinsic width for divider width setDivider(d); } final Drawable osHeader = a.getDrawable(R.styleable.ListView_overScrollHeader); if (osHeader != null) { setOverscrollHeader(osHeader); } final Drawable osFooter = a.getDrawable(R.styleable.ListView_overScrollFooter); if (osFooter != null) { setOverscrollFooter(osFooter); } // Use the width specified, zero being the default final int dividerHeight = a.getDimensionPixelSize(R.styleable.ListView_dividerHeight, 0); if (dividerHeight != 0) { setDividerHeight(dividerHeight); } mHeaderDividersEnabled = a.getBoolean(R.styleable.ListView_headerDividersEnabled, true); mFooterDividersEnabled = a.getBoolean(R.styleable.ListView_footerDividersEnabled, true); a.recycle(); }