Java Code Examples for android.content.res.TypedArray#getTextArray()

The following examples show how to use android.content.res.TypedArray#getTextArray() . 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: ListPreference.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
public ListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);
    mEntries = a.getTextArray(R.styleable.ListPreference_android_entries);
    mEntryValues = a.getTextArray(R.styleable.ListPreference_android_entryValues);
    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, defStyleAttr, defStyleRes);
    mSummary = a.getString(R.styleable.Preference_android_summary);
    a.recycle();
}
 
Example 2
Source File: LinearListView.java    From material-drawer with MIT License 6 votes vote down vote up
public LinearListView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R_styleable_LinearListView);

    // Use the thickness specified, zero being the default
    final int thickness = a.getDimensionPixelSize(
            LinearListView_dividerThickness, 0);
    if (thickness != 0) {
        setDividerThickness(thickness);
    }

    CharSequence[] entries = a.getTextArray(LinearListView_entries);
    if (entries != null) {
        setAdapter(new ArrayAdapter<>(context,
                android.R.layout.simple_list_item_1, entries));
    }

    a.recycle();
}
 
Example 3
Source File: IconListPreference.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
public IconListPreference(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0);

    CharSequence[] drawables;

    try {
        drawables = a.getTextArray(R.styleable.IconListPreference_icons);
    } finally {
        a.recycle();
    }

    for (CharSequence drawable : drawables) {
        int resId = context.getResources().getIdentifier(drawable.toString(), "mipmap", context.getPackageName());

        Drawable d = context.getResources().getDrawable(resId);

        mEntryDrawables.add(d);
    }

    setWidgetLayoutResource(R.layout.view_icon);
}
 
Example 4
Source File: MultiCheckPreference.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public MultiCheckPreference(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(
            attrs, com.android.internal.R.styleable.ListPreference, defStyleAttr, defStyleRes);
    mEntries = a.getTextArray(com.android.internal.R.styleable.ListPreference_entries);
    if (mEntries != null) {
        setEntries(mEntries);
    }
    setEntryValuesCS(a.getTextArray(
            com.android.internal.R.styleable.ListPreference_entryValues));
    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs,
            com.android.internal.R.styleable.Preference, 0, 0);
    mSummary = a.getString(com.android.internal.R.styleable.Preference_summary);
    a.recycle();
}
 
Example 5
Source File: AbsSpinner.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public AbsSpinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    // Spinner is important by default, unless app developer overrode attribute.
    if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
        setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
    }

    initAbsSpinner();

    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.AbsSpinner, defStyleAttr, defStyleRes);

    final CharSequence[] entries = a.getTextArray(R.styleable.AbsSpinner_entries);
    if (entries != null) {
        final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
                context, R.layout.simple_spinner_item, entries);
        adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
        setAdapter(adapter);
    }

    a.recycle();
}
 
Example 6
Source File: ListPreference.java    From MaterialPreferenceLibrary with Apache License 2.0 6 votes vote down vote up
@Override
    protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
        super.init(context, attrs, defStyleAttr, defStyleRes);
        TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);
        mEntries = a.getTextArray(R.styleable.ListPreference_entries);
        mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
        a.recycle();

        /* Retrieve the Preference summary attribute since it's private
         * in the Preference class.
         */
//    a=context.obtainStyledAttributes(attrs,
//            R.styleable.Preference,defStyleAttr,defStyleRes);
//    mSummary=a.getString(R.styleable.Preference_summary);
//    a.recycle();
        mSummary = super.getSummary() == null ? null : super.getSummary().toString();
    }
 
Example 7
Source File: ListPreference.java    From PreferenceFragment with Apache License 2.0 6 votes vote down vote up
public ListPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.ListPreference, 0, 0);
    mEntries = a.getTextArray(R.styleable.ListPreference_entries);
    mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs,
            R.styleable.Preference, 0, 0);
    mSummary = a.getString(R.styleable.Preference_summary);
    a.recycle();
}
 
Example 8
Source File: ListPreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    setNegativeButtonText(android.R.string.cancel);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);
    mEntries = a.getTextArray(R.styleable.ListPreference_entries);
    mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
    a.recycle();

    /* Retrieve the Preference summary attribute since it's private
     * in the Preference class.
     */
    a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.summary}, defStyleAttr, defStyleRes);
    mSummary = a.getString(0);
    a.recycle();
}
 
