use of cn.qqtheme.framework.widget.WheelView in project AndroidPicker by gzu-liyujiang.
the class AddressPicker method makeCenterView.
@NonNull
@Override
protected View makeCenterView() {
if (null == provider) {
throw new IllegalArgumentException("please set address provider before make view");
}
if (hideCounty) {
hideProvince = false;
}
int[] widths = getColumnWidths(hideProvince || hideCounty);
int provinceWidth = widths[0];
int cityWidth = widths[1];
int countyWidth = widths[2];
if (hideProvince) {
provinceWidth = 0;
cityWidth = widths[0];
countyWidth = widths[1];
}
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.CENTER);
final WheelView provinceView = new WheelView(activity);
provinceView.setLayoutParams(new LinearLayout.LayoutParams(provinceWidth, WRAP_CONTENT));
provinceView.setTextSize(textSize);
provinceView.setTextColor(textColorNormal, textColorFocus);
provinceView.setLineConfig(lineConfig);
provinceView.setOffset(offset);
provinceView.setCycleDisable(cycleDisable);
layout.addView(provinceView);
if (hideProvince) {
provinceView.setVisibility(View.GONE);
}
final WheelView cityView = new WheelView(activity);
cityView.setLayoutParams(new LinearLayout.LayoutParams(cityWidth, WRAP_CONTENT));
cityView.setTextSize(textSize);
cityView.setTextColor(textColorNormal, textColorFocus);
cityView.setLineConfig(lineConfig);
cityView.setOffset(offset);
cityView.setCycleDisable(cycleDisable);
layout.addView(cityView);
final WheelView countyView = new WheelView(activity);
countyView.setLayoutParams(new LinearLayout.LayoutParams(countyWidth, WRAP_CONTENT));
countyView.setTextSize(textSize);
countyView.setTextColor(textColorNormal, textColorFocus);
countyView.setLineConfig(lineConfig);
countyView.setOffset(offset);
countyView.setCycleDisable(cycleDisable);
layout.addView(countyView);
if (hideCounty) {
countyView.setVisibility(View.GONE);
}
provinceView.setItems(provider.provideFirstData(), selectedFirstIndex);
provinceView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedFirstItem = item;
selectedFirstIndex = index;
if (onWheelListener != null) {
onWheelListener.onProvinceWheeled(selectedFirstIndex, selectedFirstItem);
}
if (!isUserScroll) {
return;
}
LogUtils.verbose(this, "change cities after province wheeled");
//重置地级索引
selectedSecondIndex = 0;
//重置县级索引
selectedThirdIndex = 0;
//根据省份获取地市
List<String> cities = provider.provideSecondData(selectedFirstIndex);
if (cities.size() > 0) {
cityView.setItems(cities, selectedSecondIndex);
} else {
cityView.setItems(new ArrayList<String>());
}
//根据地市获取区县
List<String> counties = provider.provideThirdData(selectedFirstIndex, selectedSecondIndex);
if (counties.size() > 0) {
countyView.setItems(counties, selectedThirdIndex);
} else {
countyView.setItems(new ArrayList<String>());
}
}
});
cityView.setItems(provider.provideSecondData(selectedFirstIndex), selectedSecondIndex);
cityView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedSecondItem = item;
selectedSecondIndex = index;
if (onWheelListener != null) {
onWheelListener.onCityWheeled(selectedSecondIndex, selectedSecondItem);
}
if (!isUserScroll) {
return;
}
LogUtils.verbose(this, "change counties after city wheeled");
//重置县级索引
selectedThirdIndex = 0;
//根据地市获取区县
List<String> counties = provider.provideThirdData(selectedFirstIndex, selectedSecondIndex);
if (counties.size() > 0) {
//若不是用户手动滚动,说明联动需要指定默认项
countyView.setItems(counties, selectedThirdIndex);
} else {
countyView.setItems(new ArrayList<String>());
}
}
});
countyView.setItems(provider.provideThirdData(selectedFirstIndex, selectedSecondIndex), selectedThirdIndex);
countyView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedThirdItem = item;
selectedThirdIndex = index;
if (onWheelListener != null) {
onWheelListener.onCountyWheeled(selectedThirdIndex, selectedThirdItem);
}
}
});
return layout;
}
use of cn.qqtheme.framework.widget.WheelView in project AndroidPicker by gzu-liyujiang.
the class LinkagePicker method makeCenterView.
@NonNull
@Override
protected View makeCenterView() {
if (null == provider) {
throw new IllegalArgumentException("please set data provider before make view");
}
int[] widths = getColumnWidths(provider.isOnlyTwo());
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.CENTER);
final WheelView firstView = new WheelView(activity);
firstView.setTextSize(textSize);
firstView.setTextColor(textColorNormal, textColorFocus);
firstView.setLineConfig(lineConfig);
firstView.setOffset(offset);
firstView.setCycleDisable(cycleDisable);
layout.addView(firstView);
if (TextUtils.isEmpty(firstLabel)) {
firstView.setLayoutParams(new LinearLayout.LayoutParams(widths[0], WRAP_CONTENT));
} else {
firstView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(firstLabel);
layout.addView(labelView);
}
final WheelView secondView = new WheelView(activity);
secondView.setTextSize(textSize);
secondView.setTextColor(textColorNormal, textColorFocus);
secondView.setLineConfig(lineConfig);
secondView.setOffset(offset);
secondView.setCycleDisable(cycleDisable);
layout.addView(secondView);
if (TextUtils.isEmpty(secondLabel)) {
secondView.setLayoutParams(new LinearLayout.LayoutParams(widths[1], WRAP_CONTENT));
} else {
secondView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(secondLabel);
layout.addView(labelView);
}
final WheelView thirdView = new WheelView(activity);
if (!provider.isOnlyTwo()) {
thirdView.setTextSize(textSize);
thirdView.setTextColor(textColorNormal, textColorFocus);
thirdView.setLineConfig(lineConfig);
thirdView.setOffset(offset);
thirdView.setCycleDisable(cycleDisable);
layout.addView(thirdView);
if (TextUtils.isEmpty(thirdLabel)) {
thirdView.setLayoutParams(new LinearLayout.LayoutParams(widths[2], WRAP_CONTENT));
} else {
thirdView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(thirdLabel);
layout.addView(labelView);
}
}
firstView.setItems(provider.provideFirstData(), selectedFirstIndex);
firstView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedFirstItem = item;
selectedFirstIndex = index;
if (onWheelListener != null) {
onWheelListener.onFirstWheeled(selectedFirstIndex, selectedFirstItem);
}
if (!isUserScroll) {
return;
}
LogUtils.verbose(this, "change second data after first wheeled");
//重置第二级索引
selectedSecondIndex = 0;
//重置第三级索引
selectedThirdIndex = 0;
//根据第一级数据获取第二级数据
List<String> secondData = provider.provideSecondData(selectedFirstIndex);
secondView.setItems(secondData, selectedSecondIndex);
if (provider.isOnlyTwo()) {
//仅仅二级联动
return;
}
//根据第二级数据获取第三级数据
List<String> thirdData = provider.provideThirdData(selectedFirstIndex, selectedSecondIndex);
thirdView.setItems(thirdData, selectedThirdIndex);
}
});
secondView.setItems(provider.provideSecondData(selectedFirstIndex), selectedSecondIndex);
secondView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedSecondItem = item;
selectedSecondIndex = index;
if (onWheelListener != null) {
onWheelListener.onSecondWheeled(selectedSecondIndex, selectedSecondItem);
}
if (!isUserScroll) {
return;
}
if (provider.isOnlyTwo()) {
//仅仅二级联动
return;
}
LogUtils.verbose(this, "change third data after second wheeled");
//重置第三级索引
selectedThirdIndex = 0;
List<String> thirdData = provider.provideThirdData(selectedFirstIndex, selectedSecondIndex);
//根据第二级数据获取第三级数据
thirdView.setItems(thirdData, selectedThirdIndex);
}
});
if (provider.isOnlyTwo()) {
//仅仅二级联动
return layout;
}
thirdView.setItems(provider.provideThirdData(selectedFirstIndex, selectedSecondIndex), selectedThirdIndex);
thirdView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedThirdItem = item;
selectedThirdIndex = index;
if (onWheelListener != null) {
onWheelListener.onThirdWheeled(selectedThirdIndex, selectedThirdItem);
}
}
});
return layout;
}
use of cn.qqtheme.framework.widget.WheelView in project AndroidPicker by gzu-liyujiang.
the class DateTimePicker method makeCenterView.
@NonNull
@Override
protected View makeCenterView() {
// 如果未设置默认项,则需要在此初始化数据
if ((dateMode == YEAR_MONTH_DAY || dateMode == YEAR_MONTH) && years.size() == 0) {
LogUtils.verbose(this, "init years before make view");
initYearData();
}
if (dateMode != NONE && months.size() == 0) {
LogUtils.verbose(this, "init months before make view");
int selectedYear = DateUtils.trimZero(getSelectedYear());
changeMonthData(selectedYear);
}
if ((dateMode == YEAR_MONTH_DAY || dateMode == MONTH_DAY) && days.size() == 0) {
LogUtils.verbose(this, "init days before make view");
int selectedYear;
if (dateMode == YEAR_MONTH_DAY) {
selectedYear = DateUtils.trimZero(getSelectedYear());
} else {
selectedYear = Calendar.getInstance(Locale.CHINA).get(Calendar.YEAR);
}
int selectedMonth = DateUtils.trimZero(getSelectedMonth());
changeDayData(selectedYear, selectedMonth);
}
if (timeMode != NONE && hours.size() == 0) {
LogUtils.verbose(this, "init hours before make view");
initHourData();
}
if (timeMode != NONE && minutes.size() == 0) {
LogUtils.verbose(this, "init minutes before make view");
changeMinuteData(DateUtils.trimZero(selectedHour));
}
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.CENTER);
final WheelView yearView = new WheelView(activity);
final WheelView monthView = new WheelView(activity);
final WheelView dayView = new WheelView(activity);
final WheelView hourView = new WheelView(activity);
final WheelView minuteView = new WheelView(activity);
if (dateMode == YEAR_MONTH_DAY || dateMode == YEAR_MONTH) {
yearView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
yearView.setTextSize(textSize);
yearView.setTextColor(textColorNormal, textColorFocus);
yearView.setLineConfig(lineConfig);
yearView.setOffset(offset);
yearView.setCycleDisable(cycleDisable);
yearView.setItems(years, selectedYearIndex);
yearView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedYearIndex = index;
if (onWheelListener != null) {
onWheelListener.onYearWheeled(selectedYearIndex, item);
}
if (!isUserScroll) {
return;
}
LogUtils.verbose(this, "change months after year wheeled");
//需要根据年份及月份动态计算天数
int selectedYear = DateUtils.trimZero(item);
changeMonthData(selectedYear);
monthView.setItems(months, selectedMonthIndex);
if (months.size() <= selectedMonthIndex) {
selectedMonthIndex = months.size() - 1;
}
changeDayData(selectedYear, DateUtils.trimZero(months.get(selectedMonthIndex)));
dayView.setItems(days, selectedDayIndex);
}
});
layout.addView(yearView);
if (!TextUtils.isEmpty(yearLabel)) {
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(yearLabel);
layout.addView(labelView);
}
}
if (dateMode != NONE) {
monthView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
monthView.setTextSize(textSize);
monthView.setTextColor(textColorNormal, textColorFocus);
monthView.setLineConfig(lineConfig);
monthView.setOffset(offset);
monthView.setCycleDisable(cycleDisable);
monthView.setItems(months, selectedMonthIndex);
monthView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedMonthIndex = index;
if (onWheelListener != null) {
onWheelListener.onMonthWheeled(selectedMonthIndex, item);
}
if (!isUserScroll) {
return;
}
if (dateMode == YEAR_MONTH_DAY || dateMode == MONTH_DAY) {
LogUtils.verbose(this, "change days after month wheeled");
int selectedYear;
if (dateMode == YEAR_MONTH_DAY) {
selectedYear = DateUtils.trimZero(getSelectedYear());
} else {
selectedYear = Calendar.getInstance(Locale.CHINA).get(Calendar.YEAR);
}
changeDayData(selectedYear, DateUtils.trimZero(item));
dayView.setItems(days, selectedDayIndex);
}
}
});
layout.addView(monthView);
if (!TextUtils.isEmpty(monthLabel)) {
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(monthLabel);
layout.addView(labelView);
}
}
if (dateMode == YEAR_MONTH_DAY || dateMode == MONTH_DAY) {
dayView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
dayView.setTextSize(textSize);
dayView.setTextColor(textColorNormal, textColorFocus);
dayView.setLineConfig(lineConfig);
dayView.setOffset(offset);
dayView.setCycleDisable(cycleDisable);
dayView.setItems(days, selectedDayIndex);
dayView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedDayIndex = index;
if (onWheelListener != null) {
onWheelListener.onDayWheeled(selectedDayIndex, item);
}
}
});
layout.addView(dayView);
if (!TextUtils.isEmpty(dayLabel)) {
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(dayLabel);
layout.addView(labelView);
}
}
if (timeMode != NONE) {
hourView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
hourView.setTextSize(textSize);
hourView.setTextColor(textColorNormal, textColorFocus);
hourView.setLineConfig(lineConfig);
hourView.setCycleDisable(cycleDisable);
hourView.setItems(hours, selectedHour);
hourView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedHour = item;
if (onWheelListener != null) {
onWheelListener.onHourWheeled(index, item);
}
if (!isUserScroll) {
return;
}
LogUtils.verbose(this, "change minutes after hour wheeled");
changeMinuteData(DateUtils.trimZero(item));
minuteView.setItems(minutes, selectedMinute);
}
});
layout.addView(hourView);
if (!TextUtils.isEmpty(hourLabel)) {
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(hourLabel);
layout.addView(labelView);
}
minuteView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
minuteView.setTextSize(textSize);
minuteView.setTextColor(textColorNormal, textColorFocus);
minuteView.setLineConfig(lineConfig);
minuteView.setOffset(offset);
minuteView.setCycleDisable(cycleDisable);
minuteView.setItems(minutes, selectedMinute);
minuteView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedMinute = item;
if (onWheelListener != null) {
onWheelListener.onMinuteWheeled(index, item);
}
}
});
layout.addView(minuteView);
if (!TextUtils.isEmpty(minuteLabel)) {
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextSize(textSize);
labelView.setTextColor(textColorFocus);
labelView.setText(minuteLabel);
layout.addView(labelView);
}
}
return layout;
}
use of cn.qqtheme.framework.widget.WheelView in project AndroidPicker by gzu-liyujiang.
the class NestActivity method setContentViewAfter.
@Override
protected void setContentViewAfter(View contentView) {
final TextView textView = findView(R.id.wheelview_tips);
WheelView wheelView = findView(R.id.wheelview_single);
wheelView.setItems(new String[] { "少数民族", "贵州穿青人", "不在56个少数民族之列", "第57个民族" }, 1);
wheelView.setTextColor(0xFFFF00FF);
WheelView.LineConfig config = new WheelView.LineConfig();
//线颜色
config.setColor(0xFFFF00FF);
//线透明度
config.setAlpha(100);
//线比率
config.setRatio((float) (1.0 / 10.0));
//线粗
config.setThick(ConvertUtils.toPx(this, 10));
wheelView.setLineConfig(config);
wheelView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
textView.setText("index=" + index + ",item=" + item);
}
});
picker = new CarNumberPicker(this);
picker.setOffset(3);
picker.setOnWheelListener(new CarNumberPicker.OnWheelListener() {
@Override
public void onFirstWheeled(int index, String item) {
textView.setText(item + ":" + picker.getSelectedSecondItem());
}
@Override
public void onSecondWheeled(int index, String item) {
textView.setText(picker.getSelectedFirstItem() + ":" + item);
}
});
ViewGroup viewGroup = findView(R.id.wheelview_container);
viewGroup.addView(picker.getContentView());
findViewById(R.id.nest_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
findViewById(R.id.nest_carnumber).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
picker.show();
}
});
}
use of cn.qqtheme.framework.widget.WheelView in project AndroidPicker by gzu-liyujiang.
the class SinglePicker method makeCenterView.
@Override
@NonNull
protected View makeCenterView() {
if (items.size() == 0) {
throw new IllegalArgumentException("please initial items at first, can't be empty");
}
LinearLayout layout = new LinearLayout(activity);
layout.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.CENTER);
wheelView = new WheelView(activity);
wheelView.setTextSize(textSize);
wheelView.setTextColor(textColorNormal, textColorFocus);
wheelView.setLineConfig(lineConfig);
wheelView.setOffset(offset);
wheelView.setCycleDisable(cycleDisable);
layout.addView(wheelView);
if (TextUtils.isEmpty(label)) {
wheelView.setLayoutParams(new LinearLayout.LayoutParams(screenWidthPixels, WRAP_CONTENT));
} else {
wheelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextColor(textColorFocus);
labelView.setTextSize(textSize);
labelView.setText(label);
layout.addView(labelView);
}
wheelView.setItems(itemStrings, selectedItemIndex);
wheelView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
public void onSelected(boolean isUserScroll, int index, String item) {
selectedItemIndex = index;
if (onWheelListener != null) {
onWheelListener.onWheeled(selectedItemIndex, item);
}
}
});
if (itemWidth != ITEM_WIDTH_UNKNOWN) {
int width = ConvertUtils.toPx(activity, itemWidth);
wheelView.setLayoutParams(new LinearLayout.LayoutParams(width, wheelView.getLayoutParams().height));
}
return layout;
}
Aggregations