Example usage for android.content.res TypedArray getText

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

Introduction

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

Prototype

public CharSequence getText(@StyleableRes int index) 

Source Link

Document

Retrieves the styled string value for the attribute at index.

Usage

From source file:com.example.nitish.welcomapp.widgetpt.PeriodicTableView.java

public PeriodicTableView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mSelectedPaint = new Paint();
    mSelectedPaint.setAntiAlias(true);/*from   w  ww. j  a va2s . c  o m*/
    mSelectedPaint.setStyle(Paint.Style.STROKE);
    mSelectedPaint.setStrokeJoin(Paint.Join.ROUND);
    mSelectedPaint.setColor(COLOR_SELECTED);

    mNumberPaint = new Paint();
    mNumberPaint.setAntiAlias(true);
    mNumberPaint.setColor(COLOR_BLOCK_FOREGROUND);

    mSymbolPaint = new Paint(mNumberPaint);
    mSymbolPaint.setTextAlign(Paint.Align.CENTER);

    mTitlePaint = new Paint(mSymbolPaint);
    mHeaderPaint = new Paint(mSymbolPaint);
    mSmallTextPaint = new Paint(mSymbolPaint);

    mNumberPaint.setSubpixelText(true);
    mSmallTextPaint.setSubpixelText(true);

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

    mTitle = a.getText(R.styleable.PeriodicTableView_title);
    setFgColor(a.getColor(R.styleable.PeriodicTableView_fgColor, COLOR_DEFAULT_FOREGROUND));
    setBgColor(a.getColor(R.styleable.PeriodicTableView_bgColor, COLOR_DEFAULT_BACKGROUND));

    a.recycle();

    mLegend = new PeriodicTableLegend(context);

    mScaleGestureDetector = new ScaleGestureDetector(context, getOnScaleGestureListener());
    mGestureDetector = new GestureDetector(context, getOnGestureListener());

    mZoomer = new Zoomer(context);
    mScroller = new Scroller(context);

    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mAccessibilityDelegate = new AccessibilityDelegate(this);
        ViewCompat.setAccessibilityDelegate(this, mAccessibilityDelegate);
    }
}

From source file:com.googlecode.eyesfree.example.bargraph.BarGraphView.java

public BarGraphView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Load styled attributes.
    final int defStyleRes = (isInEditMode() ? 0 : R.style.BarGraph);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BarGraph, defStyle, defStyleRes);

    final int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        final int attr = a.getIndex(i);

        switch (attr) {
        case R.styleable.BarGraph_barMargin:
            mBarMargin = a.getDimension(attr, mBarMargin);
            break;
        case R.styleable.BarGraph_barMinWidth:
            mBarMinHeight = a.getDimension(attr, mBarMinHeight);
            break;
        case R.styleable.BarGraph_barMinHeight:
            mBarMinWidth = a.getDimension(attr, mBarMinWidth);
            break;
        case R.styleable.BarGraph_title:
            setTitle(a.getText(attr));
            break;
        case R.styleable.BarGraph_titleSize:
            mTitleSize = a.getDimension(attr, mTitleSize);
            break;
        case R.styleable.BarGraph_values:
            if (!isInEditMode()) {
                setData(context.getResources().getIntArray(a.getResourceId(attr, 0)));
            }/*  w ww  .  j  ava 2  s  . c o  m*/
            break;
        }
    }

    a.recycle();

    if (isInEditMode()) {
        // Special considerations for edit mode.
        mBarGraphAccessHelper = null;
        setData(new int[] { 1, 1, 2, 3, 5, 8 });
        setSelection(3);
    } else {
        // Set up accessibility helper class.
        mBarGraphAccessHelper = new BarGraphAccessHelper(this);
        ViewCompat.setAccessibilityDelegate(this, mBarGraphAccessHelper);
    }
}

From source file:de.mrapp.android.preference.DialogPreference.java

/**
 * Obtains the message of the dialog, which is shown by the preference, from a specific typed
 * array./*  ww w.j a va 2s.  c  o  m*/
 *
 * @param typedArray
 *         The typed array, the message should be obtained from, as an instance of the class
 *         {@link TypedArray}. The typed array may not be null
 */
private void obtainDialogMessage(@NonNull final TypedArray typedArray) {
    setDialogMessage(typedArray.getText(R.styleable.DialogPreference_android_dialogMessage));
}

From source file:de.mrapp.android.preference.DialogPreference.java

/**
 * Obtains the title of the dialog, which is shown by the preference, from a specific typed
 * array./*from  w  ww .j  a v a  2  s. c  o  m*/
 *
 * @param typedArray
 *         The typed array, the title should be obtained from, as an instance of the class
 *         {@link TypedArray}. The typed array may not be null
 */
private void obtainDialogTitle(@NonNull final TypedArray typedArray) {
    CharSequence title = typedArray.getText(R.styleable.DialogPreference_android_dialogTitle);
    setDialogTitle(title != null ? title : getTitle());
}

From source file:de.mrapp.android.preference.DialogPreference.java

/**
 * Obtains the positive button text of the dialog, which is shown by the preference, from a
 * specific typed array.//w w  w.  j av a 2 s.  co  m
 *
 * @param typedArray
 *         The typed array, the positive button text should be obtained from, as an instance of
 *         the class {@link TypedArray}. The typed array may not be null
 */
private void obtainPositiveButtonText(@NonNull final TypedArray typedArray) {
    setPositiveButtonText(typedArray.getText(R.styleable.DialogPreference_android_positiveButtonText));
}

From source file:de.mrapp.android.preference.DialogPreference.java

