OSDN Git Service

LICENSE
[android-x86/external-koush-Superuser.git] / Superuser / src / com / koushikdutta / superuser / PinViewHelper.java
1 /*
2  * Copyright (C) 2013 Koushik Dutta (@koush)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.koushikdutta.superuser;
18
19 import android.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.View.OnClickListener;
23 import android.view.ViewGroup;
24 import android.widget.Button;
25 import android.widget.EditText;
26
27 public class PinViewHelper {
28     public PinViewHelper(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
29         View ret = inflater.inflate(R.layout.pin, container, false);
30
31         final EditText password = (EditText)ret.findViewById(R.id.password);
32         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, };
33         for (int i = 0; i < ids.length; i++) {
34             int id = ids[i];
35             Button b = (Button)ret.findViewById(id);
36             final String text = String.valueOf(i);
37             b.setText(text);
38             b.setOnClickListener(new OnClickListener() {
39                 @Override
40                 public void onClick(View v) {
41                     password.setText(password.getText().toString() + text);
42                 }
43             });
44         }
45
46         ret.findViewById(R.id.pd).setOnClickListener(new OnClickListener() {
47             @Override
48             public void onClick(View v) {
49                 String curPass = password.getText().toString();
50                 if (curPass.length() > 0) {
51                     curPass = curPass.substring(0, curPass.length() - 1);
52                     password.setText(curPass);
53                 }
54             }
55         });
56         
57         ret.findViewById(R.id.cancel).setOnClickListener(new OnClickListener() {
58             @Override
59             public void onClick(View v) {
60                 onCancel();
61             }
62         });
63         
64         ret.findViewById(R.id.ok).setOnClickListener(new OnClickListener() {
65             @Override
66             public void onClick(View v) {
67                 onEnter(password.getText().toString());
68                 password.setText("");
69             }
70         });
71         
72         mView = ret;
73     }
74     
75     View mView;
76     public View getView() {
77         return mView;
78     }
79     
80     public void onEnter(String password) {
81     }
82     
83     public void onCancel() {
84     }
85 }