Permalink
Browse files

Implemented animation.

git-svn-id: http://android-wheel.googlecode.com/svn/trunk@13 c364614a-9a97-51b3-f556-90fca60df64e
  • Loading branch information...
1 parent 7e2e9ea commit 1ba1736487cd01131670ca2d1afd9f6fdb59689f yuri.kanivets committed Nov 25, 2010
@@ -17,17 +17,18 @@
public static final int wheel_val=0x7f020003;
}
public static final class id {
+ public static final int btn_mix=0x7f040008;
public static final int city=0x7f040001;
public static final int country=0x7f040000;
public static final int empty=0x7f040002;
- public static final int hour=0x7f040008;
- public static final int mins=0x7f040009;
+ public static final int hour=0x7f040009;
+ public static final int mins=0x7f04000a;
public static final int passw_1=0x7f040003;
public static final int passw_2=0x7f040004;
public static final int passw_3=0x7f040005;
public static final int passw_4=0x7f040006;
public static final int pwd_status=0x7f040007;
- public static final int time=0x7f04000a;
+ public static final int time=0x7f04000b;
}
public static final class layout {
public static final int cities_layout=0x7f030000;
@@ -44,12 +44,12 @@
android:textColor="#FFF"
android:text="Wrong PIN"/>
- <!-- Button
+ <Button android:id="@+id/btn_mix"
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=" Mix "/>
</LinearLayout>
@@ -7,6 +7,10 @@
import kankan.wheel.widget.WheelView;
import android.app.Activity;
import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.animation.AnticipateOvershootInterpolator;
+import android.widget.Button;
import android.widget.TextView;
public class PasswActivity extends Activity {
@@ -20,6 +24,16 @@ public void onCreate(Bundle savedInstanceState) {
initWheel(R.id.passw_3);
initWheel(R.id.passw_4);
+ Button mix = (Button)findViewById(R.id.btn_mix);
+ mix.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ mixWheel(R.id.passw_1);
+ mixWheel(R.id.passw_2);
+ mixWheel(R.id.passw_3);
+ mixWheel(R.id.passw_4);
+ }
+ });
+
updateStatus();
}
@@ -28,36 +42,36 @@ public void onCreate(Bundle savedInstanceState) {
// Wheel scrolled listener
OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {
- public void onScrollingStarted(WheelView wheel) {
- wheelScrolled = true;
- }
- public void onScrollingFinished(WheelView wheel) {
- wheelScrolled = false;
- updateStatus();
- }
+ public void onScrollingStarted(WheelView wheel) {
+ wheelScrolled = true;
+ }
+ public void onScrollingFinished(WheelView wheel) {
+ wheelScrolled = false;
+ updateStatus();
+ }
};
// Wheel changed listener
private OnWheelChangedListener changedListener = new OnWheelChangedListener() {
- public void onChanged(WheelView wheel, int oldValue, int newValue) {
- if (!wheelScrolled) {
- updateStatus();
- }
- }
+ public void onChanged(WheelView wheel, int oldValue, int newValue) {
+ if (!wheelScrolled) {
+ updateStatus();
+ }
+ }
};
/**
* Updates entered PIN status
*/
private void updateStatus() {
- TextView text = (TextView) findViewById(R.id.pwd_status);
- if (testPin(2, 4, 6, 1)) {
- text.setText("Congratulation!");
- } else {
- text.setText("Invalid PIN");
- }
+ TextView text = (TextView) findViewById(R.id.pwd_status);
+ if (testPin(2, 4, 6, 1)) {
+ text.setText("Congratulation!");
+ } else {
+ text.setText("Invalid PIN");
+ }
}
-
+
/**
* Initializes wheel
* @param id the wheel widget Id
@@ -70,6 +84,7 @@ private void initWheel(int id) {
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(true);
+ wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
/**
@@ -103,4 +118,13 @@ private boolean testPin(int v1, int v2, int v3, int v4) {
private boolean testWheelValue(int id, int value) {
return getWheel(id).getCurrentItem() == value;
}
+
+ /**
+ * Mixes wheel
+ * @param id the wheel id
+ */
+ private void mixWheel(int id) {
+ WheelView wheel = getWheel(id);
+ wheel.scroll(-25 + (int)(Math.random() * 50), 2000);
+ }
}
@@ -5,6 +5,7 @@
import kankan.wheel.R;
import kankan.wheel.widget.NumericWheelAdapter;
import kankan.wheel.widget.OnWheelChangedListener;
+import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;
import android.app.Activity;
@@ -15,71 +16,92 @@
// Time changed flag
private boolean timeChanged = false;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ //
+ private boolean timeScrolled = false;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
- setContentView(R.layout.time_layout);
-
- final WheelView hours = (WheelView) findViewById(R.id.hour);
- hours.setAdapter(new NumericWheelAdapter(0, 23));
- hours.setLabel("hours");
-
- final WheelView mins = (WheelView) findViewById(R.id.mins);
- mins.setAdapter(new NumericWheelAdapter(0, 59, "%02d"));
- mins.setLabel("mins");
- mins.setCyclic(true);
-
- final TimePicker picker = (TimePicker) findViewById(R.id.time);
- picker.setIs24HourView(true);
-
- // set current time
- Calendar c = Calendar.getInstance();
- int curHours = c.get(Calendar.HOUR_OF_DAY);
- int curMinutes = c.get(Calendar.MINUTE);
-
- hours.setCurrentItem(curHours);
- mins.setCurrentItem(curMinutes);
-
- picker.setCurrentHour(curHours);
- picker.setCurrentMinute(curMinutes);
-
- // add listeners
- addChangingListener(mins, "min");
- addChangingListener(hours, "hour");
-
- OnWheelChangedListener wheelListener = new OnWheelChangedListener() {
+ setContentView(R.layout.time_layout);
+
+ final WheelView hours = (WheelView) findViewById(R.id.hour);
+ hours.setAdapter(new NumericWheelAdapter(0, 23));
+ hours.setLabel("hours");
+
+ final WheelView mins = (WheelView) findViewById(R.id.mins);
+ mins.setAdapter(new NumericWheelAdapter(0, 59, "%02d"));
+ mins.setLabel("mins");
+ mins.setCyclic(true);
+
+ final TimePicker picker = (TimePicker) findViewById(R.id.time);
+ picker.setIs24HourView(true);
+
+ // set current time
+ Calendar c = Calendar.getInstance();
+ int curHours = c.get(Calendar.HOUR_OF_DAY);
+ int curMinutes = c.get(Calendar.MINUTE);
+
+ hours.setCurrentItem(curHours);
+ mins.setCurrentItem(curMinutes);
+
+ picker.setCurrentHour(curHours);
+ picker.setCurrentMinute(curMinutes);
+
+ // add listeners
+ addChangingListener(mins, "min");
+ addChangingListener(hours, "hour");
+
+ OnWheelChangedListener wheelListener = new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue, int newValue) {
- timeChanged = true;
- picker.setCurrentHour(hours.getCurrentItem());
- picker.setCurrentMinute(mins.getCurrentItem());
- timeChanged = false;
+ if (!timeScrolled) {
+ timeChanged = true;
+ picker.setCurrentHour(hours.getCurrentItem());
+ picker.setCurrentMinute(mins.getCurrentItem());
+ timeChanged = false;
+ }
}
};
-
+
hours.addChangingListener(wheelListener);
mins.addChangingListener(wheelListener);
+
+ OnWheelScrollListener scrollListener = new OnWheelScrollListener() {
+ public void onScrollingStarted(WheelView wheel) {
+ timeScrolled = true;
+ }
+ public void onScrollingFinished(WheelView wheel) {
+ timeScrolled = false;
+ timeChanged = true;
+ picker.setCurrentHour(hours.getCurrentItem());
+ picker.setCurrentMinute(mins.getCurrentItem());
+ timeChanged = false;
+ }
+ };
+
+ hours.addScrollingListener(scrollListener);
+ mins.addScrollingListener(scrollListener);
picker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
if (!timeChanged) {
- hours.setCurrentItem(hourOfDay);
- mins.setCurrentItem(minute);
+ hours.setCurrentItem(hourOfDay, true);
+ mins.setCurrentItem(minute, true);
}
}
});
- }
-
- /**
- * Adds changing listener for wheel that updates the wheel label
- * @param wheel the wheel
- * @param label the wheel label
- */
- private void addChangingListener(final WheelView wheel, final String label) {
- wheel.addChangingListener(new OnWheelChangedListener() {
+ }
+
+ /**
+ * Adds changing listener for wheel that updates the wheel label
+ * @param wheel the wheel
+ * @param label the wheel label
+ */
+ private void addChangingListener(final WheelView wheel, final String label) {
+ wheel.addChangingListener(new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue, int newValue) {
wheel.setLabel(newValue != 1 ? label + "s" : label);
}
});
- }
+ }
}
Oops, something went wrong.

0 comments on commit 1ba1736

Please sign in to comment.