Example usage for android.content.res TypedArray getFloat

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

Introduction

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

Prototype

public float getFloat(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve the float value for the attribute at index.

Usage

From source file:com.inmobi.nativead.sample.photopages.CustomViewPager.java

private void applyXmlAttributes(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomViewPager);

    this.actionDistance = a.getInteger(R.styleable.CustomViewPager_actionDistance, ACTION_DISTANCE_AUTO);
    this.scaleDownGravity = a.getFloat(R.styleable.CustomViewPager_scaleDownGravity, 1.0f);
    this.maxRotation = a.getInteger(R.styleable.CustomViewPager_maxRotation, 45);
    this.unselectedAlpha = a.getFloat(R.styleable.CustomViewPager_unselectedAlpha, 0.3f);
    this.unselectedSaturation = a.getFloat(R.styleable.CustomViewPager_unselectedSaturation, 0.0f);
    this.unselectedScale = a.getFloat(R.styleable.CustomViewPager_unselectedScale, 0.75f);

    a.recycle();//  w  w  w  .j av a 2s  . c  o  m
}

From source file:devlight.io.library.TintLayout.java

public TintLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setWillNotDraw(false);/*from www  .  j  a va 2 s  .c  om*/
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TintLayout);
    try {
        setAngle(typedArray.getFloat(R.styleable.TintLayout_tl_angle, DEFAULT_ANGLE));
        setColor(typedArray.getColor(R.styleable.TintLayout_tl_color, DEFAULT_COLOR));

        // Retrieve colors
        String[] stringColors = null;
        try {
            final int colorsId = typedArray.getResourceId(R.styleable.TintLayout_tl_colors, 0);
            stringColors = colorsId == 0 ? null : getResources().getStringArray(colorsId);
        } catch (Exception exception) {
            stringColors = null;
            exception.printStackTrace();
        } finally {
            if (stringColors == null)
                setColors(null);
            else {
                final int[] colors = new int[stringColors.length];
                for (int i = 0; i < stringColors.length; i++)
                    colors[i] = Color.parseColor(stringColors[i]);
                setColors(colors);
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.github.ppamorim.SlapBar.java

private void initializeAttributes(AttributeSet attrs) {
    TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.dragger_layout);
    if (attributes != null) {
        this.dragLimit = attributes.getFloat(R.styleable.dragger_layout_drag_limit, DEFAULT_DRAG_LIMIT);
        this.attributes = attributes;
    }/*from  w  w  w  . jav  a 2  s . com*/
}

From source file:com.microsoft.mimickeralarm.mimics.MimicColorCaptureFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    Resources resources = getResources();

    String subscriptionKey = KeyUtilities.getToken(getActivity(), "vision");
    mVisionServiceRestClient = new VisionServiceRestClient(subscriptionKey);

    String[] questions = resources.getStringArray(R.array.vision_color_questions);
    TextView instruction = (TextView) view.findViewById(R.id.instruction_text);
    mQuestionColorName = questions[new Random().nextInt(questions.length)];
    instruction.setText(String.format(resources.getString(R.string.mimic_vision_prompt), mQuestionColorName));

    TypedArray colorCodeLower = resources.obtainTypedArray(resources
            .getIdentifier(mQuestionColorName + "_range_lower", "array", getActivity().getPackageName()));
    mQuestionColorRangeLower = new float[] { colorCodeLower.getFloat(0, 0f), colorCodeLower.getFloat(1, 0f),
            colorCodeLower.getFloat(2, 0f) };
    colorCodeLower.recycle();//from   w ww . ja  v  a  2 s  .  com
    TypedArray colorCodeUpper = resources.obtainTypedArray(resources
            .getIdentifier(mQuestionColorName + "_range_upper", "array", getActivity().getPackageName()));
    mQuestionColorRangeUpper = new float[] { colorCodeUpper.getFloat(0, 0f), colorCodeUpper.getFloat(1, 0f),
            colorCodeUpper.getFloat(2, 0f) };
    colorCodeUpper.recycle();

    Logger.init(getActivity());
    Loggable playGameEvent = new Loggable.UserAction(Loggable.Key.ACTION_GAME_COLOR);
    Logger.track(playGameEvent);

    return view;
}

From source file:com.zhihu.android.app.mirror.widget.ArtboardView.java

private void init(AttributeSet attrs) {
    mDragDismissDistance = DisplayUtils.dp2px(getContext(), 112.0F);
    mDragElacticity = 0.8F;/* w  ww  .  j ava2s  .c  o  m*/
    if (attrs != null) {
        TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.ArtboardView);
        mDragDismissDistance = array.getDimensionPixelOffset(R.styleable.ArtboardView_avDragDismissDistance,
                (int) mDragDismissDistance);
        mDragElacticity = array.getFloat(R.styleable.ArtboardView_avDragElasticity, mDragElacticity);
        array.recycle();
    }

    mGestureDetector = new GestureDetector(getContext(), buildSimpleOnGestureListener());
    setOnTouchListener(this);
}

