Example usage for android.content.res TypedArray getTextArray

List of usage examples for android.content.res TypedArray getTextArray

Introduction

In this page you can find the example usage for android.content.res TypedArray getTextArray.

Prototype

public CharSequence[] getTextArray(@StyleableRes int index) 

Source Link

Document

Retrieve the CharSequence[] for the attribute at index.

Usage

From source file:de.mrapp.android.util.ThemeUtil.java

/**
 * Obtains the text array, which corresponds to a specific resource id, from a specific theme.
 * If the given resource id is invalid, a {@link NotFoundException} will be thrown.
 *
 * @param context/*  w  ww .  jav a 2  s . c o  m*/
 *         The context, which should be used, as an instance of the class {@link Context}. The
 *         context may not be null
 * @param themeResourceId
 *         The resource id of the theme, the attribute should be obtained from, as an {@link
 *         Integer} value or -1, if the attribute should be obtained from the given context's
 *         theme
 * @param resourceId
 *         The resource id of the attribute, which should be obtained, as an {@link Integer}
 *         value. The resource id must corresponds to a valid theme attribute
 * @return The text array, which has been obtained, as an array of the type {@link CharSequence}
 */
public static CharSequence[] getTextArray(@NonNull final Context context, @StyleRes final int themeResourceId,
        @AttrRes final int resourceId) {
    TypedArray typedArray = null;

    try {
        typedArray = obtainStyledAttributes(context, themeResourceId, resourceId);
        CharSequence[] textArray = typedArray.getTextArray(0);

        if (textArray == null) {
            throw new NotFoundException("Resource ID #0x" + Integer.toHexString(resourceId) + " is not valid");
        }

        return textArray;
    } finally {
        if (typedArray != null) {
            typedArray.recycle();
        }
    }
}

From source file:android.support.v14.preference.MultiSelectListPreference.java

@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
    final CharSequence[] defaultValues = a.getTextArray(index);
    final Set<String> result = new HashSet<>();

    for (final CharSequence defaultValue : defaultValues) {
        result.add(defaultValue.toString());
    }//  w w  w.j ava 2 s  .  c om

    return result;
}

From source file:de.blau.android.prefs.MultiSelectListPreference.java

@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
    final CharSequence[] defaultValues = a.getTextArray(index);
    final Set<String> result = new HashSet<String>();

    for (final CharSequence defaultValue : defaultValues) {
        result.add(defaultValue.toString());
    }// w  ww .j  av a2 s.c om

    return result;
}

From source file:android.preference.MultiSelectDragListPreference.java

@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
    final CharSequence[] defaultValues = a.getTextArray(index);
    final int valueCount = defaultValues.length;
    final List<String> result = new ArrayList<String>();

    for (int i = 0; i < valueCount; i++) {
        result.add(defaultValues[i].toString());
    }/*from w w  w  . j  a v a2  s.  c o  m*/

    return result;
}

From source file:android.preference.MultiSelectDragListPreference.java

public MultiSelectDragListPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiSelectDragListPreference, 0, 0);
    mEntries = a.getTextArray(R.styleable.MultiSelectDragListPreference_entries);
    mEntryValues = a.getTextArray(R.styleable.MultiSelectDragListPreference_entryValues);
    a.recycle();/*from  w  ww .j  a  va 2  s  .com*/
}

From source file:com.albedinsky.android.setting.SettingSelectionDialogPreference.java

/**
 * Called from one of constructors of this setting preference to perform its initialization.
 * <p>/*from  www .  j  a  va 2 s . c o m*/
 * 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.kuloud.android.calendarview.CalendarView.java

public CalendarView(Context context, AttributeSet attrs) {
    super(context, attrs);

    setClipChildren(false);//from w  w w .j av  a 2  s  .  c  om
    setClipToPadding(false);

    pager = new ViewPager(getContext());

    setupChildren();

    titleChanger = new TitleChanger(topbar);
    titleChanger.setTitleFormatter(DEFAULT_TITLE_FORMATTER);
    adapter = new MonthPagerAdapter(this);
    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.CalendarView, 0, 0);
    try {

        int tileSize = a.getDimensionPixelSize(R.styleable.CalendarView_mcv_tileSize, -1);
        if (tileSize > 0) {
            setTileSize(tileSize);
        }

        setSelectionColor(
                a.getColor(R.styleable.CalendarView_mcv_selectionColor, getThemeAccentColor(context)));

        CharSequence[] array = a.getTextArray(R.styleable.CalendarView_mcv_weekDayLabels);
        if (array != null) {
            setWeekDayFormatter(new ArrayWeekDayFormatter(array));
        }

        array = a.getTextArray(R.styleable.CalendarView_mcv_monthLabels);
        if (array != null) {
            setTitleFormatter(new MonthArrayTitleFormatter(array));
        }

        setShowOtherDates(a.getBoolean(R.styleable.CalendarView_mcv_showOtherDates, false));

        int firstDayOfWeek = a.getInt(R.styleable.CalendarView_mcv_firstDayOfWeek, -1);
        if (firstDayOfWeek < 0) {
            firstDayOfWeek = CalendarUtils.getInstance().getFirstDayOfWeek();
        }
        setFirstDayOfWeek(firstDayOfWeek);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (a != null) {
            a.recycle();
        }
    }

    currentMonth = CalendarDay.today();
    setCurrentDate(currentMonth);
}

