-
Notifications
You must be signed in to change notification settings - Fork 100
/
OptionsDialog.java
executable file
·2050 lines (1895 loc) · 83.2 KB
/
OptionsDialog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.coolreader.crengine;
import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import org.coolreader.CoolReader;
import org.coolreader.R;
import org.coolreader.crengine.ColorPickerDialog.OnColorChangedListener;
import org.coolreader.plugins.OnlineStorePluginManager;
import android.content.Context;
import android.content.DialogInterface;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabWidget;
import android.widget.TextView;
public class OptionsDialog extends BaseDialog implements TabContentFactory, OptionOwner, Settings {
ReaderView mReaderView;
BaseActivity mActivity;
String[] mFontFaces;
int[] mFontSizes = new int[] {
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 44, 48, 52, 56, 60, 64, 68, 72, 78, 84, 90, 110, 130, 150, 170, 200, 230, 260, 300, 340
};
int[] mStatusFontSizes = new int[] {
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 44, 48, 52, 56, 60, 64, 68, 72, 78, 84, 90, 110, 130, 150, 170, 200, 230, 260, 300, 340
};
int[] filterFontSizes(int[] fontSizes) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < fontSizes.length; i++) {
int sz = fontSizes[i];
if (sz >= mActivity.getMinFontSize() && sz <= mActivity.getMaxFontSize())
list.add(sz);
}
int[] res = new int[list.size()];
for (int i = 0; i < list.size(); i++)
res[i] = list.get(i);
return res;
}
public static int findBacklightSettingIndex( int value ) {
int bestIndex = 0;
int bestDiff = -1;
for ( int i=0; i<mBacklightLevels.length; i++ ) {
int diff = mBacklightLevels[i] - value;
if (diff<0)
diff = -diff;
if ( bestDiff==-1 || diff < bestDiff ) {
bestDiff = diff;
bestIndex = i;
}
}
return bestIndex;
}
public static final int[] mBacklightLevels = new int[] {
-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100
};
public static final String[] mBacklightLevelsTitles = new String[] {
"Default", "1%", "2%", "3%", "4%", "5%", "6%", "7%", "8%", "9%",
"10%", "12%", "15%", "20%", "25%", "30%", "35%", "40%", "45%", "50%", "55%", "60%", "65%", "70%", "75%", "80%", "85%", "90%", "95%", "100%",
};
int[] mInterlineSpaces = new int[] {
80, 85, 90, 95, 100, 105, 110, 115, 120, 130, 140, 150, 160, 180, 200
};
int[] mMinSpaceWidths = new int[] {
25, 30, 40, 50, 60, 70, 80, 90, 100
};
int[] mMargins = new int[] {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 20, 25, 30, 40, 50, 60, 80, 100, 130, 150, 200, 300
};
double[] mGammas = new double[] {
0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.5, 1.9
};
int[] mScreenFullUpdateInterval = new int[] {
0, 2, 3, 4, 5, 7, 10, 15, 20
};
int[] mScreenUpdateModes = new int[] {
0, 1, 2//, 2, 3
};
int[] mScreenUpdateModesTitles = new int[] {
R.string.options_screen_update_mode_quality, R.string.options_screen_update_mode_fast, R.string.options_screen_update_mode_fast2
};
int[] mCoverPageSizes = new int[] {
0, 1, 2//, 2, 3
};
int[] mCoverPageSizeTitles = new int[] {
R.string.options_app_cover_page_size_small, R.string.options_app_cover_page_size_medium, R.string.options_app_cover_page_size_big
};
int[] mHinting = new int[] {
0, 1, 2
};
int[] mHintingTitles = new int[] {
R.string.options_font_hinting_disabled, R.string.options_font_hinting_bytecode,
R.string.options_font_hinting_auto
};
int[] mOrientations = new int[] {
0, 1, 4
};
int[] mOrientationsTitles = new int[] {
R.string.options_page_orientation_0, R.string.options_page_orientation_90,
R.string.options_page_orientation_sensor
};
int[] mOrientations_API9 = new int[] {
0, 1, 2, 3, 4
};
int[] mOrientationsTitles_API9 = new int[] {
R.string.options_page_orientation_0, R.string.options_page_orientation_90, R.string.options_page_orientation_180, R.string.options_page_orientation_270
,R.string.options_page_orientation_sensor
};
int[] mToolbarPositions = new int[] {
Settings.VIEWER_TOOLBAR_NONE, Settings.VIEWER_TOOLBAR_TOP, Settings.VIEWER_TOOLBAR_BOTTOM, Settings.VIEWER_TOOLBAR_LEFT, Settings.VIEWER_TOOLBAR_RIGHT, Settings.VIEWER_TOOLBAR_SHORT_SIDE, Settings.VIEWER_TOOLBAR_LONG_SIDE
};
int[] mToolbarPositionsTitles = new int[] {
R.string.options_view_toolbar_position_none, R.string.options_view_toolbar_position_top, R.string.options_view_toolbar_position_bottom, R.string.options_view_toolbar_position_left, R.string.options_view_toolbar_position_right, R.string.options_view_toolbar_position_short_side, R.string.options_view_toolbar_position_long_side
};
int[] mStatusPositions = new int[] {
Settings.VIEWER_STATUS_NONE,
//Settings.VIEWER_STATUS_TOP, Settings.VIEWER_STATUS_BOTTOM,
Settings.VIEWER_STATUS_PAGE
};
int[] mStatusPositionsTitles = new int[] {
R.string.options_page_show_titlebar_hidden,
//R.string.options_page_show_titlebar_top, R.string.options_page_show_titlebar_bottom,
R.string.options_page_show_titlebar_page_header
};
int[] mImageScalingModes = new int[] {
0, 1, 2
};
int[] mImageScalingModesTitles = new int[] {
R.string.options_format_image_scaling_mode_disabled, R.string.options_format_image_scaling_mode_integer_factor, R.string.options_format_image_scaling_mode_arbitrary
};
int[] mImageScalingFactors = new int[] {
0, 1, 2, 3
};
int[] mImageScalingFactorsTitles = new int[] {
R.string.options_format_image_scaling_scale_auto, R.string.options_format_image_scaling_scale_1, R.string.options_format_image_scaling_scale_2, R.string.options_format_image_scaling_scale_3
};
int[] mFlickBrightness = new int[] {
0, 1, 2
};
int[] mFlickBrightnessTitles = new int[] {
R.string.options_controls_flick_brightness_none, R.string.options_controls_flick_brightness_left, R.string.options_controls_flick_brightness_right
};
int[] mBacklightTimeout = new int[] {
0, 2, 3, 4, 5, 6
};
int[] mBacklightTimeoutTitles = new int[] {
R.string.options_app_backlight_timeout_0, R.string.options_app_backlight_timeout_2, R.string.options_app_backlight_timeout_3, R.string.options_app_backlight_timeout_4, R.string.options_app_backlight_timeout_5, R.string.options_app_backlight_timeout_6
};
int[] mTapSecondaryActionType = new int[] {
TAP_ACTION_TYPE_LONGPRESS, TAP_ACTION_TYPE_DOUBLE
};
int[] mTapSecondaryActionTypeTitles = new int[] {
R.string.options_controls_tap_type_long, R.string.options_controls_tap_type_double
};
int[] mAnimation = new int[] {
ReaderView.PAGE_ANIMATION_NONE, ReaderView.PAGE_ANIMATION_SLIDE, ReaderView.PAGE_ANIMATION_SLIDE2,
ReaderView.PAGE_ANIMATION_PAPER
};
int[] mAnimationTitles = new int[] {
R.string.options_page_animation_none, R.string.options_page_animation_slide, R.string.options_page_animation_slide_2_pages,
R.string.options_page_animation_paperbook
};
int[] mHighlightMode = new int[] {
0, 1, 2
};
int[] mHighlightModeTitles = new int[] {
R.string.options_view_bookmarks_highlight_none, R.string.options_view_bookmarks_highlight_solid,
R.string.options_view_bookmarks_highlight_underline
};
int[] mSelectionAction = new int[] {
ReaderView.SELECTION_ACTION_TOOLBAR,
ReaderView.SELECTION_ACTION_COPY,
ReaderView.SELECTION_ACTION_DICTIONARY,
ReaderView.SELECTION_ACTION_BOOKMARK,
ReaderView.SELECTION_ACTION_FIND
};
int[] mSelectionActionTitles = new int[] {
R.string.options_selection_action_toolbar,
R.string.options_selection_action_copy,
R.string.options_selection_action_dictionary,
R.string.options_selection_action_bookmark,
R.string.mi_search,
};
int[] mMultiSelectionAction = new int[] {
ReaderView.SELECTION_ACTION_TOOLBAR,
ReaderView.SELECTION_ACTION_COPY,
ReaderView.SELECTION_ACTION_DICTIONARY,
ReaderView.SELECTION_ACTION_BOOKMARK
};
int[] mMultiSelectionActionTitles = new int[] {
R.string.options_selection_action_toolbar,
R.string.options_selection_action_copy,
R.string.options_selection_action_dictionary,
R.string.options_selection_action_bookmark,
};
int[] mAntialias = new int[] {
0, 1, 2
};
int[] mAntialiasTitles = new int[] {
R.string.options_font_antialias_off, R.string.options_font_antialias_on_for_big, R.string.options_font_antialias_on_for_all
};
int[] mLandscapePages = new int[] {
1, 2
};
int[] mLandscapePagesTitles = new int[] {
R.string.options_page_landscape_pages_one, R.string.options_page_landscape_pages_two
};
int[] mViewModes = new int[] {
1, 0
};
int[] mViewModeTitles = new int[] {
R.string.options_view_mode_pages, R.string.options_view_mode_scroll
};
ViewGroup mContentView;
TabHost mTabs;
LayoutInflater mInflater;
Properties mProperties;
Properties mOldProperties;
OptionsListView mOptionsStyles;
OptionsListView mOptionsCSS;
OptionsListView mOptionsPage;
OptionsListView mOptionsApplication;
OptionsListView mOptionsControls;
OptionsListView mOptionsBrowser;
public final static int OPTION_VIEW_TYPE_NORMAL = 0;
public final static int OPTION_VIEW_TYPE_BOOLEAN = 1;
public final static int OPTION_VIEW_TYPE_COLOR = 2;
public final static int OPTION_VIEW_TYPE_SUBMENU = 3;
//public final static int OPTION_VIEW_TYPE_COUNT = 3;
public BaseActivity getActivity() { return mActivity; }
public Properties getProperties() { return mProperties; }
public LayoutInflater getInflater() { return mInflater; }
public abstract static class OptionBase {
protected View myView;
Properties mProperties;
BaseActivity mActivity;
OptionOwner mOwner;
LayoutInflater mInflater;
public String label;
public String property;
public String defaultValue;
public int iconId = R.drawable.cr3_option_other;
public OptionsListView optionsListView;
protected Runnable onChangeHandler;
public OptionBase( OptionOwner owner, String label, String property ) {
this.mOwner = owner;
this.mActivity = owner.getActivity();
this.mInflater = owner.getInflater();
this.mProperties = owner.getProperties();
this.label = label;
this.property = property;
}
public OptionBase setIconId(int id) {
this.iconId = id;
return this;
}
public OptionBase noIcon() {
this.iconId = 0;
return this;
}
public OptionBase setDefaultValue(String value) {
this.defaultValue = value;
if ( mProperties.getProperty(property)==null )
mProperties.setProperty(property, value);
return this;
}
public void setOnChangeHandler( Runnable handler ) {
onChangeHandler = handler;
}
public int getItemViewType() {
return OPTION_VIEW_TYPE_NORMAL;
}
protected void refreshItem()
{
getView(null, null).invalidate();
//if ( optionsListView!=null )
// optionsListView.refresh();
}
protected void refreshList()
{
getView(null, null).invalidate();
if ( optionsListView!=null )
optionsListView.refresh();
}
public View getView(View convertView, ViewGroup parent) {
View view;
convertView = myView;
if ( convertView==null ) {
//view = new TextView(getContext());
view = mInflater.inflate(R.layout.option_item, null);
} else {
view = (View)convertView;
}
myView = view;
TextView labelView = (TextView)view.findViewById(R.id.option_label);
TextView valueView = (TextView)view.findViewById(R.id.option_value);
labelView.setText(label);
if (valueView != null) {
String valueLabel = getValueLabel();
if (valueLabel != null && valueLabel.length() > 0) {
valueView.setText(valueLabel);
valueView.setVisibility(View.VISIBLE);
} else {
valueView.setText("");
valueView.setVisibility(View.INVISIBLE);
}
}
ImageView icon = (ImageView)view.findViewById(R.id.option_icon);
if (icon != null) {
if (iconId != 0 && showIcons) {
icon.setVisibility(View.VISIBLE);
icon.setImageResource(iconId);
} else {
icon.setImageResource(0);
icon.setVisibility(View.INVISIBLE);
}
}
return view;
}
public String getValueLabel() { return mProperties.getProperty(property); }
public void onSelect() { refreshList(); }
}
class ColorOption extends OptionBase {
final int defColor;
public ColorOption( OptionOwner owner, String label, String property, int defColor ) {
super(owner, label, property);
this.defColor = defColor;
}
public String getValueLabel() { return mProperties.getProperty(property); }
public void onSelect()
{
ColorPickerDialog dlg = new ColorPickerDialog(mActivity, new OnColorChangedListener() {
public void colorChanged(int color) {
mProperties.setColor(property, color);
if ( property.equals(PROP_BACKGROUND_COLOR) ) {
String texture = mProperties.getProperty(PROP_PAGE_BACKGROUND_IMAGE, Engine.NO_TEXTURE.id);
if ( texture!=null && !texture.equals(Engine.NO_TEXTURE.id) ) {
// reset background image
mProperties.setProperty(PROP_PAGE_BACKGROUND_IMAGE, Engine.NO_TEXTURE.id);
// TODO: show notification?
}
}
refreshList();
}
}, mProperties.getColor(property, defColor), label);
dlg.show();
}
public int getItemViewType() {
return OPTION_VIEW_TYPE_COLOR;
}
public View getView(View convertView, ViewGroup parent) {
View view;
convertView = myView;
if ( convertView==null ) {
//view = new TextView(getContext());
view = mInflater.inflate(R.layout.option_item_color, null);
} else {
view = (View)convertView;
}
myView = view;
TextView labelView = (TextView)view.findViewById(R.id.option_label);
ImageView valueView = (ImageView)view.findViewById(R.id.option_value_color);
labelView.setText(label);
int cl = mProperties.getColor(property, defColor);
valueView.setBackgroundColor(cl);
ImageView icon = (ImageView)view.findViewById(R.id.option_icon);
if (icon != null) {
if (iconId != 0 && showIcons) {
icon.setVisibility(View.VISIBLE);
icon.setImageResource(iconId);
} else {
icon.setImageResource(0);
icon.setVisibility(View.INVISIBLE);
}
}
return view;
}
}
private static boolean showIcons = true;
private static boolean isTextFormat = false;
private static boolean isEpubFormat = false;
private Mode mode;
class IconsBoolOption extends BoolOption {
public IconsBoolOption( OptionOwner owner, String label, String property ) {
super(owner, label, property);
}
public void onSelect() {
mProperties.setProperty(property, "1".equals(mProperties.getProperty(property)) ? "0" : "1");
showIcons = mProperties.getBool(property, true);
mOptionsStyles.refresh();
mOptionsCSS.refresh();
mOptionsPage.refresh();
mOptionsApplication.refresh();
mOptionsControls.refresh();
}
}
class BoolOption extends OptionBase {
private boolean inverse = false;
public BoolOption( OptionOwner owner, String label, String property ) {
super(owner, label, property);
}
private boolean getValueBoolean() { return "1".equals(mProperties.getProperty(property)) ^ inverse; }
public String getValueLabel() { return getValueBoolean() ? getString(R.string.options_value_on) : getString(R.string.options_value_off); }
public void onSelect() {
mProperties.setProperty(property, "1".equals(mProperties.getProperty(property)) ? "0" : "1");
refreshList();
}
public BoolOption setInverse() { inverse = true; return this; }
public int getItemViewType() {
return OPTION_VIEW_TYPE_BOOLEAN;
}
public View getView(View convertView, ViewGroup parent) {
View view;
convertView = myView;
if ( convertView==null ) {
//view = new TextView(getContext());
view = mInflater.inflate(R.layout.option_item_boolean, null);
} else {
view = (View)convertView;
}
myView = view;
TextView labelView = (TextView)view.findViewById(R.id.option_label);
CheckBox valueView = (CheckBox)view.findViewById(R.id.option_value_cb);
// valueView.setFocusable(false);
// valueView.setClickable(false);
labelView.setText(label);
valueView.setChecked(getValueBoolean());
valueView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0,
boolean checked) {
// mProperties.setBool(property, checked);
// refreshList();
}
});
ImageView icon = (ImageView)view.findViewById(R.id.option_icon);
if (icon != null) {
if (iconId != 0 && showIcons) {
icon.setVisibility(View.VISIBLE);
icon.setImageResource(iconId);
} else {
icon.setImageResource(0);
icon.setVisibility(View.INVISIBLE);
}
}
// view.setClickable(true);
// view.setFocusable(true);
return view;
}
}
static public void saveColor( Properties mProperties, boolean night )
{
if ( night ) {
mProperties.setProperty(PROP_PAGE_BACKGROUND_IMAGE_NIGHT, mProperties.getProperty(PROP_PAGE_BACKGROUND_IMAGE, "(NONE)"));
mProperties.setColor(PROP_BACKGROUND_COLOR_NIGHT, mProperties.getColor(PROP_BACKGROUND_COLOR, 0x000000));
mProperties.setColor(PROP_FONT_COLOR_NIGHT, mProperties.getColor(PROP_FONT_COLOR, 0xFFFFFF));
mProperties.setColor(PROP_STATUS_FONT_COLOR_NIGHT, mProperties.getColor(PROP_STATUS_FONT_COLOR, 0xFFFFFF));
mProperties.setInt(PROP_APP_SCREEN_BACKLIGHT_NIGHT, mProperties.getInt(PROP_APP_SCREEN_BACKLIGHT, -1));
mProperties.setProperty(PROP_FONT_GAMMA_NIGHT, mProperties.getProperty(PROP_FONT_GAMMA, "1.0"));
mProperties.setProperty(PROP_APP_THEME_NIGHT, mProperties.getProperty(PROP_APP_THEME, "BLACK"));
mProperties.setInt(PROP_APP_HIGHLIGHT_BOOKMARKS_NIGHT, mProperties.getInt(PROP_APP_HIGHLIGHT_BOOKMARKS, 1));
mProperties.setColor(PROP_HIGHLIGHT_SELECTION_COLOR_NIGHT, mProperties.getColor(PROP_HIGHLIGHT_SELECTION_COLOR, 0xCCCCCC));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT_NIGHT, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT, 0xFFFF40));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION_NIGHT, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION, 0xFF8000));
} else {
mProperties.setProperty(PROP_PAGE_BACKGROUND_IMAGE_DAY, mProperties.getProperty(PROP_PAGE_BACKGROUND_IMAGE, "(NONE)"));
mProperties.setColor(PROP_BACKGROUND_COLOR_DAY, mProperties.getColor(PROP_BACKGROUND_COLOR, 0xFFFFFF));
mProperties.setColor(PROP_FONT_COLOR_DAY, mProperties.getColor(PROP_FONT_COLOR, 0x000000));
mProperties.setColor(PROP_STATUS_FONT_COLOR_DAY, mProperties.getColor(PROP_STATUS_FONT_COLOR, 0x000000));
mProperties.setInt(PROP_APP_SCREEN_BACKLIGHT_DAY, mProperties.getInt(PROP_APP_SCREEN_BACKLIGHT, -1));
mProperties.setProperty(PROP_FONT_GAMMA_DAY, mProperties.getProperty(PROP_FONT_GAMMA, "1.0"));
mProperties.setProperty(PROP_APP_THEME_DAY, mProperties.getProperty(PROP_APP_THEME, "WHITE"));
mProperties.setInt(PROP_APP_HIGHLIGHT_BOOKMARKS_DAY, mProperties.getInt(PROP_APP_HIGHLIGHT_BOOKMARKS, 1));
mProperties.setColor(PROP_HIGHLIGHT_SELECTION_COLOR_DAY, mProperties.getColor(PROP_HIGHLIGHT_SELECTION_COLOR, 0xCCCCCC));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT_DAY, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT, 0xFFFF40));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION_DAY, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION, 0xFF8000));
}
for (String code : styleCodes) {
String styleName = "styles." + code + ".color";
String v = mProperties.getProperty(styleName);
if (v != null) {
if ( night )
mProperties.setProperty(styleName + ".night", v);
else
mProperties.setProperty(styleName + ".day", v);
}
}
}
static public void restoreColor( Properties mProperties, boolean night )
{
if ( night ) {
mProperties.setProperty(PROP_PAGE_BACKGROUND_IMAGE, mProperties.getProperty(PROP_PAGE_BACKGROUND_IMAGE_NIGHT, "(NONE)"));
mProperties.setColor(PROP_BACKGROUND_COLOR, mProperties.getColor(PROP_BACKGROUND_COLOR_NIGHT, 0x000000));
mProperties.setColor(PROP_FONT_COLOR, mProperties.getColor(PROP_FONT_COLOR_NIGHT, 0xFFFFFF));
mProperties.setColor(PROP_STATUS_FONT_COLOR, mProperties.getColor(PROP_STATUS_FONT_COLOR_NIGHT, 0xFFFFFF));
mProperties.setInt(PROP_APP_SCREEN_BACKLIGHT, mProperties.getInt(PROP_APP_SCREEN_BACKLIGHT_NIGHT, 70));
mProperties.setProperty(PROP_FONT_GAMMA, mProperties.getProperty(PROP_FONT_GAMMA_NIGHT, "1.0"));
mProperties.setProperty(PROP_APP_THEME, mProperties.getProperty(PROP_APP_THEME_NIGHT, "BLACK"));
mProperties.setInt(PROP_APP_HIGHLIGHT_BOOKMARKS, mProperties.getInt(PROP_APP_HIGHLIGHT_BOOKMARKS_NIGHT, 1));
mProperties.setColor(PROP_HIGHLIGHT_SELECTION_COLOR, mProperties.getColor(PROP_HIGHLIGHT_SELECTION_COLOR_NIGHT, 0xCCCCCC));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT_NIGHT, 0xFFFF40));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION_NIGHT, 0xFF8000));
} else {
mProperties.setProperty(PROP_PAGE_BACKGROUND_IMAGE, mProperties.getProperty(PROP_PAGE_BACKGROUND_IMAGE_DAY, "(NONE)"));
mProperties.setColor(PROP_BACKGROUND_COLOR, mProperties.getColor(PROP_BACKGROUND_COLOR_DAY, 0xFFFFFF));
mProperties.setColor(PROP_FONT_COLOR, mProperties.getColor(PROP_FONT_COLOR_DAY, 0x000000));
mProperties.setColor(PROP_STATUS_FONT_COLOR, mProperties.getColor(PROP_STATUS_FONT_COLOR_DAY, 0x000000));
mProperties.setInt(PROP_APP_SCREEN_BACKLIGHT, mProperties.getInt(PROP_APP_SCREEN_BACKLIGHT_DAY, 80));
mProperties.setProperty(PROP_FONT_GAMMA, mProperties.getProperty(PROP_FONT_GAMMA_DAY, "1.0"));
mProperties.setProperty(PROP_APP_THEME, mProperties.getProperty(PROP_APP_THEME_DAY, "WHITE"));
mProperties.setInt(PROP_APP_HIGHLIGHT_BOOKMARKS, mProperties.getInt(PROP_APP_HIGHLIGHT_BOOKMARKS_DAY, 1));
mProperties.setColor(PROP_HIGHLIGHT_SELECTION_COLOR, mProperties.getColor(PROP_HIGHLIGHT_SELECTION_COLOR_DAY, 0xCCCCCC));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_COMMENT_DAY, 0xFFFF40));
mProperties.setColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION, mProperties.getColor(PROP_HIGHLIGHT_BOOKMARK_COLOR_CORRECTION_DAY, 0xFF8000));
}
for (String code : styleCodes) {
String styleName = "styles." + code + ".color";
String pname = night ? styleName + ".night" : styleName + ".day";
String v = mProperties.getProperty(pname);
if (v != null)
mProperties.setProperty(styleName, mProperties.getProperty(pname));
}
}
static public void toggleDayNightMode( Properties mProperties ) {
boolean oldMode = mProperties.getBool(PROP_NIGHT_MODE, false);
saveColor(mProperties, oldMode);
boolean newMode = !oldMode;
restoreColor(mProperties, newMode);
mProperties.setBool(PROP_NIGHT_MODE, newMode);
}
class NightModeOption extends BoolOption {
public NightModeOption( OptionOwner owner, String label, String property ) {
super(owner, label, property);
}
public void onSelect() {
toggleDayNightMode(mProperties);
refreshList();
}
}
class LangOption extends ListOption {
public LangOption(OptionOwner owner) {
super(owner, getString(R.string.options_app_locale), PROP_APP_LOCALE);
for (Lang lang : Lang.values()) {
add(lang.code, getString(lang.nameId));
}
if ( mProperties.getProperty(property)==null )
mProperties.setProperty(property, Lang.DEFAULT.code);
}
}
class ActionOption extends ListOption {
public ActionOption( OptionOwner owner, String label, String property, boolean isTap, boolean allowRepeat ) {
super(owner, label, property);
ReaderAction[] actions = ReaderAction.AVAILABLE_ACTIONS;
for ( ReaderAction a : actions )
if ( !isTap || a.mayAssignOnTap() )
add(a.id, getString(a.nameId));
if ( allowRepeat )
add(ReaderAction.REPEAT.id, getString(ReaderAction.REPEAT.nameId));
if ( mProperties.getProperty(property)==null )
mProperties.setProperty(property, ReaderAction.NONE.id);
}
}
class KeyMapOption extends SubmenuOption {
public KeyMapOption( OptionOwner owner, String label ) {
super(owner, label, PROP_APP_KEY_ACTIONS_PRESS);
}
private void addKey( OptionsListView list, int keyCode, String keyName ) {
final String propName = ReaderAction.getKeyProp(keyCode, ReaderAction.NORMAL);
final String longPropName = ReaderAction.getKeyProp(keyCode, ReaderAction.LONG);
final String dblPropName = ReaderAction.getKeyProp(keyCode, ReaderAction.DOUBLE);
list.add(new ActionOption(mOwner, keyName, propName, false, false));
list.add(new ActionOption(mOwner, keyName + " " + getContext().getString(R.string.options_app_key_long_press), longPropName, false, true));
list.add(new ActionOption(mOwner, keyName + " " + getContext().getString(R.string.options_app_key_double_press), dblPropName, false, false));
}
public void onSelect() {
BaseDialog dlg = new BaseDialog(mActivity, label, false, false);
OptionsListView listView = new OptionsListView(getContext());
if ( DeviceInfo.NOOK_NAVIGATION_KEYS ) {
addKey(listView, ReaderView.KEYCODE_PAGE_TOPLEFT, "Top left navigation button");
addKey(listView, ReaderView.KEYCODE_PAGE_BOTTOMLEFT, "Bottom left navigation button");
addKey(listView, ReaderView.KEYCODE_PAGE_TOPRIGHT, "Top right navigation button");
addKey(listView, ReaderView.NOOK_12_KEY_NEXT_LEFT, "Bottom right navigation button");
// addKey(listView, ReaderView.KEYCODE_PAGE_BOTTOMRIGHT, "Bottom right navigation button");
// on rooted Nook, side navigation keys may be reassigned on some standard android keycode
addKey(listView, KeyEvent.KEYCODE_MENU, "Menu");
addKey(listView, KeyEvent.KEYCODE_BACK, "Back");
addKey(listView, KeyEvent.KEYCODE_SEARCH, "Search");
addKey(listView, KeyEvent.KEYCODE_HOME, "Home");
addKey(listView, KeyEvent.KEYCODE_2, "Up");
addKey(listView, KeyEvent.KEYCODE_8, "Down");
} else if ( DeviceInfo.SONY_NAVIGATION_KEYS ) {
// addKey(listView, KeyEvent.KEYCODE_DPAD_UP, "Prev button");
// addKey(listView, KeyEvent.KEYCODE_DPAD_DOWN, "Next button");
addKey(listView, ReaderView.SONY_DPAD_UP_SCANCODE, "Prev button");
addKey(listView, ReaderView.SONY_DPAD_DOWN_SCANCODE, "Next button");
addKey(listView, ReaderView.SONY_DPAD_LEFT_SCANCODE, "Left button");
addKey(listView, ReaderView.SONY_DPAD_RIGHT_SCANCODE, "Right button");
// addKey(listView, ReaderView.SONY_MENU_SCANCODE, "Menu");
// addKey(listView, ReaderView.SONY_BACK_SCANCODE, "Back");
// addKey(listView, ReaderView.SONY_HOME_SCANCODE, "Home");
addKey(listView, KeyEvent.KEYCODE_MENU, "Menu");
addKey(listView, KeyEvent.KEYCODE_BACK, "Back");
addKey(listView, KeyEvent.KEYCODE_HOME, "Home");
} else {
addKey(listView, KeyEvent.KEYCODE_MENU, "Menu");
addKey(listView, KeyEvent.KEYCODE_BACK, "Back");
addKey(listView, KeyEvent.KEYCODE_DPAD_LEFT, "Left");
addKey(listView, KeyEvent.KEYCODE_DPAD_RIGHT, "Right");
addKey(listView, KeyEvent.KEYCODE_DPAD_UP, "Up");
addKey(listView, KeyEvent.KEYCODE_DPAD_DOWN, "Down");
addKey(listView, KeyEvent.KEYCODE_DPAD_CENTER, "Center");
addKey(listView, KeyEvent.KEYCODE_SEARCH, "Search");
addKey(listView, KeyEvent.KEYCODE_VOLUME_UP, "Volume Up");
addKey(listView, KeyEvent.KEYCODE_VOLUME_DOWN, "Volume Down");
addKey(listView, KeyEvent.KEYCODE_CAMERA, "Camera");
addKey(listView, KeyEvent.KEYCODE_HEADSETHOOK, "Headset Hook");
addKey(listView, ReaderView.KEYCODE_ESCAPE, "Escape");
}
dlg.setView(listView);
dlg.show();
}
public String getValueLabel() { return ">"; }
}
class StatusBarOption extends SubmenuOption {
public StatusBarOption( OptionOwner owner, String label ) {
super(owner, label, PROP_SHOW_TITLE);
}
public void onSelect() {
BaseDialog dlg = new BaseDialog(mActivity, label, false, false);
OptionsListView listView = new OptionsListView(getContext());
listView.add(new ListOption(mOwner, getString(R.string.options_page_show_titlebar), PROP_STATUS_LOCATION).add(mStatusPositions, mStatusPositionsTitles).setDefaultValue("1"));
listView.add(new ListOption(mOwner, getString(R.string.options_page_titlebar_font_face), PROP_STATUS_FONT_FACE).add(mFontFaces).setDefaultValue(mFontFaces[0]).setIconId(R.drawable.cr3_option_font_face));
listView.add(new ListOption(mOwner, getString(R.string.options_page_titlebar_font_size), PROP_STATUS_FONT_SIZE).add(filterFontSizes(mStatusFontSizes)).setDefaultValue("18").setIconId(R.drawable.cr3_option_font_size));
listView.add(new ColorOption(mOwner, getString(R.string.options_page_titlebar_font_color), PROP_STATUS_FONT_COLOR, 0x000000));
listView.add(new BoolOption(mOwner, getString(R.string.options_page_show_titlebar_title), PROP_SHOW_TITLE).setDefaultValue("1"));
listView.add(new BoolOption(mOwner, getString(R.string.options_page_show_titlebar_page_number), PROP_SHOW_PAGE_NUMBER).setDefaultValue("1"));
listView.add(new BoolOption(mOwner, getString(R.string.options_page_show_titlebar_page_count), PROP_SHOW_PAGE_COUNT).setDefaultValue("1"));
listView.add(new BoolOption(mOwner, getString(R.string.options_page_show_titlebar_percent), PROP_SHOW_POS_PERCENT).setDefaultValue("0"));
listView.add(new BoolOption(mOwner, getString(R.string.options_page_show_titlebar_chapter_marks), PROP_STATUS_CHAPTER_MARKS).setDefaultValue("1"));
listView.add(new BoolOption(mOwner, getString(R.string.options_page_show_titlebar_battery_percent), PROP_SHOW_BATTERY_PERCENT).setDefaultValue("1"));
dlg.setView(listView);
dlg.show();
}
public String getValueLabel() { return ">"; }
}
class PluginsOption extends SubmenuOption {
public PluginsOption( OptionOwner owner, String label ) {
super(owner, label, PROP_APP_PLUGIN_ENABLED);
}
public void onSelect() {
BaseDialog dlg = new BaseDialog(mActivity, label, false, false);
OptionsListView listView = new OptionsListView(getContext());
boolean defEnableLitres = activity.getCurrentLanguage().toLowerCase().startsWith("ru") && !DeviceInfo.POCKETBOOK;
listView.add(new BoolOption(mOwner, "LitRes", PROP_APP_PLUGIN_ENABLED + "." + OnlineStorePluginManager.PLUGIN_PKG_LITRES).setDefaultValue(defEnableLitres ? "1" : "0"));
dlg.setView(listView);
dlg.show();
}
public String getValueLabel() { return ">"; }
}
class ImageScalingOption extends SubmenuOption {
public ImageScalingOption( OptionOwner owner, String label ) {
super(owner, label, PROP_IMG_SCALING_ZOOMIN_BLOCK_MODE);
}
public void onSelect() {
BaseDialog dlg = new BaseDialog(mActivity, label, false, false);
OptionsListView listView = new OptionsListView(getContext());
listView.add(new ListOption(mOwner, getString(R.string.options_format_image_scaling_block_mode), PROP_IMG_SCALING_ZOOMIN_BLOCK_MODE).add(mImageScalingModes, mImageScalingModesTitles).setDefaultValue("2"));
listView.add(new ListOption(mOwner, getString(R.string.options_format_image_scaling_block_scale), PROP_IMG_SCALING_ZOOMIN_BLOCK_SCALE).add(mImageScalingFactors, mImageScalingFactorsTitles).setDefaultValue("2"));
listView.add(new ListOption(mOwner, getString(R.string.options_format_image_scaling_inline_mode), PROP_IMG_SCALING_ZOOMIN_INLINE_MODE).add(mImageScalingModes, mImageScalingModesTitles).setDefaultValue("2"));
listView.add(new ListOption(mOwner, getString(R.string.options_format_image_scaling_inline_scale), PROP_IMG_SCALING_ZOOMIN_INLINE_SCALE).add(mImageScalingFactors, mImageScalingFactorsTitles).setDefaultValue("2"));
dlg.setView(listView);
dlg.show();
}
private void copyProperty( String to, String from ) {
mProperties.put(to, mProperties.get(from));
}
protected void closed() {
copyProperty(PROP_IMG_SCALING_ZOOMOUT_BLOCK_MODE, PROP_IMG_SCALING_ZOOMIN_BLOCK_MODE);
copyProperty(PROP_IMG_SCALING_ZOOMOUT_INLINE_MODE, PROP_IMG_SCALING_ZOOMIN_INLINE_MODE);
copyProperty(PROP_IMG_SCALING_ZOOMOUT_BLOCK_SCALE, PROP_IMG_SCALING_ZOOMIN_BLOCK_SCALE);
copyProperty(PROP_IMG_SCALING_ZOOMOUT_INLINE_SCALE, PROP_IMG_SCALING_ZOOMIN_INLINE_SCALE);
}
public String getValueLabel() { return ">"; }
}
class TapZoneOption extends SubmenuOption {
public TapZoneOption( OptionOwner owner, String label, String property ) {
super( owner, label, property);
}
View grid;
private void initTapZone( View view, final int tapZoneId )
{
if ( view==null )
return;
final TextView text = (TextView)view.findViewById(R.id.tap_zone_action_text_short);
final TextView longtext = (TextView)view.findViewById(R.id.tap_zone_action_text_long);
final String propName = property + "." + tapZoneId;
final String longPropName = property + ".long." + tapZoneId;
ReaderAction action = ReaderAction.findById( mProperties.getProperty(propName) );
ReaderAction longAction = ReaderAction.findById( mProperties.getProperty(longPropName) );
text.setText(getString(action.nameId));
longtext.setText(getString(longAction.nameId));
view.setLongClickable(true);
view.setOnClickListener(new View.OnClickListener () {
@Override
public void onClick(View v) {
// TODO: i18n
ActionOption option = new ActionOption(mOwner, getString(R.string.options_app_tap_action_short), propName, true, false);
option.setOnChangeHandler(new Runnable() {
public void run() {
ReaderAction action = ReaderAction.findById( mProperties.getProperty(propName) );
text.setText(getString(action.nameId));
}
});
option.onSelect();
}
});
view.setOnLongClickListener(new View.OnLongClickListener () {
@Override
public boolean onLongClick(View v) {
// TODO: i18n
ActionOption option = new ActionOption(mOwner, getString(R.string.options_app_tap_action_long), longPropName, true, true);
option.setOnChangeHandler(new Runnable() {
public void run() {
ReaderAction longAction = ReaderAction.findById( mProperties.getProperty(longPropName) );
longtext.setText(getString(longAction.nameId));
}
});
option.onSelect();
return true;
}
});
}
public String getValueLabel() { return ">"; }
public void onSelect() {
BaseDialog dlg = new BaseDialog(mActivity, label, false, false);
grid = (View)mInflater.inflate(R.layout.options_tap_zone_grid, null);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell1), 1);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell2), 2);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell3), 3);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell4), 4);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell5), 5);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell6), 6);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell7), 7);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell8), 8);
initTapZone(grid.findViewById(R.id.tap_zone_grid_cell9), 9);
dlg.setView(grid);
dlg.show();
}
}
public static class Pair {
public String value;
public String label;
public Pair(String value, String label) {
this.value = value;
this.label = label;
}
}
public static class SubmenuOption extends ListOption {
public SubmenuOption( OptionOwner owner, String label, String property ) {
super(owner, label, property);
}
public int getItemViewType() {
return OPTION_VIEW_TYPE_SUBMENU;
}
public View getView(View convertView, ViewGroup parent) {
View view;
convertView = myView;
if ( convertView==null ) {
//view = new TextView(getContext());
view = mInflater.inflate(R.layout.option_item_submenu, null);
} else {
view = (View)convertView;
}
myView = view;
TextView labelView = (TextView)view.findViewById(R.id.option_label);
labelView.setText(label);
ImageView icon = (ImageView)view.findViewById(R.id.option_icon);
if (icon != null) {
if (iconId != 0 && showIcons) {
icon.setVisibility(View.VISIBLE);
icon.setImageResource(iconId);
} else {
icon.setImageResource(0);
icon.setVisibility(View.INVISIBLE);
}
}
return view;
}
}
public static class ListOption extends OptionBase {
private ArrayList<Pair> list = new ArrayList<Pair>();
public ListOption( OptionOwner owner, String label, String property ) {
super(owner, label, property);
}
public void add(String value, String label) {
list.add( new Pair(value, label) );
}
public ListOption add(String[]values) {
for ( String item : values ) {
add(item, item);
}
return this;
}
public ListOption add(double[]values) {
for ( double item : values ) {
String s = String.valueOf(item);
add(s, s);
}
return this;
}
public ListOption add(int[]values) {
for ( int item : values ) {
String s = String.valueOf(item);
add(s, s);
}
return this;
}
public ListOption add(int[]values, int[]labelIDs) {
for ( int i=0; i<values.length; i++ ) {
String value = String.valueOf(values[i]);
String label = mActivity.getString(labelIDs[i]);
add(value, label);
}
return this;
}
public ListOption add(String[]values, int[]labelIDs) {
for ( int i=0; i<values.length; i++ ) {
String value = values[i];
String label = mActivity.getString(labelIDs[i]);
add(value, label);
}
return this;
}
public ListOption add(String[]values, String[]labels) {
for ( int i=0; i<values.length; i++ ) {
String value = values[i];
String label = labels[i];
add(value, label);
}
return this;
}
public ListOption add(int[]values, String[]labels) {
for ( int i=0; i<values.length; i++ ) {
String value = String.valueOf(values[i]);
String label = labels[i];
add(value, label);
}
return this;
}
public ListOption addPercents(int[]values) {
for ( int item : values ) {
String s = String.valueOf(item);
add(s, s + "%");
}
return this;
}
public String findValueLabel( String value ) {
for ( Pair pair : list ) {
if ( value!=null && pair.value.equals(value) )
return pair.label;
}
return null;
}
public int findValue( String value ) {
if ( value==null )
return -1;
for ( int i=0; i<list.size(); i++ ) {
if ( value.equals(list.get(i).value) )
return i;
}
return -1;
}
public int getSelectedItemIndex() {
return findValue(mProperties.getProperty(property));
}
protected void closed() {
}
protected int getItemLayoutId() {
return R.layout.option_value;
}
protected void updateItemContents( final View layout, final Pair item, final ListView listView, final int position ) {
TextView view;
RadioButton cb;
view = (TextView)layout.findViewById(R.id.option_value_text);
cb = (RadioButton)layout.findViewById(R.id.option_value_check);
view.setText(item.label);
String currValue = mProperties.getProperty(property);
boolean isSelected = item.value!=null && currValue!=null && item.value.equals(currValue) ;//getSelectedItemIndex()==position;
cb.setChecked(isSelected);
cb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listView.getOnItemClickListener().onItemClick(listView, listView, position, 0);
// mProperties.setProperty(property, item.value);
// dismiss();
// optionsListView.refresh();
}
});
}
public String getValueLabel() { return findValueLabel(mProperties.getProperty(property)); }
public void onSelect() {
final BaseDialog dlg = new BaseDialog(mActivity, label, false, false);
final ListView listView = new BaseListView(mActivity, false);
ListAdapter listAdapter = new BaseAdapter() {
public boolean areAllItemsEnabled() {
return true;
}
public boolean isEnabled(int position) {
return true;
}
public int getCount() {
return list.size();
}
public Object getItem(int position) {
return list.get(position);
}
public long getItemId(int position) {
return position;