锁屏   Launcher   輸入法  應用程序開發

   ICS lockscreen :http://go.rritw.com/blog.chinaunix.net/uid-26153587-id-3202374.html

/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * 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.
 */

package com.ExpandableListActivity;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.ColorStateList;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.text.format.DateFormat;
import android.view.GestureDetector.OnGestureListener;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.media.AudioManager;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;

import java.util.Date;
import java.io.File;

/**
 * The screen within {@link LockPatternKeyguardView} that shows general
 * information about the device depending on its state, and how to get past it,
 * as applicable.
 */
class LockScreen extends LinearLayout implements View.OnTouchListener,
        OnGestureListener {

    private String TAG = "yzy";
    private float fingx;
    private float fingy;
    
    private float bigCircleX ;
    private float bigCircleY ;
    private float bigCircleR ;
    

    public LockScreen(Context context, float widthPixels) {
        super(context);
        setWillNotDraw(false);
        
        this.bigCircleX = widthPixels/2;
        this.bigCircleY = 500;
        this.bigCircleR = 200;
        this.setOnTouchListener(this);

    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.d("yzy", "ondraw.......");
        // 創建畫筆
        Paint p = new Paint();
        p.setColor(Color.RED);// 設置紅色
        p.setStyle(Style.STROKE);
        p.setAntiAlias(true);// 設置畫筆的鋸齒效果。 true是去除,大家一看效果就明白了
        canvas.drawCircle(fingx, fingy, 100, p);// 大圓
        
        p.setColor(Color.WHITE);// 設置紅色
        canvas.drawCircle(bigCircleX, bigCircleY, bigCircleR, p);

    }

    public boolean dispatchTouchEvent(MotionEvent ev) {
        // 這裏必須返回 super.dispatchTouchEvent(ev); 滑動得時候才會多次觸發ACTION_MOVE
        return super.dispatchTouchEvent(ev);
        // return true;
        // return false;

    }

    public boolean onInterceptTouchEvent(MotionEvent ev) {

        super.onTouchEvent(ev);
        int action = ev.getAction();

        switch (action) {
            case MotionEvent.ACTION_MOVE:

                //現在代碼沒有走這裏 而是走得下面得onToucEvent
                fingx = ev.getX();
                fingy = ev.getY() < 500 ? 500 : ev.getY();
                Log.d("yzy", "fingx =" + fingx);
                Log.d("yzy", "fingy =" + fingy);

                Log.d(TAG, "---onTouchEvent action:ACTION_MOVE");
                break;

            case MotionEvent.ACTION_DOWN:

                Log.d(TAG, "---onTouchEvent action:ACTION_DOWN");

                break;

            case MotionEvent.ACTION_UP:

                Log.d(TAG, "---onTouchEvent action:ACTION_UP");

                break;

            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "---onTouchEvent action:ACTION_CANCEL");

                break;
        }

        return super.onInterceptTouchEvent(ev);

    }

    public boolean onTouchEvent(MotionEvent ev) {
        super.onTouchEvent(ev);
        int action = ev.getAction();

        switch (action) {
            case MotionEvent.ACTION_MOVE:
                fingx = ev.getX();
                fingy = ev.getY();
                if(getDistance(this.fingx,this.fingy,this.bigCircleX,this.bigCircleY)<=this.bigCircleR){
                    Log.d("yzy", "fingx =" + fingx);
                    Log.d("yzy", "fingy =" + fingy);
                    this.invalidate();
                }
                
               
                break;

            case MotionEvent.ACTION_DOWN:

                Log.d(TAG, "---onTouchEvent action:ACTION_DOWN");

                break;

            case MotionEvent.ACTION_UP:

                float x = ev.getX();
                float y = ev.getY();
                if(isTriggered(x,y)){
                    
                }else{
                    this.fingx = 240;this.fingy = 600;
                    this.invalidate();
                    
                }
                Log.d(TAG, "---onTouchEvent action:ACTION_UP");

                break;

            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "---onTouchEvent action:ACTION_CANCEL");

                break;
        }

        return true;

    }

    private boolean isTriggered(float x, float y) {
        // TODO Auto-generated method stub
        return false;
    }

    private double getDistance(float fingx2, float fingy2, float bigCircleX2, float bigCircleY2) {
        double  x = StrictMath.pow(fingx2-bigCircleX2, 2) + StrictMath.pow(fingy2-bigCircleY2, 2);
        return StrictMath.pow(x, 0.5);
    }

    // --------------------------------------------------
    @Override
    public boolean onDown(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        // TODO Auto-generated method stub
        // fingx = ev.getX();
        // fingy = ev.getY();
        //this.invalidate();
        //Log.d(TAG, "---onTouchEvent action:ACTION_MOVE");
        return true;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    // --------------------------------------------------
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.d("yzy", "touch.........");
        // TODO Auto-generated method stub
        return false;
    }

}
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()