Example usage for android.content.res TypedArray getString

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

Introduction

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

Prototype

@Nullable
public String getString(@StyleableRes int index) 

Source Link

Document

Retrieves the string value for the attribute at index.

Usage

From source file:com.android.server.MountService.java

private void readStorageListLocked() {
    mVolumes.clear();//from   w w w  . j av a 2s  .  c  o  m
    mVolumeStates.clear();

    Resources resources = mContext.getResources();

    int id = com.android.internal.R.xml.storage_list;
    XmlResourceParser parser = resources.getXml(id);
    AttributeSet attrs = Xml.asAttributeSet(parser);

    try {
        XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
        while (true) {
            XmlUtils.nextElement(parser);

            String element = parser.getName();
            if (element == null)
                break;

            if (TAG_STORAGE.equals(element)) {
                TypedArray a = resources.obtainAttributes(attrs, com.android.internal.R.styleable.Storage);

                String path = a.getString(com.android.internal.R.styleable.Storage_mountPoint);
                int descriptionId = a.getResourceId(com.android.internal.R.styleable.Storage_storageDescription,
                        -1);
                CharSequence description = a
                        .getText(com.android.internal.R.styleable.Storage_storageDescription);
                boolean primary = a.getBoolean(com.android.internal.R.styleable.Storage_primary, false);
                boolean removable = a.getBoolean(com.android.internal.R.styleable.Storage_removable, false);
                boolean emulated = a.getBoolean(com.android.internal.R.styleable.Storage_emulated, false);
                int mtpReserve = a.getInt(com.android.internal.R.styleable.Storage_mtpReserve, 0);
                boolean allowMassStorage = a
                        .getBoolean(com.android.internal.R.styleable.Storage_allowMassStorage, false);
                boolean allowMtp = a.getBoolean(com.android.internal.R.styleable.Storage_allowMtp, true);
                // resource parser does not support longs, so XML value is in megabytes
                long maxFileSize = a.getInt(com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L
                        * 1024L;

                Slog.d(TAG,
                        "got storage path: " + path + " description: " + description + " primary: " + primary
                                + " removable: " + removable + " emulated: " + emulated + " mtpReserve: "
                                + mtpReserve + " allowMassStorage: " + allowMassStorage + " maxFileSize: "
                                + maxFileSize + " allowMtp: " + allowMtp);

                if (emulated) {
                    // For devices with emulated storage, we create separate
                    // volumes for each known user.
                    mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false, true, mtpReserve,
                            false, maxFileSize, null, allowMtp);

                    final UserManagerService userManager = UserManagerService.getInstance();
                    for (UserInfo user : userManager.getUsers(false)) {
                        createEmulatedVolumeForUserLocked(user.getUserHandle());
                    }

                } else {
                    if (path == null || description == null) {
                        Slog.e(TAG, "Missing storage path or description in readStorageList");
                    } else {
                        final StorageVolume volume = new StorageVolume(new File(path), descriptionId, primary,
                                removable, emulated, mtpReserve, allowMassStorage, maxFileSize, null, allowMtp);
                        addVolumeLocked(volume);

                        // Until we hear otherwise, treat as unmounted
                        mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED);
                        volume.setState(Environment.MEDIA_UNMOUNTED);
                    }
                }

                a.recycle();
            }
        }
    } catch (XmlPullParserException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        // Compute storage ID for each physical volume; emulated storage is
        // always 0 when defined.
        int index = isExternalStorageEmulated() ? 1 : 0;
        for (StorageVolume volume : mVolumes) {
            if (!volume.isEmulated()) {
                volume.setStorageId(index++);
            }
        }
        parser.close();
    }
}

From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java

