diff --git a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimePickerDialog.java b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimePickerDialog.java index 5e86668..658f3de 100644 --- a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimePickerDialog.java +++ b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimePickerDialog.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.StringRes; import android.support.v4.app.DialogFragment; import android.view.Gravity; import android.view.LayoutInflater; @@ -150,17 +151,17 @@ public Builder setThemeColor(int color) { return this; } - public Builder setCancelStringId(String left) { + public Builder setCancelStringId(@StringRes int left) { mPickerConfig.mCancelString = left; return this; } - public Builder setSureStringId(String right) { + public Builder setSureStringId(@StringRes int right) { mPickerConfig.mSureString = right; return this; } - public Builder setTitleStringId(String title) { + public Builder setTitleStringId(@StringRes int title) { mPickerConfig.mTitleString = title; return this; } @@ -205,27 +206,27 @@ public Builder setCurrentMillseconds(long millseconds) { return this; } - public Builder setYearText(String year){ + public Builder setYearTextId(@StringRes int year){ mPickerConfig.mYear = year; return this; } - public Builder setMonthText(String month){ + public Builder setMonthTextId(@StringRes int month){ mPickerConfig.mMonth = month; return this; } - public Builder setDayText(String day){ + public Builder setDayTextId(@StringRes int day){ mPickerConfig.mDay = day; return this; } - public Builder setHourText(String hour){ + public Builder setHourTextId(@StringRes int hour){ mPickerConfig.mHour = hour; return this; } - public Builder setMinuteText(String minute){ + public Builder setMinuteTextId(@StringRes int minute){ mPickerConfig.mMinute = minute; return this; } @@ -234,6 +235,10 @@ public Builder setCallBack(OnDateSetListener listener) { mPickerConfig.mCallBack = listener; return this; } + public Builder setTimeGap(int timeGap) { + mPickerConfig.mTimeGap = timeGap; + return this; + } public TimePickerDialog build() { return newIntance(mPickerConfig); diff --git a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimeWheel.java b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimeWheel.java index 3ba6588..563027b 100644 --- a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimeWheel.java +++ b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/TimeWheel.java @@ -111,7 +111,7 @@ void initYear() { int minYear = mRepository.getMinYear(); int maxYear = mRepository.getMaxYear(); - mYearAdapter = new NumericWheelAdapter(mContext, minYear, maxYear, PickerContants.FORMAT, mPickerConfig.mYear); + mYearAdapter = new NumericWheelAdapter(mContext, minYear, maxYear, PickerContants.FORMAT, mPickerConfig.mYear, PickerContants.YEAR); mYearAdapter.setConfig(mPickerConfig); year.setViewAdapter(mYearAdapter); year.setCurrentItem(mRepository.getDefaultCalendar().year - minYear); @@ -166,7 +166,7 @@ void updateMonths() { int curYear = getCurrentYear(); int minMonth = mRepository.getMinMonth(curYear); int maxMonth = mRepository.getMaxMonth(curYear); - mMonthAdapter = new NumericWheelAdapter(mContext, minMonth, maxMonth, PickerContants.FORMAT, mPickerConfig.mMonth); + mMonthAdapter = new NumericWheelAdapter(mContext, minMonth, maxMonth, PickerContants.FORMAT, mPickerConfig.mMonth, PickerContants.MONTH); mMonthAdapter.setConfig(mPickerConfig); month.setViewAdapter(mMonthAdapter); @@ -188,7 +188,7 @@ void updateDays() { int maxDay = mRepository.getMaxDay(curYear, curMonth); int minDay = mRepository.getMinDay(curYear, curMonth); - mDayAdapter = new NumericWheelAdapter(mContext, minDay, maxDay, PickerContants.FORMAT, mPickerConfig.mDay); + mDayAdapter = new NumericWheelAdapter(mContext, minDay, maxDay, PickerContants.FORMAT, mPickerConfig.mDay, PickerContants.DAY); mDayAdapter.setConfig(mPickerConfig); day.setViewAdapter(mDayAdapter); @@ -213,7 +213,7 @@ void updateHours() { int minHour = mRepository.getMinHour(curYear, curMonth, curDay); int maxHour = mRepository.getMaxHour(curYear, curMonth, curDay); - mHourAdapter = new NumericWheelAdapter(mContext, minHour, maxHour, PickerContants.FORMAT, mPickerConfig.mHour); + mHourAdapter = new NumericWheelAdapter(mContext, minHour, maxHour, PickerContants.FORMAT, mPickerConfig.mHour, PickerContants.HOUR); mHourAdapter.setConfig(mPickerConfig); hour.setViewAdapter(mHourAdapter); @@ -233,7 +233,8 @@ void updateMinutes() { int minMinute = mRepository.getMinMinute(curYear, curMonth, curDay, curHour); int maxMinute = mRepository.getMaxMinute(curYear, curMonth, curDay, curHour); - mMinuteAdapter = new NumericWheelAdapter(mContext, minMinute, maxMinute, PickerContants.FORMAT, mPickerConfig.mMinute); + mMinuteAdapter = new NumericWheelAdapter(mContext, minMinute, maxMinute, PickerContants.FORMAT + , mPickerConfig.mMinute, PickerContants.MINUTE, mPickerConfig.mTimeGap); mMinuteAdapter.setConfig(mPickerConfig); minute.setViewAdapter(mMinuteAdapter); diff --git a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/adapters/NumericWheelAdapter.java b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/adapters/NumericWheelAdapter.java index 4cb9910..6e5b342 100644 --- a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/adapters/NumericWheelAdapter.java +++ b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/adapters/NumericWheelAdapter.java @@ -17,8 +17,11 @@ package com.jzxiang.pickerview.adapters; import android.content.Context; +import android.support.annotation.StringRes; import android.text.TextUtils; +import com.jzxiang.pickerview.utils.PickerContants; + /** * Numeric Wheel adapter. */ @@ -34,35 +37,23 @@ public class NumericWheelAdapter extends AbstractWheelTextAdapter { */ private static final int DEFAULT_MIN_VALUE = 0; + /** + * The default time gep value + */ + private static final int DEFAULT_MIN_TIME_GEP = 1; + + Context context; // Values private int minValue; private int maxValue; + private int timeGap = DEFAULT_MIN_TIME_GEP; // format private String format; //unit - private String unit; - - - /** - * Constructor - * - * @param context the current context - */ - public NumericWheelAdapter(Context context) { - this(context, DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE); - } - - /** - * Constructor - * - * @param context the current context - * @param minValue the wheel min value - * @param maxValue the wheel max value - */ - public NumericWheelAdapter(Context context, int minValue, int maxValue) { - this(context, minValue, maxValue, null); - } + @StringRes private int unit; + //type + private int type; /** * Constructor @@ -71,9 +62,16 @@ public NumericWheelAdapter(Context context, int minValue, int maxValue) { * @param minValue the wheel min value * @param maxValue the wheel max value * @param format the format string + * @param unit the wheel unit value */ - public NumericWheelAdapter(Context context, int minValue, int maxValue, String format) { - this(context, minValue, maxValue, format, null); + public NumericWheelAdapter(Context context, int minValue, int maxValue, String format, @StringRes int unit, int type) { + super(context); + this.context = context; + this.minValue = minValue; + this.maxValue = maxValue; + this.format = format; + this.unit = unit; + this.type = type; } /** @@ -84,21 +82,30 @@ public NumericWheelAdapter(Context context, int minValue, int maxValue, String f * @param maxValue the wheel max value * @param format the format string * @param unit the wheel unit value + * @param type the wheel type value + * @param type the wheel type value */ - public NumericWheelAdapter(Context context, int minValue, int maxValue, String format, String unit) { + public NumericWheelAdapter(Context context, int minValue, int maxValue, String format, @StringRes int unit, int type, int timeGap) { super(context); + this.context = context; this.minValue = minValue; this.maxValue = maxValue; this.format = format; this.unit = unit; + this.type = type; + this.timeGap = timeGap; } @Override public CharSequence getItemText(int index) { if (index >= 0 && index < getItemsCount()) { int value = minValue + index; + + if(type == PickerContants.MINUTE) { + value = minValue + (index * timeGap); + } String text = !TextUtils.isEmpty(format) ? String.format(format, value) : Integer.toString(value); - text = TextUtils.isEmpty(unit) ? text : text + unit; + text = TextUtils.isEmpty(context.getString(unit)) ? text : text + context.getString(unit); return text; } @@ -107,8 +114,10 @@ public CharSequence getItemText(int index) { @Override public int getItemsCount() { - return maxValue - minValue + 1; + if(type == PickerContants.MINUTE) { + return (( maxValue - minValue) / timeGap) + 1; + } else { + return maxValue - minValue + 1; + } } - - } diff --git a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/DefaultConfig.java b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/DefaultConfig.java index 4a43b34..dc82f57 100644 --- a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/DefaultConfig.java +++ b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/DefaultConfig.java @@ -1,5 +1,8 @@ package com.jzxiang.pickerview.config; +import android.support.annotation.StringRes; + +import com.jzxiang.pickerview.R; import com.jzxiang.pickerview.data.Type; /** @@ -13,14 +16,15 @@ public class DefaultConfig { public static final int TV_SELECTOR_COLOR = 0XFF404040; public static final int TV_SIZE = 12; public static final boolean CYCLIC = true; - public static String CANCEL = "取消"; - public static String SURE = "确定"; - public static String TITLE = "TimePicker"; - public static String YEAR = "年"; - public static String MONTH = "月"; - public static String DAY = "日"; - public static String HOUR = "时"; - public static String MINUTE = "分"; + @StringRes public static int CANCEL = R.string.picker_cancel; + @StringRes public static int SURE = R.string.picker_sure; + @StringRes public static int TITLE = R.string.picker_title; + @StringRes public static int YEAR = R.string.picker_year; + @StringRes public static int MONTH = R.string.picker_month; + @StringRes public static int DAY = R.string.picker_day; + @StringRes public static int HOUR = R.string.picker_hour; + @StringRes public static int MINUTE = R.string.picker_minute; + public static int TIMEGAP = 1; } diff --git a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/PickerConfig.java b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/PickerConfig.java index ad3be79..8b70068 100644 --- a/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/PickerConfig.java +++ b/TimePickerDialog/src/main/java/com/jzxiang/pickerview/config/PickerConfig.java @@ -1,5 +1,7 @@ package com.jzxiang.pickerview.config; +import android.support.annotation.StringRes; + import com.jzxiang.pickerview.data.Type; import com.jzxiang.pickerview.data.WheelCalendar; import com.jzxiang.pickerview.listener.OnDateSetListener; @@ -13,9 +15,9 @@ public class PickerConfig { public Type mType = DefaultConfig.TYPE; public int mThemeColor = DefaultConfig.COLOR; - public String mCancelString = DefaultConfig.CANCEL; - public String mSureString = DefaultConfig.SURE; - public String mTitleString = DefaultConfig.TITLE; + @StringRes public int mCancelString = DefaultConfig.CANCEL; + @StringRes public int mSureString = DefaultConfig.SURE; + @StringRes public int mTitleString = DefaultConfig.TITLE; public int mToolBarTVColor = DefaultConfig.TOOLBAR_TV_COLOR; public int mWheelTVNormalColor = DefaultConfig.TV_NORMAL_COLOR; @@ -23,11 +25,12 @@ public class PickerConfig { public int mWheelTVSize = DefaultConfig.TV_SIZE; public boolean cyclic = DefaultConfig.CYCLIC; - public String mYear = DefaultConfig.YEAR; - public String mMonth = DefaultConfig.MONTH; - public String mDay = DefaultConfig.DAY; - public String mHour = DefaultConfig.HOUR; - public String mMinute = DefaultConfig.MINUTE; + @StringRes public int mYear = DefaultConfig.YEAR; + @StringRes public int mMonth = DefaultConfig.MONTH; + @StringRes public int mDay = DefaultConfig.DAY; + @StringRes public int mHour = DefaultConfig.HOUR; + @StringRes public int mMinute = DefaultConfig.MINUTE; + public int mTimeGap = DefaultConfig.TIMEGAP; /** * The min timeMillseconds diff --git a/TimePickerDialog/src/main/res/values-ko/strings.xml b/TimePickerDialog/src/main/res/values-ko/strings.xml new file mode 100644 index 0000000..c4a8006 --- /dev/null +++ b/TimePickerDialog/src/main/res/values-ko/strings.xml @@ -0,0 +1,11 @@ + + + + 취소 + + + + 확인 + 시간선택 + + \ No newline at end of file