Example 9
Source File: TextInputSpinner.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    setInputType(InputType.TYPE_NULL);
    setCursorVisible(false);
    Drawable arrow = getResources().getDrawable(R.drawable.ic_arrow_drop_down_black_24dp);
    arrow.setBounds(0, 0, arrow.getIntrinsicWidth(), arrow.getIntrinsicHeight());
    setCompoundDrawablesRelative(null, null, arrow, null);
    AppCompat.setTint(arrow, getResources().getColor(R.color.colorMenuText));

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.TextInputSpinner, defStyleAttr, 0);
    mEntities = a.getTextArray(R.styleable.TextInputSpinner_android_entries);
    a.recycle();

    mPopup = new ListPopupWindow(context, attrs, defStyleAttr, R.style.AppTheme_PopupMenu_Overflow);
    mPopup.setAdapter(new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item, mEntities));
    mPopup.setOnItemClickListener((parent, view, position, id) -> {
        setSelection(position);
        mPopup.dismiss();
    });
    mPopup.setAnchorView(this);
    mPopup.setVerticalOffset(-ScreenUtils.dpToPx(5));
    mPopup.setHorizontalOffset(ScreenUtils.dpToPx(4));
    mPopup.setWidth(getResources().getDisplayMetrics().widthPixels - ScreenUtils.dpToPx(16));
    mPopup.setModal(true);

    setSelection(0);
}
 
Example 10
Source File: MultiSelectDragListPreference.javaMultiSelectDragListPreference.java    From Klyph with MIT License 5 votes vote down vote up
@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());
	}

	return result;
}
 
Example 11
Source File: QuestionnaireView.java    From QuestionnaireView with MIT License 5 votes vote down vote up
private void parseAttributes(Context context, AttributeSet attrs, int defStyleAttr) {
    drawInnerViews(context, attrs);
    TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.QuestionBaseView);
    int viewType = values.getInt(R.styleable.QuestionBaseView_view_type, 1);
    setViewType(viewType);
    String text = values.getString(R.styleable.QuestionBaseView_question);
    setQuestion(text);
    CharSequence[] answers =  values.getTextArray(R.styleable.QuestionBaseView_entries);
    if(answers != null) setAnswers(answers);

    values.recycle();
}
 
Example 12
Source File: RangeSeekBar.java    From RangeSeekBar with Apache License 2.0 5 votes vote down vote up
private void initAttrs(AttributeSet attrs) {
    try {
        TypedArray t = getContext().obtainStyledAttributes(attrs, R.styleable.RangeSeekBar);
        seekBarMode = t.getInt(R.styleable.RangeSeekBar_rsb_mode, SEEKBAR_MODE_RANGE);
        minProgress = t.getFloat(R.styleable.RangeSeekBar_rsb_min, 0);
        maxProgress = t.getFloat(R.styleable.RangeSeekBar_rsb_max, 100);
        minInterval = t.getFloat(R.styleable.RangeSeekBar_rsb_min_interval, 0);
        gravity = t.getInt(R.styleable.RangeSeekBar_rsb_gravity, Gravity.TOP);
        progressColor = t.getColor(R.styleable.RangeSeekBar_rsb_progress_color, 0xFF4BD962);
        progressRadius = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_progress_radius, -1);
        progressDefaultColor = t.getColor(R.styleable.RangeSeekBar_rsb_progress_default_color, 0xFFD7D7D7);
        progressDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_progress_drawable, 0);
        progressDefaultDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_progress_drawable_default, 0);
        progressHeight = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_progress_height, Utils.dp2px(getContext(), 2));
        tickMarkMode = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_mode, TRICK_MARK_MODE_NUMBER);
        tickMarkGravity = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_gravity, TICK_MARK_GRAVITY_CENTER);
        tickMarkLayoutGravity = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_layout_gravity, Gravity.TOP);
        tickMarkTextArray = t.getTextArray(R.styleable.RangeSeekBar_rsb_tick_mark_text_array);
        tickMarkTextMargin = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_tick_mark_text_margin, Utils.dp2px(getContext(), 7));
        tickMarkTextSize = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_tick_mark_text_size, Utils.dp2px(getContext(), 12));
        tickMarkTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressDefaultColor);
        tickMarkInRangeTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressColor);
        steps = t.getInt(R.styleable.RangeSeekBar_rsb_steps, 0);
        stepsColor = t.getColor(R.styleable.RangeSeekBar_rsb_step_color, 0xFF9d9d9d);
        stepsRadius = t.getDimension(R.styleable.RangeSeekBar_rsb_step_radius, 0);
        stepsWidth = t.getDimension(R.styleable.RangeSeekBar_rsb_step_width, 0);
        stepsHeight = t.getDimension(R.styleable.RangeSeekBar_rsb_step_height, 0);
        stepsDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_step_drawable, 0);
        stepsAutoBonding = t.getBoolean(R.styleable.RangeSeekBar_rsb_step_auto_bonding, true);
        t.recycle();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 13