private void init(Context context, AttributeSet attrs) {
    float barHeight;
    int thumbNormal = R.drawable.seek_thumb;
    int thumbPressed = R.drawable.seek_thumb_pressed;
    int thumbDisabled = R.drawable.seek_thumb_disabled;
    int thumbShadowColor;
    int defaultShadowColor = Color.argb(75, 0, 0, 0);
    int defaultShadowYOffset = PixelUtil.dpToPx(context, 2);
    int defaultShadowXOffset = PixelUtil.dpToPx(context, 0);
    int defaultShadowBlur = PixelUtil.dpToPx(context, 2);

    offset = PixelUtil.dpToPx(context, TEXT_LATERAL_PADDING_IN_DP);
    textSeperation = PixelUtil.dpToPx(context, DEFAULT_TEXT_SEPERATION_IN_DP);
    step = DEFAULT_STEP;//from   w  ww  .  j  a v  a  2s  .c  o m
    snapTolerance = DEFAULT_SNAP_TOLERANCE_PERCENT / 100;
    minimumDistance = DEFAULT_MINIMUM_DISTANCE;
    increments = DEFAULT_INCREMENTS;
    incrementRanges = DEFAULT_INCREMENT_RANGES;

    if (attrs == null) {
        rangeType = DEFAULT_RANGE_TYPE;
        setRangeToDefaultValues();
        mInternalPad = PixelUtil.dpToPx(context, INITIAL_PADDING_IN_DP);
        barHeight = PixelUtil.dpToPx(context, LINE_HEIGHT_IN_DP);
        mActiveColor = ACTIVE_COLOR;
        mDefaultColor = Color.parseColor("#e5e8eb");
        mAlwaysActive = true;
        mShowTextAboveThumbs = true;
        mTextAboveThumbsColor = Color.WHITE;
        thumbShadowColor = defaultShadowColor;
        mThumbShadowXOffset = defaultShadowXOffset;
        mThumbShadowYOffset = defaultShadowYOffset;
        mThumbShadowBlur = defaultShadowBlur;
        mActivateOnDefaultValues = true;
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RangeSeekBar, 0, 0);
        try {
            switch (a.getInt(R.styleable.RangeSeekBar_rangeType, 0)) {
            case 0:
                rangeType = RangeType.LINEAR;
                break;
            case 1:
                rangeType = RangeType.PREDEFINED;
                break;
            case 2:
                rangeType = RangeType.CUBIC;
                break;
            default:
                rangeType = RangeType.LINEAR;
            }
            setRangeValues(
                    extractNumericValueFromAttributes(a, R.styleable.RangeSeekBar_absoluteMinValue,
                            DEFAULT_MINIMUM),
                    extractNumericValueFromAttributes(a, R.styleable.RangeSeekBar_absoluteMaxValue,
                            DEFAULT_MAXIMUM));
            mShowTextAboveThumbs = a.getBoolean(R.styleable.RangeSeekBar_valuesAboveThumbs, true);
            mTextAboveThumbsColor = a.getColor(R.styleable.RangeSeekBar_textAboveThumbsColor, Color.WHITE);
            mSingleThumb = a.getBoolean(R.styleable.RangeSeekBar_singleThumb, false);
            mShowLabels = a.getBoolean(R.styleable.RangeSeekBar_showLabels, true);
            mInternalPad = PixelUtil.dpToPx(context,
                    a.getInt(R.styleable.RangeSeekBar_internalPadding, INITIAL_PADDING_IN_DP));
            barHeight = PixelUtil.dpToPx(context,
                    a.getInt(R.styleable.RangeSeekBar_barHeight, LINE_HEIGHT_IN_DP));
            mActiveColor = a.getColor(R.styleable.RangeSeekBar_activeColor, ACTIVE_COLOR);
            mDefaultColor = a.getColor(R.styleable.RangeSeekBar_defaultColor, Color.parseColor("#e5e8eb"));
            mAlwaysActive = a.getBoolean(R.styleable.RangeSeekBar_alwaysActive, true);
            customMinValueLabel = a.getString(R.styleable.RangeSeekBar_minValueLabel);
            customMaxValueLabel = a.getString(R.styleable.RangeSeekBar_maxValueLabel);

            Drawable normalDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbNormal);
            if (normalDrawable != null) {
                thumbImage = BitmapUtil.drawableToBitmap(normalDrawable);
            }
            Drawable disabledDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbDisabled);
            if (disabledDrawable != null) {
                thumbDisabledImage = BitmapUtil.drawableToBitmap(disabledDrawable);
            }
            Drawable pressedDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbPressed);
            if (pressedDrawable != null) {
                thumbPressedImage = BitmapUtil.drawableToBitmap(pressedDrawable);
            }
            mThumbShadow = a.getBoolean(R.styleable.RangeSeekBar_thumbShadow, false);
            thumbShadowColor = a.getColor(R.styleable.RangeSeekBar_thumbShadowColor, defaultShadowColor);
            mThumbShadowXOffset = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowXOffset,
                    defaultShadowXOffset);
            mThumbShadowYOffset = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowYOffset,
                    defaultShadowYOffset);
            mThumbShadowBlur = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowBlur,
                    defaultShadowBlur);

            mActivateOnDefaultValues = a.getBoolean(R.styleable.RangeSeekBar_activateOnDefaultValues, true);
        } finally {
            a.recycle();
        }
    }

    Resources resources = getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 18, resources.getDisplayMetrics());

    if (thumbImage == null) {
        thumbImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        Drawable thumbDrawableNormal = getResources().getDrawable(thumbNormal);
        thumbDrawableNormal.setBounds(0, 0, px, px);
        thumbDrawableNormal.draw(new Canvas(thumbImage));
    }
    if (thumbPressedImage == null) {
        Drawable thumbDrawablePressed = getResources().getDrawable(thumbPressed);
        thumbDrawablePressed.setBounds(0, 0, px, px);
        thumbPressedImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        thumbDrawablePressed.draw(new Canvas(thumbPressedImage));
    }
    if (thumbDisabledImage == null) {
        Drawable thumbDrawableDisabled = getResources().getDrawable(thumbDisabled);
        thumbDrawableDisabled.setBounds(0, 0, px, px);
        thumbDisabledImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        thumbDrawableDisabled.draw(new Canvas(thumbDisabledImage));
    }

    mThumbHalfWidth = 0.5f * thumbImage.getWidth();
    mThumbHalfHeight = 0.5f * thumbImage.getHeight();

    setValuePrimAndNumberType();

    mTextSize = PixelUtil.spToPx(context, DEFAULT_TEXT_SIZE_IN_SP);
    mDistanceToTop = PixelUtil.dpToPx(context, DEFAULT_TEXT_DISTANCE_TO_TOP_IN_DP);
    mTextOffset = !mShowTextAboveThumbs ? 0
            : this.mTextSize + PixelUtil.dpToPx(context, DEFAULT_TEXT_DISTANCE_TO_BUTTON_IN_DP)
                    + this.mDistanceToTop;

    mRect = new RectF(padding, mTextOffset + mThumbHalfHeight - barHeight / 2, getWidth() - padding,
            mTextOffset + mThumbHalfHeight + barHeight / 2);

    // make RangeSeekBar focusable. This solves focus handling issues in case EditText widgets are being used along with the RangeSeekBar within ScrollViews.
    setFocusable(true);
    setFocusableInTouchMode(true);
    mScaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();

    if (mThumbShadow) {
        // We need to remove hardware acceleration in order to blur the shadow
        setLayerType(LAYER_TYPE_SOFTWARE, null);
        shadowPaint.setColor(thumbShadowColor);
        shadowPaint.setMaskFilter(new BlurMaskFilter(mThumbShadowBlur, BlurMaskFilter.Blur.NORMAL));
        mThumbShadowPath = new Path();
        mThumbShadowPath.addCircle(0, 0, mThumbHalfHeight, Path.Direction.CW);
    }
}

