Search in sources :

Example 26 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project FloatingActionButton by Clans.

the class Label method onActionDown.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[] { android.R.attr.state_pressed });
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed });
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
//        setPressed(true);
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 27 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project FloatingActionButton by Clans.

the class Label method createFillDrawable.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, createRectDrawable(mColorPressed));
    drawable.addState(new int[] {}, createRectDrawable(mColorNormal));
    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][] { {} }, new int[] { mColorRipple }), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }
    mBackgroundDrawable = drawable;
    return drawable;
}
Also used : ColorStateList(android.content.res.ColorStateList) Outline(android.graphics.Outline) StateListDrawable(android.graphics.drawable.StateListDrawable) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View) TextView(android.widget.TextView) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 28 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project FloatingActionButton by Clans.

the class FloatingActionButton method createFillDrawable.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { -android.R.attr.state_enabled }, createCircleDrawable(mColorDisabled));
    drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(mColorPressed));
    drawable.addState(new int[] {}, createCircleDrawable(mColorNormal));
    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][] { {} }, new int[] { mColorRipple }), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }
    mBackgroundDrawable = drawable;
    return drawable;
}
Also used : ColorStateList(android.content.res.ColorStateList) Outline(android.graphics.Outline) StateListDrawable(android.graphics.drawable.StateListDrawable) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View) TextView(android.widget.TextView) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 29 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project android_frameworks_base by AOSPA.

the class PlatLogoActivity method onAttachedToWindow.

@Override
public void onAttachedToWindow() {
    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float dp = dm.density;
    final int size = (int) (Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600 * dp) - 100 * dp);
    final ImageView im = new ImageView(this);
    final int pad = (int) (40 * dp);
    im.setPadding(pad, pad, pad, pad);
    im.setTranslationZ(20);
    im.setScaleX(0.5f);
    im.setScaleY(0.5f);
    im.setAlpha(0f);
    im.setBackground(new RippleDrawable(ColorStateList.valueOf(0xFFFFFFFF), getDrawable(com.android.internal.R.drawable.platlogo), null));
    //        im.setOutlineProvider(new ViewOutlineProvider() {
    //            @Override
    //            public void getOutline(View view, Outline outline) {
    //                outline.setOval(0, 0, view.getWidth(), view.getHeight());
    //            }
    //        });
    im.setClickable(true);
    im.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            im.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    if (mTapCount < 5)
                        return false;
                    if (REVEAL_THE_NAME) {
                        final Drawable overlay = getDrawable(com.android.internal.R.drawable.platlogo_m);
                        overlay.setBounds(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
                        im.getOverlay().clear();
                        im.getOverlay().add(overlay);
                        overlay.setAlpha(0);
                        ObjectAnimator.ofInt(overlay, "alpha", 0, 255).setDuration(500).start();
                    }
                    final ContentResolver cr = getContentResolver();
                    if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0) == 0) {
                        // For posterity: the moment this user unlocked the easter egg
                        try {
                            Settings.System.putLong(cr, Settings.System.EGG_MODE, System.currentTimeMillis());
                        } catch (RuntimeException e) {
                            Log.e("PlatLogoActivity", "Can't write settings", e);
                        }
                    }
                    im.post(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                startActivity(new Intent(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).addCategory("com.android.internal.category.PLATLOGO"));
                            } catch (ActivityNotFoundException ex) {
                                Log.e("PlatLogoActivity", "No more eggs.");
                            }
                            if (FINISH)
                                finish();
                        }
                    });
                    return true;
                }
            });
            mTapCount++;
        }
    });
    // Enable hardware keyboard input for TV compatibility.
    im.setFocusable(true);
    im.requestFocus();
    im.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode != KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                ++mKeyCount;
                if (mKeyCount > 2) {
                    if (mTapCount > 5) {
                        im.performLongClick();
                    } else {
                        im.performClick();
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    });
    mLayout.addView(im, new FrameLayout.LayoutParams(size, size, Gravity.CENTER));
    im.animate().scaleX(1f).scaleY(1f).alpha(1f).setInterpolator(mInterpolator).setDuration(500).setStartDelay(800).start();
}
Also used : Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) Intent(android.content.Intent) DisplayMetrics(android.util.DisplayMetrics) ImageView(android.widget.ImageView) View(android.view.View) Paint(android.graphics.Paint) RippleDrawable(android.graphics.drawable.RippleDrawable) ContentResolver(android.content.ContentResolver) KeyEvent(android.view.KeyEvent) ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView)

Example 30 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project PhotoNoter by yydcdut.

the class ColorChooserDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_color_chooser, null);
    AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.note_dialog).setTitle(R.string.color_chooser).setCancelable(true).setView(v).create();
    final TypedArray ta = getActivity().getResources().obtainTypedArray(R.array.colors);
    mColors = new int[ta.length()];
    for (int i = 0; i < ta.length(); i++) {
        mColors[i] = ta.getColor(i, 0);
    }
    ta.recycle();
    final GridLayout list = (GridLayout) v.findViewById(R.id.grid);
    final int preselect = getArguments().getInt("preselect", -1);
    for (int i = 0; i < mColors.length; i++) {
        FrameLayout child = (FrameLayout) list.getChildAt(i);
        child.setTag(i);
        child.setOnClickListener(this);
        child.getChildAt(0).setVisibility(preselect == i ? View.VISIBLE : View.GONE);
        Drawable selector = createSelector(mColors[i]);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int[][] states = new int[][] { new int[] { -android.R.attr.state_pressed }, new int[] { android.R.attr.state_pressed } };
            int[] colors = new int[] { shiftColor(mColors[i]), mColors[i] };
            ColorStateList rippleColors = new ColorStateList(states, colors);
            setBackgroundCompat(child, new RippleDrawable(rippleColors, selector, null));
        } else {
            setBackgroundCompat(child, selector);
        }
    }
    return dialog;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) GridLayout(android.widget.GridLayout) TypedArray(android.content.res.TypedArray) FrameLayout(android.widget.FrameLayout) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) ColorStateList(android.content.res.ColorStateList) View(android.view.View) RippleDrawable(android.graphics.drawable.RippleDrawable)

Aggregations

RippleDrawable (android.graphics.drawable.RippleDrawable)34 Drawable (android.graphics.drawable.Drawable)11 Paint (android.graphics.Paint)10 StateListDrawable (android.graphics.drawable.StateListDrawable)10 View (android.view.View)10 ShapeDrawable (android.graphics.drawable.ShapeDrawable)8 TargetApi (android.annotation.TargetApi)7 ColorStateList (android.content.res.ColorStateList)7 GradientDrawable (android.graphics.drawable.GradientDrawable)7 FrameLayout (android.widget.FrameLayout)6 ImageView (android.widget.ImageView)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5 ContentResolver (android.content.ContentResolver)5 Intent (android.content.Intent)5 DisplayMetrics (android.util.DisplayMetrics)5 KeyEvent (android.view.KeyEvent)5 SuppressLint (android.annotation.SuppressLint)4 Outline (android.graphics.Outline)3 ViewOutlineProvider (android.view.ViewOutlineProvider)3 TextView (android.widget.TextView)3