1 package com.zhangwen0302;
2
3 import java.io.File;
4 import java.util.Timer;
5 import java.util.TimerTask;
6
7 import android.app.Activity;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.content.SharedPreferences;
11 import android.os.Bundle;
12 import android.os.Environment;
13 import android.view.KeyEvent;
14 import android.view.View;
15 import android.view.View.OnClickListener;
16 import android.widget.Button;
17 import android.widget.Toast;
18 import android.widget.ToggleButton;
19
20
21 public class Zhangwen0302Activity extends Activity {
22
23 private Button b1Button;
24 private ToggleButton toggleButton;
25 private Button about;
26
27 /** Called when the activity is first created. */
28 @Override
29 public void onCreate(Bundle savedInstanceState) {
30
31 super.onCreate(savedInstanceState);
32
33 setContentView(R.layout.main);
34
35 b1Button=(Button) findViewById(R.id.zhuce);
36 about=(Button) findViewById(R.id.about);
37 toggleButton=(ToggleButton) findViewById(R.id.on_off);
38
39 //生成文件夹
40 createSDCardDir("/zhangwen");
41
42
43 //初始化界面打开的开关
44 SharedPreferences sharedPreferences=getSharedPreferences("lock_screen_on_off", Context.MODE_WORLD_READABLE);
45 final Boolean o_offBoolean= sharedPreferences.getBoolean("on_off",false);
46 toggleButton.setChecked(o_offBoolean);
47 //得到on_off的值,如果有值就是值,没值就是false。。。。
48
49 toggleButton.setOnClickListener(new OnClickListener() {
50
51 public void onClick(View v) {
52
53 SharedPreferences mySharedPreferences = getSharedPreferences("lock_screen_on_off", Context.MODE_WORLD_READABLE);
54 SharedPreferences.Editor editor2 = mySharedPreferences.edit();
55 editor2.putBoolean("on_off",toggleButton.isChecked());
56 editor2.commit();
57 //
58
59 }
60 });
61
62
63 //注册按钮
64 b1Button.setOnClickListener(new Button.OnClickListener()
65 {
66 public void onClick(View v) {
67
68 Intent intent=new Intent();
69 intent.setClass(Zhangwen0302Activity.this,zhuce.class );
70 startActivity(intent);
71 Zhangwen0302Activity.this.finish();
72 }
73 });
74
75 //关于按钮
76 about.setOnClickListener(new Button.OnClickListener()
77 {
78 public void onClick(View v) {
79
80 //ExitDialog(Zhangwen0302Activity.this).show();
81
82 Intent intent=new Intent();
83 intent.setClass(Zhangwen0302Activity.this,about.class );
84 startActivity(intent);
85 Zhangwen0302Activity.this.finish();
86 }
87 });
88
89
90 }
91
92
93
94
95
96 @Override
97 protected void onStop() {
98 // TODO Auto-generated method stub
99 /* SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
100 editor.putBoolean("lock_screen_on_off", toggleButton.isChecked());
101 editor.commit();*/
102 super.onStop();
103 }
104
105 /* *//**
106 * 捕捉back
107 *//*
108 @Override
109 public boolean onKeyDown(int keyCode, KeyEvent event) {
110 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
111 ExitDialog(Zhangwen0302Activity.this).show();
112 return true;
113 }
114
115 return super.onKeyDown(keyCode, event);
116 }*/
117
118 public static void createSDCardDir(String nameString){
119
120 // 创建一个文件夹对象,赋值为外部存储器的目录
121 File sdcardDir =Environment.getExternalStorageDirectory();
122 //得到一个路径,内容是sdcard的文件夹路径和名字
123 String path=sdcardDir.getPath()+nameString;
124 File path1 = new File(path);
125 if (!path1.exists()) {
126 //若不存在,创建目录,可以在应用启动的时候创建
127 path1.mkdirs();
128 }
129 }
130
131 /* void EnableSystemKeyguard(boolean bEnable){
132 KeyguardManager mKeyguardManager=null;
133 KeyguardLock mKeyguardLock=null;
134
135 mKeyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
136 mKeyguardLock = mKeyguardManager.newKeyguardLock("");
137 if(bEnable)
138 mKeyguardLock.reenableKeyguard();
139 else
140 mKeyguardLock.disableKeyguard();
141 }
142 */
143
144 private static Boolean isExit = false;
145 private static Boolean hasTask = false;
146 Timer tExit = new Timer();
147 TimerTask task = new TimerTask() {
148
149 @Override
150 public void run() {
151 isExit = false;
152 hasTask = true;
153 }
154 };
155
156 public boolean onKeyDown(int keyCode, KeyEvent event) {
157 if(keyCode == KeyEvent.KEYCODE_BACK){
158 if(isExit == false){
159 isExit = true;
160 Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
161 if(!hasTask){
162 tExit.schedule(task, 2000);
163 }
164 }else{
165 finish();
166 System.exit(0);
167 }
168 }
169 return false;
170 }
171
172
173 /* private Dialog ExitDialog(Context context) {
174 AlertDialog.Builder builder = new AlertDialog.Builder(context);
175 builder.setTitle("软件信息");
176 builder.setMessage("掌纹识别系统版本号:1.0。 希望大家在使用过程中注意几点:选择黑色背景拍摄手掌照片;让手完全在摄像头里面,张开手指拍摄;建议在无光照的条件下进行注册解锁。 本掌纹识别系统由916实验室版权所有,欢迎大家使用,谢谢!");
177 builder.setNegativeButton("确定",
178 new DialogInterface.OnClickListener() {
179 public void onClick(DialogInterface dialog, int whichButton) {
180 }
181 });
182 return builder.create();
183 }*/
184
185
186
187 }
1 package com.zhangwen0302;
2 import get.roi.procedure.GetROI;
3 import get.roi.process.ImageValues;
4
5 import java.io.File;
6
7 import recog.processutil.DoGCode;
8 import recog.processutil.UtilValues;
9 import recog.usrprocedure.UserRegist;
10 import android.app.Activity;
11 import android.app.ProgressDialog;
12 import android.content.Context;
13 import android.content.Intent;
14 import android.content.SharedPreferences;
15 import android.graphics.Bitmap;
16 import android.net.Uri;
17 import android.os.Bundle;
18 import android.os.Environment;
19 import android.os.Handler;
20 import android.os.Message;
21 import android.provider.MediaStore;
22 import android.util.Log;
23 import android.view.KeyEvent;
24 import android.view.View;
25 import android.widget.Button;
26 import android.widget.EditText;
27 import android.widget.ImageView;
28 import android.widget.Toast;
29 import dalvik.system.VMRuntime;
30
31 public class zhuce extends Activity {
32 public static final int NONE = 0;
33 public static final int PHOTOHRAPH = 1;// 拍照
34 public static final int PHOTOHRAPH2 = 1;// 拍照
35 public static final int PHOTOHRAPH3 = 1;// 拍照
36
37 ImageView imageView = null;
38 ImageView imageView2 = null;
39 ImageView imageView3 = null;
40
41 private Button b4Button;//拍照按钮
42 private Button b5Button;//提交照按钮
43
44 private EditText editText;//备注密码
45
46 private Thread thread;
47
48 private Handler handler;
49
50 private final static float TARGET_HEAP_UTILIZATION = 0.75f;
51 private final static int CWJ_HEAP_SIZE = 6* 1024* 1024 ;
52
53 ProgressDialog myProgressDialog = null;
54
55 String z1="z1.jpg";
56 String z2="z2.jpg";
57 String z3="z3.jpg";
58 /* //String c1="c1.jpg";
59 String c2="c2.jpg";
60 String c3="c3.jpg";*/
61
62
63 /** Called when the activity is first created. */
64 @Override
65 public void onCreate(Bundle savedInstanceState) {
66 super.onCreate(savedInstanceState);
67
68 setContentView(R.layout.zhuce);//加载注册界面
69
70 /* final ProgressBar progressHorizontal = (ProgressBar)findViewById(R.id.progressBar1);
71 progressHorizontal.setIndeterminate(false);
72
73 */
74
75 VMRuntime.getRuntime().setTargetHeapUtilization(TARGET_HEAP_UTILIZATION);
76 VMRuntime.getRuntime().setMinimumHeapSize(CWJ_HEAP_SIZE);
77
78 /* imageView = (ImageView) findViewById(R.id.imageID);
79 imageView2 = (ImageView) findViewById(R.id.imageID2);
80 imageView3 = (ImageView) findViewById(R.id.imageID3);*/
81
82 b4Button=(Button) findViewById(R.id.widget44);
83 editText=(EditText) findViewById(R.id.zhucepassword);
84
85 /*
86 String path11=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/z1.jpg";
87 DeleteFile(path11);
88
89 String path22=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/z2.jpg";
90 DeleteFile(path22);
91
92 String path33=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/z3.jpg";
93 DeleteFile(path33);
94
95 String path119=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/c1.jpg";
96 DeleteFile(path119);
97
98
99 String path229=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/c2.jpg";
100 DeleteFile(path229);
101
102
103 String path339=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/c3.jpg";
104 DeleteFile(path339);*/
105
106 handler=new Handler(){
107
108 public void handleMessage(Message msg){
109 String message=(String)msg.obj;//obj不一定是String类,可以是别的类,看用户具体的应用
110 //根据message中的信息对主线程的UI进行改动
111 Toast.makeText(zhuce.this,message,300).show();
112 }
113 };
114
115 //拍照按钮
116 b4Button.setOnClickListener(new Button.OnClickListener()
117 {
118 public void onClick(View v) {
119
120 int q=1;
121 if(q==1){
122
123 String imagepath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/"+z1;
124 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
125 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(imagepath)));
126 startActivityForResult(intent, PHOTOHRAPH);
127 q++;
128 }
129 if (q==2) {
130 String imagepath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/"+z2;
131 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
132 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(imagepath)));
133 startActivityForResult(intent, PHOTOHRAPH2);
134 q++;
135 }
136 if (q==3) {
137 String imagepath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/"+z3;
138 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
139 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(imagepath)));
140 startActivityForResult(intent, PHOTOHRAPH3);
141 q++;
142 }
143 }
144 });
145
146
147
148
149 b5Button=(Button) findViewById(R.id.widget45);
150 //提交按钮
151 b5Button.setOnClickListener(new Button.OnClickListener()
152 {
153 public void onClick(View v) {
154 // 照片处理过程,然后保存到匹配库
155 if (editText.getText().toString().trim().equalsIgnoreCase(""))
156 {
157 Toast.makeText(zhuce.this,"请输入备注密码!",500).show();
158 }
159 else
160 {
161 myProgressDialog = ProgressDialog.show(zhuce.this,"Palmprint Unlock", "正在处理,请耐心等待...", true);
162 //progressHorizontal.setVisibility(View.VISIBLE);
163 thread=new Thread(new Runnable() {
164 public void run() {
165 // TODO Auto-generated method stub
166 AA();
167 }
168 });
169 thread.start();
170 }
171 }});
172 }
173
174 @Override
175 protected void onDestroy() {
176 // TODO Auto-generated method stub
177 super.onDestroy();
178 }
179
180 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
181 super.onActivityResult(requestCode, resultCode, data);
182
183 /*
184
185 if (resultCode == NONE)
186 return;
187 // 拍照
188 if (requestCode == PHOTOHRAPH) {
189
190 //设置文件保存路径这里放在跟目录下
191 Bitmap bmpDefaultPic;
192 bmpDefaultPic = BitmapFactory.decodeFile(
193 Environment.getExternalStorageDirectory()+
194 "/zhangwen/zhuce/"+z1,null);
195 imageView.setImageBitmap(roi.doFix(bmpDefaultPic));
196 }
197 if (requestCode == PHOTOHRAPH2) {
198
199 //设置文件保存路径这里放在跟目录下
200 Bitmap bmpDefaultPic;
201 bmpDefaultPic = BitmapFactory.decodeFile(
202 Environment.getExternalStorageDirectory()+
203 "/zhangwen/zhuce/"+z2,null);
204 imageView2.setImageBitmap(roi.doFix(bmpDefaultPic));
205 }
206 if (requestCode == PHOTOHRAPH3) {
207 //设置文件保存路径这里放在跟目录下
208 Bitmap bmpDefaultPic;
209 bmpDefaultPic = BitmapFactory.decodeFile(
210 Environment.getExternalStorageDirectory()+
211 "/zhangwen/zhuce/"+z3,null);
212 imageView3.setImageBitmap(roi.doFix(bmpDefaultPic));
213 } */
214 }
215 /**
216 * 捕捉back
217 */
218 @Override
219 public boolean onKeyDown(int keyCode, KeyEvent event) {
220 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
221 Intent intent=new Intent();
222 intent.setClass(zhuce.this,Zhangwen0302Activity.class );
223 startActivity(intent);
224 zhuce.this.finish();
225 return true;
226 }
227 return super.onKeyDown(keyCode, event);
228 }
229
230 private void AA()
231 {
232 SharedPreferences mySharedPreferences = getSharedPreferences("PASSWORD", Context.MODE_WORLD_READABLE);
233 SharedPreferences.Editor editor2 = mySharedPreferences.edit();
234 editor2.putString("password",editText.getText().toString());
235 editor2.commit();
236
237 GetROI roi=new GetROI();
238
239 Bitmap bmp1 = null;
240 Bitmap bmp2 = null;
241 Bitmap bmp3 = null;
242 Bitmap bmp4 = null;
243 Bitmap bmp5 = null;
244 Bitmap bmp6 = null;
245
246 try {
247 bmp4=roi.doFix(roi.getImgfromSdcard("z1.jpg",ImageValues.ImagePath));
248 bmp5=roi.doFix(roi.getImgfromSdcard("z2.jpg",ImageValues.ImagePath));
249 bmp6=roi.doFix(roi.getImgfromSdcard("z3.jpg",ImageValues.ImagePath));
250
251 bmp1 = roi.imageProcess2(bmp4);
252 bmp2 = roi.imageProcess2(bmp5);
253 bmp3 = roi.imageProcess2(bmp6);
254
255 bmp4.recycle(); //回收图片所占的内存
256 bmp5.recycle(); //回收图片所占的内存
257 bmp6.recycle(); //回收图片所占的内存
258
259 bmp4=null;
260 bmp5=null;
261 bmp6=null;
262 }
263 catch (Exception e)
264 {
265 // TODO: handle exception
266 String str_temp="出错啦!请重新拍照注册!";
267 Message message = Message.obtain();
268 message.obj=str_temp;
269 //通过Handler发布传送消息,handler
270 handler.sendMessage(message);
271 //Toast.makeText(zhuce.this,"出错啦!请重新拍照注册!",300).show();
272 }
273 try {
274 roi.outputImgtoSdcard(bmp1,"c1.jpg");
275 roi.outputImgtoSdcard(bmp2,"c2.jpg");
276 roi.outputImgtoSdcard(bmp3,"c3.jpg");
277
278 bmp1.recycle(); //回收图片所占的内存
279 bmp2.recycle(); //回收图片所占的内存
280 bmp3.recycle(); //回收图片所占的内存
281 bmp1=null;
282 bmp2=null;
283 bmp3=null;
284
285 } catch (Exception e)
286 {
287 // TODO Auto-generated catch block
288 //Toast.makeText(zhuce.this,"出错啦!请重新拍照注册!",300).show();
289 }
290
291 try {
292 UserRegist regist = new UserRegist();
293 UtilValues utl = new UtilValues();
294 DoGCode dog = new DoGCode();
295
296 //计算三张图片的fiximage后的图片矩阵(固定大小+灰度后)
297 double[][] img1=regist.getProcessedImg(regist.getImgfromSdcard("c1.jpg"));
298 double[][] img2=regist.getProcessedImg(regist.getImgfromSdcard("c2.jpg"));
299 double[][] img3=regist.getProcessedImg(regist.getImgfromSdcard("c3.jpg"));
300
301 //将三张照片进行DoG算法0-1编码
302 int[][] c1x = regist.getDoGCode(img1, utl.coltepl1);
303 int[][] c1y = regist.getDoGCode(img1, utl.coltepl2);
304 int[][] c2x = regist.getDoGCode(img2, utl.coltepl1);
305 int[][] c2y = regist.getDoGCode(img2, utl.coltepl2);
306 int[][] c3x = regist.getDoGCode(img3, utl.coltepl1);
307 int[][] c3y = regist.getDoGCode(img3, utl.coltepl2);
308
309 //将6个0-1矩阵存入文件
310 regist.writeRegistResultToSdcard(c1x, "c1x.txt");
311 regist.writeRegistResultToSdcard(c1y, "c1y.txt");
312 regist.writeRegistResultToSdcard(c2x, "c2x.txt");
313 regist.writeRegistResultToSdcard(c2y, "c2y.txt");
314 regist.writeRegistResultToSdcard(c3x, "c3x.txt");
315 regist.writeRegistResultToSdcard(c3y, "c3y.txt");
316
317 //计算3张照片两两modified hamming distance
318 int d12 = dog.modifiedHD(c1x, c1y, c2x, c2y);
319 int d13 = dog.modifiedHD(c1x, c1y, c3x, c3y);
320 int d23 = dog.modifiedHD(c2x, c2y, c3x, c3y);
321
322 //选最大modified hamming distance并存入文件
323 int max = regist.getMaxMhamdis(d12, d13, d23);
324 regist.writeRegistResultToSdcard(max, "maxmhd.txt");
325 } catch (Exception e)
326 {
327 // TODO Auto-generated catch block
328
329 /* String str_temp="出错啦!请重新注册!";
330 Message message = Message.obtain();
331 message.obj=str_temp;
332 //通过Handler发布传送消息,handler
333 handler.sendMessage(message);
334 //Toast.makeText(zhuce.this,"出错啦!请重新注册!",300).show();
335 */
336 }
337 Intent intent=new Intent();
338 intent.setClass(zhuce.this,Zhangwen0302Activity.class );
339 startActivity(intent);
340 zhuce.this.finish();
341 }
342
343 public Handler getHandler(){
344 return this.handler;
345 }
346
347
348 private void DeleteFile(String strPath) {
349 File file = new File(strPath);
350 if (file.exists())
351 file.delete();
352 else {
353 Log.e(z1, "不存在");
354 }
355 }
356 }
1 package com.zhangwen0302;
2
3 import android.content.BroadcastReceiver;
4 import android.content.Context;
5 import android.content.Intent;
6 import android.content.SharedPreferences;
7
8 public class MyLockScreenReceiver extends BroadcastReceiver {
9
10 @Override
11 public void onReceive(Context context, Intent intent) {
12 {
13 SharedPreferences sharedPreferences=context.getSharedPreferences("lock_screen_on_off", Context.MODE_WORLD_READABLE);
14 Boolean o_offBoolean= sharedPreferences.getBoolean("on_off",false);
15 if (o_offBoolean) {
16 Intent i = new Intent();
17 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
18 i.setClass(context, login.class);
19 context.startActivity(i);
20
21 }
22 else {
23 }
24
25 }
26 }
27
28 }
29
30
1 package com.zhangwen0302;
2 import get.roi.procedure.GetROI;
3 import get.roi.process.ImageValues;
4
5 import java.io.File;
6
7 import recog.processutil.DoGCode;
8 import recog.processutil.UtilValues;
9 import recog.usrprocedure.UserLogin;
10 import recog.usrprocedure.UserRegist;
11 import android.app.Activity;
12 import android.app.ProgressDialog;
13 import android.content.Context;
14 import android.content.Intent;
15 import android.content.SharedPreferences;
16 import android.graphics.Bitmap;
17 import android.net.Uri;
18 import android.os.Bundle;
19 import android.os.Environment;
20 import android.os.Handler;
21 import android.os.Message;
22 import android.provider.MediaStore;
23 import android.util.Log;
24 import android.view.KeyEvent;
25 import android.view.View;
26 import android.view.WindowManager;
27 import android.widget.Button;
28 import android.widget.EditText;
29 import android.widget.ImageView;
30 import android.widget.Toast;
31
32 public class login extends Activity {
33
34 public static final int PHOTOHRAPH = 1;// 拍照
35 ImageView imageView = null;
36 private Button b6Button;//拍照按钮
37 private Button b7Button;//提交照按钮
38 private String b="login.jpg";
39 private EditText testnum;//匹配成功则解锁
40
41 ProgressDialog myProgressDialog2 = null;
42 private Thread thread2;
43 private Handler handler2;
44 private Handler handler3;
45
46 /** Called when the activity is first created. */
47 @Override
48 public void onCreate(Bundle savedInstanceState) {
49 super.onCreate(savedInstanceState);
50
51 setContentView(R.layout.login);//加载登录界面
52 /*
53 imageView = (ImageView) findViewById(R.id.imageID2);*/
54 b6Button=(Button) findViewById(R.id.photo2);
55 testnum=(EditText) findViewById(R.id.testnum);
56
57 /* final ProgressBar progressHorizontal2 = (ProgressBar)findViewById(R.id.progressBar2);
58 progressHorizontal2.setIndeterminate(false);*/
59
60 String path=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/login.jpg";
61 String path11=Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/l1.jpg";
62 DeleteFile(path11);
63 DeleteFile(path);
64
65
66 handler2=new Handler(){
67 public void handleMessage(Message msg){
68 String message=(String)msg.obj;//obj不一定是String类,可以是别的类,看用户具体的应用
69 //根据message中的信息对主线程的UI进行改动
70 Toast.makeText(login.this,message,300).show();
71 }
72 };
73 handler3=new Handler(){
74 public void handleMessage(Message tz){
75 String message2=(String)tz.obj;//obj不一定是String类,可以是别的类,看用户具体的应用
76 if (message2.equals("home")) {
77 login.this.finish();
78 Intent i= new Intent(Intent.ACTION_MAIN);
79 i.addCategory(Intent.CATEGORY_HOME);
80 login.this.startActivity(i);
81 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
82 System.exit(0);
83 }
84 else if (message2.equals("login")) {
85 Intent intent=new Intent();
86 intent.setClass(login.this,login.class );
87 startActivity(intent);
88 login.this.finish();
89 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
90 System.exit(0);
91 }
92 }
93 };
94
95
96 //拍照按钮
97 b6Button.setOnClickListener(new Button.OnClickListener()
98 {
99 public void onClick(View v) {
100 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
101 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File
102 (Environment.getExternalStorageDirectory().getAbsolutePath()+"/zhangwen/"+b)));
103 startActivityForResult(intent, PHOTOHRAPH);
104 }
105 });
106
107 b7Button=(Button) findViewById(R.id.tijiao);
108 //提交按钮
109 b7Button.setOnClickListener(new Button.OnClickListener()
110 {
111 public void onClick(View v) {
112
113 //progressHorizontal2.setVisibility(View.VISIBLE);
114 SharedPreferences mySharedPreferences = getSharedPreferences("PASSWORD", Context.MODE_WORLD_READABLE);
115 String name = mySharedPreferences.getString("password", "");
116
117 if ((!testnum.getText().toString().trim().equalsIgnoreCase(""))){
118 //不是空的
119
120 if ((testnum.getText().toString().trim().equalsIgnoreCase(name))) {
121 //且匹配
122 login.this.finish();
123 Intent i= new Intent(Intent.ACTION_MAIN);
124 i.addCategory(Intent.CATEGORY_HOME);
125 login.this.startActivity(i);
126 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
127 System.exit(0);
128 }
129 else {
130 Intent intent=new Intent();
131 intent.setClass(login.this,login.class );
132 startActivity(intent);
133 login.this.finish();
134 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
135 System.exit(0);
136 }
137 }
138 else {
139 myProgressDialog2 = ProgressDialog.show(login.this,"Palmprint Unlock", "正在处理,请耐心等待...", true);
140
141 // TODO: handle exception
142 thread2=new Thread(new Runnable() {
143
144 public void run() {
145 // TODO Auto-generated method stub
146 BB();
147 //progressHorizontal2.setVisibility(View.INVISIBLE);
148 //myProgressDialog2 = ProgressDialog.show(login.this,"Palmprint Unlock", "正在处理图片,请耐心等待...", false);
149 }
150 });
151 thread2.start();
152
153 }
154 }});
155 }
156
157
158 @Override
159 protected void onDestroy() {
160 // TODO Auto-generated method stub
161 thread2.destroy();
162 super.onDestroy();
163 }
164
165
166 @Override
167 protected void onPause() {
168 // TODO Auto-generated method stub
169 // thread2.destroy();
170 super.onPause();
171 }
172
173 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
174 super.onActivityResult(requestCode, resultCode, data);
175
176 /* // 拍照
177 if (requestCode == PHOTOHRAPH) {
178
179 Bitmap bmpDefaultPic;
180 bmpDefaultPic = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() +
181 "/zhangwen/load/"+b,null);
182 imageView.setImageBitmap(bmpDefaultPic);
183 }*/
184 }
185
186 //捕捉home键,设置无效
187 public void onAttachedToWindow() {
188 this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
189 super.onAttachedToWindow();
190 }
191
192 /* *//**
193 * 捕捉back等其他键,设置无效
194 */
195 public boolean onKeyDown(int keyCode, KeyEvent event) {
196 switch (keyCode) {
197 case KeyEvent.KEYCODE_BACK:
198 return true;
199 }
200 switch (keyCode) {
201 case KeyEvent.KEYCODE_HOME:
202 return true;
203 case KeyEvent.KEYCODE_BACK:
204 return true;
205 case KeyEvent.KEYCODE_CALL:
206 return true;
207 case KeyEvent.KEYCODE_SYM:
208 return true;
209 case KeyEvent.KEYCODE_VOLUME_DOWN:
210 return true;
211 case KeyEvent.KEYCODE_VOLUME_UP:
212 return true;
213 case KeyEvent.KEYCODE_STAR:
214 return true;
215 }
216 return super.onKeyDown(keyCode, event);
217 }
218
219 public void BB() {//空的
220
221 GetROI roi=new GetROI();
222 Bitmap bmp1 = null;
223 Bitmap bmp2 = null;
224 try {
225 bmp2=roi.doFix(roi.getImgfromSdcard("login.jpg",ImageValues.ImagePath2));
226 bmp1 = roi.imageProcess2(bmp2);
227 bmp2.recycle(); //回收图片所占的内存
228 bmp2=null;
229 } catch (Exception e) {
230 // TODO Auto-generated catch block
231 String str_temp="请按规范拍摄手掌照片!";
232 Message message = Message.obtain();
233 message.obj=str_temp;
234 //通过Handler发布传送消息,handler
235 handler2.sendMessage(message);
236 /* Intent intent=new Intent();
237 intent.setClass(login.this,login.class );
238 startActivity(intent);
239 login.this.finish();
240 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
241 System.exit(0); */
242
243 String temp="login";
244 Message tz = Message.obtain();
245 tz.obj=temp;
246 handler3.sendMessage(tz);
247 }
248 try {
249 roi.outputImgtoSdcard(bmp1,"l1.jpg");
250 bmp1.recycle(); //回收图片所占的内存
251 bmp1=null;
252 } catch (Exception e) {
253 e.printStackTrace();
254 }
255
256 try {
257 UtilValues utl= new UtilValues();
258 UserRegist regist = new UserRegist();
259 UserLogin log = new UserLogin();
260 DoGCode dog = new DoGCode();
261
262 //处理登录掌纹照片得到double[][]
263 double[][] logImg=regist.getProcessedImg(regist.getImgfromSdcard("l1.jpg"));
264 //对图片进行编码
265 int[][] cx = regist.getDoGCode(logImg, utl.coltepl1);
266 int[][] cy = regist.getDoGCode(logImg, utl.coltepl2);
267
268 //读取注册信息
269 int[][] c1x = (int [][])regist.readRegistResultFromSdcard("c1x.txt");
270 int[][] c1y = (int [][])regist.readRegistResultFromSdcard("c1y.txt");
271 int[][] c2x = (int [][])regist.readRegistResultFromSdcard("c2x.txt");
272 int[][] c2y = (int [][])regist.readRegistResultFromSdcard("c2y.txt");
273 int[][] c3x = (int [][])regist.readRegistResultFromSdcard("c3x.txt");
274 int[][] c3y = (int [][])regist.readRegistResultFromSdcard("c3y.txt");
275 int maxmhd=(Integer)regist.readRegistResultFromSdcard("maxmhd.txt");
276
277 //计算modified hamming distance
278 int d1 = dog.modifiedHD(cx, cy, c1x, c1y);
279 int d2 = dog.modifiedHD(cx, cy, c2x, c2y);
280 int d3 = dog.modifiedHD(cx, cy, c3x, c3y);
281
282 int hdm = log.getLegalNum(d1, d2, d3, maxmhd);
283
284
285
286 if(hdm>0){
287 //合法
288 String temp="home";
289 Message tz = Message.obtain();
290 tz.obj=temp;
291 handler3.sendMessage(tz);
292
293 /* login.this.finish();
294 Intent i= new Intent(Intent.ACTION_MAIN);
295 i.addCategory(Intent.CATEGORY_HOME);
296 login.this.startActivity(i);
297 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
298 System.exit(0); */
299 }
300 else{
301 //非法
302 String temp="login";
303 Message tz = Message.obtain();
304 tz.obj=temp;
305 handler3.sendMessage(tz);
306
307 /* Intent intent=new Intent();
308 intent.setClass(login.this,login.class );
309 startActivity(intent);
310 login.this.finish();
311 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
312 System.exit(0); */
313 }
314
315 } catch (Exception e) {
316 // TODO Auto-generated catch block
317 String str_temp="出错啦!";
318 Message message = Message.obtain();
319 message.obj=str_temp;
320 //通过Handler发布传送消息,handler
321 handler2.sendMessage(message);
322
323 String temp="login";
324 Message tz = Message.obtain();
325 tz.obj=temp;
326 handler3.sendMessage(tz);
327
328 /* Intent intent=new Intent();
329 intent.setClass(login.this,login.class );
330 startActivity(intent);
331 login.this.finish();
332 android.os.Process.killProcess(android.os.Process.myPid()); //获取PID
333 System.exit(0); */
334 }
335
336 }
337 private void DeleteFile(String strPath) {
338 File file = new File(strPath);
339 if (file.exists())
340 file.delete();
341 else {
342 Log.e(b, "不存在");
343 }
344 }
345
346 }
1 package com.zhangwen0302;
2
3 import android.app.Activity;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.view.KeyEvent;
7
8 public class about extends Activity{
9
10 @Override
11 protected void onCreate(Bundle savedInstanceState) {
12 // TODO Auto-generated method stub
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.about);
15 }
16
17 /**
18 * 捕捉back
19 */
20 @Override
21 public boolean onKeyDown(int keyCode, KeyEvent event) {
22 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
23 Intent intent=new Intent();
24 intent.setClass(about.this,Zhangwen0302Activity.class );
25 startActivity(intent);
26 about.this.finish();
27 return true;
28 }
29 return super.onKeyDown(keyCode, event);
30 }
31
32 }