From 9590a8924e3fbad72f3985a9f84fa472969d1a0d Mon Sep 17 00:00:00 2001 From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674> Date: 星期三, 03 五月 2017 11:11:48 +0800 Subject: [PATCH] --- VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelViewDialog.java | 302 +++++++ VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/IWheelView.java | 96 ++ VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/ArrayWheelAdapter.java | 53 + VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelView.java | 707 ++++++++++++++++++ VisitFace/DemoForBsk/app/src/main/res/layout/dialog_country.xml | 10 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/WheelDrawable.java | 70 + VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelData.java | 71 + VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/CommonDrawable.java | 101 ++ VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/DrawableFactory.java | 41 + VisitFace/DemoForBsk/app/src/main/res/layout/dialog_date_select.xml | 8 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelConstants.java | 127 +++ VisitFace/DemoForBsk/app/src/main/res/layout/dialog_select.xml | 13 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/AddDialog.java | 4 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/SelectDialog.java | 4 VisitFace/DemoForBsk/app/src/main/res/layout/dialog_add.xml | 4 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/SimpleWheelAdapter.java | 50 + VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelViewException.java | 40 + VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/BaseWheelAdapter.java | 168 ++++ VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/util/WheelUtils.java | 100 ++ VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelItem.java | 111 ++ VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountryDialog.java | 2 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/MyWheelView.java | 24 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/NestedScrollView.java | 63 + VisitFace/DemoForBsk/app/src/main/res/layout/dialog_row.xml | 2 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/HoloDrawable.java | 68 + 25 files changed, 2,218 insertions(+), 21 deletions(-) diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/AddDialog.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/AddDialog.java index 7c07784..b8746a7 100644 --- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/AddDialog.java +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/AddDialog.java @@ -18,8 +18,8 @@ import com.lidroid.xutils.ViewUtils; import com.lidroid.xutils.view.annotation.ViewInject; import com.lidroid.xutils.view.annotation.event.OnClick; -import com.wx.wheelview.adapter.BaseWheelAdapter; -import com.wx.wheelview.widget.WheelView; +import cn.com.basic.face.dialog.wheelview.adapter.BaseWheelAdapter; +import cn.com.basic.face.dialog.wheelview.widget.WheelView; import java.util.ArrayList; import java.util.List; diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountryDialog.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountryDialog.java index 4dee775..e2eb339 100644 --- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountryDialog.java +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountryDialog.java @@ -18,7 +18,7 @@ import com.lidroid.xutils.ViewUtils; import com.lidroid.xutils.view.annotation.ViewInject; import com.lidroid.xutils.view.annotation.event.OnClick; -import com.wx.wheelview.widget.WheelView; +import cn.com.basic.face.dialog.wheelview.widget.WheelView; import java.util.ArrayList; import java.util.HashMap; diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/MyWheelView.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/MyWheelView.java new file mode 100644 index 0000000..bf5ae60 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/MyWheelView.java @@ -0,0 +1,24 @@ +package cn.com.basic.face.dialog; + +import android.content.Context; +import android.util.AttributeSet; + +import cn.com.basic.face.dialog.wheelview.widget.WheelView; + +public class MyWheelView extends WheelView { + public MyWheelView(Context context) { + super(context); + } + + public MyWheelView(Context context, WheelViewStyle style) { + super(context, style); + } + + public MyWheelView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public MyWheelView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/SelectDialog.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/SelectDialog.java index cedd08e..18166fe 100644 --- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/SelectDialog.java +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/SelectDialog.java @@ -22,8 +22,8 @@ import com.lidroid.xutils.ViewUtils; import com.lidroid.xutils.view.annotation.ViewInject; import com.lidroid.xutils.view.annotation.event.OnClick; -import com.wx.wheelview.adapter.BaseWheelAdapter; -import com.wx.wheelview.widget.WheelView; +import cn.com.basic.face.dialog.wheelview.adapter.BaseWheelAdapter; +import cn.com.basic.face.dialog.wheelview.widget.WheelView; import java.util.ArrayList; import java.util.List; diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/ArrayWheelAdapter.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/ArrayWheelAdapter.java new file mode 100644 index 0000000..43b126c --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/ArrayWheelAdapter.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.adapter; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; + +import cn.com.basic.face.dialog.wheelview.adapter.*; +import cn.com.basic.face.dialog.wheelview.widget.WheelItem; + +/** + * 婊氳疆鏁扮粍閫傞厤鍣� + * + * @author venshine + */ +public class ArrayWheelAdapter<T> extends cn.com.basic.face.dialog.wheelview.adapter.BaseWheelAdapter<T> { + + private Context mContext; + + public ArrayWheelAdapter(Context context) { + mContext = context; + } + + @Override + public View bindView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = new WheelItem(mContext); + } + WheelItem wheelItem = (WheelItem) convertView; + T item = getItem(position); + if (wheelItem instanceof CharSequence) { + wheelItem.setText((CharSequence) item); + } else { + wheelItem.setText(item.toString()); + } + return convertView; + } + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/BaseWheelAdapter.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/BaseWheelAdapter.java new file mode 100644 index 0000000..c1624ba --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/BaseWheelAdapter.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.adapter; + +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; + +import cn.com.basic.face.dialog.wheelview.util.WheelUtils; +import cn.com.basic.face.dialog.wheelview.widget.IWheelView; + +import java.util.List; + +/** + * 婊氳疆鎶借薄鏁版嵁閫傞厤鍣� + * + * @author venshine + */ +public abstract class BaseWheelAdapter<T> extends BaseAdapter { + + protected List<T> mList = null; + + protected boolean mLoop = IWheelView.LOOP; + + protected int mWheelSize = IWheelView.WHEEL_SIZE; + + protected boolean mClickable = IWheelView.CLICKABLE; + + private int mCurrentPositon = -1; + + protected abstract View bindView(int position, View convertView, ViewGroup parent); + + /** + * 璁剧疆褰撳墠鍒诲害 + * + * @param position + */ + public final void setCurrentPosition(int position) { + mCurrentPositon = position; + } + + @Override + public final int getCount() { + if (mLoop) { + return Integer.MAX_VALUE; + } + return !WheelUtils.isEmpty(mList) ? (mList.size() + mWheelSize - 1) : 0; + } + + @Override + public final long getItemId(int position) { + return !WheelUtils.isEmpty(mList) ? position % mList.size() : position; + } + + @Override + public final T getItem(int position) { + return !WheelUtils.isEmpty(mList) ? mList.get(position % mList.size()) : null; + } + + @Override + public boolean areAllItemsEnabled() { + return mClickable ? false : true; + } + + @Override + public boolean isEnabled(int position) { + if (mClickable) { + if (mLoop) { + if (position % mList.size() == mCurrentPositon) { + return true; + } + } else { + if (position == (mCurrentPositon + mWheelSize / 2)) { + return true; + } + } + } + return false; + } + + @Override + public final View getView(int position, View convertView, ViewGroup parent) { + if (mLoop) { + position = position % mList.size(); + } else { + if (position < mWheelSize / 2) { + position = -1; + } else if (position >= mWheelSize / 2 + mList.size()) { + position = -1; + } else { + position = position - mWheelSize / 2; + } + } + View view; + if (position == -1) { + view = bindView(0, convertView, parent); + } else { + view = bindView(position, convertView, parent); + } + if (!mLoop) { + if (position == -1) { + view.setVisibility(View.INVISIBLE); + } else { + view.setVisibility(View.VISIBLE); + } + } + return view; + } + + public final BaseWheelAdapter setClickable(boolean clickable) { + if (clickable != mClickable) { + mClickable = clickable; + super.notifyDataSetChanged(); + } + return this; + } + + public final BaseWheelAdapter setLoop(boolean loop) { + if (loop != mLoop) { + mLoop = loop; + super.notifyDataSetChanged(); + } + return this; + } + + public final BaseWheelAdapter setWheelSize(int wheelSize) { + mWheelSize = wheelSize; + super.notifyDataSetChanged(); + return this; + } + + public final BaseWheelAdapter setData(List<T> list) { + mList = list; + super.notifyDataSetChanged(); + return this; + } + + /** + * 鏁版嵁宸叉敼鍙橈紝閲嶇粯鍙鍖哄煙 + */ + @Override + @Deprecated + public final void notifyDataSetChanged() { + super.notifyDataSetChanged(); + } + + /** + * 鏁版嵁澶辨晥锛岄噸缁樻帶浠� + */ + @Override + @Deprecated + public final void notifyDataSetInvalidated() { + super.notifyDataSetInvalidated(); + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/SimpleWheelAdapter.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/SimpleWheelAdapter.java new file mode 100644 index 0000000..6b5bda0 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/adapter/SimpleWheelAdapter.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.adapter; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; + +import cn.com.basic.face.dialog.wheelview.adapter.*; +import cn.com.basic.face.dialog.wheelview.common.WheelData; +import cn.com.basic.face.dialog.wheelview.widget.WheelItem; + +/** + * 婊氳疆鍥剧墖鍜屾枃鏈�傞厤鍣� + * + * @author venshine + */ +public class SimpleWheelAdapter extends cn.com.basic.face.dialog.wheelview.adapter.BaseWheelAdapter<WheelData> { + + private Context mContext; + + public SimpleWheelAdapter(Context context) { + mContext = context; + } + + @Override + public View bindView(int position, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = new WheelItem(mContext); + } + WheelItem item = (WheelItem) convertView; + item.setImage(mList.get(position).getId()); + item.setText(mList.get(position).getName()); + return convertView; + } + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelConstants.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelConstants.java new file mode 100644 index 0000000..432f943 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelConstants.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.common; + +import android.graphics.Color; + +/** + * 婊氳疆甯搁噺绫� + * + * @author venshine + */ +public class WheelConstants { + + /** + * 婊氳疆tag + */ + public static final String TAG = "com.wx.wheelview"; + + /** + * 婊氳疆姣忎竴椤圭殑鍐呰竟璺� + */ + public static final int WHEEL_ITEM_PADDING = 20; + + /** + * 婊氳疆姣忎竴椤圭殑鍐呴儴鎺т欢澶栬竟璺� + */ + public static final int WHEEL_ITEM_MARGIN = 20; + + /** + * 婊氳疆姣忎竴椤圭殑鍥剧墖TAG + */ + public static final int WHEEL_ITEM_IMAGE_TAG = 100; + + /** + * 婊氳疆姣忎竴椤圭殑鏂囨湰TAG + */ + public static final int WHEEL_ITEM_TEXT_TAG = 101; + + /** + * 骞虫粦婊氬姩鎸佺画鏃堕棿 + */ + public static final int WHEEL_SMOOTH_SCROLL_DURATION = 50; + + /** + * 榛樿鑳屾櫙 + */ + public static final int WHEEL_BG = Color.WHITE; + + /** + * common鐨偆榛樿鑳屾櫙 + */ + public static final int WHEEL_SKIN_COMMON_BG = Color.parseColor("#dddddd"); + + /** + * holo鐨偆榛樿鑳屾櫙 + */ + public static final int WHEEL_SKIN_HOLO_BG = Color.WHITE; + + /** + * holo鐨偆榛樿閫変腑妗嗛鑹� + */ + public static final int WHEEL_SKIN_HOLO_BORDER_COLOR = Color.parseColor("#83cde6"); + + /** + * 婊氳疆item楂樺害 + */ + public static final int WHEEL_ITEM_HEIGHT = 45; + + /** + * 婊氳疆榛樿鏂囨湰棰滆壊 + */ + public static final int WHEEL_TEXT_COLOR = Color.BLACK; + + /** + * 婊氳疆榛樿鏂囨湰澶у皬 + */ + public static final int WHEEL_TEXT_SIZE = 16; + + /** + * 婊氳疆榛樿鏂囨湰閫忔槑搴� + */ + public static final float WHEEL_TEXT_ALPHA = 0.7f; + + /** + * common鐨偆榛樿閫変腑妗嗛鑹� + */ + public static final int WHEEL_SKIN_COMMON_COLOR = Color.parseColor("#f0cfcfcf"); + + /** + * common鐨偆閫変腑妗哾ivider棰滆壊 + */ + public static final int WHEEL_SKIN_COMMON_DIVIDER_COLOR = Color.parseColor("#b5b5b5"); + + /** + * common鐨偆宸﹀彸杈规棰滆壊 + */ + public static final int WHEEL_SKIN_COMMON_BORDER_COLOR = Color.parseColor("#666666"); + + /** + * 婊氳疆婊戝姩鏃跺睍绀洪�変腑椤� + */ + public static final int WHEEL_SCROLL_HANDLER_WHAT = 0x0100; + + /** + * 婊氳疆婊戝姩鏃跺睍绀洪�変腑椤瑰欢杩熸椂闂� + */ + public static final int WHEEL_SCROLL_DELAY_DURATION = 300; + + /** + * dialog榛樿棰滆壊 + */ + public static final int DIALOG_WHEEL_COLOR = WHEEL_SKIN_HOLO_BORDER_COLOR; + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelData.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelData.java new file mode 100644 index 0000000..e89523a --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelData.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.common; + +import java.io.Serializable; + +/** + * 婊氳疆鏁版嵁 + * + * @author venshine + */ +public class WheelData implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 璧勬簮id + */ + private int id; + + /** + * 鏁版嵁鍚嶇О + */ + private String name; + + public WheelData() { + } + + public WheelData(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("WheelData{"); + sb.append("id=").append(id); + sb.append(", name='").append(name).append('\''); + sb.append('}'); + return sb.toString(); + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelViewException.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelViewException.java new file mode 100644 index 0000000..9d7bd04 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/common/WheelViewException.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.common; + +/** + * 婊氳疆寮傚父绫� + * + * @author venshine + */ +public class WheelViewException extends RuntimeException { + + public WheelViewException() { + super(); + } + + public WheelViewException(String detailMessage) { + super(detailMessage); + } + + public WheelViewException(String detailMessage, Throwable throwable) { + super(detailMessage, throwable); + } + + public WheelViewException(Throwable throwable) { + super(throwable); + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/CommonDrawable.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/CommonDrawable.java new file mode 100644 index 0000000..c43ce33 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/CommonDrawable.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.graphics; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.drawable.GradientDrawable; + +import cn.com.basic.face.dialog.wheelview.common.WheelConstants; +import cn.com.basic.face.dialog.wheelview.graphics.*; +import cn.com.basic.face.dialog.wheelview.widget.WheelView; + +/** + * common婊氳疆鏍峰紡 + * + * @author venshine + */ +public class CommonDrawable extends cn.com.basic.face.dialog.wheelview.graphics.WheelDrawable { + + private static final int[] SHADOWS_COLORS = + { + 0xFF111111, + 0x00AAAAAA, + 0x00AAAAAA + }; // 闃村奖鑹插�� + + private GradientDrawable mTopShadow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, + SHADOWS_COLORS); // 椤堕儴闃村奖 + + private GradientDrawable mBottomShadow = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, + SHADOWS_COLORS); // 搴曢儴闃村奖 + + private Paint mCommonBgPaint, mCommonPaint, mCommonDividerPaint, mCommonBorderPaint; + + private int mWheelSize, mItemH; + + public CommonDrawable(int width, int height, WheelView.WheelViewStyle style, int wheelSize, int itemH) { + super(width, height, style); + mWheelSize = wheelSize; + mItemH = itemH; + init(); + } + + private void init() { + mCommonBgPaint = new Paint(); + mCommonBgPaint.setColor(mStyle.backgroundColor != -1 ? mStyle.backgroundColor : WheelConstants + .WHEEL_SKIN_COMMON_BG); + + mCommonPaint = new Paint(); + mCommonPaint.setColor(WheelConstants.WHEEL_SKIN_COMMON_COLOR); + + mCommonDividerPaint = new Paint(); + mCommonDividerPaint.setColor(WheelConstants.WHEEL_SKIN_COMMON_DIVIDER_COLOR); + mCommonDividerPaint.setStrokeWidth(2); + + mCommonBorderPaint = new Paint(); + mCommonBorderPaint.setStrokeWidth(6); + mCommonBorderPaint.setColor(WheelConstants.WHEEL_SKIN_COMMON_BORDER_COLOR); + + } + + @Override + public void draw(Canvas canvas) { + // draw background + canvas.drawRect(0, 0, mWidth, mHeight, mCommonBgPaint); + + // draw select border + if (mItemH != 0) { + canvas.drawRect(0, mItemH * (mWheelSize / 2), mWidth, mItemH + * (mWheelSize / 2 + 1), mCommonPaint); + canvas.drawLine(0, mItemH * (mWheelSize / 2), mWidth, mItemH + * (mWheelSize / 2), mCommonDividerPaint); + canvas.drawLine(0, mItemH * (mWheelSize / 2 + 1), mWidth, mItemH + * (mWheelSize / 2 + 1), mCommonDividerPaint); + + // top, bottom + mTopShadow.setBounds(0, 0, mWidth, mItemH); + mTopShadow.draw(canvas); + + mBottomShadow.setBounds(0, mHeight - mItemH, mWidth, mHeight); + mBottomShadow.draw(canvas); + + // left,right + canvas.drawLine(0, 0, 0, mHeight, mCommonBorderPaint); + canvas.drawLine(mWidth, 0, mWidth, mHeight, mCommonBorderPaint); + } + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/DrawableFactory.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/DrawableFactory.java new file mode 100644 index 0000000..aaed69e --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/DrawableFactory.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.graphics; + +import android.graphics.drawable.Drawable; + +import cn.com.basic.face.dialog.wheelview.graphics.*; +import cn.com.basic.face.dialog.wheelview.graphics.HoloDrawable; +import cn.com.basic.face.dialog.wheelview.graphics.WheelDrawable; +import cn.com.basic.face.dialog.wheelview.widget.WheelView; + +/** + * @author venshine + */ +public class DrawableFactory { + + public static Drawable createDrawable(WheelView.Skin skin, int width, int height, WheelView.WheelViewStyle + style, int wheelSize, int itemH) { + if (skin.equals(WheelView.Skin.Common)) { + return new cn.com.basic.face.dialog.wheelview.graphics.CommonDrawable(width, height, style, wheelSize, itemH); + } else if (skin.equals(WheelView.Skin.Holo)) { + return new HoloDrawable(width, height, style, wheelSize, itemH); + } else { + return new WheelDrawable(width, height, style); + } + } + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/HoloDrawable.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/HoloDrawable.java new file mode 100644 index 0000000..73ed844 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/HoloDrawable.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.graphics; + +import android.graphics.Canvas; +import android.graphics.Paint; + +import cn.com.basic.face.dialog.wheelview.common.WheelConstants; +import cn.com.basic.face.dialog.wheelview.graphics.WheelDrawable; +import cn.com.basic.face.dialog.wheelview.widget.WheelView; + +/** + * holo婊氳疆鏍峰紡 + * + * @author venshine + */ +public class HoloDrawable extends WheelDrawable { + + private Paint mHoloBgPaint, mHoloPaint; + + private int mWheelSize, mItemH; + + public HoloDrawable(int width, int height, WheelView.WheelViewStyle style, int wheelSize, int itemH) { + super(width, height, style); + mWheelSize = wheelSize; + mItemH = itemH; + init(); + } + + private void init() { + mHoloBgPaint = new Paint(); + mHoloBgPaint.setColor(mStyle.backgroundColor != -1 ? mStyle.backgroundColor : WheelConstants + .WHEEL_SKIN_HOLO_BG); + + mHoloPaint = new Paint(); + mHoloPaint.setStrokeWidth(mStyle.holoBorderWidth != -1 ? mStyle.holoBorderWidth : 3); + mHoloPaint.setColor(mStyle.holoBorderColor != -1 ? mStyle.holoBorderColor : WheelConstants + .WHEEL_SKIN_HOLO_BORDER_COLOR); + } + + + @Override + public void draw(Canvas canvas) { + // draw background + canvas.drawRect(0, 0, mWidth, mHeight, mHoloBgPaint); + + // draw select border + if (mItemH != 0) { + canvas.drawLine(0, mItemH * (mWheelSize / 2), mWidth, mItemH + * (mWheelSize / 2), mHoloPaint); + canvas.drawLine(0, mItemH * (mWheelSize / 2 + 1), mWidth, mItemH + * (mWheelSize / 2 + 1), mHoloPaint); + } + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/WheelDrawable.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/WheelDrawable.java new file mode 100644 index 0000000..4ba54a6 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/graphics/WheelDrawable.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.graphics; + +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.drawable.Drawable; + +import cn.com.basic.face.dialog.wheelview.common.WheelConstants; +import cn.com.basic.face.dialog.wheelview.widget.WheelView; + +/** + * 婊氳疆鏍峰紡 + * + * @author venshine + */ +public class WheelDrawable extends Drawable { + + protected int mWidth; // 鎺т欢瀹� + + protected int mHeight; // 鎺т欢楂� + + protected WheelView.WheelViewStyle mStyle; + + private Paint mBgPaint; + + public WheelDrawable(int width, int height, WheelView.WheelViewStyle style) { + mWidth = width; + mHeight = height; + mStyle = style; + init(); + } + + private void init() { + mBgPaint = new Paint(); + mBgPaint.setColor(mStyle.backgroundColor != -1 ? mStyle.backgroundColor : WheelConstants.WHEEL_BG); + } + + @Override + public void draw(Canvas canvas) { + canvas.drawRect(0, 0, mWidth, mHeight, mBgPaint); + } + + @Override + public void setAlpha(int alpha) { + } + + @Override + public void setColorFilter(ColorFilter colorFilter) { + } + + @Override + public int getOpacity() { + return 0; + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/util/WheelUtils.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/util/WheelUtils.java new file mode 100644 index 0000000..95065f8 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/util/WheelUtils.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.util; + +import android.content.Context; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.util.Collection; + +/** + * 婊氳疆宸ュ叿绫� + * + * @author venshine + */ +public class WheelUtils { + + private static final String TAG = "WheelView"; + + /** + * 鎵撳嵃鏃ュ織 + * + * @param msg + */ + public static void log(String msg) { + if (!TextUtils.isEmpty(msg)) { + Log.d(TAG, msg); + } + } + + /** + * 鍒ゆ柇闆嗗悎鏄惁涓虹┖ + * + * @param c + * @param <V> + * @return + */ + public static <V> boolean isEmpty(Collection<V> c) { + return (c == null || c.size() == 0); + } + + /** + * 閬嶅巻鏌ユ壘TextView + * + * @param view + * @return + */ + public static TextView findTextView(View view) { + if (view instanceof TextView) { + return (TextView) view; + } else { + if (view instanceof ViewGroup) { + return findTextView(((ViewGroup) view).getChildAt(0)); + } else { + return null; + } + } + } + + /** + * dip杞崲鍒皃x + * + * @param context + * @param dp + * @return + */ + public static int dip2px(Context context, float dp) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dp * scale + 0.5f); + } + + /** + * sp杞崲鍒皃x + * + * @param context + * @param sp + * @return + */ + public static int sp2px(Context context, float sp) { + final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; + return (int) (sp * fontScale + 0.5f); + } + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/IWheelView.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/IWheelView.java new file mode 100644 index 0000000..3c32a61 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/IWheelView.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.widget; + +import cn.com.basic.face.dialog.wheelview.adapter.BaseWheelAdapter; +import cn.com.basic.face.dialog.wheelview.widget.*; + +import java.util.HashMap; +import java.util.List; + +/** + * 婊氳疆鎶借薄鎺ュ彛 + * + * @author venshine + */ +public interface IWheelView<T> { + + /** + * 婊氳疆鏁版嵁鏄惁寰幆锛岄粯璁や笉寰幆 + */ + boolean LOOP = false; + + /** + * 婊氳疆榛樿鏁伴噺 + */ + int WHEEL_SIZE = 3; + + /** + * 婊氳疆閫変腑鍒诲害鏄惁鍙偣鍑� + */ + boolean CLICKABLE = false; + + /** + * 璁剧疆婊氳疆閫変腑鍒诲害鏄惁鍙偣鍑� + * + * @param clickable + */ + void setWheelClickable(boolean clickable); + + /** + * 璁剧疆婊氳疆鏄惁寰幆婊氬姩 + * + * @param loop + */ + void setLoop(boolean loop); + + /** + * 璁剧疆婊氳疆涓暟 + * + * @param wheelSize + */ + void setWheelSize(int wheelSize); + + /** + * 璁剧疆婊氳疆鏁版嵁 + * + * @param list + */ + void setWheelData(List<T> list); + + /** + * 璁剧疆婊氳疆鏁版嵁婧愰�傞厤鍣� + * + * @param adapter + */ + void setWheelAdapter(BaseWheelAdapter<T> adapter); + + /** + * 杩炴帴鍓疻heelView + * + * @param wheelView + */ + void join(cn.com.basic.face.dialog.wheelview.widget.WheelView wheelView); + + /** + * 鍓疻heelView鏁版嵁 + * + * @param map + */ + void joinDatas(HashMap<String, List<T>> map); + + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/NestedScrollView.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/NestedScrollView.java new file mode 100644 index 0000000..061cd56 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/NestedScrollView.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.widget.ScrollView; + +import cn.com.basic.face.dialog.wheelview.common.WheelConstants; +import cn.com.basic.face.dialog.wheelview.widget.*; + +/** + * 宓屽ScrollView + * + * @author venshine + */ +public class NestedScrollView extends ScrollView { + + public NestedScrollView(Context context) { + super(context); + init(); + } + + public NestedScrollView(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public NestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + private void init() { + setOnTouchListener(new OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + cn.com.basic.face.dialog.wheelview.widget.WheelView wv = (cn.com.basic.face.dialog.wheelview.widget.WheelView) findViewWithTag(WheelConstants.TAG); + if (wv != null) { + wv.getParent().requestDisallowInterceptTouchEvent(false); + } + return false; + } + }); + } + + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelItem.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelItem.java new file mode 100644 index 0000000..c4bafd5 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelItem.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.widget; + +import android.content.Context; +import android.graphics.Color; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import cn.com.basic.face.dialog.wheelview.common.WheelConstants; +import cn.com.basic.face.dialog.wheelview.util.WheelUtils; + +/** + * 婊氳疆Item甯冨眬锛屽寘鍚浘鐗囧拰鏂囨湰 + * + * @author venshine + */ +public class WheelItem extends FrameLayout { + + private ImageView mImage; + private TextView mText; + + public WheelItem(Context context) { + super(context); + init(); + } + + public WheelItem(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public WheelItem(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + /** + * 鍒濆鍖� + */ + private void init() { + LinearLayout layout = new LinearLayout(getContext()); + LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, WheelUtils.dip2px(getContext(), + WheelConstants + .WHEEL_ITEM_HEIGHT)); + layout.setOrientation(LinearLayout.HORIZONTAL); + layout.setPadding(WheelConstants.WHEEL_ITEM_PADDING, WheelConstants.WHEEL_ITEM_PADDING, WheelConstants + .WHEEL_ITEM_PADDING, WheelConstants.WHEEL_ITEM_PADDING); + layout.setGravity(Gravity.CENTER); + addView(layout, layoutParams); + + // 鍥剧墖 + mImage = new ImageView(getContext()); + mImage.setTag(WheelConstants.WHEEL_ITEM_IMAGE_TAG); + mImage.setVisibility(View.GONE); + LayoutParams imageParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + imageParams.rightMargin = WheelConstants.WHEEL_ITEM_MARGIN; + layout.addView(mImage, imageParams); + + // 鏂囨湰 + mText = new TextView(getContext()); + mText.setTag(WheelConstants.WHEEL_ITEM_TEXT_TAG); + mText.setEllipsize(TextUtils.TruncateAt.END); + mText.setSingleLine(); + mText.setIncludeFontPadding(false); + mText.setGravity(Gravity.CENTER); + mText.setTextColor(Color.BLACK); + LayoutParams textParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + layout.addView(mText, textParams); + } + + /** + * 璁剧疆鏂囨湰 + * + * @param text + */ + public void setText(CharSequence text) { + mText.setText(text); + } + + /** + * 璁剧疆鍥剧墖璧勬簮 + * + * @param resId + */ + public void setImage(int resId) { + mImage.setVisibility(View.VISIBLE); + mImage.setImageResource(resId); + } + + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelView.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelView.java new file mode 100644 index 0000000..16edfbb --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelView.java @@ -0,0 +1,707 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.widget; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.os.Handler; +import android.os.Message; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.widget.AbsListView; +import android.widget.AdapterView; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import cn.com.basic.face.dialog.wheelview.adapter.ArrayWheelAdapter; +import cn.com.basic.face.dialog.wheelview.adapter.BaseWheelAdapter; +import cn.com.basic.face.dialog.wheelview.adapter.SimpleWheelAdapter; +import cn.com.basic.face.dialog.wheelview.common.WheelConstants; +import cn.com.basic.face.dialog.wheelview.common.WheelViewException; +import cn.com.basic.face.dialog.wheelview.graphics.DrawableFactory; +import cn.com.basic.face.dialog.wheelview.util.WheelUtils; +import cn.com.basic.face.dialog.wheelview.widget.IWheelView; + +import java.util.HashMap; +import java.util.List; + +/** + * 婊氳疆鎺т欢 + * + * @author venshine + */ +public class WheelView<T> extends ListView implements IWheelView<T> { + + private int mItemH = 0; // 姣忎竴椤归珮搴� + private int mWheelSize = WHEEL_SIZE; // 婊氳疆涓暟 + private boolean mLoop = LOOP; // 鏄惁寰幆婊氬姩 + private List<T> mList = null; // 婊氳疆鏁版嵁鍒楄〃 + private int mCurrentPositon = -1; // 璁板綍婊氳疆褰撳墠鍒诲害 + private String mExtraText; // 娣诲姞婊氳疆閫変腑浣嶇疆闄勫姞鏂囨湰 + private int mExtraTextColor; // 闄勫姞鏂囨湰棰滆壊 + private int mExtraTextSize; // 闄勫姞鏂囨湰澶у皬 + private int mExtraMargin; // 闄勫姞鏂囨湰澶栬竟璺� + private int mSelection = 0; // 閫変腑浣嶇疆 + private boolean mClickable = CLICKABLE; // 鏄惁鍙偣鍑� + + private Paint mTextPaint; // 闄勫姞鏂囨湰鐢荤瑪 + + private Skin mSkin = Skin.None; // 鐨偆椋庢牸 + + private WheelViewStyle mStyle; // 婊氳疆鏍峰紡 + + private WheelView mJoinWheelView; // 鍓疻heelView + + private HashMap<String, List<T>> mJoinMap; // 鍓粴杞暟鎹垪琛� + + private BaseWheelAdapter<T> mWheelAdapter; + + private OnWheelItemSelectedListener<T> mOnWheelItemSelectedListener; + + private OnWheelItemClickListener<T> mOnWheelItemClickListener; + + private Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + if (msg.what == WheelConstants.WHEEL_SCROLL_HANDLER_WHAT) { + if (mOnWheelItemSelectedListener != null) { + mOnWheelItemSelectedListener.onItemSelected + (getCurrentPosition(), getSelectionItem()); + } + if (mJoinWheelView != null) { + if (!mJoinMap.isEmpty()) { + mJoinWheelView.resetDataFromTop(mJoinMap.get(mList.get + (getCurrentPosition())) + ); + } else { + throw new WheelViewException("JoinList is error."); + } + } + } + } + }; + + private OnItemClickListener mOnItemClickListener = new OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + if (mOnWheelItemClickListener != null) { + mOnWheelItemClickListener.onItemClick(getCurrentPosition(), getSelectionItem()); + } + } + }; + + private OnTouchListener mTouchListener = new OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + v.getParent().requestDisallowInterceptTouchEvent(true); + return false; + } + }; + + private OnScrollListener mOnScrollListener = new OnScrollListener() { + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + if (scrollState == SCROLL_STATE_IDLE) { + View itemView = getChildAt(0); + if (itemView != null) { + float deltaY = itemView.getY(); + if (deltaY == 0 || mItemH == 0) { + return; + } + if (Math.abs(deltaY) < mItemH / 2) { + int d = getSmoothDistance(deltaY); + smoothScrollBy(d, WheelConstants + .WHEEL_SMOOTH_SCROLL_DURATION); + } else { + int d = getSmoothDistance(mItemH + deltaY); + smoothScrollBy(d, WheelConstants + .WHEEL_SMOOTH_SCROLL_DURATION); + } + } + } + } + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int + visibleItemCount, int totalItemCount) { + if (visibleItemCount != 0) { + refreshCurrentPosition(false); + } + } + }; + + public WheelView(Context context) { + super(context); + init(); + } + + public WheelView(Context context, WheelViewStyle style) { + super(context); + setStyle(style); + init(); + } + + public WheelView(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public WheelView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + /** + * 璁剧疆婊氳疆婊戝姩鍋滄鏃朵簨浠讹紝鐩戝惉婊氳疆閫変腑椤� + * + * @param onWheelItemSelectedListener + */ + public void setOnWheelItemSelectedListener(OnWheelItemSelectedListener<T> + onWheelItemSelectedListener) { + mOnWheelItemSelectedListener = onWheelItemSelectedListener; + } + + /** + * 璁剧疆婊氳疆閫変腑椤圭偣鍑讳簨浠� + * + * @param onWheelItemClickListener + */ + public void setOnWheelItemClickListener(OnWheelItemClickListener<T> onWheelItemClickListener) { + mOnWheelItemClickListener = onWheelItemClickListener; + } + + /** + * 鍒濆鍖� + */ + private void init() { + if (mStyle == null) { + mStyle = new WheelViewStyle(); + } + + mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + + setTag(WheelConstants.TAG); + setVerticalScrollBarEnabled(false); + setScrollingCacheEnabled(false); + setCacheColorHint(Color.TRANSPARENT); + setFadingEdgeLength(0); + setOverScrollMode(OVER_SCROLL_NEVER); + setDividerHeight(0); + setOnItemClickListener(mOnItemClickListener); + setOnScrollListener(mOnScrollListener); + setOnTouchListener(mTouchListener); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + setNestedScrollingEnabled(true); + } + addOnGlobalLayoutListener(); + } + + private void addOnGlobalLayoutListener() { + getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver + .OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + getViewTreeObserver().removeGlobalOnLayoutListener(this); + } + if (getChildCount() > 0 && mItemH == 0) { + mItemH = getChildAt(0).getHeight(); + if (mItemH != 0) { + ViewGroup.LayoutParams params = getLayoutParams(); + params.height = mItemH * mWheelSize; + refreshVisibleItems(getFirstVisiblePosition(), + getCurrentPosition() + mWheelSize / 2, + mWheelSize / 2); + setBackground(); + } else { + throw new WheelViewException("wheel item is error."); + } + } + } + }); + } + + /** + * 鑾峰緱婊氳疆鏍峰紡 + * + * @return + */ + public WheelViewStyle getStyle() { + return mStyle; + } + + /** + * 璁剧疆婊氳疆鏍峰紡 + * + * @param style + */ + public void setStyle(WheelViewStyle style) { + mStyle = style; + } + + /** + * 璁剧疆鑳屾櫙 + */ + private void setBackground() { + Drawable drawable = DrawableFactory.createDrawable(mSkin, getWidth(), + mItemH * mWheelSize, mStyle, mWheelSize, mItemH); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + setBackground(drawable); + } else { + setBackgroundDrawable(drawable); + } + } + + /** + * 鑾峰緱鐨偆椋庢牸 + * + * @return + */ + public Skin getSkin() { + return mSkin; + } + + /** + * 璁剧疆鐨偆椋庢牸 + * + * @param skin + */ + public void setSkin(Skin skin) { + mSkin = skin; + } + + /** + * 璁剧疆婊氳疆涓暟 + * + * @param wheelSize + */ + @Override + public void setWheelSize(int wheelSize) { + if ((wheelSize & 1) == 0) { + throw new WheelViewException("wheel size must be an odd number."); + } + mWheelSize = wheelSize; + if (mWheelAdapter != null) { + mWheelAdapter.setWheelSize(wheelSize); + } + } + + /** + * 璁剧疆婊氳疆鏄惁寰幆婊氬姩 + * + * @param loop + */ + @Override + public void setLoop(boolean loop) { + if (loop != mLoop) { + mLoop = loop; + setSelection(0); + if (mWheelAdapter != null) { + mWheelAdapter.setLoop(loop); + } + } + } + + /** + * 璁剧疆婊氳疆閫変腑椤规槸鍚﹀彲鐐瑰嚮 + * + * @param clickable + */ + @Override + public void setWheelClickable(boolean clickable) { + if (clickable != mClickable) { + mClickable = clickable; + if (mWheelAdapter != null) { + mWheelAdapter.setClickable(clickable); + } + } + } + + /** + * 閲嶇疆鏁版嵁 + * + * @param list + */ + public void resetDataFromTop(final List<T> list) { + if (WheelUtils.isEmpty(list)) { + throw new WheelViewException("join map data is error."); + } + WheelView.this.postDelayed(new Runnable() { + @Override + public void run() { + setWheelData(list); + WheelView.super.setSelection(0); + refreshCurrentPosition(true); + } + }, 10); + } + + /** + * 鑾峰彇婊氳疆浣嶇疆 + * + * @return + */ + public int getSelection() { + return mSelection; + } + + /** + * 璁剧疆婊氳疆浣嶇疆 + * + * @param selection + */ + @Override + public void setSelection(final int selection) { + mSelection = selection; + setVisibility(View.INVISIBLE); + WheelView.this.postDelayed(new Runnable() { + @Override + public void run() { + WheelView.super.setSelection(getRealPosition(selection)); + refreshCurrentPosition(false); + setVisibility(View.VISIBLE); + } + }, 500); + } + + /** + * 杩炴帴鍓疻heelView + * + * @param wheelView + */ + @Override + public void join(WheelView wheelView) { + if (wheelView == null) { + throw new WheelViewException("wheelview cannot be null."); + } + mJoinWheelView = wheelView; + } + + /** + * 鍓疻heelView鏁版嵁 + * + * @param map + */ + public void joinDatas(HashMap<String, List<T>> map) { + mJoinMap = map; + } + + /** + * 鑾峰緱婊氳疆褰撳墠鐪熷疄浣嶇疆 + * + * @param positon + * @return + */ + private int getRealPosition(int positon) { + if (WheelUtils.isEmpty(mList)) { + return 0; + } + if (mLoop) { + int d = Integer.MAX_VALUE / 2 / mList.size(); + return positon + d * mList.size() - mWheelSize / 2; + } + return positon; + } + + /** + * 鑾峰彇褰撳墠婊氳疆浣嶇疆 + * + * @return + */ + public int getCurrentPosition() { + return mCurrentPositon; + } + + /** + * 鑾峰彇褰撳墠婊氳疆浣嶇疆鐨勬暟鎹� + * + * @return + */ + public T getSelectionItem() { + int position = getCurrentPosition(); + position = position < 0 ? 0 : position; + if (mList != null && mList.size() > position) { + return mList.get(position); + } + return null; + } + + /** + * 璁剧疆婊氳疆鏁版嵁閫傞厤鍣紝宸插純鐢紝鍏蜂綋浣跨敤{@link #setWheelAdapter(BaseWheelAdapter)} + * + * @param adapter + */ + @Override + @Deprecated + public void setAdapter(ListAdapter adapter) { + if (adapter != null && adapter instanceof BaseWheelAdapter) { + setWheelAdapter((BaseWheelAdapter) adapter); + } else { + throw new WheelViewException("please invoke setWheelAdapter " + + "method."); + } + } + + /** + * 璁剧疆婊氳疆鏁版嵁婧愰�傞厤鍣� + * + * @param adapter + */ + @Override + public void setWheelAdapter(BaseWheelAdapter<T> adapter) { + super.setAdapter(adapter); + mWheelAdapter = adapter; + mWheelAdapter.setData(mList).setWheelSize(mWheelSize).setLoop(mLoop).setClickable(mClickable); + } + + /** + * 璁剧疆婊氳疆鏁版嵁 + * + * @param list + */ + @Override + public void setWheelData(List<T> list) { + if (WheelUtils.isEmpty(list)) { + throw new WheelViewException("wheel datas are error."); + } + mList = list; + if (mWheelAdapter != null) { + mWheelAdapter.setData(list); + } + } + + /** + * 璁剧疆閫変腑琛岄檮鍔犳枃鏈� + * + * @param text + * @param textColor + * @param textSize + * @param margin + */ + public void setExtraText(String text, int textColor, int textSize, int + margin) { + mExtraText = text; + mExtraTextColor = textColor; + mExtraTextSize = textSize; + mExtraMargin = margin; + } + + /** + * 鑾峰緱婊氳疆鏁版嵁鎬绘暟 + * + * @return + */ + public int getWheelCount() { + return !WheelUtils.isEmpty(mList) ? mList.size() : 0; + } + + /** + * 骞虫粦鐨勬粴鍔ㄨ窛绂� + * + * @param scrollDistance + * @return + */ + private int getSmoothDistance(float scrollDistance) { + if (Math.abs(scrollDistance) <= 2) { + return (int) scrollDistance; + } else if (Math.abs(scrollDistance) < 12) { + return scrollDistance > 0 ? 2 : -2; + } else { + return (int) (scrollDistance / 6); // 鍑忕紦骞虫粦婊戝姩閫熺巼 + } + } + + /** + * 鍒锋柊褰撳墠浣嶇疆 + * + * @param join + */ + private void refreshCurrentPosition(boolean join) { + if (getChildAt(0) == null || mItemH == 0) { + return; + } + int firstPosition = getFirstVisiblePosition(); + if (mLoop && firstPosition == 0) { + return; + } + int position = 0; + if (Math.abs(getChildAt(0).getY()) <= mItemH / 2) { + position = firstPosition; + } else { + position = firstPosition + 1; + } + refreshVisibleItems(firstPosition, position + mWheelSize / 2, + mWheelSize / 2); + if (mLoop) { + position = (position + mWheelSize / 2) % getWheelCount(); + } + if (position == mCurrentPositon && !join) { + return; + } + mCurrentPositon = position; + mWheelAdapter.setCurrentPosition(position); + mHandler.removeMessages(WheelConstants.WHEEL_SCROLL_HANDLER_WHAT); + mHandler.sendEmptyMessageDelayed(WheelConstants + .WHEEL_SCROLL_HANDLER_WHAT, WheelConstants + .WHEEL_SCROLL_DELAY_DURATION); + } + + /** + * 鍒锋柊鍙婊氬姩鍒楄〃 + * + * @param firstPosition + * @param curPosition + * @param offset + */ + private void refreshVisibleItems(int firstPosition, int curPosition, int + offset) { + for (int i = curPosition - offset; i <= curPosition + offset; i++) { + View itemView = getChildAt(i - firstPosition); + if (itemView == null) { + continue; + } + if (mWheelAdapter instanceof ArrayWheelAdapter || mWheelAdapter + instanceof SimpleWheelAdapter) { + TextView textView = (TextView) itemView.findViewWithTag + (WheelConstants.WHEEL_ITEM_TEXT_TAG); + refreshTextView(i, curPosition, itemView, textView); + } else { // 鑷畾涔夌被鍨� + TextView textView = WheelUtils.findTextView(itemView); + if (textView != null) { + refreshTextView(i, curPosition, itemView, textView); + } + } + } + } + + /** + * 鍒锋柊鏂囨湰 + * + * @param position + * @param curPosition + * @param itemView + * @param textView + */ + private void refreshTextView(int position, int curPosition, View + itemView, TextView textView) { + if (curPosition == position) { // 閫変腑 + int textColor = mStyle.selectedTextColor != -1 ? mStyle + .selectedTextColor : (mStyle.textColor != -1 ? mStyle + .textColor : WheelConstants.WHEEL_TEXT_COLOR); + float defTextSize = mStyle.textSize != -1 ? mStyle.textSize : WheelConstants.WHEEL_TEXT_SIZE; + float textSize = mStyle.selectedTextSize != -1 ? mStyle + .selectedTextSize : (mStyle.selectedTextZoom != -1 ? (defTextSize * mStyle.selectedTextZoom) : + defTextSize); + setTextView(itemView, textView, textColor, textSize, 1.0f); + } else { // 鏈�変腑 + int textColor = mStyle.textColor != -1 ? mStyle.textColor : + WheelConstants.WHEEL_TEXT_COLOR; + float textSize = mStyle.textSize != -1 ? mStyle.textSize : + WheelConstants.WHEEL_TEXT_SIZE; + int delta = Math.abs(position - curPosition); + float alpha = (float) Math.pow(mStyle.textAlpha != -1 ? mStyle.textAlpha : WheelConstants + .WHEEL_TEXT_ALPHA, delta); + setTextView(itemView, textView, textColor, textSize, alpha); + } + } + + /** + * 璁剧疆TextView + * + * @param itemView + * @param textView + * @param textColor + * @param textSize + * @param textAlpha + */ + private void setTextView(View itemView, TextView textView, int textColor, float textSize, float textAlpha) { + textView.setTextColor(textColor); + textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + itemView.setAlpha(textAlpha); + } + + @Override + protected void dispatchDraw(Canvas canvas) { + super.dispatchDraw(canvas); + if (!TextUtils.isEmpty(mExtraText)) { + Rect targetRect = new Rect(0, mItemH * (mWheelSize / 2), getWidth + (), mItemH * (mWheelSize / 2 + 1)); + mTextPaint.setTextSize(mExtraTextSize); + mTextPaint.setColor(mExtraTextColor); + Paint.FontMetricsInt fontMetrics = mTextPaint.getFontMetricsInt(); + int baseline = (targetRect.bottom + targetRect.top - fontMetrics + .bottom - fontMetrics.top) / 2; + mTextPaint.setTextAlign(Paint.Align.CENTER); + canvas.drawText(mExtraText, targetRect.centerX() + mExtraMargin, + baseline, mTextPaint); + } + } + + public enum Skin { // 婊氳疆鐨偆 + Common, Holo, None + } + + public interface OnWheelItemSelectedListener<T> { + void onItemSelected(int position, T t); + } + + public interface OnWheelItemClickListener<T> { + void onItemClick(int position, T t); + } + + public static class WheelViewStyle { + + public int backgroundColor = -1; // 鑳屾櫙棰滆壊 + public int holoBorderColor = -1; // holo鏍峰紡杈规棰滆壊 + public int holoBorderWidth = -1;//holo鏍峰紡杈规瀹藉害 + public int textColor = -1; // 鏂囨湰棰滆壊 + public int selectedTextColor = -1; // 閫変腑鏂囨湰棰滆壊 + public int textSize = -1;// 鏂囨湰澶у皬 + public int selectedTextSize = -1; // 閫変腑鏂囨湰澶у皬 + public float textAlpha = -1; // 鏂囨湰閫忔槑搴�(0f ~ 1f) + public float selectedTextZoom = -1; // 閫変腑鏂囨湰鏀惧ぇ鍊嶆暟 + + public WheelViewStyle() { + } + + public WheelViewStyle(WheelViewStyle style) { + this.backgroundColor = style.backgroundColor; + this.holoBorderColor = style.holoBorderColor; + this.holoBorderWidth = style.holoBorderWidth; + this.textColor = style.textColor; + this.selectedTextColor = style.selectedTextColor; + this.textSize = style.textSize; + this.selectedTextSize = style.selectedTextSize; + this.textAlpha = style.textAlpha; + this.selectedTextZoom = style.selectedTextZoom; + } + + } + +} diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelViewDialog.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelViewDialog.java new file mode 100644 index 0000000..e881dc4 --- /dev/null +++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/wheelview/widget/WheelViewDialog.java @@ -0,0 +1,302 @@ +/* + * Copyright (C) 2016 venshine.cn@gmail.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.com.basic.face.dialog.wheelview.widget; + +import android.app.AlertDialog; +import android.content.Context; +import android.graphics.Color; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import cn.com.basic.face.dialog.wheelview.adapter.ArrayWheelAdapter; +import cn.com.basic.face.dialog.wheelview.common.WheelConstants; +import cn.com.basic.face.dialog.wheelview.util.WheelUtils; +import cn.com.basic.face.dialog.wheelview.widget.*; + +import java.util.Arrays; +import java.util.List; + +/** + * 婊氳疆瀵硅瘽妗� + * + * @author venshine + */ +public class WheelViewDialog<T> implements View.OnClickListener { + + private TextView mTitle; + + private View mLine1, mLine2; + + private cn.com.basic.face.dialog.wheelview.widget.WheelView<T> mWheelView; + + private cn.com.basic.face.dialog.wheelview.widget.WheelView.WheelViewStyle mStyle; + + private TextView mButton; + + private AlertDialog mDialog; + + private Context mContext; + + private OnDialogItemClickListener mOnDialogItemClickListener; + + private int mSelectedPos; + + private T mSelectedText; + + public WheelViewDialog(Context context) { + mContext = context; + init(); + } + + private void init() { + LinearLayout layout = new LinearLayout(mContext); + layout.setOrientation(LinearLayout.VERTICAL); + layout.setPadding(WheelUtils.dip2px(mContext, 20), 0, WheelUtils.dip2px(mContext, 20), 0); + + mTitle = new TextView(mContext); + mTitle.setTextColor(WheelConstants.DIALOG_WHEEL_COLOR); + mTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); + mTitle.setGravity(Gravity.CENTER); + LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, + WheelUtils.dip2px(mContext, 50)); + layout.addView(mTitle, titleParams); + + mLine1 = new View(mContext); + mLine1.setBackgroundColor(WheelConstants.DIALOG_WHEEL_COLOR); + LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, + WheelUtils.dip2px(mContext, 2)); + layout.addView(mLine1, lineParams); + + mWheelView = new cn.com.basic.face.dialog.wheelview.widget.WheelView(mContext); + mWheelView.setSkin(cn.com.basic.face.dialog.wheelview.widget.WheelView.Skin.Holo); + mWheelView.setWheelAdapter(new ArrayWheelAdapter(mContext)); + mStyle = new cn.com.basic.face.dialog.wheelview.widget.WheelView.WheelViewStyle(); + mStyle.textColor = Color.GRAY; + mStyle.selectedTextZoom = 1.2f; + mWheelView.setStyle(mStyle); + + mWheelView.setOnWheelItemSelectedListener(new cn.com.basic.face.dialog.wheelview.widget.WheelView.OnWheelItemSelectedListener<T>() { + @Override + public void onItemSelected(int position, T text) { + mSelectedPos = position; + mSelectedText = text; + } + }); + ViewGroup.MarginLayoutParams wheelParams = new ViewGroup.MarginLayoutParams(LinearLayout.LayoutParams + .MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + layout.addView(mWheelView, wheelParams); + + mLine2 = new View(mContext); + mLine2.setBackgroundColor(WheelConstants.DIALOG_WHEEL_COLOR); + LinearLayout.LayoutParams line2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, + WheelUtils.dip2px(mContext, 1f)); + layout.addView(mLine2, line2Params); + + mButton = new TextView(mContext); + mButton.setTextColor(WheelConstants.DIALOG_WHEEL_COLOR); + mButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); + mButton.setGravity(Gravity.CENTER); + mButton.setClickable(true); + mButton.setOnClickListener(this); + mButton.setText("OK"); + LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, + WheelUtils.dip2px(mContext, 45)); + layout.addView(mButton, buttonParams); + + mDialog = new AlertDialog.Builder(mContext).create(); + mDialog.setView(layout); + mDialog.setCanceledOnTouchOutside(false); + } + + /** + * 鐐瑰嚮浜嬩欢 + * + * @param onDialogItemClickListener + * @return + */ + public WheelViewDialog setOnDialogItemClickListener(OnDialogItemClickListener onDialogItemClickListener) { + mOnDialogItemClickListener = onDialogItemClickListener; + return this; + } + + /** + * 璁剧疆dialog澶栬棰滆壊 + * + * @param color + * @return + */ + public WheelViewDialog setDialogStyle(int color) { + mTitle.setTextColor(color); + mLine1.setBackgroundColor(color); + mLine2.setBackgroundColor(color); + mButton.setTextColor(color); + mStyle.selectedTextColor = color; + mStyle.holoBorderColor = color; + return this; + } + + /** + * 璁剧疆鏍囬 + * + * @param title + * @return + */ + public WheelViewDialog setTitle(String title) { + mTitle.setText(title); + return this; + } + + /** + * 璁剧疆鏍囬棰滆壊 + * + * @param color + * @return + */ + public WheelViewDialog setTextColor(int color) { + mTitle.setTextColor(color); + return this; + } + + /** + * 璁剧疆鏍囬澶у皬 + * + * @param size + * @return + */ + public WheelViewDialog setTextSize(int size) { + mTitle.setTextSize(size); + return this; + } + + /** + * 璁剧疆鎸夐挳鏂囨湰 + * + * @param text + * @return + */ + public WheelViewDialog setButtonText(String text) { + mButton.setText(text); + return this; + } + + /** + * 璁剧疆鎸夐挳鏂囨湰棰滆壊 + * + * @param color + * @return + */ + public WheelViewDialog setButtonColor(int color) { + mButton.setTextColor(color); + return this; + } + + /** + * 璁剧疆鎸夐挳鏂囨湰灏哄 + * + * @param size + * @return + */ + public WheelViewDialog setButtonSize(int size) { + mButton.setTextSize(size); + return this; + } + + /** + * 璁剧疆鏁版嵁椤规樉绀轰釜鏁� + * + * @param count + */ + public WheelViewDialog setCount(int count) { + mWheelView.setWheelSize(count); + return this; + } + + /** + * 鏁版嵁椤规槸鍚﹀惊鐜樉绀� + * + * @param loop + */ + public WheelViewDialog setLoop(boolean loop) { + mWheelView.setLoop(loop); + return this; + } + + /** + * 璁剧疆鏁版嵁椤规樉绀轰綅缃� + * + * @param selection + */ + public WheelViewDialog setSelection(int selection) { + mWheelView.setSelection(selection); + return this; + } + + /** + * 璁剧疆鏁版嵁椤� + * + * @param arrays + */ + public WheelViewDialog setItems(T[] arrays) { + return setItems(Arrays.asList(arrays)); + } + + /** + * 璁剧疆鏁版嵁椤� + * + * @param list + */ + public WheelViewDialog setItems(List<T> list) { + mWheelView.setWheelData(list); + return this; + } + + /** + * 鏄剧ず + */ + public WheelViewDialog show() { + if (!mDialog.isShowing()) { + mDialog.show(); + } + return this; + } + + /** + * 闅愯棌 + */ + public WheelViewDialog dismiss() { + if (mDialog.isShowing()) { + mDialog.dismiss(); + } + return this; + } + + @Override + public void onClick(View v) { + dismiss(); + if (null != mOnDialogItemClickListener) { + mOnDialogItemClickListener.onItemClick(mSelectedPos, mSelectedText); + } + } + + public interface OnDialogItemClickListener<T> { + void onItemClick(int position, T s); + } +} diff --git a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_add.xml b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_add.xml index 61ebd00..6529ce1 100644 --- a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_add.xml +++ b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_add.xml @@ -18,13 +18,13 @@ android:padding="@dimen/w20dp" android:gravity="center" android:textColor="@android:color/white" - android:textSize="@dimen/text_size_big" + android:textSize="@dimen/w16dp" android:background="@color/colorPrimary"/> <EditText android:id="@+id/dialog_add_content" android:layout_width="@dimen/w200dp" android:layout_height="wrap_content" - android:textSize="@dimen/text_size_big" + android:textSize="@dimen/w16dp" android:textColor="@color/colorText_5" android:padding="@dimen/w22dp" android:gravity="center" diff --git a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_country.xml b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_country.xml index 6f3c40a..b6ab983 100644 --- a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_country.xml +++ b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_country.xml @@ -18,7 +18,7 @@ android:gravity="center" android:text="@string/country" android:textColor="@android:color/white" - android:textSize="@dimen/text_size_big" + android:textSize="@dimen/w16dp" android:background="@color/colorPrimary"/> <LinearLayout android:layout_width="@dimen/w300dp" @@ -26,12 +26,12 @@ android:paddingLeft="@dimen/w10dp" android:paddingRight="@dimen/w10dp" android:orientation="horizontal"> - <com.wx.wheelview.widget.WheelView + <cn.com.basic.face.dialog.wheelview.widget.WheelView android:id="@+id/dialog_country_name_first_letter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"/> - <com.wx.wheelview.widget.WheelView + <cn.com.basic.face.dialog.wheelview.widget.WheelView android:id="@+id/dialog_country_name" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -53,7 +53,7 @@ android:layout_height="match_parent" android:gravity="center" android:text="@string/confirm" - android:textSize="@dimen/text_size_big"/> + android:textSize="@dimen/w16dp"/> <View android:layout_width="0.5dp" android:layout_height="match_parent" @@ -65,7 +65,7 @@ android:layout_height="match_parent" android:gravity="center" android:text="@string/cancel" - android:textSize="@dimen/text_size_big"/> + android:textSize="@dimen/w16dp"/> </LinearLayout> </LinearLayout> </LinearLayout> \ No newline at end of file diff --git a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_date_select.xml b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_date_select.xml index 25d0bea..8c48479 100644 --- a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_date_select.xml +++ b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_date_select.xml @@ -27,7 +27,9 @@ android:layout_height="@dimen/h50dp" android:gravity="center" android:text="@string/confirm" - android:textColor="#000000" /> + android:textColor="#000000" + android:textSize="@dimen/w16dp" + /> <TextView android:id="@+id/dialog_date_select_cancel" android:layout_weight="1" @@ -35,6 +37,8 @@ android:layout_height="@dimen/h50dp" android:gravity="center" android:text="@string/cancel" - android:textColor="#000000" /> + android:textColor="#000000" + android:textSize="@dimen/w16dp" + /> </LinearLayout> </LinearLayout> \ No newline at end of file diff --git a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_row.xml b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_row.xml index 3762019..c87625e 100644 --- a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_row.xml +++ b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_row.xml @@ -10,5 +10,5 @@ android:layout_margin="@dimen/w8dp" android:gravity="center" android:singleLine="true" - android:textSize="@dimen/text_size_big"/> + android:textSize="@dimen/w16dp"/> </RelativeLayout> \ No newline at end of file diff --git a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_select.xml b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_select.xml index bffcd58..83ad706 100644 --- a/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_select.xml +++ b/VisitFace/DemoForBsk/app/src/main/res/layout/dialog_select.xml @@ -18,12 +18,13 @@ android:padding="@dimen/w20dp" android:gravity="center" android:textColor="@android:color/white" - android:textSize="@dimen/text_size_big" + android:textSize="@dimen/w16dp" android:background="@color/colorPrimary"/> - <com.wx.wheelview.widget.WheelView + <cn.com.basic.face.dialog.wheelview.widget.WheelView android:id="@+id/dialog_select_list_view" android:layout_width="@dimen/w200dp" - android:layout_height="wrap_content"/> + android:layout_height="wrap_content" + /> <View android:layout_width="match_parent" android:layout_height="0.5dp" @@ -39,7 +40,7 @@ android:layout_height="match_parent" android:gravity="center" android:text="@string/confirm" - android:textSize="@dimen/text_size_big"/> + android:textSize="@dimen/w16dp"/> <View android:id="@+id/dialog_select_add_separator" android:layout_width="0.5dp" @@ -54,7 +55,7 @@ android:layout_height="match_parent" android:gravity="center" android:text="@string/add" - android:textSize="@dimen/text_size_big" + android:textSize="@dimen/w16dp" android:visibility="gone" /> <View @@ -68,7 +69,7 @@ android:layout_height="match_parent" android:gravity="center" android:text="@string/cancel" - android:textSize="@dimen/text_size_big"/> + android:textSize="@dimen/w16dp"/> </LinearLayout> </LinearLayout> </LinearLayout> \ No newline at end of file -- Gitblit v1.8.0