2 * Copyright (C) 2013 Koushik Dutta (@koush)
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.koushikdutta.superuser;
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;
27 public class PinViewHelper {
28 public PinViewHelper(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
29 View ret = inflater.inflate(R.layout.pin, container, false);
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++) {
35 Button b = (Button)ret.findViewById(id);
36 final String text = String.valueOf(i);
38 b.setOnClickListener(new OnClickListener() {
40 public void onClick(View v) {
41 password.setText(password.getText().toString() + text);
46 ret.findViewById(R.id.pd).setOnClickListener(new OnClickListener() {
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);
57 ret.findViewById(R.id.cancel).setOnClickListener(new OnClickListener() {
59 public void onClick(View v) {
64 ret.findViewById(R.id.ok).setOnClickListener(new OnClickListener() {
66 public void onClick(View v) {
67 onEnter(password.getText().toString());
76 public View getView() {
80 public void onEnter(String password) {
83 public void onCancel() {