/**
 * Obtains the negative button text of the dialog, which is shown by the preference, from a
 * specific typed array./*from   ww w  .  ja  va  2s .  co m*/
 *
 * @param typedArray
 *         The typed array, the negative button text should be obtained from, as an instance of
 *         the class {@link TypedArray}. The typed array may not be null
 */
private void obtainNegativeButtonText(@NonNull final TypedArray typedArray) {
    setNegativeButtonText(typedArray.getText(R.styleable.DialogPreference_android_negativeButtonText));
}

From source file:net.xpece.android.support.preference.SeekBarPreference.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekBarPreference, defStyleAttr,
            defStyleRes);/*from  ww w  .  j  a v a  2 s.c  o m*/

    /**
     * The ordering of these two statements are important. If we want to set max first, we need
     * to perform the same steps by changing min/max to max/min as following:
     * mMax = a.getInt(...) and setMin(...).
     */
    mMin = a.getInt(R.styleable.SeekBarPreference_asp_min, mMin);
    setMax(a.getInt(R.styleable.SeekBarPreference_android_max, mMax));

    try {
        mMin = a.getInt(R.styleable.SeekBarPreference_min, mMin);
        setMax(a.getInt(R.styleable.SeekBarPreference_android_max, mMax));
        setSeekBarIncrement(a.getInt(R.styleable.SeekBarPreference_seekBarIncrement, mSeekBarIncrement));
        mAdjustable = a.getBoolean(R.styleable.SeekBarPreference_adjustable, mAdjustable);
        mShowSeekBarValue = a.getBoolean(R.styleable.SeekBarPreference_showSeekBarValue, mShowSeekBarValue);
    } catch (NoSuchFieldError e) {
        // These are only available since support libs 25.1.0.
    }

    setInfo(a.getText(R.styleable.SeekBarPreference_asp_info));

    a.recycle();
}

From source file:com.albedinsky.android.ui.widget.SearchView.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/*from  w w  w . jav  a2s  .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>.
 */
@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:com.commonsware.cwac.crossport.design.widget.TextInputLayout.java

public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    // Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10
    super(context, attrs);

    // ThemeUtils.checkAppCompatTheme(context);

    setOrientation(VERTICAL);//from  w  w w .  ja va 2s.c o  m
    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    mInputFrame = new FrameLayout(context);
    mInputFrame.setAddStatesFromChildren(true);
    addView(mInputFrame);

    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
    mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator());
    mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START);

    mHintExpanded = mCollapsingTextHelper.getExpansionFraction() == 1f;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr,
            R.style.Widget_Design_TextInputLayout);
    mHintEnabled = a.getBoolean(R.styleable.TextInputLayout_hintEnabled, true);
    setHint(a.getText(R.styleable.TextInputLayout_android_hint));
    mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true);

    if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) {
        mDefaultTextColor = mFocusedTextColor = a
                .getColorStateList(R.styleable.TextInputLayout_android_textColorHint);
    }

    final int hintAppearance = a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1);
    if (hintAppearance != -1) {
        setHintTextAppearance(a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0));
    }

    mErrorTextAppearance = a.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0);
    final boolean errorEnabled = a.getBoolean(R.styleable.TextInputLayout_errorEnabled, false);

    final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false);
    setCounterMaxLength(a.getInt(R.styleable.TextInputLayout_counterMaxLength, INVALID_MAX_LENGTH));
    mCounterTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterTextAppearance, 0);
    mCounterOverflowTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterOverflowTextAppearance,
            0);

    mPasswordToggleEnabled = a.getBoolean(R.styleable.TextInputLayout_passwordToggleEnabled, false);
    mPasswordToggleDrawable = a.getDrawable(R.styleable.TextInputLayout_passwordToggleDrawable);
    mPasswordToggleContentDesc = a.getText(R.styleable.TextInputLayout_passwordToggleContentDescription);
    if (a.hasValue(R.styleable.TextInputLayout_passwordToggleTint)) {
        mHasPasswordToggleTintList = true;
        mPasswordToggleTintList = a.getColorStateList(R.styleable.TextInputLayout_passwordToggleTint);
    }
    if (a.hasValue(R.styleable.TextInputLayout_passwordToggleTintMode)) {
        mHasPasswordToggleTintMode = true;
        mPasswordToggleTintMode = ViewUtils
                .parseTintMode(a.getInt(R.styleable.TextInputLayout_passwordToggleTintMode, -1), null);
    }

    a.recycle();

    setErrorEnabled(errorEnabled);
    setCounterEnabled(counterEnabled);
    applyPasswordToggleTint();

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        // Make sure we're important for accessibility if we haven't been explicitly not
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate());
}

From source file:android.support.v7.internal.widget.ActionBarView.java

public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;// w  w  w . j av a  2  s .  c o m

    // Background is always provided by the container.
    setBackgroundResource(0);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar, R.attr.actionBarStyle, 0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.ActionBar_title);
    mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
    mLogo = a.getDrawable(R.styleable.ActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            if (context instanceof Activity) {
                try {
                    mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Activity component name not found!", e);
                }
            }
            if (mLogo == null) {
                mLogo = appInfo.loadLogo(pm);
            }
        }
    }

    // TODO(trevorjohns): Should these use the android namespace
    mIcon = a.getDrawable(R.styleable.ActionBar_icon);
    if (mIcon == null) {
        if (context instanceof Activity) {
            try {
                mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Activity component name not found!", e);
            }
        }
        if (mIcon == null) {
            mIcon = appInfo.loadIcon(pm);
        }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId = a.getResourceId(R.styleable.ActionBar_homeLayout, R.layout.abc_action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abc_action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.ActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0);

    setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));

    final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
    if (customNavId != 0) {
        mCustomNavView = (View) inflater.inflate(customNavId, this, false);
        mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
        setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
    a.recycle();
    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);

}