Source File: ListPreference.java    From MDPreference with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.list_preference, defStyleAttr, defStyleRes);
    mEntries = a.getTextArray(R.styleable.list_preference_entry_arr);
    mEntryValues = a.getTextArray(R.styleable.list_preference_value_arr);
    mFormat = a.getString(R.styleable.list_preference_format_str);
    a.recycle();
}
 
Example 14
Source File: HListView.java    From Klyph with MIT License 5 votes vote down vote up
public HListView( Context context, AttributeSet attrs, int defStyle ) {
	super( context, attrs, defStyle );

	TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.HListView, defStyle, 0 );

	CharSequence[] entries = a.getTextArray( R.styleable.HListView_android_entries );
	if ( entries != null ) {
		setAdapter( new ArrayAdapter<CharSequence>( context, android.R.layout.simple_list_item_1, entries ) );
	}

	final Drawable d = a.getDrawable( R.styleable.HListView_android_divider );
	if ( d != null ) {
		// If a divider is specified use its intrinsic height for divider height
		setDivider( d );
	}

	final Drawable osHeader = a.getDrawable( R.styleable.HListView_overScrollHeader );
	if ( osHeader != null ) {
		setOverscrollHeader( osHeader );
	}

	final Drawable osFooter = a.getDrawable( R.styleable.HListView_overScrollFooter );
	if ( osFooter != null ) {
		setOverscrollFooter( osFooter );
	}

	// Use the height specified, zero being the default
	final int dividerWidth = a.getDimensionPixelSize( R.styleable.HListView_dividerWidth, 0 );
	if ( dividerWidth != 0 ) {
		setDividerWidth( dividerWidth );
	}

	mHeaderDividersEnabled = a.getBoolean( R.styleable.HListView_headerDividersEnabled, true );
	mFooterDividersEnabled = a.getBoolean( R.styleable.HListView_footerDividersEnabled, true );
	mMeasureWithChild = a.getInteger( R.styleable.HListView_measureWithChild, -1 );
	
	Log.d( LOG_TAG, "mMeasureWithChild: " + mMeasureWithChild );

	a.recycle();
}
 
Example 15
Source File: MultiSelectDragListPreference.javaMultiSelectDragListPreference.java    From Klyph with MIT License 5 votes vote down vote up
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();
}
 
Example 16
Source File: CassowaryLayout.java    From android-cassowary-layout with Apache License 2.0 5 votes vote down vote up
private void readConstraintsFromXml(AttributeSet attrs) {
    TypedArray a = getContext().getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.CassowaryLayout,
            0, 0);

    try {
        final CharSequence[] constraints = a.getTextArray(R.styleable.CassowaryLayout_constraints);

        asyncSetup = a.getBoolean(R.styleable.CassowaryLayout_asyncSetup, asyncSetup);
        aspectRatioFixed = a.getBoolean(R.styleable.CassowaryLayout_aspectRatioFixed, aspectRatioFixed);
        aspectRatioWidthFactor = a.getFloat(R.styleable.CassowaryLayout_aspectRatioWidthFactor, aspectRatioWidthFactor);
        aspectRatioHeightFactor = a.getFloat(R.styleable.CassowaryLayout_aspectRatioHeightFactor, aspectRatioHeightFactor);

        log("readConstraintsFromXml asyncSetup " + asyncSetup );
        if (asyncSetup) {
            setupSolverAsync(constraints);
        } else {
            cassowaryModel.addConstraints(constraints);
            state = State.PARSING_COMPLETE;
        }

        if (constraints == null) {
            throw new RuntimeException("missing cassowary:constraints attribute in XML");
        }

    } finally {
        a.recycle();
    }

}
 
