comparison src/com/five_ten_sg/connectbot/util/StringPickerDialog.java @ 307:071eccdff8ea ganymed

fix java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:16:58 -0700
parents 61ed3984fc1d
children
comparison
equal deleted inserted replaced
305:d2b303406d63 307:071eccdff8ea
36 36
37 /** 37 /**
38 * Dialog for choosing accented characters related to a base character. 38 * Dialog for choosing accented characters related to a base character.
39 */ 39 */
40 public class StringPickerDialog extends Dialog 40 public class StringPickerDialog extends Dialog
41 implements OnItemClickListener, OnClickListener { 41 implements OnItemClickListener, OnClickListener {
42 private View mView; 42 private View mView;
43 private Editable mText; 43 private Editable mText;
44 private String []mOptions; 44 private String []mOptions;
45 private boolean mInsert; 45 private boolean mInsert;
46 private LayoutInflater mInflater; 46 private LayoutInflater mInflater;
50 * Creates a new StringPickerDialog that presents the specified 50 * Creates a new StringPickerDialog that presents the specified
51 * <code>options</code> for insertion or replacement (depending on 51 * <code>options</code> for insertion or replacement (depending on
52 * the sense of <code>insert</code>) into <code>text</code>. 52 * the sense of <code>insert</code>) into <code>text</code>.
53 */ 53 */
54 public StringPickerDialog(Context context, View view, 54 public StringPickerDialog(Context context, View view,
55 Editable text, String []options, 55 Editable text, String []options,
56 boolean insert) { 56 boolean insert) {
57 //super(context, com.android.internal.R.style.Theme_Panel); 57 //super(context, com.android.internal.R.style.Theme_Panel);
58
59 //Resources res = Resources.getSystem(); 58 //Resources res = Resources.getSystem();
60 //int id = res.getIdentifier("Theme_Panel", "style", "android"); 59 //int id = res.getIdentifier("Theme_Panel", "style", "android");
61 //int id = android.R.style.Theme_Panel; 60 //int id = android.R.style.Theme_Panel;
62 super(context, android.R.style.Theme_Panel); 61 super(context, android.R.style.Theme_Panel);
63 mView = view; 62 mView = view;
68 } 67 }
69 68
70 @Override 69 @Override
71 protected void onCreate(Bundle savedInstanceState) { 70 protected void onCreate(Bundle savedInstanceState) {
72 super.onCreate(savedInstanceState); 71 super.onCreate(savedInstanceState);
73
74 WindowManager.LayoutParams params = getWindow().getAttributes(); 72 WindowManager.LayoutParams params = getWindow().getAttributes();
75 params.token = mView.getApplicationWindowToken(); 73 params.token = mView.getApplicationWindowToken();
76 params.type = params.TYPE_APPLICATION_ATTACHED_DIALOG; 74 params.type = params.TYPE_APPLICATION_ATTACHED_DIALOG;
77 params.flags = params.flags | Window.FEATURE_NO_TITLE; 75 params.flags = params.flags | Window.FEATURE_NO_TITLE;
78
79 setContentView(R.layout.string_picker); 76 setContentView(R.layout.string_picker);
80
81 GridView grid = (GridView) findViewById(R.id.stringPicker); 77 GridView grid = (GridView) findViewById(R.id.stringPicker);
82 grid.setAdapter(new OptionsAdapter(getContext())); 78 grid.setAdapter(new OptionsAdapter(getContext()));
83 grid.setOnItemClickListener(this); 79 grid.setOnItemClickListener(this);
84
85 mCancelButton = (Button) findViewById(R.id.cancel); 80 mCancelButton = (Button) findViewById(R.id.cancel);
86 mCancelButton.setOnClickListener(this); 81 mCancelButton.setOnClickListener(this);
87 } 82 }
88 83
89 /** 84 /**
94 replaceCharacterAndClose(result); 89 replaceCharacterAndClose(result);
95 } 90 }
96 91
97 private void replaceCharacterAndClose(CharSequence replace) { 92 private void replaceCharacterAndClose(CharSequence replace) {
98 int selEnd = Selection.getSelectionEnd(mText); 93 int selEnd = Selection.getSelectionEnd(mText);
94
99 if (mInsert || selEnd == 0) { 95 if (mInsert || selEnd == 0) {
100 mText.insert(selEnd, replace); 96 mText.insert(selEnd, replace);
101 } else { 97 }
98 else {
102 mText.replace(selEnd - 1, selEnd, replace); 99 mText.replace(selEnd - 1, selEnd, replace);
103 } 100 }
104 101
105 dismiss(); 102 dismiss();
106 } 103 }
109 * Handles clicks on the Cancel button. 106 * Handles clicks on the Cancel button.
110 */ 107 */
111 public void onClick(View v) { 108 public void onClick(View v) {
112 if (v == mCancelButton) { 109 if (v == mCancelButton) {
113 dismiss(); 110 dismiss();
114 } else if (v instanceof Button) { 111 }
112 else if (v instanceof Button) {
115 CharSequence result = ((Button) v).getText(); 113 CharSequence result = ((Button) v).getText();
116 replaceCharacterAndClose(result); 114 replaceCharacterAndClose(result);
117 } 115 }
118 } 116 }
119 117
123 super(); 121 super();
124 } 122 }
125 123
126 public View getView(int position, View convertView, ViewGroup parent) { 124 public View getView(int position, View convertView, ViewGroup parent) {
127 Button b = (Button) 125 Button b = (Button)
128 mInflater.inflate(R.layout.string_picker_button, null); 126 mInflater.inflate(R.layout.string_picker_button, null);
129 b.setText(mOptions[position]); 127 b.setText(mOptions[position]);
130 b.setOnClickListener(StringPickerDialog.this); 128 b.setOnClickListener(StringPickerDialog.this);
131 return b; 129 return b;
132 } 130 }
133 131