watermark

原创 2016年05月31日 14:23:46
 
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;
    }




}











相关文章推荐

itext生成重复水印(watermark)

在这里只讲在生成pdf的文件过程中添加水印,至于向已存在的pdf文件中添加水印,那并不是本文所探讨的内容。     在网上搜了很多文字都不知道该怎么做。因为网上大部分都是讲的向已经存在的pdf文件中添...
  • Ctrain
  • Ctrain
  • 2015年07月30日 10:13
  • 228

ffmpeg如何给视频添加水印(watermark)

折腾了几天,问题倒是解决了。现在把相关命令行写下,做个记录: G:\TOOLS\ffmpeg-0.8-win32-bin>ffmpeg -i input.avi -vf "movie=log...

Modifying XPS Document: Add Watermark

Windows Platform Foundation has provided easy APIs and solutions for XPS document generation, visual...
  • wzsy
  • wzsy
  • 2011年11月25日 11:03
  • 1358

Aoao Video Watermark Pro 5.2破解版

  • 2017年10月29日 12:44
  • 16.08MB
  • 下载

textarea 标签中placeholder提示信息手动换行(jQuery水印插件watermark.js )

textarea中的placeholder信息有时需要作换行处理,如果利用空格填充让其内容自动换行的话,不大好控制。于是上网百度了一下,用了watermark.js 这个插件。这个插件据说还可以做水印...
  • diu_man
  • diu_man
  • 2017年07月21日 10:21
  • 187

c# add watermark

  • 2013年11月08日 06:27
  • 21.09MB
  • 下载

Image processing of watermark with blind extraction

Hello, this post is about  For many reason,like safety,

watermark图像

  • 2007年07月30日 10:20
  • 237KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:watermark
举报原因:
原因补充:

(最多只允许输入30个字)