Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * The MIT License (MIT)
 * Copyright (c) 2014 longkai
 * The software shall be used for good, not evil.
 */

import android.graphics.PorterDuff;

import android.view.MotionEvent;
import android.view.View;

import android.widget.ImageView;

public class Main {
    /**
     * inject a image touch overley
     * @param v
     * @param event
     */
    public static boolean imageOverlay(View v, MotionEvent event) {
        ImageView view = (ImageView) v;
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            // overlay is black with transparency of 0x77 (119)
            view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
            view.invalidate();
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL: {
            // clear the overlay
            view.getDrawable().clearColorFilter();
            view.invalidate();
            break;
        }
        }
        return false;
    }
}