21
21
/**
22
22
* For displaying DeviceInfo fields in a ListView
23
23
*/
24
- public class DeviceConfigurationAdapter extends BaseAdapter implements View .OnClickListener {
24
+ class DeviceConfigurationAdapter extends BaseAdapter implements View .OnClickListener {
25
25
public static class ReviewItem {
26
- public static final int DEFAULT_WEIGHT = 0 ;
27
26
28
- public String mTitle ;
27
+ public final String mTitle ;
29
28
public String mDisplayValueString ;
30
29
public int mDisplayValueInt ;
31
30
public boolean mDisplayValueBoolean ;
32
- public int mPageKey ;
31
+ public final int mPageKey ;
33
32
public int type = 0 ; // o string, 1 int, 2 boolean
34
33
public boolean mEnabled ;
35
34
@@ -49,19 +48,19 @@ public ReviewItem(String title, int displayValue, int pageKey, boolean enabled)
49
48
type = 1 ;
50
49
}
51
50
52
- public ReviewItem (String title , boolean displayValue , int pageKey ) {
51
+ public ReviewItem (String title , boolean displayValue ) {
53
52
mTitle = title ;
54
53
mDisplayValueBoolean = displayValue ;
55
- mPageKey = pageKey ;
54
+ mPageKey = DeviceConfigurationAdapter . DefaultPorts ;
56
55
mEnabled = true ;
57
56
type = 2 ;
58
57
}
59
58
}
60
59
61
- public List <ReviewItem > deviceConfigurationOptions = new ArrayList <ReviewItem >();
62
- private Context context ;
63
- private DeviceInfo deviceInfo ;
64
- private LayoutInflater inflater ;
60
+ private final List <ReviewItem > deviceConfigurationOptions = new ArrayList <ReviewItem >();
61
+ private final Context context ;
62
+ private final DeviceInfo deviceInfo ;
63
+ private final LayoutInflater inflater ;
65
64
66
65
private static final int DeviceName = 0 ;
67
66
private static final int HostName = 1 ;
@@ -79,7 +78,7 @@ public DeviceConfigurationAdapter(Context context, DeviceInfo deviceInfo) {
79
78
deviceConfigurationOptions .add (new ReviewItem (context .getString (R .string .device_ip ), deviceInfo .HostName , HostName ));
80
79
deviceConfigurationOptions .add (new ReviewItem (context .getString (R .string .device_username ), deviceInfo .UserName , UserName ));
81
80
deviceConfigurationOptions .add (new ReviewItem (context .getString (R .string .device_password ), deviceInfo .Password , Password ));
82
- deviceConfigurationOptions .add (new ReviewItem (context .getString (R .string .device_default_ports ), deviceInfo .DefaultPorts , DefaultPorts ));
81
+ deviceConfigurationOptions .add (new ReviewItem (context .getString (R .string .device_default_ports ), deviceInfo .DefaultPorts ));
83
82
deviceConfigurationOptions .add (new ReviewItem (context .getString (R .string .device_recv_udp ), deviceInfo .ReceivePort , ReceivePort , !deviceInfo .DefaultPorts ));
84
83
deviceConfigurationOptions .add (new ReviewItem (context .getString (R .string .device_send_udp ), deviceInfo .SendPort , SendPort , !deviceInfo .DefaultPorts ));
85
84
}
@@ -120,6 +119,7 @@ public View getView(int position, View convertView, ViewGroup container) {
120
119
convertView = inflater .inflate (R .layout .device_configuration_item , null );
121
120
122
121
ReviewItem reviewItem = deviceConfigurationOptions .get (position );
122
+ assert convertView != null ;
123
123
((TextView ) convertView .findViewById (R .id .titleText )).setText (reviewItem .mTitle );
124
124
TextView text = (TextView ) convertView .findViewById (R .id .textOption );
125
125
CheckBox checkbox = (CheckBox ) convertView .findViewById (R .id .checkboxOption );
@@ -171,17 +171,20 @@ public void onClick(final View view) {
171
171
return ;
172
172
}
173
173
174
- final EditText text = new EditText (context );
175
- text .setText (((TextView ) view ).getText ());
174
+ EditText textView = new EditText (context );
175
+ textView .setText (((TextView ) view ).getText ());
176
176
AlertDialog .Builder builder = new AlertDialog .Builder (context );
177
- builder .setView (text );
177
+ builder .setView (textView );
178
+
179
+ @ SuppressWarnings ("ConstantConditions" )
180
+ final String text = textView .getText ().toString ();
178
181
179
182
switch (key ) {
180
183
case DeviceName :
181
184
builder .setPositiveButton (android .R .string .ok , new DialogInterface .OnClickListener () {
182
185
@ Override
183
186
public void onClick (DialogInterface dialogInterface , int i ) {
184
- item .mDisplayValueString = text . getText (). toString () ;
187
+ item .mDisplayValueString = text ;
185
188
deviceInfo .DeviceName = item .mDisplayValueString ;
186
189
notifyDataSetChanged ();
187
190
}
@@ -191,7 +194,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
191
194
builder .setPositiveButton (android .R .string .ok , new DialogInterface .OnClickListener () {
192
195
@ Override
193
196
public void onClick (DialogInterface dialogInterface , int i ) {
194
- item .mDisplayValueString = text . getText (). toString () ;
197
+ item .mDisplayValueString = text ;
195
198
deviceInfo .HostName = item .mDisplayValueString ;
196
199
notifyDataSetChanged ();
197
200
}
@@ -201,7 +204,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
201
204
builder .setPositiveButton (android .R .string .ok , new DialogInterface .OnClickListener () {
202
205
@ Override
203
206
public void onClick (DialogInterface dialogInterface , int i ) {
204
- item .mDisplayValueString = text . getText (). toString () ;
207
+ item .mDisplayValueString = text ;
205
208
deviceInfo .UserName = item .mDisplayValueString ;
206
209
notifyDataSetChanged ();
207
210
}
@@ -211,29 +214,29 @@ public void onClick(DialogInterface dialogInterface, int i) {
211
214
builder .setPositiveButton (android .R .string .ok , new DialogInterface .OnClickListener () {
212
215
@ Override
213
216
public void onClick (DialogInterface dialogInterface , int i ) {
214
- item .mDisplayValueString = text . getText (). toString () ;
217
+ item .mDisplayValueString = text ;
215
218
deviceInfo .Password = item .mDisplayValueString ;
216
219
notifyDataSetChanged ();
217
220
}
218
221
});
219
222
break ;
220
223
case ReceivePort :
221
- text .setInputType (InputType .TYPE_CLASS_NUMBER );
224
+ textView .setInputType (InputType .TYPE_CLASS_NUMBER );
222
225
builder .setPositiveButton (android .R .string .ok , new DialogInterface .OnClickListener () {
223
226
@ Override
224
227
public void onClick (DialogInterface dialogInterface , int i ) {
225
- item .mDisplayValueInt = Integer .valueOf (text . getText (). toString () );
228
+ item .mDisplayValueInt = Integer .valueOf (text );
226
229
deviceInfo .ReceivePort = item .mDisplayValueInt ;
227
230
notifyDataSetChanged ();
228
231
}
229
232
});
230
233
break ;
231
234
case SendPort :
232
- text .setInputType (InputType .TYPE_CLASS_NUMBER );
235
+ textView .setInputType (InputType .TYPE_CLASS_NUMBER );
233
236
builder .setPositiveButton (android .R .string .ok , new DialogInterface .OnClickListener () {
234
237
@ Override
235
238
public void onClick (DialogInterface dialogInterface , int i ) {
236
- item .mDisplayValueInt = Integer .valueOf (text . getText (). toString () );
239
+ item .mDisplayValueInt = Integer .valueOf (text );
237
240
deviceInfo .SendPort = item .mDisplayValueInt ;
238
241
notifyDataSetChanged ();
239
242
}
0 commit comments