annotate src/com/five_ten_sg/connectbot/util/StringPickerDialog.java @ 408:0c519d0acdd4 stable-1.9.0-7

bump version number
author Carl Byington <carl@five-ten-sg.com>
date Fri, 24 Oct 2014 14:27:11 -0700
parents 071eccdff8ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
223
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 /*
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2 * Copyright (C) 2008 The Android Open Source Project
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 *
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 * You may obtain a copy of the License at
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 *
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 *
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 * Unless required by applicable law or agreed to in writing, software
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 * distributed under the License is distributed on an "AS IS" BASIS,
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 * See the License for the specific language governing permissions and
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 * limitations under the License.
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 */
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 package com.five_ten_sg.connectbot.util;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 import com.five_ten_sg.connectbot.R;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 import android.app.Dialog;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 import android.content.Context;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 import android.os.Bundle;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 import android.text.*;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 import android.view.LayoutInflater;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 import android.view.View.OnClickListener;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27 import android.view.View;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 import android.view.ViewGroup;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 import android.view.Window;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 import android.view.WindowManager;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 import android.widget.AdapterView.OnItemClickListener;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 import android.widget.AdapterView;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 import android.widget.BaseAdapter;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 import android.widget.Button;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 import android.widget.GridView;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 /**
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 * Dialog for choosing accented characters related to a base character.
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
39 */
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 public class StringPickerDialog extends Dialog
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
41 implements OnItemClickListener, OnClickListener {
223
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 private View mView;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 private Editable mText;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 private String []mOptions;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 private boolean mInsert;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 private LayoutInflater mInflater;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 private Button mCancelButton;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 /**
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 * Creates a new StringPickerDialog that presents the specified
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 * <code>options</code> for insertion or replacement (depending on
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 * the sense of <code>insert</code>) into <code>text</code>.
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 */
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 public StringPickerDialog(Context context, View view,
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
55 Editable text, String []options,
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
56 boolean insert) {
223
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 //super(context, com.android.internal.R.style.Theme_Panel);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 //Resources res = Resources.getSystem();
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 //int id = res.getIdentifier("Theme_Panel", "style", "android");
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 //int id = android.R.style.Theme_Panel;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 super(context, android.R.style.Theme_Panel);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
62 mView = view;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 mText = text;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 mOptions = options;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
65 mInsert = insert;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 mInflater = LayoutInflater.from(context);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
68
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
69 @Override
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
70 protected void onCreate(Bundle savedInstanceState) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
71 super.onCreate(savedInstanceState);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
72 WindowManager.LayoutParams params = getWindow().getAttributes();
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
73 params.token = mView.getApplicationWindowToken();
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
74 params.type = params.TYPE_APPLICATION_ATTACHED_DIALOG;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 params.flags = params.flags | Window.FEATURE_NO_TITLE;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76 setContentView(R.layout.string_picker);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 GridView grid = (GridView) findViewById(R.id.stringPicker);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 grid.setAdapter(new OptionsAdapter(getContext()));
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79 grid.setOnItemClickListener(this);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 mCancelButton = (Button) findViewById(R.id.cancel);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 mCancelButton.setOnClickListener(this);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 /**
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 * Handles clicks on the character buttons.
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 */
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 public void onItemClick(AdapterView parent, View view, int position, long id) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88 String result = mOptions[position];
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 replaceCharacterAndClose(result);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 private void replaceCharacterAndClose(CharSequence replace) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93 int selEnd = Selection.getSelectionEnd(mText);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
94
223
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 if (mInsert || selEnd == 0) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 mText.insert(selEnd, replace);
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
97 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
98 else {
223
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 mText.replace(selEnd - 1, selEnd, replace);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
102 dismiss();
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
103 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
104
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
105 /**
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
106 * Handles clicks on the Cancel button.
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
107 */
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
108 public void onClick(View v) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
109 if (v == mCancelButton) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
110 dismiss();
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
111 }
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
112 else if (v instanceof Button) {
223
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
113 CharSequence result = ((Button) v).getText();
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
114 replaceCharacterAndClose(result);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
115 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
116 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
117
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
118 private class OptionsAdapter extends BaseAdapter {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
119
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
120 public OptionsAdapter(Context context) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
121 super();
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
122 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
123
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
124 public View getView(int position, View convertView, ViewGroup parent) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
125 Button b = (Button)
307
071eccdff8ea fix java formatting
Carl Byington <carl@five-ten-sg.com>
parents: 223
diff changeset
126 mInflater.inflate(R.layout.string_picker_button, null);
223
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
127 b.setText(mOptions[position]);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
128 b.setOnClickListener(StringPickerDialog.this);
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
129 return b;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
130 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
131
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
132 public final int getCount() {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
133 return mOptions.length;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
134 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
135
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
136 public final Object getItem(int position) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
137 return mOptions[position];
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
138 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
139
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
140 public final long getItemId(int position) {
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
141 return position;
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
142 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
143 }
61ed3984fc1d proper labels on the soft 24 function keypad
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
144 }