Skip to content

Commit

Permalink
Add TimePicker dialog with spinner mode. Add View with NumberPicker w…
Browse files Browse the repository at this point in the history
…ith custom displayed values. (#28)
  • Loading branch information
vmaxim authored and KazuCocoa committed Mar 14, 2019
1 parent e4ee6e0 commit e92e653
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,13 @@
</intent-filter>
</activity>

<activity android:name=".view.CustomPicker1" android:label="Views/Picker">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="appium.android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>

<!-- ************************************* -->
<!-- GRAPHICS SAMPLES -->
<!-- ************************************* -->
Expand Down
54 changes: 54 additions & 0 deletions app/src/main/java/io/appium/android/apis/view/CustomPicker1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.android.apis.view;

// Need the following import to get access to the app resources, since this
// class is in a sub-package.
import io.appium.android.apis.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.NumberPicker;
import android.widget.TextView;

public class CustomPicker1 extends Activity {

private NumberPicker numberPicker1;
private TextView textView1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_picker_1);
numberPicker1= (NumberPicker) findViewById(R.id.numberPicker1);
textView1 = (TextView) findViewById(R.id.textView1);
final String values[] = { "परीक्षण", "测试", "テスト", "kupima", "การทดสอบ" };

numberPicker1.setMinValue(0);
numberPicker1.setMaxValue(values.length - 1);
numberPicker1.setDisplayedValues(values);

NumberPicker.OnValueChangeListener myValChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
textView1.setText("Value: " + values[newVal]);
}
};

numberPicker1.setOnValueChangedListener(myValChangedListener);
}
}
19 changes: 17 additions & 2 deletions app/src/main/java/io/appium/android/apis/view/DateWidgets1.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class DateWidgets1 extends Activity {

static final int TIME_DIALOG_ID = 0;
static final int DATE_DIALOG_ID = 1;
static final int TIME_DIALOG_SPINNER_ID = 2;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -78,12 +79,20 @@ public void onClick(View v) {
}
});

Button pickTimeSpinner = (Button) findViewById(R.id.pickTimeSpinner);
pickTimeSpinner.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
showDialog(TIME_DIALOG_SPINNER_ID);
}
});

final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
mHour = 1;
mMinute = 2;

updateDisplay();
}
Expand All @@ -94,6 +103,9 @@ protected Dialog onCreateDialog(int id) {
case TIME_DIALOG_ID:
return new TimePickerDialog(this,
mTimeSetListener, mHour, mMinute, false);
case TIME_DIALOG_SPINNER_ID:
return new TimePickerDialog(this, android.R.style.Theme_Holo_Dialog_NoActionBar,
mTimeSetListener, mHour, mMinute, false);
case DATE_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
Expand All @@ -108,6 +120,9 @@ protected void onPrepareDialog(int id, Dialog dialog) {
case TIME_DIALOG_ID:
((TimePickerDialog) dialog).updateTime(mHour, mMinute);
break;
case TIME_DIALOG_SPINNER_ID:
((TimePickerDialog) dialog).updateTime(mHour, mMinute);
break;
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
break;
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/res/layout/custom_picker_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!-- Demonstrates defining custom views in a layout file. -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

2 changes: 2 additions & 0 deletions app/src/main/res/layout/date_widgets_example_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@

<Button android:id="@+id/pickTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/date_widgets_example_pickTime_text" android:contentDescription="@string/date_widgets_example_pickTime_text"/>

<Button android:id="@+id/pickTimeSpinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/date_widgets_example_pickTime_spinner_text" android:contentDescription="@string/date_widgets_example_pickTime_spinner_text"/>

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@

<string name="date_widgets_example_dateDisplay_text"></string>
<string name="date_widgets_example_pickTime_text">change the time</string>
<string name="date_widgets_example_pickTime_spinner_text">change the time (spinner)</string>
<string name="date_widgets_example_pickDate_text">change the date</string>

<string name="buttons_1_normal">Normal</string>
Expand Down

0 comments on commit e92e653

Please sign in to comment.