Permalink
Browse files

Added wheel adapters

git-svn-id: http://android-wheel.googlecode.com/svn/trunk@3 c364614a-9a97-51b3-f556-90fca60df64e
  • Loading branch information...
1 parent 548557c commit f3c83c630c374acfb4214f11fe4ed4b4b36f3912 yuri.kanivets committed Jun 21, 2010
View
@@ -24,19 +24,25 @@
<application android:icon="@drawable/icon" android:label="WheelDemo">
- <activity android:name="WheelDemo">
+ <activity android:name="kankan.wheel.demo.WheelDemo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- <activity android:name="TimeActivity" android:label="Time">
+ <activity android:name="kankan.wheel.demo.TimeActivity" android:label="Time">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="kankan.wheel.WHEEL_SAMPLE"/>
</intent-filter>
</activity>
- <activity android:name="PasswActivity" android:label="Password">
+ <activity android:name="kankan.wheel.demo.PasswActivity" android:label="Password">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="kankan.wheel.WHEEL_SAMPLE"/>
+ </intent-filter>
+ </activity>
+ <activity android:name="kankan.wheel.demo.CitiesActivity" android:label="Cities">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="kankan.wheel.WHEEL_SAMPLE"/>
@@ -17,11 +17,13 @@
public static final int wheel_val=0x7f020003;
}
public static final class id {
- public static final int hour=0x7f040000;
- public static final int mins=0x7f040001;
+ public static final int city=0x7f040000;
+ public static final int hour=0x7f040001;
+ public static final int mins=0x7f040002;
}
public static final class layout {
- public static final int passw_layout=0x7f030000;
- public static final int time_layout=0x7f030001;
+ public static final int cities_layout=0x7f030000;
+ public static final int passw_layout=0x7f030001;
+ public static final int time_layout=0x7f030002;
}
}
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2010 Yuri Kanivets
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:background="@drawable/layout_bg"
+ android:layout_width="fill_parent">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="24dp"
+ android:layout_gravity="center_horizontal"
+ android:textSize="20sp"
+ android:text="Please select the city"/>
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_width="fill_parent"
+ android:paddingLeft="12dp"
+ android:paddingRight="12dp"
+ android:paddingTop="4dp"
+ android:layout_marginTop="8dp">
+
+ <kankan.wheel.widget.WheelView android:id="@+id/city"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"/>
+
+ </LinearLayout>
+
+ <!-- Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="18dp"
+ android:textSize="18sp"
+ android:text=" Next > "/-->
+
+</LinearLayout>
@@ -19,7 +19,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:background="@drawable/layout_bg" android:layout_width="fill_parent">
+ android:background="@drawable/layout_bg"
+ android:layout_width="fill_parent">
<TextView
android:layout_width="wrap_content"
@@ -30,31 +31,31 @@
android:text="Please enter password"/>
<LinearLayout
- android:layout_marginTop="8dp"
+ android:layout_marginTop="24dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
- <kankan.wheel.NumericWheel
+ <kankan.wheel.widget.WheelView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
- <kankan.wheel.NumericWheel
+ <kankan.wheel.widget.WheelView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
- <kankan.wheel.NumericWheel
+ <kankan.wheel.widget.WheelView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
- <kankan.wheel.NumericWheel
+ <kankan.wheel.widget.WheelView
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
- <Button
+ <!-- Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:textSize="18sp"
- android:text="Check password"/>
+ android:text="Check password"/-->
</LinearLayout>
@@ -19,19 +19,35 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
- android:paddingLeft="12dp"
- android:paddingRight="12dp"
- android:paddingTop="4dp"
+ android:layout_marginTop="12dp"
+ android:orientation="vertical"
android:background="@drawable/layout_bg">
-
- <kankan.wheel.NumericWheel android:id="@+id/hour"
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
- android:layout_weight="1"/>
- <kankan.wheel.NumericWheel android:id="@+id/mins"
+ android:layout_gravity="center_horizontal"
+ android:paddingLeft="12dp"
+ android:paddingRight="12dp"
+ android:paddingTop="10dp">
+
+ <kankan.wheel.widget.WheelView android:id="@+id/hour"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:layout_weight="1"/>
+ <kankan.wheel.widget.WheelView android:id="@+id/mins"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:layout_weight="1"/>
+ </LinearLayout>
+
+ <!-- Button
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:layout_weight="1"/>
-</LinearLayout>
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="32dp"
+ android:textSize="18sp"
+ android:text=" Done "/-->
+
+</LinearLayout>
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Yuri Kanivets
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package kankan.wheel.demo;
+
+import kankan.wheel.R;
+import kankan.wheel.widget.ArrayWheelAdapter;
+import kankan.wheel.widget.WheelView;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class CitiesActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.cities_layout);
+
+ WheelView city = (WheelView) findViewById(R.id.city);
+ String cities[] = new String[] {"New York", "Washington", "Chicago",
+ "Los Angeles", "Atlanta", "Boston", "Miami", "Orlando"};
+ city.setAdapter(new ArrayWheelAdapter<String>(cities));
+ city.setVisibleItems(7);
+ city.setCurrentItem(5);
+ }
+}
@@ -15,8 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package kankan.wheel;
+package kankan.wheel.demo;
+import kankan.wheel.R;
import android.app.Activity;
import android.os.Bundle;
@@ -15,10 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-package kankan.wheel;
+package kankan.wheel.demo;
import java.util.Calendar;
+import kankan.wheel.R;
+import kankan.wheel.widget.NumericWheelAdapter;
+import kankan.wheel.widget.WheelView;
+
import android.app.Activity;
import android.os.Bundle;
@@ -29,16 +33,16 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.time_layout);
- NumericWheel hours = (NumericWheel) findViewById(R.id.hour);
- hours.setMaxValue(23);
+ WheelView hours = (WheelView) findViewById(R.id.hour);
+ hours.setAdapter(new NumericWheelAdapter(0, 23));
hours.setLabel("hour");
- NumericWheel mins = (NumericWheel) findViewById(R.id.mins);
- mins.setMaxValue(59);
+ WheelView mins = (WheelView) findViewById(R.id.mins);
+ mins.setAdapter(new NumericWheelAdapter(0, 59));
mins.setLabel("mins");
Calendar c = Calendar.getInstance();
- mins.setValue(c.get(Calendar.MINUTE));
- hours.setValue(c.get(Calendar.HOUR_OF_DAY));
+ mins.setCurrentItem(c.get(Calendar.MINUTE));
+ hours.setCurrentItem(c.get(Calendar.HOUR_OF_DAY));
}
}
@@ -1,4 +1,4 @@
-package kankan.wheel;
+package kankan.wheel.demo;
import java.text.Collator;
import java.util.ArrayList;
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 Yuri Kanivets
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package kankan.wheel.widget;
+
+/**
+ * The simple Array wheel adapter
+ * @param <T> the element type
+ */
+public class ArrayWheelAdapter<T> implements WheelAdapter {
+
+ /** The default items length */
+ public static final int DEFAULT_LENGTH = -1;
+
+ // items
+ private T items[];
+ // length
+ private int length;
+
+ /**
+ * Constructor
+ * @param items the items
+ * @param length the max items length
+ */
+ public ArrayWheelAdapter(T items[], int length) {
+ this.items = items;
+ this.length = length;
+ }
+
+ /**
+ * Contructor
+ * @param items the items
+ */
+ public ArrayWheelAdapter(T items[]) {
+ this(items, DEFAULT_LENGTH);
+ }
+
+ @Override
+ public String getItem(int index) {
+ if (index >= 0 && index < items.length) {
+ return items[index].toString();
+ }
+ return null;
+ }
+
+ @Override
+ public int getItemsCount() {
+ return items.length;
+ }
+
+ @Override
+ public int getMaximumLength() {
+ return length;
+ }
+
+}
Oops, something went wrong.

0 comments on commit f3c83c6

Please sign in to comment.