Android Open Source - android-wheel Speed Activity






From Project

Back to project page android-wheel.

License

The source code is released under:

Apache License

If you think the Android project android-wheel listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package kankan.wheel.demo;
/*  w w  w.  j  av a  2  s.com*/
import kankan.wheel.widget.OnWheelChangedListener;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.ArrayWheelAdapter;
import kankan.wheel.widget.adapters.NumericWheelAdapter;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

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

        setContentView(R.layout.speed1_layout);
        final WheelView speed = (WheelView) findViewById(R.id.speed);
        final SpeedAdapter speedAdapter = new SpeedAdapter(this, 245, 5);
        speed.setViewAdapter(speedAdapter);

        final String unitsValues[] = new String[] {
                "km/h",
                "m/h",
                "m/s",
        };

        final WheelView units = (WheelView) findViewById(R.id.units);
        ArrayWheelAdapter<String> unitsAdapter =
            new ArrayWheelAdapter<String>(this, unitsValues);
        unitsAdapter.setItemResource(R.layout.units_item);
        unitsAdapter.setItemTextResource(R.id.text);
        unitsAdapter.setEmptyItemResource(R.layout.units_item);
        units.setViewAdapter(unitsAdapter);
        //units.setVisibleItems(3);

        units.addChangingListener(new OnWheelChangedListener() {
            @Override
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                String value = unitsValues[units.getCurrentItem()];
                speedAdapter.setUnits(" " + value);
                speed.invalidateWheel(false);
            }
        });

        units.setCurrentItem(1);
    }

    /**
     * Speed adapter
     */
    private class SpeedAdapter extends NumericWheelAdapter {
        // Items step value
        private int step;

        /**
         * Constructor
         */
        public SpeedAdapter(Context context, int maxValue, int step) {
            super(context, 0, maxValue / step);
            this.step = step;

            setItemResource(R.layout.wheel_text_item);
            setItemTextResource(R.id.text);
        }

        /**
         * Sets units
         */
        public void setUnits(String units) {
            //this.units = units;
        }

        @Override
        public CharSequence getItemText(int index) {
            if (index >= 0 && index < getItemsCount()) {
                int value = index * step;
                return Integer.toString(value);
            }
            return null;
        }
    }
}




Java Source Code List

kankan.wheel.demo.CitiesActivity.java
kankan.wheel.demo.DateActivity.java
kankan.wheel.demo.PasswActivity.java
kankan.wheel.demo.SlotMachineActivity.java
kankan.wheel.demo.SpeedActivity.java
kankan.wheel.demo.Time2Activity.java
kankan.wheel.demo.TimeActivity.java
kankan.wheel.demo.WheelDemo.java
kankan.wheel.widget.ItemsRange.java
kankan.wheel.widget.OnWheelChangedListener.java
kankan.wheel.widget.OnWheelClickedListener.java
kankan.wheel.widget.OnWheelScrollListener.java
kankan.wheel.widget.WheelAdapter.java
kankan.wheel.widget.WheelRecycle.java
kankan.wheel.widget.WheelScroller.java
kankan.wheel.widget.WheelView.java
kankan.wheel.widget.adapters.AbstractWheelAdapter.java
kankan.wheel.widget.adapters.AbstractWheelTextAdapter.java
kankan.wheel.widget.adapters.AdapterWheel.java
kankan.wheel.widget.adapters.ArrayWheelAdapter.java
kankan.wheel.widget.adapters.NumericWheelAdapter.java
kankan.wheel.widget.adapters.WheelViewAdapter.java