From source file:in.sc9.discreteslider.DiscreteSlider.java

public DiscreteSlider(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFocusable(true);/*from  w  w  w . j a  v a 2s  .  c o  m*/
    setWillNotDraw(false);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;
    mTrackHeight = (int) (1 * density);
    mScrubberHeight = (int) (4 * density);
    int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP);

    //Extra pixels for a touch area of 48dp
    int touchBounds = (int) (density * 32);
    mAddedTouchBounds = (touchBounds - thumbSize) / 2;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSlider, defStyleAttr,
            R.style.Widget_DiscreteSeekBar);

    int max = 100;
    int min = 0;
    int value = 0;
    mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSlider_dsb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSlider_dsb_allowTrackClickToDrag, mAllowTrackClick);
    mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorPopupEnabled,
            mIndicatorPopupEnabled);
    mIndicatorTextFromArray = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorTextFromArray,
            mIndicatorTextFromArray);
    int indexMax = R.styleable.DiscreteSlider_dsb_max;
    int indexMin = R.styleable.DiscreteSlider_dsb_min;
    int indexValue = R.styleable.DiscreteSlider_dsb_value;
    final TypedValue out = new TypedValue();
    //Not sure why, but we wanted to be able to use dimensions here...
    if (a.getValue(indexMax, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            max = a.getDimensionPixelSize(indexMax, max);
        } else {
            max = a.getInteger(indexMax, max);
        }
    }
    if (a.getValue(indexMin, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            min = a.getDimensionPixelSize(indexMin, min);
        } else {
            min = a.getInteger(indexMin, min);
        }
    }
    if (a.getValue(indexValue, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            value = a.getDimensionPixelSize(indexValue, value);
        } else {
            value = a.getInteger(indexValue, value);
        }
    }

    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mIndicatorFormatter = a.getString(R.styleable.DiscreteSlider_dsb_indicatorFormatter);

    mDiscretePointsEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsEnabled, false);
    mDiscretePointsShowAlways = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsShowAlways, false);

    ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_trackColor);
    ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_rippleColor);
    int discretePointColor = a.getColor(R.styleable.DiscreteSlider_dsb_discretePointsColor, Color.RED);

    mtextColor = a.getColor(R.styleable.DiscreteSlider_dsb_textColor, Color.BLACK);
    mTextSize = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextSize);
    mTextPaddingTop = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextPaddingTop);
    textStyle = a.getInt(R.styleable.DiscreteSlider_dsb_TextStyle, textStyle);

    boolean editMode = isInEditMode();
    if (editMode || rippleColor == null) {
        rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY });
    }
    if (editMode || trackColor == null) {
        trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY });
    }
    if (editMode || progressColor == null) {
        progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR });
    }
    if (editMode) {
        discretePointColor = Color.RED;
        mtextColor = Color.BLACK;
    }
    mRipple = SeekBarCompat.getRipple(rippleColor);
    if (isLollipopOrGreater) {
        SeekBarCompat.setBackground(this, mRipple);
    } else {
        mRipple.setCallback(this);
    }

    TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);
    mTrack = shapeDrawable;
    mTrack.setCallback(this);

    shapeDrawable = new TrackRectDrawable(progressColor);
    mScrubber = shapeDrawable;
    mScrubber.setCallback(this);

    mThumb = new ThumbDrawable(progressColor, thumbSize);
    mThumb.setCallback(this);
    mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight());

    textArray = new String[((mMax - mMin) + 1)];

    int j = mMin;
    for (int i = 0; i < ((mMax - mMin) + 1); i++) {
        if (j <= mMax) {
            textArray[i] = j + "";
            j++;
        } else
            break;
    }

    if (!editMode) {
        mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax));
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

    mDiscretePoints = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscretePoints.setColor(discretePointColor);
    mDiscretePoints.setStyle(Paint.Style.FILL);
    mDiscretePointsTran = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscretePointsTran.setColor(Color.TRANSPARENT);
    mDiscretePointsTran.setStyle(Paint.Style.FILL_AND_STROKE);
    position = new RectF();

}

