OSDN Git Service

4a8a5c319c83c350e92605d13357f47288c04aaa
[android-x86/external-koush-Superuser.git] / Superuser / src / com / koushikdutta / superuser / PinViewHelper.java
1 package com.koushikdutta.superuser;
2
3 import android.os.Bundle;
4 import android.view.LayoutInflater;
5 import android.view.View;
6 import android.view.View.OnClickListener;
7 import android.view.ViewGroup;
8 import android.widget.Button;
9 import android.widget.EditText;
10
11 public class PinViewHelper {
12     public PinViewHelper(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
13         View ret = inflater.inflate(R.layout.pin, container, false);
14
15         final EditText password = (EditText)ret.findViewById(R.id.password);
16         int[] ids = new int[] { R.id.p0, R.id.p1, R.id.p2, R.id.p3, R.id.p4, R.id.p5, R.id.p6, R.id.p7, R.id.p8, R.id.p9, };
17         for (int i = 0; i < ids.length; i++) {
18             int id = ids[i];
19             Button b = (Button)ret.findViewById(id);
20             final String text = String.valueOf(i);
21             b.setText(text);
22             b.setOnClickListener(new OnClickListener() {
23                 @Override
24                 public void onClick(View v) {
25                     password.setText(password.getText().toString() + text);
26                 }
27             });
28         }
29
30         ret.findViewById(R.id.pd).setOnClickListener(new OnClickListener() {
31             @Override
32             public void onClick(View v) {
33                 String curPass = password.getText().toString();
34                 if (curPass.length() > 0) {
35                     curPass = curPass.substring(0, curPass.length() - 1);
36                     password.setText(curPass);
37                 }
38             }
39         });
40         
41         ret.findViewById(R.id.cancel).setOnClickListener(new OnClickListener() {
42             @Override
43             public void onClick(View v) {
44                 onCancel();
45             }
46         });
47         
48         ret.findViewById(R.id.ok).setOnClickListener(new OnClickListener() {
49             @Override
50             public void onClick(View v) {
51                 onEnter(password.getText().toString());
52                 password.setText("");
53             }
54         });
55         
56         mView = ret;
57     }
58     
59     View mView;
60     public View getView() {
61         return mView;
62     }
63     
64     public void onEnter(String password) {
65     }
66     
67     public void onCancel() {
68     }
69 }