From source file:com.farbod.labelledspinner.LabelledSpinner.java

private void setUpLayout(Context context, AttributeSet attrs) {
    prepareLayout(context);/*from w w  w .  j av a 2 s.c  o m*/

    mLabel = (TextView) getChildAt(0);
    mSpinner = (Spinner) getChildAt(1);
    mDivider = getChildAt(2);
    mErrorLabel = (TextView) getChildAt(3);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LabelledSpinner, 0, 0);

    String labelText = a.getString(R.styleable.LabelledSpinner_labelText);
    mWidgetColor = a.getColor(R.styleable.LabelledSpinner_widgetColor,
            ContextCompat.getColor(context, R.color.widget_labelled_spinner_default));

    mLabel.setText(labelText);
    mLabel.setPadding(0, dpToPixels(16), 0, 0);
    mSpinner.setPadding(0, dpToPixels(8), 0, dpToPixels(8));
    mSpinner.setOnItemSelectedListener(this);

    MarginLayoutParams dividerParams = (MarginLayoutParams) mDivider.getLayoutParams();
    dividerParams.rightMargin = dpToPixels(4);
    dividerParams.bottomMargin = dpToPixels(8);
    mDivider.setLayoutParams(dividerParams);

    mLabel.setTextColor(mWidgetColor);
    mDivider.setBackgroundColor(mWidgetColor);

    alignLabelWithSpinnerItem(4);

    final CharSequence[] entries = a.getTextArray(R.styleable.LabelledSpinner_entries);
    if (entries != null) {
        setItemsArray(entries);
    }

    mDefaultErrorEnabled = a.getBoolean(R.styleable.LabelledSpinner_defaultErrorEnabled, false);
    mDefaultErrorText = getResources().getString(R.string.widget_labelled_spinner_errorText);

    a.recycle();
}

From source file:com.satsuware.usefulviews.LabelledSpinner.java

/**
 * Sets up views and widget attributes//ww  w . j  a v  a 2  s. c om
 *
 * @param context Context passed from constructor
 * @param attrs AttributeSet passed from constructor
 */
private void initializeLayout(Context context, AttributeSet attrs) {
    prepareLayout(context);

    mLabel = (TextView) getChildAt(0);
    mSpinner = (Spinner) getChildAt(1);
    mDivider = getChildAt(2);
    mErrorLabel = (TextView) getChildAt(3);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LabelledSpinner, 0, 0);

    String labelText = a.getString(R.styleable.LabelledSpinner_labelText);
    mWidgetColor = a.getColor(R.styleable.LabelledSpinner_widgetColor,
            ContextCompat.getColor(context, R.color.widget_labelled_spinner_default));

    mLabel.setText(labelText);
    mLabel.setPadding(0, dpToPixels(16), 0, 0);
    mSpinner.setPadding(0, dpToPixels(8), 0, dpToPixels(8));
    mSpinner.setOnItemSelectedListener(this);

    MarginLayoutParams dividerParams = (MarginLayoutParams) mDivider.getLayoutParams();
    dividerParams.rightMargin = dpToPixels(4);
    dividerParams.bottomMargin = dpToPixels(8);
    mDivider.setLayoutParams(dividerParams);

    mLabel.setTextColor(mWidgetColor);
    mDivider.setBackgroundColor(mWidgetColor);

    alignLabelWithSpinnerItem(4);

    final CharSequence[] entries = a.getTextArray(R.styleable.LabelledSpinner_spinnerEntries);
    if (entries != null) {
        setItemsArray(entries);
    }

    mDefaultErrorEnabled = a.getBoolean(R.styleable.LabelledSpinner_defaultErrorEnabled, false);
    mDefaultErrorText = getResources().getString(R.string.widget_labelled_spinner_errorText);

    a.recycle();
}

From source file:com.lab47billion.appchooser.HorizontalPicker.java

public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    _context = context;//  w  w w.  ja  v  a  2  s.  c o  m

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);
    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);
        mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize);
        mNormalTextSize = a.getDimension(R.styleable.HorizontalPicker_normalTextSize, 20);
        mSelectedTextSize = a.getDimension(R.styleable.HorizontalPicker_selectedTextSize, -1);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        if (mNormalTextSize > -1) {
            setTextSize(mNormalTextSize);
        }
        if (mSelectedTextSize == -1) {
            mSelectedTextSize = mNormalTextSize;
        }

    } 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);*/

}