From source file:android.transitions.everywhere.Transition.java

/**
 * Perform inflation from XML and apply a class-specific base style from a
 * theme attribute or style resource. This constructor of Transition allows
 * subclasses to use their own base style when they are inflating.
 *
 * @param context The Context the transition is running in, through which it can
 *        access the current theme, resources, etc.
 * @param attrs The attributes of the XML tag that is inflating the transition.
 *//*from ww w  .ja v a  2  s .c  o m*/
public Transition(Context context, AttributeSet attrs) {

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Transition);
    long duration = a.getInt(R.styleable.Transition_duration, -1);
    if (duration >= 0) {
        setDuration(duration);
    } else {
        duration = a.getInt(R.styleable.Transition_android_duration, -1);
        if (duration >= 0) {
            setDuration(duration);
        }
    }
    long startDelay = a.getInt(R.styleable.Transition_startDelay, -1);
    if (startDelay > 0) {
        setStartDelay(startDelay);
    }
    int resID = a.getResourceId(R.styleable.Transition_interpolator, 0);
    if (resID > 0) {
        setInterpolator(AnimationUtils.loadInterpolator(context, resID));
    } else {
        resID = a.getResourceId(R.styleable.Transition_android_interpolator, 0);
        if (resID > 0) {
            setInterpolator(AnimationUtils.loadInterpolator(context, resID));
        }
    }
    String matchOrder = a.getString(R.styleable.Transition_matchOrder);
    if (matchOrder != null) {
        setMatchOrder(parseMatchOrder(matchOrder));
    }
    a.recycle();
}