Example 17
Source File: MultiSelectListPreference.java    From PreferenceFragment with Apache License 2.0 5 votes vote down vote up
public MultiSelectListPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.MultiSelectListPreference, 0, 0);
    mEntries = a.getTextArray(R.styleable.MultiSelectListPreference_entries);
    mEntryValues = a.getTextArray(R.styleable.MultiSelectListPreference_entryValues);
    a.recycle();
}
 
Example 18
Source File: SingleValueInputView.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void init(Context context, AttributeSet attrs) {

        rootView = inflate(context, R.layout.singlevalueinput_view, this);
        titleTextView = rootView.findViewById(R.id.singlevalueinput_title);
        valueEditText = rootView.findViewById(R.id.singlevalueinput_value);
        unitSpinner = rootView.findViewById(R.id.singlevalueinput_unitSpinner);
        commentTextView = rootView.findViewById(R.id.singlevalueinput_comment);
        commentLayout = rootView.findViewById(R.id.singlevalueinput_commentLayout);

        TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.SingleValueInputView,
            0, 0);

        try {
            mShowUnit = a.getBoolean(R.styleable.SingleValueInputView_showUnit, false);
            setShowUnit(mShowUnit);
            mShowComment = a.getBoolean(R.styleable.SingleValueInputView_showComment, false);
            setShowComment(mShowComment);
            mTitle = a.getString(R.styleable.SingleValueInputView_title);
            setTitle(mTitle);
            mComment = a.getString(R.styleable.SingleValueInputView_comment);
            setComment(mComment);
            mValue = a.getString(R.styleable.SingleValueInputView_value);
            setValue(mValue);
            mType = a.getInteger(R.styleable.SingleValueInputView_type, 0);
            setType(mType);
            CharSequence[] entries = a.getTextArray(R.styleable.SingleValueInputView_units);
            if (entries != null)
            {
                setUnits(entries);
            }
        } finally {
            a.recycle();
        }
    }
 
Example 19
Source File: MultiSelectListPreference.java    From MDPreference with Apache License 2.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.list_preference, defStyleAttr, defStyleRes);
    mEntries = a.getTextArray(R.styleable.list_preference_entry_arr);
    a.recycle();
}
 
Example 20
Source File: CircleRangeView.java    From CircleRangeView with Apache License 2.0 4 votes vote down vote up
public CircleRangeView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleRangeView);

    rangeColorArray = typedArray.getTextArray(R.styleable.CircleRangeView_rangeColorArray);
    rangeValueArray = typedArray.getTextArray(R.styleable.CircleRangeView_rangeValueArray);
    rangeTextArray = typedArray.getTextArray(R.styleable.CircleRangeView_rangeTextArray);

    borderColor = typedArray.getColor(R.styleable.CircleRangeView_borderColor, borderColor);
    cursorColor = typedArray.getColor(R.styleable.CircleRangeView_cursorColor, cursorColor);
    extraTextColor = typedArray.getColor(R.styleable.CircleRangeView_extraTextColor, extraTextColor);

    rangeTextSize = typedArray.getDimensionPixelSize(R.styleable.CircleRangeView_rangeTextSize, rangeTextSize);
    extraTextSize = typedArray.getDimensionPixelSize(R.styleable.CircleRangeView_extraTextSize, extraTextSize);

    typedArray.recycle();

    if (rangeColorArray == null || rangeValueArray == null || rangeTextArray == null) {
        throw new IllegalArgumentException("CircleRangeView : rangeColorArray态 rangeValueArray态rangeTextArray  must be not null ");
    }
    if (rangeColorArray.length != rangeValueArray.length
            || rangeColorArray.length != rangeTextArray.length
            || rangeValueArray.length != rangeTextArray.length) {
        throw new IllegalArgumentException("arrays must be equal length");
    }

    this.mSection = rangeColorArray.length;

    mSparkleWidth = dp2px(15);
    mCalibrationWidth = dp2px(10);

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    mRectFProgressArc = new RectF();
    mRectFCalibrationFArc = new RectF();
    mRectText = new Rect();

    mBackgroundColor = android.R.color.transparent;
}