maoruibin / maoruibin/maoruibin.github.com

自定义的 AutoAlphaView

Open
#33 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
22
Forks
4
PR merge metrics
No merged PRs in 30d

Description

/**
 * Created by GuDong on 2017/3/10 15:47.
 * Contact with ruibin.mao@moji.com.
 */

public class AutoAlphaView extends TextView {
    private static final String TAG = "AutoAlphaView";
    private static final float DEFAULT_ALPHA_VALUE = 0.7f;
    private float mPressedAlphaValue = DEFAULT_ALPHA_VALUE;

    public AutoAlphaView(Context context) {
        this(context, null);
    }

    public AutoAlphaView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AutoAlphaView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AutoAlphaView, defStyleAttr, 0);
        mPressedAlphaValue = attributes.getFloat(R.styleable.AutoAlphaView_pressed_alpha_value, DEFAULT_ALPHA_VALUE);
        attributes.recycle();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                setBackgroundByAlpha(getAlpha(mPressedAlphaValue));
                break;
            case MotionEvent.ACTION_UP:
                setBackgroundByAlpha(255);
                break;
            case MotionEvent.ACTION_CANCEL:
                setBackgroundByAlpha(255);
                break;
        }
        return super.onTouchEvent(event);
    }

    public static int getAlpha(@FloatRange(from = 0, to = 1) float alpha) {
        return (int) (255 * alpha);
    }

    private void setBackgroundByAlpha(@IntRange(from = 0, to = 255) int alpha) {
        Drawable drawableUp = getBackground();
        drawableUp.setAlpha(alpha);
        setBackgroundDrawable(drawableUp);
    }
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue only provides an AutoAlphaView Java snippet and does not name a repository file, test, or requested change. Clarify the intended Android change and its acceptance criteria before locating the relevant entry point and deciding what test or behavior will demonstrate completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.