From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java

private void applyXmlAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView,
            defStyleAttr, defStyleRes);/*from ww  w .jav a 2  s  . c o m*/

    // Search bar width
    View suggestionsContainer = findViewById(R.id.fsv_suggestions_container);
    int searchBarWidth = a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_searchBarWidth,
            searchContainer.getLayoutParams().width);
    searchContainer.getLayoutParams().width = searchBarWidth;
    suggestionsContainer.getLayoutParams().width = searchBarWidth;

    // Divider
    ViewUtils.setBackground(divider, a.getDrawable(R.styleable.FloatingSearchView_android_divider));
    int dividerHeight = a.getDimensionPixelSize(R.styleable.FloatingSearchView_android_dividerHeight, -1);

    MarginLayoutParams dividerLP = (MarginLayoutParams) divider.getLayoutParams();

    if (divider.getBackground() != null && dividerHeight != -1)
        dividerLP.height = dividerHeight;

    float maxShadowSize = searchBackground.getMaxShadowSize();
    float cornerRadius = searchBackground.getCornerRadius();
    int horizontalPadding = (int) (RoundRectDrawableWithShadow.calculateHorizontalPadding(maxShadowSize,
            cornerRadius, false) + .5f);

    dividerLP.setMargins(horizontalPadding, dividerLP.topMargin, horizontalPadding, dividerLP.bottomMargin);
    divider.setLayoutParams(dividerLP);

    // Content inset
    MarginLayoutParams searchParams = (MarginLayoutParams) searchInput.getLayoutParams();

    int contentInsetStart = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetStart,
            MarginLayoutParamsCompat.getMarginStart(searchParams));
    int contentInsetEnd = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetEnd,
            MarginLayoutParamsCompat.getMarginEnd(searchParams));

    MarginLayoutParamsCompat.setMarginStart(searchParams, contentInsetStart);
    MarginLayoutParamsCompat.setMarginEnd(searchParams, contentInsetEnd);

    // anything else
    setLogo(a.getDrawable(R.styleable.FloatingSearchView_logo));
    setContentBackgroundColor(
            a.getColor(R.styleable.FloatingSearchView_fsv_contentBackgroundColor, DEFAULT_CONTENT_COLOR));
    setRadius(a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_cornerRadius,
            ViewUtils.dpToPx(DEFAULT_RADIUS)));
    inflateMenu(a.getResourceId(R.styleable.FloatingSearchView_fsv_menu, 0));
    setPopupTheme(a.getResourceId(R.styleable.FloatingSearchView_popupTheme, 0));
    setHint(a.getString(R.styleable.FloatingSearchView_android_hint));
    setIcon(a.getDrawable(R.styleable.FloatingSearchView_fsv_icon));

    a.recycle();
}

