Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TimeGep method, Some Method Change #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
Expand All @@ -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;
}
}


}
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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;


}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,21 +15,22 @@ 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;
public int mWheelTVSelectorColor = DefaultConfig.TV_SELECTOR_COLOR;
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
Expand Down
11 changes: 11 additions & 0 deletions TimePickerDialog/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="picker_minute">분</string>
<string name="picker_cancel">취소</string>
<string name="picker_day">일</string>
<string name="picker_hour">시</string>
<string name="picker_month">월</string>
<string name="picker_sure">확인</string>
<string name="picker_title">시간선택</string>
<string name="picker_year">년</string>
</resources>