7
7
import android .content .Intent ;
8
8
import android .graphics .Color ;
9
9
import android .graphics .Point ;
10
+ import android .os .Build ;
10
11
import android .os .Bundle ;
11
12
import android .support .v7 .app .AppCompatActivity ;
12
13
import android .support .v7 .widget .DefaultItemAnimator ;
13
14
import android .support .v7 .widget .LinearLayoutManager ;
14
15
import android .support .v7 .widget .RecyclerView ;
16
+ import android .util .DisplayMetrics ;
15
17
import android .util .Log ;
16
18
import android .view .View ;
17
19
import android .widget .Button ;
@@ -93,8 +95,8 @@ protected void onCreate(Bundle savedInstanceState) {
93
95
adjustallSeekBar .setOnSeekBarChangeListener (new SeekBar .OnSeekBarChangeListener () {
94
96
@ Override
95
97
public void onProgressChanged (SeekBar seekBar , int progress , boolean fromUser ) {
96
- adjustmentFactor = 1 + ((progress - 25 )* 0.02 );
97
- adjustPercentage .setText (JoH .qs (adjustmentFactor * 100 ,0 )+ "%" );
98
+ adjustmentFactor = 1 + ((progress - 25 ) * 0.02 );
99
+ adjustPercentage .setText (JoH .qs (adjustmentFactor * 100 , 0 ) + "%" );
98
100
}
99
101
100
102
@ Override
@@ -115,7 +117,6 @@ public void onStopTrackingTouch(SeekBar seekBar) {
115
117
});
116
118
117
119
118
-
119
120
recyclerView = (RecyclerView ) findViewById (R .id .profile_recycler_view );
120
121
121
122
mAdapter = new ProfileAdapter (this , profileItemList , doMgdl );
@@ -141,7 +142,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
141
142
@ Override
142
143
public void onChanged () {
143
144
super .onChanged ();
144
- // Log.d(TAG, "onChanged");
145
+ // Log.d(TAG, "onChanged");
145
146
146
147
}
147
148
@@ -179,10 +180,19 @@ public void onItemRangeChanged(final int positionStart, int itemCount, Object pa
179
180
// split or delete
180
181
} else if (payload .toString ().equals ("long-split" )) {
181
182
183
+ final DisplayMetrics dm = new DisplayMetrics ();
184
+ getWindowManager ().getDefaultDisplay ().getMetrics (dm );
185
+ final int screen_width = dm .widthPixels ;
186
+ final int screen_height = dm .heightPixels ;
187
+ boolean small_screen = false ;
188
+ // smaller screens or lower version don't seem to play well with long dialog button names
189
+ if ((screen_width < 720 ) || (screen_height < 720 ) || ((Build .VERSION .SDK_INT < Build .VERSION_CODES .M )))
190
+ small_screen = true ;
191
+
182
192
AlertDialog .Builder alertDialogBuilder = new AlertDialog .Builder (mContext );
183
193
alertDialogBuilder .setMessage (R .string .split_delete_or_do_nothing );
184
194
185
- alertDialogBuilder .setPositiveButton (R .string .split_this_block_in_two , new DialogInterface .OnClickListener () {
195
+ alertDialogBuilder .setPositiveButton (small_screen ? getString ( R .string .split ) : getString ( R . string . split_this_block_in_two ) , new DialogInterface .OnClickListener () {
186
196
@ Override
187
197
public void onClick (DialogInterface arg0 , int arg1 ) {
188
198
@@ -203,7 +213,7 @@ public void onClick(DialogInterface arg0, int arg1) {
203
213
}
204
214
});
205
215
if (profileItemList .size () > 1 ) {
206
- alertDialogBuilder .setNeutralButton (R .string .delete_this_time_block , new DialogInterface .OnClickListener () {
216
+ alertDialogBuilder .setNeutralButton (small_screen ? getString ( R .string .delete ) : getString ( R . string . delete_this_time_block ) , new DialogInterface .OnClickListener () {
207
217
@ Override
208
218
public void onClick (DialogInterface dialog , int which ) {
209
219
profileItemList .remove (positionStart );
@@ -212,7 +222,7 @@ public void onClick(DialogInterface dialog, int which) {
212
222
});
213
223
}
214
224
215
- alertDialogBuilder .setNegativeButton (R .string .cancel_do_nothing , new DialogInterface .OnClickListener () {
225
+ alertDialogBuilder .setNegativeButton (small_screen ? getString ( R .string .cancel ) : getString ( R . string . cancel_do_nothing ) , new DialogInterface .OnClickListener () {
216
226
@ Override
217
227
public void onClick (DialogInterface dialog , int which ) {
218
228
@@ -227,7 +237,6 @@ public void onClick(DialogInterface dialog, int which) {
227
237
}
228
238
229
239
230
-
231
240
}
232
241
});
233
242
@@ -260,49 +269,44 @@ public void onPause() {
260
269
}
261
270
}
262
271
263
- private static void updateAdjustmentFactor (double factor )
264
- {
265
- adjustmentFactor =factor ;
272
+ private static void updateAdjustmentFactor (double factor ) {
273
+ adjustmentFactor = factor ;
266
274
adjustPercentage .setText (JoH .qs (adjustmentFactor * 100 , 0 ) + "%" );
267
275
268
- int position = (int )((adjustmentFactor - 1 ) /0.02 )+ 25 ;
276
+ int position = (int ) ((adjustmentFactor - 1 ) / 0.02 ) + 25 ;
269
277
adjustallSeekBar .setProgress (position > 0 ? position : 0 );
270
278
271
279
}
272
280
273
281
private void saveData (boolean for_real ) {
274
282
final Gson gson = new GsonBuilder ()
275
283
.excludeFieldsWithoutExposeAnnotation ()
276
- //.registerTypeAdapter(Date.class, new DateTypeAdapter())
284
+ //.registerTypeAdapter(Date.class, new DateTypeAdapter())
277
285
.serializeSpecialFloatingPointValues ()
278
286
.create ();
279
287
280
288
final List <ProfileItem > profileItemListTmp = new ArrayList <>();
281
289
282
290
283
- if (!for_real )
284
- {
285
- Log .d (TAG ,"Saving for real with adjustment factor: " +adjustmentFactor );
291
+ if (!for_real ) {
292
+ Log .d (TAG , "Saving for real with adjustment factor: " + adjustmentFactor );
286
293
// save working set clean of adjustment factor to avoid stacking
287
- for (ProfileItem item : profileItemList )
288
- {
294
+ for (ProfileItem item : profileItemList ) {
289
295
profileItemListTmp .add (item .clone ());
290
296
}
291
297
292
- for (ProfileItem item : profileItemListTmp )
293
- {
294
- item .carb_ratio = item .carb_ratio /adjustmentFactor ;
295
- item .sensitivity = item .sensitivity *adjustmentFactor ;
296
- }
298
+ for (ProfileItem item : profileItemListTmp ) {
299
+ item .carb_ratio = item .carb_ratio / adjustmentFactor ;
300
+ item .sensitivity = item .sensitivity * adjustmentFactor ;
301
+ }
297
302
298
303
} else {
299
304
// for real save
300
305
profileItemListTmp .addAll (profileItemList ); // no need to clone
301
306
302
- for (ProfileItem item : profileItemListTmp )
303
- {
307
+ for (ProfileItem item : profileItemListTmp ) {
304
308
item .carb_ratio = Math .round (item .carb_ratio ); // round to nearest g
305
- item .sensitivity = (double )(Math .round (item .sensitivity * 10 ))/ 10 ;
309
+ item .sensitivity = (double ) (Math .round (item .sensitivity * 10 )) / 10 ;
306
310
}
307
311
}
308
312
@@ -312,7 +316,7 @@ private void saveData(boolean for_real) {
312
316
Home .setPreferencesString ("saved_profile_list_json" , data );
313
317
Home .setPreferencesString ("saved_profile_list_json_working" , "" );
314
318
Log .d (TAG , "Saved final data" );
315
- UserError .Log .uel (TAG ,"Saved Treatment Profile data, timeblocks:" + profileItemListTmp .size ());
319
+ UserError .Log .uel (TAG , "Saved Treatment Profile data, timeblocks:" + profileItemListTmp .size ());
316
320
updateAdjustmentFactor (1.0 ); // reset it
317
321
dataChanged = true ;
318
322
Profile .invalidateProfile ();
@@ -341,7 +345,7 @@ public void profileSaveButton(View myview) {
341
345
342
346
public void profileUndoButton (View myview ) {
343
347
clearWorkingData ();
344
- adjustmentFactor = 1 ;
348
+ adjustmentFactor = 1 ;
345
349
adjustallSeekBar .setProgress (25 );
346
350
profileItemList .clear ();
347
351
// we must preserve the existing object reference used by the adapter
@@ -394,10 +398,9 @@ public static List<ProfileItem> loadData(boolean buttons) {
394
398
ProfileItem [] restored = new GsonBuilder ().excludeFieldsWithoutExposeAnnotation ().create ().fromJson (data , ProfileItem [].class );
395
399
if (restored != null ) {
396
400
// process adjustment factor
397
- for (ProfileItem item : restored )
398
- {
399
- item .carb_ratio = item .carb_ratio *adjustmentFactor ;
400
- item .sensitivity = item .sensitivity /adjustmentFactor ;
401
+ for (ProfileItem item : restored ) {
402
+ item .carb_ratio = item .carb_ratio * adjustmentFactor ;
403
+ item .sensitivity = item .sensitivity / adjustmentFactor ;
401
404
}
402
405
Collections .addAll (myprofileItemList , restored );
403
406
}
0 commit comments