Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2016 Ege Aker <egeaker@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.annotation.TargetApi;

import android.content.res.ColorStateList;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.ShapeDrawable;

import android.graphics.drawable.shapes.RectShape;
import android.os.Build;

public class Main {
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private static Drawable getRippleDrawable(int pressedColor, Integer normalColor) {
        ColorStateList colorStateList = getPressedColorSelector(pressedColor);
        Drawable mask, content = null;

        if (null == normalColor) {
            mask = new ShapeDrawable();
        } else {
            content = new ColorDrawable(normalColor);
            mask = getRippleMask(Color.WHITE);
        }
        return new RippleDrawable(colorStateList, content, mask);
    }

    private static ColorStateList getPressedColorSelector(int pressedColor) {
        return new ColorStateList(new int[][] { new int[] {} }, new int[] { pressedColor });
    }

    private static Drawable getRippleMask(int color) {
        ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
        shapeDrawable.getPaint().setColor(color);
        return shapeDrawable;
    }
}