关闭

watermark

111人阅读 评论(0) 收藏 举报
分类:
 
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;


public class WM extends View {
	private Paint mPaint;
	private int mColor;
	private String uid;

	private int startX;
	private int startY;

	private final int hCount = 10;
	private final int sCount = 10;


	public WM(Context context) {
		super(context);
		init();
	}

	public WM(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public WM(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	private void init() {
		uid = " ";
		mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
		mColor = Color.argb(140, 192, 192, 192);
		mPaint.setColor(mColor);
		mPaint.setTextSize(12);

	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		startX =  0;
		startY =  0;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		float x, y;
		float distance = 100;
		canvas.rotate(30);
		for (int i = 0; i < sCount; i++) {
			for (int j = 0; j < hCount ; j++) {
				x = startX + (float)(j*distance*Math.cos(Math.PI/6));
				y = i*distance+startY - (float)(j*distance*Math.sin(Math.PI/6));
				canvas.drawText(uid ,x ,y ,mPaint);
			}
		}








	}

	public void setText(String uid) {
		this.uid = uid;
		invalidate();
	}
}


package com.midea.widget;

import android.content.Context;
import android.graphics.PixelFormat;
import android.util.Log;
import android.view.WindowManager;

import com.midea.activity.MdBaseActivity;


/**
 *  
 */
public class WaterMarkManager {
    private static  WM mWM;
    private static  WindowManager mWindowManager;
    private static  Context mContext;
    private static  String uid;
    public static boolean isShowing;
    public static boolean needShow;

    private static WaterMarkManager mWaterMarmManager   ;

    private WaterMarkManager( ){

    }

    public static WaterMarkManager getInstance(  ){
        if(mWaterMarmManager == null){
            mWaterMarmManager = new WaterMarkManager(  );
        }
        return mWaterMarmManager;
    }

    public static WaterMarkManager setUID(String uidp){
        uid = uidp;
        return mWaterMarmManager;
    }

    public static WaterMarkManager setContext(Context contextp){
        mContext = contextp;
        return mWaterMarmManager;
    }



    public static String getUID(){
        return uid;
    }




    public static void showWaterMark(){
        if(needShow && !isShowing){
            Log.e("WaterMarkManager", "SHOW");
            if(mWM == null){
                mWM = new WM(mContext);
            }
            mWM.setText(uid);
            if(mWindowManager==null){
                mWindowManager =(WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
            }
            WindowManager.LayoutParams  lp = new WindowManager.LayoutParams( mWindowManager.getDefaultDisplay().getWidth(),
                    mWindowManager.getDefaultDisplay().getHeight());

            lp.format = PixelFormat.RGBA_8888;
            lp.flags=WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

            mWindowManager.addView(mWM,lp);
            isShowing = true;
        }
    }


    public static void removeWaterMark(){
        if(isShowing){
            if(mWM!=null && mWM.getParent()!=null  ){

                if(mWindowManager!=null){
                    Log.e("WaterMarkManager", "REMOVE");
                    mWindowManager.removeView(mWM);
                    mWM = null;
                    mWindowManager  = null;
                }
            }
        }
        isShowing = false;
    }




}











0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:42474次
    • 积分:641
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:121篇
    • 译文:0篇
    • 评论:0条