/** * Creates an wheelView (Dialog) so the user can set the date and time. Requires wheel_src library * project. * * @param Context to show in * @param Time to show in milliseconds * @return Dialog */ public Dialog showDateDialog(Context in, long timeinms) { Dialog timeDialog = new Dialog(in); timeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); timeDialog.setContentView(R.layout.time2_layout); LayoutParams params = timeDialog.getWindow().getAttributes(); params.width = LayoutParams.FILL_PARENT; timeDialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); boolean tf = false; tf = sp.getBoolean("prefs_time_24", true); int nhours = 23; int startH = 0; if (tf) { nhours = 23; startH = 0; } else { startH = 1; nhours = 12; } final WheelView hours = (WheelView) timeDialog.findViewById(R.id.hour); NumericWheelAdapter hourAdapter = new NumericWheelAdapter(TimeClock.this, startH, nhours); hourAdapter.setItemResource(R.layout.wheel_text_item); hourAdapter.setItemTextResource(R.id.text); hours.setViewAdapter(hourAdapter); final WheelView mins = (WheelView) timeDialog.findViewById(R.id.mins); NumericWheelAdapter minAdapter = new NumericWheelAdapter(TimeClock.this, 0, 59, "%02d"); minAdapter.setItemResource(R.layout.wheel_text_item); minAdapter.setItemTextResource(R.id.text); mins.setViewAdapter(minAdapter); mins.setCyclic(true); final WheelView ampm = (WheelView) timeDialog.findViewById(R.id.ampm); ArrayWheelAdapter<String> ampmAdapter = new ArrayWheelAdapter<String>(TimeClock.this, new String[] {"AM", "PM"}); ampmAdapter.setItemResource(R.layout.wheel_text_item); ampmAdapter.setItemTextResource(R.id.text); ampm.setViewAdapter(ampmAdapter); // set current time Calendar calendar = Calendar.getInstance(Locale.US); calendar.setTimeInMillis(timeinms); mins.setCurrentItem(calendar.get(Calendar.MINUTE)); ampm.setCurrentItem(calendar.get(Calendar.AM_PM)); if (tf) { hours.setCurrentItem(calendar.get(Calendar.HOUR_OF_DAY)); ampm.setVisibility(View.GONE); } else { hours.setCurrentItem(calendar.get(Calendar.HOUR) - 1); ampm.setVisibility(View.VISIBLE); } final WheelView day = (WheelView) timeDialog.findViewById(R.id.day); day.setViewAdapter(new DayArrayAdapter(TimeClock.this, calendar)); day.setCurrentItem(20); return timeDialog; }
private Dialog createDialog() { Dialog dialog = new Dialog(this, R.style.NobackDialog); View view = LayoutInflater.from(this).inflate(R.layout.dialog_time_picker, null); Button btn_submit = (Button) view.findViewById(R.id.btn_dialog_submit); final WheelView hours = (WheelView) view.findViewById(R.id.wheel_hour); hours.setViewAdapter(new NumericWheelAdapter(this, 0, 23)); hours.setCyclic(true); final WheelView mins = (WheelView) view.findViewById(R.id.wheel_mins); mins.setViewAdapter(new NumericWheelAdapter(this, 0, 59, "%02d")); mins.setCyclic(true); int curHours = 0; int curMinutes = 0; Map<String, uSDKDeviceAttribute> attrs = mDevice.getAttributeMap(); switch (mCurrentType) { case 1: if (!TextUtils.isEmpty(getTime(attrs, 1))) { curHours = Integer.parseInt(getTime(attrs, 1).split(":")[0]); curMinutes = Integer.parseInt(getTime(attrs, 1).split(":")[1]); } break; case 2: if (!TextUtils.isEmpty(getTime(attrs, 2))) { curHours = Integer.parseInt(getTime(attrs, 2).split(":")[0]); curMinutes = Integer.parseInt(getTime(attrs, 2).split(":")[1]); } break; } hours.setCurrentItem(curHours); mins.setCurrentItem(curMinutes); OnWheelClickedListener click = new OnWheelClickedListener() { public void onItemClicked(WheelView wheel, int itemIndex) { wheel.setCurrentItem(itemIndex, true); } }; hours.addClickingListener(click); mins.addClickingListener(click); btn_submit.setOnClickListener( new OnClickListener() { public void onClick(View v) { mSetTime = formatTime(hours.getCurrentItem(), mins.getCurrentItem()); mDialog.dismiss(); switch (mCurrentType) { case 1: mSetTime0 = mSetTime; mOvenTime.setText(mSetTime0); sendCommand(mDevice, "20v00f", mSetTime0); break; } } }); dialog.setContentView(view); dialog.setCanceledOnTouchOutside(true); return dialog; }
/** * Scrolls the wheel * * @param delta the scrolling value */ private void doScroll(int delta) { scrollingOffset += delta; int itemHeight = getItemHeight(); int count = scrollingOffset / itemHeight; int pos = currentItem - count; int itemCount = viewAdapter.getItemsCount(); int fixPos = scrollingOffset % itemHeight; if (Math.abs(fixPos) <= itemHeight / 2) { fixPos = 0; } if (isCyclic && itemCount > 0) { if (fixPos > 0) { pos--; count++; } else if (fixPos < 0) { pos++; count--; } // fix position by rotating while (pos < 0) { pos += itemCount; } pos %= itemCount; } else { // if (pos < 0) { count = currentItem; pos = 0; } else if (pos >= itemCount) { count = currentItem - itemCount + 1; pos = itemCount - 1; } else if (pos > 0 && fixPos > 0) { pos--; count++; } else if (pos < itemCount - 1 && fixPos < 0) { pos++; count--; } } int offset = scrollingOffset; if (pos != currentItem) { setCurrentItem(pos, false); } else { invalidate(); } // update offset scrollingOffset = offset - count * itemHeight; if (scrollingOffset > getHeight()) { scrollingOffset = scrollingOffset % getHeight() + getHeight(); } }
void updateReps(WheelView reps) { // Calendar calendar = Calendar.getInstance(); // calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + year.getCurrentItem()); // calendar.set(Calendar.MONTH, month.getCurrentItem()); int maxReps = 50; reps.setViewAdapter(new DateNumericAdapter(this, 1, maxReps, 10)); int curDay = Math.min(maxReps, reps.getCurrentItem() + 1); reps.setCurrentItem(curDay - 1, true); }
void updateWhight(WheelView wheight) { // Calendar calendar = Calendar.getInstance(); // calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + year.getCurrentItem()); // calendar.set(Calendar.MONTH, month.getCurrentItem()); int maxDays = 500; wheight.setViewAdapter(new DateNumericAdapter(this, 1, maxDays, 100)); int curDay = Math.min(maxDays, wheight.getCurrentItem() + 1); wheight.setCurrentItem(curDay - 1, true); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_squat); final WheelView whight = (WheelView) findViewById(R.id.whight); final WheelView reps = (WheelView) findViewById(R.id.reps); OnWheelChangedListener listener = new OnWheelChangedListener() { public void onChanged(WheelView wheel, int oldValue, int newValue) { updateWhight(whight); } }; updateWhight(whight); whight.setCurrentItem(100); updateReps(reps); reps.setCurrentItem(5); }
/** * Update chapter wheel by users hand scrolling * * @param wheel * @param total */ private void updateChapterWheel(WheelView wheel, int total) { // Get String which is in current wheel position String[] totalItems = new String[total]; for (int i = 0; i < total; i++) totalItems[i] = (String.valueOf(i + 1)); // Make Adapter // Set String and position ArrayWheelAdapter<String> adapter = new ArrayWheelAdapter<String>(this, totalItems); adapter.setTextSize(18); wheel.setViewAdapter(adapter); wheel.setCurrentItem(0); }
/** * Update verse wheel by users hand scrolling * * @param wheel * @param bid * @param chpid */ private void updateVerseWheel(WheelView wheel, int bid, int chpid) { // Get total verse Strings from DB int versetotal = databaseManager.getVerseCount(bid, chpid); String[] totalItems = new String[versetotal]; for (int i = 0; i < versetotal; i++) totalItems[i] = (String.valueOf(i + 1)); // Make Adapter // Set String and position ArrayWheelAdapter<String> adapter = new ArrayWheelAdapter<String>(this, totalItems); adapter.setTextSize(18); wheel.setViewAdapter(adapter); wheel.setCurrentItem(0); }
public TimeSelectManager(Context context) { this.context = context; view = LayoutInflater.from(context).inflate(R.layout.time_select_layout, null); view.findViewById(R.id.empty).setOnClickListener(this); view.findViewById(R.id.cancel).setOnClickListener(this); view.findViewById(R.id.sure).setOnClickListener(this); hours = (WheelView) view.findViewById(R.id.hour); NumericWheelAdapter hourAdapter = new NumericWheelAdapter(context, 0, 23, "%s时"); hourAdapter.setItemResource(R.layout.wheel_text_item); hourAdapter.setItemTextResource(R.id.text); hours.setViewAdapter(hourAdapter); // final WheelView mins = (WheelView) view.findViewById(R.id.mins); // NumericWheelAdapter minAdapter = new NumericWheelAdapter(context, 0, 59, "%02d"); // minAdapter.setItemResource(R.layout.wheel_text_item); // minAdapter.setItemTextResource(R.id.text); // mins.setViewAdapter(minAdapter); // mins.setCyclic(true); // // final WheelView ampm = (WheelView) view.findViewById(R.id.ampm); // ArrayWheelAdapter<String> ampmAdapter = // new ArrayWheelAdapter<String>(context, new String[] {"AM", "PM"}); // ampmAdapter.setItemResource(R.layout.wheel_text_item); // ampmAdapter.setItemTextResource(R.id.text); // ampm.setViewAdapter(ampmAdapter); // set current time calendar = Calendar.getInstance(Locale.US); hours.setCurrentItem(calendar.get(Calendar.HOUR)); // mins.setCurrentItem(calendar.get(Calendar.MINUTE)); // ampm.setCurrentItem(calendar.get(Calendar.AM_PM)); day = (WheelView) view.findViewById(R.id.day); day.setViewAdapter(new DayArrayAdapter(context, calendar)); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cities_layout); googleUnits.put("Hour", "hr"); googleUnits.put("Minutes", "minutes"); googleUnits.put("Seconds", "sec"); googleUnits.put("Millisecond", "millisecond"); googleUnits.put("Day", "day"); googleUnits.put("Week", "week"); googleUnits.put("Year", "year"); final String cities[][] = new String[][] { new String[] {"Hour", "Minutes", "Seconds", "Millisecond", "Day", "Week", "Year"} }; BtnCalc = (Button) findViewById(R.id.btnCalc); etFrom = (EditText) findViewById(R.id.edittext_from); etTo = (EditText) findViewById(R.id.edittext_to); final WheelView city = (WheelView) findViewById(R.id.city); final WheelView country = (WheelView) findViewById(R.id.country); BtnCalc.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { String element1 = (String) googleUnits.get(cities[0][country.getCurrentItem()]); String element2 = (String) googleUnits.get(cities[0][city.getCurrentItem()]); System.out.println( country.getCurrentItem() + "selected item in else::" + city.getCurrentItem()); result = etFrom.getText().toString(); new GetData().execute(result + element1 + "=?" + element2); } }); city.setVisibleItems(cities[0].length); updateCities(country, cities, 0); updateCities(city, cities, 0); country.addChangingListener( new OnWheelChangedListener() { public void onChanged(WheelView wheel, int oldValue, int newValue) { if (!scrolling) { updateCities(city, cities, 0); } } }); city.addChangingListener( new OnWheelChangedListener() { public void onChanged(WheelView wheel, int oldValue, int newValue) { if (!scrolling) { System.out.println( "CitiesActivity.onCreate(...).new OnWheelChangedListener() {...}.onChanged()"); } } }); country.addScrollingListener( new OnWheelScrollListener() { public void onScrollingStarted(WheelView wheel) { scrolling = true; } public void onScrollingFinished(WheelView wheel) { scrolling = false; // updateCities(city, cities, country.getCurrentItem()); } }); System.out.println("sElected ::" + 0); country.setCurrentItem(0); etFrom.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) { String element1 = (String) googleUnits.get(cities[0][country.getCurrentItem()]); String element2 = (String) googleUnits.get(cities[0][city.getCurrentItem()]); System.out.println( country.getCurrentItem() + "selected item in else::" + city.getCurrentItem()); result = etFrom.getText().toString(); new GetData().execute(result + element1 + "=?" + element2); } }); }
/** Updates the city wheel */ private void updateCities(WheelView city, String cities[][], int index) { ArrayWheelAdapter<String> adapter = new ArrayWheelAdapter<String>(this, cities[index]); adapter.setTextSize(15); city.setViewAdapter(adapter); city.setCurrentItem(cities[index].length / 2); }
/** * Sets the current item w/o animation. Does nothing when index is wrong. * * @param index the item index */ public void setCurrentItem(int index) { setCurrentItem(index, false); }