44import android .content .Context ;
55import android .graphics .Color ;
66import android .view .Gravity ;
7- import android .view .View ;
87import android .widget .Button ;
98import android .widget .LinearLayout ;
109import android .widget .NumberPicker ;
1413
1514@ SuppressLint ("ViewConstructor" )
1615public class DataTimePickerDialog extends Dialog implements DialogInterface {
17- private final LinearLayout m_options ;
18-
1916 private int m_year = 0 ;
2017 private int m_month = 0 ;
2118 private int m_day = 0 ;
@@ -51,7 +48,7 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
5148 setGravity (Gravity .CENTER );
5249
5350 LinearLayout vertical = new LinearLayout (context );
54- vertical .setBackgroundColor ( Color . WHITE );
51+ vertical .setBackground ( getBackGround ( 16 ) );
5552 vertical .setOrientation (LinearLayout .VERTICAL );
5653 vertical .setGravity (Gravity .CENTER );
5754 vertical .setLayoutParams (new LayoutParams ((int ) (DEFAULT_VIEW_SIZE * 0.75f ), LayoutParams .WRAP_CONTENT ));
@@ -65,15 +62,15 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
6562 datePicker .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
6663
6764 m_year = c .get (Calendar .YEAR );
68- NumberPicker yearPicker = getNumberPicker (context , 0 , 3000 , m_year , DEFAULT_NUMBER_PICKER_SIZE_X , DEFAULT_NUMBER_PICKER_SIZE_Y , (picker , oldVal , newVal ) -> m_year = newVal );
65+ NumberPicker yearPicker = getNumberPicker (context , 0 , 3000 , m_year , (picker , oldVal , newVal ) -> m_year = newVal );
6966 datePicker .addView (yearPicker );
7067
7168 m_month = c .get (Calendar .MONTH ) + 1 ;
72- NumberPicker monthPicker = getNumberPicker (context , 1 , 12 , m_month , DEFAULT_NUMBER_PICKER_SIZE_X , DEFAULT_NUMBER_PICKER_SIZE_Y , (picker , oldVal , newVal ) -> m_month = newVal );
69+ NumberPicker monthPicker = getNumberPicker (context , 1 , 12 , m_month , (picker , oldVal , newVal ) -> m_month = newVal );
7370 datePicker .addView (monthPicker );
7471
7572 m_day = c .get (Calendar .DATE );
76- NumberPicker dayPicker = getNumberPicker (context , 1 , 31 , m_day , DEFAULT_NUMBER_PICKER_SIZE_X , DEFAULT_NUMBER_PICKER_SIZE_Y , (picker , oldVal , newVal ) -> m_day = newVal );
73+ NumberPicker dayPicker = getNumberPicker (context , 1 , 31 , m_day , (picker , oldVal , newVal ) -> m_day = newVal );
7774 datePicker .addView (dayPicker );
7875
7976 vertical .addView (datePicker );
@@ -86,25 +83,20 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
8683 timePicker .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
8784
8885 m_hour = c .get (Calendar .HOUR );
89- NumberPicker hourPicker = getNumberPicker (context , 0 , 23 , m_hour , DEFAULT_NUMBER_PICKER_SIZE_X , DEFAULT_NUMBER_PICKER_SIZE_Y , (picker , oldVal , newVal ) -> m_hour = newVal );
86+ NumberPicker hourPicker = getNumberPicker (context , 0 , 23 , m_hour , (picker , oldVal , newVal ) -> m_hour = newVal );
9087 timePicker .addView (hourPicker );
9188
9289 m_minutes = c .get (Calendar .MINUTE );
93- NumberPicker minutesPicker = getNumberPicker (context , 0 , 59 , m_minutes , DEFAULT_NUMBER_PICKER_SIZE_X , DEFAULT_NUMBER_PICKER_SIZE_Y , (picker , oldVal , newVal ) -> m_minutes = newVal );
90+ NumberPicker minutesPicker = getNumberPicker (context , 0 , 59 , m_minutes , (picker , oldVal , newVal ) -> m_minutes = newVal );
9491 timePicker .addView (minutesPicker );
9592
9693 vertical .addView (timePicker );
9794 }
9895
99- m_options = new LinearLayout (context );
100- m_options .setOrientation (LinearLayout .HORIZONTAL );
101- m_options .setGravity (Gravity .RIGHT | Gravity .BOTTOM );
102- m_options .setLayoutParams (new LayoutParams (LayoutParams .MATCH_PARENT , LayoutParams .WRAP_CONTENT ));
103-
10496 vertical .addView (m_options );
10597
10698 TextView dummy = new TextView (m_context );
107- dummy .setText (" " );
99+ dummy .setText (" " );
108100 dummy .setTextSize (7 );
109101 dummy .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
110102
@@ -113,50 +105,13 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
113105 addView (vertical );
114106 }
115107
116- private NumberPicker getNumberPicker (Context context , int min , int max , int init , int width , int height , NumberPicker .OnValueChangeListener listener ) {
108+ private NumberPicker getNumberPicker (Context context , int min , int max , int init , NumberPicker .OnValueChangeListener listener ) {
117109 NumberPicker numberPicker = new NumberPicker (context );
118110 numberPicker .setMinValue (min );
119111 numberPicker .setMaxValue (max );
120112 numberPicker .setValue (init );
121113 numberPicker .setOnValueChangedListener (listener );
122- numberPicker .setLayoutParams (new LayoutParams (width , height ));
114+ numberPicker .setLayoutParams (new LayoutParams (150 , 300 ));
123115 return numberPicker ;
124116 }
125-
126- public void setOptions (String option , final DialogInterface .OnSelectOptionListener listener ) {
127- TextView dummy = new TextView (m_context );
128- dummy .setText (" " );
129- dummy .setTextSize (15 );
130- dummy .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
131-
132- m_options .addView (dummy );
133-
134- Button button = getButton (option , listener );
135-
136- m_options .addView (button );
137-
138- dummy = new TextView (m_context );
139- dummy .setText (" " );
140- dummy .setTextSize (15 );
141- dummy .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
142-
143- m_options .addView (dummy );
144- }
145-
146- private Button getButton (String option , OnSelectOptionListener listener ) {
147- Button button = new Button (m_context );
148- button .setPadding (10 , 10 , 10 , 10 );
149- button .setMinWidth (0 );
150- button .setMinHeight (0 );
151- button .setMinimumWidth (0 );
152- button .setMinimumHeight (0 );
153- button .setTextSize (15 );
154- button .setText (option );
155- button .setTextColor (Color .GREEN );
156- button .setBackgroundColor (Color .WHITE );
157-
158- button .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
159- button .setOnClickListener (v -> listener .OnSelectOption (option ));
160- return button ;
161- }
162117}
0 commit comments