From source file:com.cocoa.cocoautils.widget.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB// w  ww  .j  a v  a2s. com

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, -2f));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, -2f));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//from w w w. j  a  v a 2  s .  c o  m

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:devlight.io.library.ntb.NavigationTabBar.java

@SuppressWarnings({ "ResourceAsColor", "ResourceType" })
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB/*w w w  .ja v  a  2 s.c om*/

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.hippo.vectorold.drawable.VectorDrawable.java

private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = state.mVPathRenderer;

    // Account for any configuration changes.
    state.mChangingConfigurations |= 0; //a.getChangingConfigurations();

    final int tintMode = a.getInt(R.styleable.VectorDrawable_tintMode, -1);
    if (tintMode != -1) {
        state.mTintMode = DrawableUtils.parseTintMode(tintMode, Mode.SRC_IN);
    }//from  w w w  . j  a v  a 2  s .  c  om

    final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_tint);
    if (tint != null) {
        state.mTint = tint;
    }

    state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);

    pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_viewportWidth,
            pathRenderer.mViewportWidth);
    pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_viewportHeight,
            pathRenderer.mViewportHeight);

    if (pathRenderer.mViewportWidth <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportWidth > 0");
    } else if (pathRenderer.mViewportHeight <= 0) {
        throw new XmlPullParserException(
                a.getPositionDescription() + "<vector> tag requires viewportHeight > 0");
    }

    pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_width, pathRenderer.mBaseWidth);
    pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_height, pathRenderer.mBaseHeight);

    if (pathRenderer.mBaseWidth <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires width > 0");
    } else if (pathRenderer.mBaseHeight <= 0) {
        throw new XmlPullParserException(a.getPositionDescription() + "<vector> tag requires height > 0");
    }

    final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_alpha, pathRenderer.getAlpha());
    pathRenderer.setAlpha(alphaInFloat);

    final String name = a.getString(R.styleable.VectorDrawable_name);
    if (name != null) {
        pathRenderer.mRootName = name;
        pathRenderer.mVGTargetsMap.put(name, pathRenderer);
    }
}

From source file:net.qiujuer.genius.ui.widget.GeniusAbsSeekBar.java