From source file:com.github.ppamorim.library.DraggerView.java

private void initializeAttributes(AttributeSet attrs) {
    TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.dragger_layout);
    this.dragLimit = attributes.getFloat(R.styleable.dragger_layout_drag_limit, DEFAULT_DRAG_LIMIT);
    this.dragPosition = DraggerPosition.getDragPosition(
            attributes.getInt(R.styleable.dragger_layout_drag_position, DEFAULT_DRAG_POSITION));
    this.attributes = attributes;
}

From source file:com.reddyetwo.hashmypass.app.view.ViewPagerIndicator.java

/**
 * Constructor//from w  ww  . j av a2s. co  m
 *
 * @param context the {@link android.content.Context} instance
 * @param attrs   the view attributes
 */
public ViewPagerIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ViewPagerIndicator, 0, 0);
    mRadius = array.getDimensionPixelSize(R.styleable.ViewPagerIndicator_radius, 0);
    mSpacing = array.getDimensionPixelSize(R.styleable.ViewPagerIndicator_spacing, 0);
    mAlpha = (int) (array.getFloat(R.styleable.ViewPagerIndicator_alpha, DEFAULT_ALPHA) * ALPHA_MAX);
    mCurrentPositionAlpha = (int) (array.getFloat(R.styleable.ViewPagerIndicator_current_position_alpha,
            DEFAULT_CURRENT_POSITION_ALPHA) * ALPHA_MAX);

    // Initialize paint
    mPaint.setAntiAlias(true);
    mPaint.setColor(getResources().getColor(android.R.color.white));

}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticLayout.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticLayout_layout_round, round);
    bgShape.setCornerRadius(round);/*from   w w  w  . ja v a2 s  .  c o  m*/

    color = typedArray.getInt(R.styleable.ElasticLayout_layout_backgroundColor, color);
    bgShape.setColor(color);

    scale = typedArray.getFloat(R.styleable.ElasticLayout_layout_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticLayout_layout_duration, duration);
}

From source file:io.nuclei.cyto.ui.view.GlideImageView.java

void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlideImageView, defStyleAttr,
            defStyleRes);/*from w ww.java2s.c  o  m*/

    mCircle = a.getBoolean(R.styleable.GlideImageView_circle, false);
    mRatio = a.getFloat(R.styleable.GlideImageView_ratio, 0);
    mRadius = a.getDimensionPixelSize(R.styleable.GlideImageView_radius, 0);
    mPlaceholderId = a.getResourceId(R.styleable.GlideImageView_placeholder, 0);

    String uri = a.getString(R.styleable.GlideImageView_url);
    a.recycle();

    if (uri == null) {
        if (mPlaceholderId > 0) {
            if (mCircle || mRadius > 0) {
                if (mTransformation == null)
                    mTransformation = new CornerTransformation(getContext(), mCircle, mRadius);
                Glide.with(getContext()).load(mPlaceholderId).asBitmap().diskCacheStrategy(getStrategy())
                        .transform(mTransformation).into(this);
            } else
                Glide.with(context).load(mPlaceholderId).into(this);
        }
    } else
        setImageURI(uri);
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticButton.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticButton_button_round, round);
    bgShape.setCornerRadius(round);// w  w w. ja v  a  2  s . c  om

    color = typedArray.getInt(R.styleable.ElasticButton_button_backgroundColor, color);
    bgShape.setColor(color);

    scale = typedArray.getFloat(R.styleable.ElasticButton_button_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticButton_button_duration, duration);

    labelText = typedArray.getString(R.styleable.ElasticButton_button_labelText);
    view.setText(labelText);

    labelColor = typedArray.getInt(R.styleable.ElasticButton_button_labelColor, labelColor);
    view.setTextColor(labelColor);

    labelSize = typedArray.getInt(R.styleable.ElasticButton_button_labelSize, labelSize);
    view.setTextSize(labelSize);

    labelStyle = typedArray.getInt(R.styleable.ElasticButton_button_labelStyle, labelStyle);

    if (labelStyle == 0)
        view.setTypeface(null, Typeface.NORMAL);
    else if (labelStyle == 1)
        view.setTypeface(null, Typeface.BOLD);
    else if (labelStyle == 2)
        view.setTypeface(null, Typeface.ITALIC);
}