不需要修改framework直接java绘制。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122package com.example.hellocursor; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.graphics.PixelFormat; import android.util.Log; import android.view.Menu; import android.view.MotionEvent; import android.view.WindowManager; import android.widget.ImageView; @SuppressLint("HandlerLeak") public class MainActivity extends Activity { private WindowManager wM; private WindowManager.LayoutParams lP; private ImageView ivCursor; private static final int msgUpdateView =1; volatile boolean bThreadRun = true; static int gaga = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //full screen; getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //WindowManager; wM = (WindowManager)getBaseContext().getSystemService(Context.WINDOW_SERVICE); //top view for cursor; //copy from frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java lP = new WindowManager.LayoutParams(); lP.height = WindowManager.LayoutParams.WRAP_CONTENT; lP.width = WindowManager.LayoutParams.WRAP_CONTENT; //need:<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> lP.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; lP.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; lP.format = PixelFormat.TRANSLUCENT; //notice ,x=y=0; means center of window; lP.x = 0; lP.y = 0; //cursor image; ivCursor = new ImageView(this.getBaseContext()); ivCursor.setImageResource(R.drawable.cursor); wM.addView(ivCursor, lP); } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub Log.i("mouse->", "onTouchEvent"); //pen down and pen up; so use gaga; if(1 == gaga) { bThreadRun = true; lP.x = 0; lP.y = 0; new PrintMouse().start(); gaga++; } //return super.onTouchEvent(event); return true; } class PrintMouse extends Thread { public void run() { while (bThreadRun) { Log.i("mouse->", "Thread"); try { sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Message m = new Message(); m.what = msgUpdateView; myMessageHandler.sendMessage(m); } } } Handler myMessageHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case msgUpdateView: lP.x = relX(); lP.y = relY(); if(bThreadRun) { wM.updateViewLayout(ivCursor, lP); } break; } super.handleMessage(msg); } }; @Override public void finish() { // TODO Auto-generated method stub bThreadRun = false; gaga = 1; wM.removeView(ivCursor); super.finish(); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public native int relX(); public native int relY(); static { System.loadLibrary("mouse"); } }
最后
以上就是要减肥镜子最近收集整理的关于android_绘制鼠标的全部内容,更多相关android_绘制鼠标内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复