private void init(AttributeSet attrs, int defStyle) {
    final Context context = getContext();
    final Resources resources = getResources();
    final boolean notEdit = !isInEditMode();

    ColorStateList trackColor = mAttributes.getTrackColor();
    ColorStateList thumbColor = mAttributes.getThumbColor();
    ColorStateList scrubberColor = mAttributes.getScrubberColor();
    ColorStateList rippleColor = mAttributes.getRippleColor();
    ColorStateList indicatorColor = mAttributes.getIndicatorColor();

    int textAppearanceId = R.style.DefaultBalloonMarkerTextAppearanceStyle;

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GeniusSeekBar,
                R.attr.GeniusSeekBarStyle, defStyle);

        // Getting common attributes
        int customTheme = a.getResourceId(R.styleable.GeniusSeekBar_g_theme, Attributes.DEFAULT_THEME);
        mAttributes.setTheme(customTheme, resources);

        // Values
        int max = a.getInteger(R.styleable.GeniusSeekBar_g_max, mMax);
        int min = a.getInteger(R.styleable.GeniusSeekBar_g_min, mMin);
        int value = a.getInteger(R.styleable.GeniusSeekBar_g_value, mValue);

        mMin = min;/*from w w w  . j  a  v  a 2 s  . c  om*/
        mMax = Math.max(min + 1, max);
        mValue = Math.max(min, Math.min(max, value));

        // Colors
        trackColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_trackColor);
        thumbColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_thumbColor);
        scrubberColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_scrubberColor);
        rippleColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_rippleColor);
        indicatorColor = a.getColorStateList(R.styleable.GeniusSeekBar_g_indicatorBackgroundColor);

        // Size
        int tickSize = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_tickSize,
                mSeekBarDrawable.getTickRadius());
        int thumbSize = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_thumbSize,
                mSeekBarDrawable.getThumbRadius());
        int touchSize = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_touchSize,
                mSeekBarDrawable.getTouchRadius());
        int trackStroke = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_trackStroke,
                mSeekBarDrawable.getTrackStroke());
        int scrubberStroke = a.getDimensionPixelSize(R.styleable.GeniusSeekBar_g_scrubberStroke,
                mSeekBarDrawable.getScrubberStroke());

        // Set Size
        setTrackStroke(trackStroke);
        setScrubberStroke(scrubberStroke);
        setThumbRadius(thumbSize);
        setTouchRadius(touchSize);
        setTickRadius(tickSize);

        // Other
        mMirrorForRtl = a.getBoolean(R.styleable.GeniusSeekBar_g_mirrorForRtl, mMirrorForRtl);
        mAllowTrackClick = a.getBoolean(R.styleable.GeniusSeekBar_g_allowTrackClickToDrag, mAllowTrackClick);
        mIndicatorFormatter = a.getString(R.styleable.GeniusSeekBar_g_indicatorFormatter);

        textAppearanceId = a.getResourceId(R.styleable.GeniusSeekBar_g_indicatorTextAppearance,
                textAppearanceId);

        a.recycle();
    }

    // Init Colors
    if (rippleColor == null) {
        rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { mAttributes.getColor(1) });
    } else {
        mAttributes.setRippleColor(rippleColor);
    }
    if (trackColor == null) {
        int[] colors = new int[] { mAttributes.getColor(4), mAttributes.getColor(5) };
        int[][] states = new int[][] { new int[] { android.R.attr.state_enabled },
                new int[] { -android.R.attr.state_enabled } };
        trackColor = new ColorStateList(states, colors);
    } else {
        mAttributes.setTrackColor(trackColor);
    }
    if (thumbColor == null) {
        int[] colors = new int[] { mAttributes.getColor(2), mAttributes.getColor(3) };
        int[][] states = new int[][] { new int[] { android.R.attr.state_enabled },
                new int[] { -android.R.attr.state_enabled } };
        thumbColor = new ColorStateList(states, colors);
    } else {
        mAttributes.setThumbColor(thumbColor);
    }
    if (scrubberColor == null) {
        int[] colors = new int[] { mAttributes.getColor(2), mAttributes.getColor(3) };
        int[][] states = new int[][] { new int[] { android.R.attr.state_enabled },
                new int[] { -android.R.attr.state_enabled } };
        scrubberColor = new ColorStateList(states, colors);
    } else {
        mAttributes.setScrubberColor(scrubberColor);
    }
    if (indicatorColor == null) {
        int[] colors = new int[] { mAttributes.getColor(2), mAttributes.getColor(1) };
        int[][] states = new int[][] { new int[] { android.R.attr.state_enabled },
                new int[] { android.R.attr.state_pressed } };
        indicatorColor = new ColorStateList(states, colors);
    } else {
        mAttributes.setIndicatorColor(indicatorColor);
    }

    // Set Colors
    mRipple.setColorStateList(rippleColor);
    mSeekBarDrawable.setTrackColor(trackColor);
    mSeekBarDrawable.setScrubberColor(scrubberColor);
    mSeekBarDrawable.setThumbColor(thumbColor);
    if (notEdit) {
        mIndicator.setIndicatorColor(indicatorColor);
        mIndicator.setIndicatorTextAppearance(textAppearanceId);
    }

    // Set Values
    mSeekBarDrawable.setNumSegments(mMax - mMin);
    updateKeyboardRange();
}