Skip to content

Commit

Permalink
Added Empty wheel activity to demo.
Browse files Browse the repository at this point in the history
Fixed issue with last item (the previous fix was wrong)
  • Loading branch information
yuri.kanivets committed Jul 7, 2010
1 parent 63befcf commit 7d3a119
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 11 deletions.
6 changes: 6 additions & 0 deletions wheel/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<category android:name="kankan.wheel.WHEEL_SAMPLE"/>
</intent-filter>
</activity>
<activity android:name="kankan.wheel.demo.EmptyActivity" android:label="Empty wheel">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="kankan.wheel.WHEEL_SAMPLE"/>
</intent-filter>
</activity>

</application>

Expand Down
14 changes: 10 additions & 4 deletions wheel/gen/kankan/wheel/R.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ public static final class drawable {
}
public static final class id {
public static final int city=0x7f040000;
public static final int hour=0x7f040001;
public static final int mins=0x7f040002;
public static final int empty=0x7f040001;
public static final int hour=0x7f040006;
public static final int mins=0x7f040007;
public static final int passw_1=0x7f040002;
public static final int passw_2=0x7f040003;
public static final int passw_3=0x7f040004;
public static final int passw_4=0x7f040005;
}
public static final class layout {
public static final int cities_layout=0x7f030000;
public static final int passw_layout=0x7f030001;
public static final int time_layout=0x7f030002;
public static final int empty_layout=0x7f030001;
public static final int passw_layout=0x7f030002;
public static final int time_layout=0x7f030003;
}
}
29 changes: 29 additions & 0 deletions wheel/res/layout/empty_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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">

<kankan.wheel.widget.WheelView android:id="@+id/empty"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>

</LinearLayout>
8 changes: 4 additions & 4 deletions wheel/res/layout/passw_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<kankan.wheel.widget.WheelView
<kankan.wheel.widget.WheelView android:id="@+id/passw_1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<kankan.wheel.widget.WheelView
<kankan.wheel.widget.WheelView android:id="@+id/passw_2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<kankan.wheel.widget.WheelView
<kankan.wheel.widget.WheelView android:id="@+id/passw_3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<kankan.wheel.widget.WheelView
<kankan.wheel.widget.WheelView android:id="@+id/passw_4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
Expand Down
32 changes: 32 additions & 0 deletions wheel/src/kankan/wheel/demo/EmptyActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 android.app.Activity;
import android.os.Bundle;

public class EmptyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.empty_layout);
}
}
16 changes: 16 additions & 0 deletions wheel/src/kankan/wheel/demo/PasswActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package kankan.wheel.demo;

import kankan.wheel.R;
import kankan.wheel.widget.NumericWheelAdapter;
import kankan.wheel.widget.WheelView;
import android.app.Activity;
import android.os.Bundle;

Expand All @@ -27,5 +29,19 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.passw_layout);
initWheel(R.id.passw_1);
initWheel(R.id.passw_2);
initWheel(R.id.passw_3);
initWheel(R.id.passw_4);
}

/**
* Initializes wheel
* @param id the wheel widget id
*/
private void initWheel(int id) {
WheelView wheel = (WheelView) findViewById(id);
wheel.setAdapter(new NumericWheelAdapter(0, 9));
wheel.setCurrentItem((int)(Math.random() * 10));
}
}
6 changes: 3 additions & 3 deletions wheel/src/kankan/wheel/widget/WheelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class WheelView extends View {
private static final int DEF_VISIBLE_ITEMS = 5;

// Wheel Values
private WheelAdapter adapter = new NumericWheelAdapter(); // to do: do not initialize it
private WheelAdapter adapter = null;
private int currentItem = 0;

// Widths
Expand Down Expand Up @@ -283,7 +283,7 @@ private String buildText() {

itemsText.append("\n"); // here will be current value

for (int i = currentItem + 1; i < currentItem + addItems; i++) {
for (int i = currentItem + 1; i <= currentItem + addItems; i++) {
if (adapter != null && i < adapter.getItemsCount()) {
String text = adapter.getItem(i);
if (text != null) {
Expand Down Expand Up @@ -553,7 +553,7 @@ public boolean onTouchEvent(MotionEvent event) {
int count = (int) (visibleItems * delta / getHeight());
int pos = currentItem - count;
pos = Math.max(pos, 0);
pos = Math.min(pos, adapter.getItemsCount());
pos = Math.min(pos, adapter.getItemsCount() - 1);
if (pos != currentItem) {
lastYTouch = event.getY();
setCurrentItem(pos);
Expand Down

0 comments on commit 7d3a119

Please sign in to comment.