Commit 0fccab18 by gao.chao

标题栏,日期选择对话框,时间选择对话框,地方选择对话框

parent 3dbab070
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".TsetActviity" /> <activity android:name=".ViewActviity" />
<activity android:name=".QRActivity" /> <activity android:name=".QRActivity" />
<activity android:name=".TitleActivity" />
</application> </application>
<!-- 配置APP ID --> <!-- 配置APP ID -->
......
...@@ -10,8 +10,6 @@ import android.view.ViewGroup; ...@@ -10,8 +10,6 @@ import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import com.mayi.fastdevelop.base.BaseActivity; import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.util.LogUtils;
import com.mayi.fastdevelop.util.SpUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -25,14 +23,10 @@ public class MainActivity extends BaseActivity { ...@@ -25,14 +23,10 @@ public class MainActivity extends BaseActivity {
RecyclerView listView = findViewById(R.id.list); RecyclerView listView = findViewById(R.id.list);
listView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); listView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
final List<ItemBean> list = new ArrayList<>(); final List<ItemBean> list = new ArrayList<>();
list.add(new ItemBean("BaseActivity", new View.OnClickListener() { list.add(new ItemBean("常用控件", new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
LogUtils.postCatchedException(new Exception("11")); gotoActivity(ViewActviity.class);
SpUtil.set("ss",System.currentTimeMillis());
LogUtils.i("ss="+ SpUtil.get("ss",-1L));
// gotoActivity(TsetActviity.class);
} }
})); }));
list.add(new ItemBean("二维码", new View.OnClickListener() { list.add(new ItemBean("二维码", new View.OnClickListener() {
......
package com.mayi.demo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.util.ToastUtil;
import com.mayi.fastdevelop.view.CustomTitleBar;
public class TitleActivity extends BaseActivity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.title_activity_layout);
CustomTitleBar titleBar1=findViewById(R.id.title1);
titleBar1.setOnClickLeftViewListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtil.show(v.getContext(),"点击返回");
}
});
titleBar1.setTextCenter("标题1");
CustomTitleBar titleBar2=findViewById(R.id.title2);
titleBar2.setTextCenter("标题2");
titleBar2.hideLeftView();
titleBar2.setOnClickCenterTextListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtil.show(v.getContext(),"点击标题");
}
});
CustomTitleBar titleBar3=findViewById(R.id.title3);
titleBar3.setTextCenter("标题3");
titleBar3.showLeftCloseView();
titleBar3.setTextRight("右边");
titleBar3.setOnClickRightTextListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtil.show(v.getContext(),"点击右边");
}
});
titleBar3.hideLeftView();
titleBar3.setOnClickLeftCloseListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtil.show(v.getContext(),"点击关闭");
}
});
CustomTitleBar titleBar4=findViewById(R.id.title4);
titleBar4.setTextCenter("标题4");
titleBar4.setImageRight(R.mipmap.icon_back);
titleBar4.showRightView();
titleBar4.setOnClickRightViewListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtil.show(v.getContext(),"点击右边");
}
});
CustomTitleBar titleBar5=findViewById(R.id.title5);
titleBar5.setTextCenter("标题5");
titleBar5.setTextCenterDrawableLeftRight(R.mipmap.ic_launcher,R.mipmap.ic_launcher_round);
}
}
package com.mayi.demo;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import com.mayi.fastdevelop.base.BaseActivity;
public class TsetActviity extends BaseActivity {
private Handler handler;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_layout);
handler = new Handler();
findViewById(R.id.showLoading).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showLoadingDialog();
handler.postDelayed(new Runnable() {
@Override
public void run() {
dismssLoadingDialog();
}
}, 4000);
}
});
}
}
package com.mayi.demo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.util.DialogUtils;
import com.mayi.fastdevelop.util.ToastUtil;
import com.mayi.fastdevelop.view.wheel.ChangeAddressDialog;
import com.mayi.fastdevelop.view.wheel.ChangeBirthDialog;
import com.mayi.fastdevelop.view.wheel.ChangeDateDialog;
import com.mayi.fastdevelop.view.wheel.ChangeTimeDialog;
public class ViewActviity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_layout);
findViewById(R.id.b1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ChangeAddressDialog(v.getContext(), new ChangeAddressDialog.OnAddressCListener() {
@Override
public void onClick(String province, String city) {
ToastUtil.show(ViewActviity.this, "province=" + province + " city=" + city);
}
}).show();
}
});
findViewById(R.id.b2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ChangeBirthDialog(v.getContext(), new ChangeBirthDialog.OnBirthListener() {
@Override
public void onClick(String year, String month, String day) {
ToastUtil.show(ViewActviity.this, "year=" + year + " month=" + month + " day=" + day);
}
}).show();
}
});
findViewById(R.id.b3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ChangeDateDialog(v.getContext(), new ChangeDateDialog.OnDateListener() {
@Override
public void onClick(String year, String month, String day) {
ToastUtil.show(ViewActviity.this, "year=" + year + " month=" + month + " day=" + day);
}
}).show();
}
});
findViewById(R.id.b4).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ChangeTimeDialog(v.getContext(), new ChangeTimeDialog.OnTimeListener() {
@Override
public void onClick(String year, String month, String day, String hour, String minute) {
ToastUtil.show(ViewActviity.this, "year=" + year + " month="
+ month + " day=" + day + " hour=" + hour + " minute=" + minute);
}
}).show();
}
});
findViewById(R.id.b5).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogUtils.showCommonDialog("标题", "左边", "右边", v.getContext(), new DialogUtils.DefaultDialogListener() {
@Override
public void onClickLeft() {
ToastUtil.show(ViewActviity.this,"点击左边");
}
@Override
public void onClickRight() {
ToastUtil.show(ViewActviity.this,"点击右边");
}
});
}
});
findViewById(R.id.b6).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogUtils.showCommonDialog("标题", v.getContext(), new DialogUtils.DefaultDialogListener() {
@Override
public void onClickLeft() {
ToastUtil.show(ViewActviity.this,"取消");
}
@Override
public void onClickRight() {
ToastUtil.show(ViewActviity.this,"确定");
}
});
}
});
findViewById(R.id.b7).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogUtils.showTipsDialog("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", v.getContext(), new DialogUtils.TipsDialogListener() {
@Override
public void onClickOK() {
ToastUtil.show(ViewActviity.this,"确定");
}
});
}
});
findViewById(R.id.b8).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogUtils.showTipsDialog("1234567890yiersn", v.getContext(), new DialogUtils.TipsDialogListener() {
@Override
public void onClickOK() {
ToastUtil.show(ViewActviity.this,"确定");
}
});
}
});
findViewById(R.id.b9).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoActivity(TitleActivity.class);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<Button <LinearLayout
android:id="@+id/showLoading" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="wrap_content" android:orientation="vertical">
android:text="显示对话框"/>
</LinearLayout> <Button
\ No newline at end of file android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="城市二级联动对话框" />
<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="日期选择对话框1" />
<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="日期选择对话框2" />
<Button
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="日期时间对话框" />
<Button
android:id="@+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="常用对话框-样式1" />
<Button
android:id="@+id/b6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="常用对话框-样式2" />
<Button
android:id="@+id/b7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="常用对话框-样式3" />
<Button
android:id="@+id/b8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="常用对话框-样式4" />
<Button
android:id="@+id/b9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题栏" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.mayi.fastdevelop.view.CustomTitleBar
android:id="@+id/title1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/im_dp_20" />
<com.mayi.fastdevelop.view.CustomTitleBar
android:id="@+id/title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/im_dp_20" />
<com.mayi.fastdevelop.view.CustomTitleBar
android:id="@+id/title3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/im_dp_20" />
<com.mayi.fastdevelop.view.CustomTitleBar
android:id="@+id/title4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/im_dp_20" />
<com.mayi.fastdevelop.view.CustomTitleBar
android:id="@+id/title5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/im_dp_20" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
{
"citylist": [
{
"cl": [
{
"nm": "黄浦区"
},
{
"nm": "卢湾区"
},
{
"nm": "徐汇区"
},
{
"nm": "长宁区"
},
{
"nm": "静安区"
},
{
"nm": "普陀区"
},
{
"nm": "闸北区"
},
{
"nm": "虹口区"
},
{
"nm": "杨浦区"
},
{
"nm": "闵行区"
},
{
"nm": "宝山区"
},
{
"nm": "嘉定区"
},
{
"nm": "浦东新区"
},
{
"nm": "金山区"
},
{
"nm": "松江区"
},
{
"nm": "青浦区"
},
{
"nm": "南汇区"
},
{
"nm": "奉贤区"
},
{
"nm": "崇明县"
}
],
"nm": "上海市"
},
{
"cl": [
{
"nm": "杭州市"
},
{
"nm": "宁波市"
},
{
"nm": "温州市"
},
{
"nm": "嘉兴市"
},
{
"nm": "湖州市"
},
{
"nm": "绍兴市"
},
{
"nm": "金华市"
},
{
"nm": "衢州市"
},
{
"nm": "舟山市"
},
{
"nm": "台州市"
},
{
"nm": "丽水市"
}
],
"nm": "浙江省"
},
{
"cl": [
{
"nm": "和平区"
},
{
"nm": "河东区"
},
{
"nm": "河西区"
},
{
"nm": "南开区"
},
{
"nm": "河北区"
},
{
"nm": "红桥区"
},
{
"nm": "塘沽区"
},
{
"nm": "汉沽区"
},
{
"nm": "大港区"
},
{
"nm": "东丽区"
},
{
"nm": "西青区"
},
{
"nm": "津南区"
},
{
"nm": "北辰区"
},
{
"nm": "武清区"
},
{
"nm": "宝坻区"
},
{
"nm": "滨海新区"
}
],
"nm": "天津市"
},
{
"cl": [
{
"nm": "东城区"
},
{
"nm": "西城区"
},
{
"nm": "崇文区"
},
{
"nm": "宣武区"
},
{
"nm": "朝阳区"
},
{
"nm": "丰台区"
},
{
"nm": "石景山区"
},
{
"nm": "海淀区"
},
{
"nm": "门头沟区"
},
{
"nm": "房山区"
},
{
"nm": "通州区"
},
{
"nm": "顺义区"
},
{
"nm": "昌平区"
},
{
"nm": "大兴区"
},
{
"nm": "怀柔区"
},
{
"nm": "平谷区"
},
{
"nm": "密云县"
},
{
"nm": "延庆县"
}
],
"nm": "北京市"
},
{
"cl": [
{
"nm": "石家庄市"
},
{
"nm": "唐山市"
},
{
"nm": "秦皇岛市"
},
{
"nm": "邯郸市"
},
{
"nm": "邢台市"
},
{
"nm": "保定市"
},
{
"nm": "张家口市"
},
{
"nm": "承德市"
},
{
"nm": "沧州市"
},
{
"nm": "廊坊市"
},
{
"nm": "衡水市"
}
],
"nm": "河北省"
},
{
"cl": [
{
"nm": "太原市"
},
{
"nm": "大同市"
},
{
"nm": "阳泉市"
},
{
"nm": "长治市"
},
{
"nm": "晋城市"
},
{
"nm": "朔州市"
},
{
"nm": "晋中市"
},
{
"nm": "运城市"
},
{
"nm": "忻州市"
},
{
"nm": "临汾市"
},
{
"nm": "吕梁市"
}
],
"nm": "山西省"
},
{
"cl": [
{
"nm": "呼和浩特市"
},
{
"nm": "包头市"
},
{
"nm": "乌海市"
},
{
"nm": "赤峰市"
},
{
"nm": "通辽市"
},
{
"nm": "鄂尔多斯市"
},
{
"nm": "呼伦贝尔市"
},
{
"nm": "巴彦淖尔市"
},
{
"nm": "乌兰察布市"
},
{
"nm": "兴安盟"
},
{
"nm": "锡林郭勒盟"
},
{
"nm": "阿拉善盟"
}
],
"nm": "内蒙古自治区"
},
{
"cl": [
{
"nm": "沈阳市"
},
{
"nm": "大连市"
},
{
"nm": "鞍山市"
},
{
"nm": "抚顺市"
},
{
"nm": "本溪市"
},
{
"nm": "丹东市"
},
{
"nm": "锦州市"
},
{
"nm": "营口市"
},
{
"nm": "阜新市"
},
{
"nm": "辽阳市"
},
{
"nm": "盘锦市"
},
{
"nm": "铁岭市"
},
{
"nm": "朝阳市"
},
{
"nm": "葫芦岛市"
}
],
"nm": "辽宁省"
},
{
"cl": [
{
"nm": "长春市"
},
{
"nm": "吉林市"
},
{
"nm": "四平市"
},
{
"nm": "辽源市"
},
{
"nm": "通化市"
},
{
"nm": "白山市"
},
{
"nm": "松原市"
},
{
"nm": "白城市"
},
{
"nm": "延边朝鲜族自治州"
}
],
"nm": "吉林省"
},
{
"cl": [
{
"nm": "哈尔滨市"
},
{
"nm": "齐齐哈尔市"
},
{
"nm": "鸡西市"
},
{
"nm": "鹤岗市"
},
{
"nm": "双鸭山市"
},
{
"nm": "大庆市"
},
{
"nm": "伊春市"
},
{
"nm": "佳木斯市"
},
{
"nm": "七台河市"
},
{
"nm": "牡丹江市"
},
{
"nm": "黑河市"
},
{
"nm": "绥化市"
},
{
"nm": "大兴安岭地区"
}
],
"nm": "黑龙江省"
},
{
"cl": [
{
"nm": "南京市"
},
{
"nm": "无锡市"
},
{
"nm": "徐州市"
},
{
"nm": "常州市"
},
{
"nm": "苏州市"
},
{
"nm": "南通市"
},
{
"nm": "连云港市"
},
{
"nm": "淮安市"
},
{
"nm": "盐城市"
},
{
"nm": "扬州市"
},
{
"nm": "镇江市"
},
{
"nm": "泰州市"
},
{
"nm": "宿迁市"
}
],
"nm": "江苏省"
},
{
"cl": [
{
"nm": "合肥市"
},
{
"nm": "芜湖市"
},
{
"nm": "蚌埠市"
},
{
"nm": "淮南市"
},
{
"nm": "马鞍山市"
},
{
"nm": "淮北市"
},
{
"nm": "铜陵市"
},
{
"nm": "安庆市"
},
{
"nm": "黄山市"
},
{
"nm": "滁州市"
},
{
"nm": "阜阳市"
},
{
"nm": "宿州市"
},
{
"nm": "巢湖市"
},
{
"nm": "六安市"
},
{
"nm": "亳州市"
},
{
"nm": "池州市"
},
{
"nm": "宣城市"
}
],
"nm": "安徽省"
},
{
"cl": [
{
"nm": "福州市"
},
{
"nm": "厦门市"
},
{
"nm": "莆田市"
},
{
"nm": "三明市"
},
{
"nm": "泉州市"
},
{
"nm": "漳州市"
},
{
"nm": "南平市"
},
{
"nm": "龙岩市"
},
{
"nm": "宁德市"
}
],
"nm": "福建省"
},
{
"cl": [
{
"nm": "南昌市"
},
{
"nm": "景德镇市"
},
{
"nm": "萍乡市"
},
{
"nm": "九江市"
},
{
"nm": "新余市"
},
{
"nm": "鹰潭市"
},
{
"nm": "赣州市"
},
{
"nm": "吉安市"
},
{
"nm": "宜春市"
},
{
"nm": "抚州市"
},
{
"nm": "上饶市"
}
],
"nm": "江西省"
},
{
"cl": [
{
"nm": "济南市"
},
{
"nm": "青岛市"
},
{
"nm": "淄博市"
},
{
"nm": "枣庄市"
},
{
"nm": "东营市"
},
{
"nm": "烟台市"
},
{
"nm": "潍坊市"
},
{
"nm": "济宁市"
},
{
"nm": "泰安市"
},
{
"nm": "威海市"
},
{
"nm": "日照市"
},
{
"nm": "莱芜市"
},
{
"nm": "临沂市"
},
{
"nm": "德州市"
},
{
"nm": "聊城市"
},
{
"nm": "滨州市"
},
{
"nm": "荷泽市"
}
],
"nm": "山东省"
},
{
"cl": [
{
"nm": "郑州市"
},
{
"nm": "开封市"
},
{
"nm": "洛阳市"
},
{
"nm": "平顶山市"
},
{
"nm": "安阳市"
},
{
"nm": "鹤壁市"
},
{
"nm": "新乡市"
},
{
"nm": "焦作市"
},
{
"nm": "濮阳市"
},
{
"nm": "许昌市"
},
{
"nm": "漯河市"
},
{
"nm": "三门峡市"
},
{
"nm": "南阳市"
},
{
"nm": "商丘市"
},
{
"nm": "信阳市"
},
{
"nm": "周口市"
},
{
"nm": "驻马店市"
}
],
"nm": "河南省"
},
{
"cl": [
{
"nm": "武汉市"
},
{
"nm": "黄石市"
},
{
"nm": "十堰市"
},
{
"nm": "宜昌市"
},
{
"nm": "襄樊市"
},
{
"nm": "鄂州市"
},
{
"nm": "荆门市"
},
{
"nm": "孝感市"
},
{
"nm": "荆州市"
},
{
"nm": "黄冈市"
},
{
"nm": "咸宁市"
},
{
"nm": "随州市"
},
{
"nm": "恩施土家族苗族自治州"
},
{
"nm": "省直辖行政单位"
}
],
"nm": "湖北省"
},
{
"cl": [
{
"nm": "长沙市"
},
{
"nm": "株洲市"
},
{
"nm": "湘潭市"
},
{
"nm": "衡阳市"
},
{
"nm": "邵阳市"
},
{
"nm": "岳阳市"
},
{
"nm": "常德市"
},
{
"nm": "张家界市"
},
{
"nm": "益阳市"
},
{
"nm": "郴州市"
},
{
"nm": "永州市"
},
{
"nm": "怀化市"
},
{
"nm": "娄底市"
},
{
"nm": "湘西土家族苗族自治州"
}
],
"nm": "湖南省"
},
{
"cl": [
{
"nm": "广州市"
},
{
"nm": "韶关市"
},
{
"nm": "深圳市"
},
{
"nm": "珠海市"
},
{
"nm": "汕头市"
},
{
"nm": "佛山市"
},
{
"nm": "江门市"
},
{
"nm": "湛江市"
},
{
"nm": "茂名市"
},
{
"nm": "肇庆市"
},
{
"nm": "惠州市"
},
{
"nm": "梅州市"
},
{
"nm": "汕尾市"
},
{
"nm": "河源市"
},
{
"nm": "阳江市"
},
{
"nm": "清远市"
},
{
"nm": "中山市"
},
{
"nm": "潮州市"
},
{
"nm": "揭阳市"
},
{
"nm": "云浮市"
}
],
"nm": "广东省"
},
{
"cl": [
{
"nm": "南宁市"
},
{
"nm": "柳州市"
},
{
"nm": "桂林市"
},
{
"nm": "梧州市"
},
{
"nm": "北海市"
},
{
"nm": "防城港市"
},
{
"nm": "钦州市"
},
{
"nm": "贵港市"
},
{
"nm": "玉林市"
},
{
"nm": "百色市"
},
{
"nm": "贺州市"
},
{
"nm": "河池市"
},
{
"nm": "来宾市"
},
{
"nm": "崇左市"
}
],
"nm": "广西壮族自治区"
},
{
"cl": [
{
"nm": "海口市"
},
{
"nm": "三亚市"
},
{
"nm": "省直辖县级行政单位"
}
],
"nm": "海南省"
},
{
"cl": [
{
"nm": "万州区"
},
{
"nm": "涪陵区"
},
{
"nm": "渝中区"
},
{
"nm": "大渡口区"
},
{
"nm": "江北区"
},
{
"nm": "沙坪坝区"
},
{
"nm": "九龙坡区"
},
{
"nm": "南岸区"
},
{
"nm": "北碚区"
},
{
"nm": "万盛区"
},
{
"nm": "双桥区"
},
{
"nm": "渝北区"
},
{
"nm": "巴南区"
},
{
"nm": "黔江区"
},
{
"nm": "长寿区"
},
{
"nm": "綦江县"
},
{
"nm": "潼南县"
},
{
"nm": "铜梁县"
},
{
"nm": "大足县"
},
{
"nm": "荣昌县"
},
{
"nm": "璧山县"
},
{
"nm": "梁平县"
},
{
"nm": "城口县"
},
{
"nm": "丰都县"
},
{
"nm": "垫江县"
},
{
"nm": "武隆县"
},
{
"nm": "忠 县"
},
{
"nm": "开 县"
},
{
"nm": "云阳县"
},
{
"nm": "奉节县"
},
{
"nm": "巫山县"
},
{
"nm": "巫溪县"
},
{
"nm": "石柱土家族自治县"
},
{
"nm": "秀山土家族苗族自治县"
},
{
"nm": "酉阳土家族苗族自治县"
},
{
"nm": "彭水苗族土家族自治县"
},
{
"nm": "江津市"
},
{
"nm": "合川市"
},
{
"nm": "永川市"
},
{
"nm": "南川市"
}
],
"nm": "重庆市"
},
{
"cl": [
{
"nm": "成都市"
},
{
"nm": "自贡市"
},
{
"nm": "攀枝花市"
},
{
"nm": "泸州市"
},
{
"nm": "德阳市"
},
{
"nm": "绵阳市"
},
{
"nm": "广元市"
},
{
"nm": "遂宁市"
},
{
"nm": "内江市"
},
{
"nm": "乐山市"
},
{
"nm": "南充市"
},
{
"nm": "眉山市"
},
{
"nm": "宜宾市"
},
{
"nm": "广安市"
},
{
"nm": "达州市"
},
{
"nm": "雅安市"
},
{
"nm": "巴中市"
},
{
"nm": "资阳市"
},
{
"nm": "阿坝藏族羌族自治州"
},
{
"nm": "甘孜藏族自治州"
},
{
"nm": "凉山彝族自治州"
}
],
"nm": "四川省"
},
{
"cl": [
{
"nm": "贵阳市"
},
{
"nm": "六盘水市"
},
{
"nm": "遵义市"
},
{
"nm": "安顺市"
},
{
"nm": "铜仁地区"
},
{
"nm": "黔西南布依族苗族自治州"
},
{
"nm": "毕节地区"
},
{
"nm": "黔东南苗族侗族自治州"
},
{
"nm": "黔南布依族苗族自治州"
}
],
"nm": "贵州省"
},
{
"cl": [
{
"nm": "昆明市"
},
{
"nm": "曲靖市"
},
{
"nm": "玉溪市"
},
{
"nm": "保山市"
},
{
"nm": "昭通市"
},
{
"nm": "丽江市"
},
{
"nm": "思茅市"
},
{
"nm": "临沧市"
},
{
"nm": "楚雄彝族自治州"
},
{
"nm": "红河哈尼族彝族自治州"
},
{
"nm": "文山壮族苗族自治州"
},
{
"nm": "西双版纳傣族自治州"
},
{
"nm": "大理白族自治州"
},
{
"nm": "德宏傣族景颇族自治州"
},
{
"nm": "怒江傈僳族自治州"
},
{
"nm": "迪庆藏族自治州"
}
],
"nm": "云南省"
},
{
"cl": [
{
"nm": "拉萨市"
},
{
"nm": "昌都地区"
},
{
"nm": "山南地区"
},
{
"nm": "日喀则地区"
},
{
"nm": "那曲地区"
},
{
"nm": "阿里地区"
},
{
"nm": "林芝地区"
}
],
"nm": "西藏自治区"
},
{
"cl": [
{
"nm": "西安市"
},
{
"nm": "铜川市"
},
{
"nm": "宝鸡市"
},
{
"nm": "咸阳市"
},
{
"nm": "渭南市"
},
{
"nm": "延安市"
},
{
"nm": "汉中市"
},
{
"nm": "榆林市"
},
{
"nm": "安康市"
},
{
"nm": "商洛市"
}
],
"nm": "陕西省"
},
{
"cl": [
{
"nm": "兰州市"
},
{
"nm": "嘉峪关市"
},
{
"nm": "金昌市"
},
{
"nm": "白银市"
},
{
"nm": "天水市"
},
{
"nm": "武威市"
},
{
"nm": "张掖市"
},
{
"nm": "平凉市"
},
{
"nm": "酒泉市"
},
{
"nm": "庆阳市"
},
{
"nm": "定西市"
},
{
"nm": "陇南市"
},
{
"nm": "临夏回族自治州"
},
{
"nm": "甘南藏族自治州"
}
],
"nm": "甘肃省"
},
{
"cl": [
{
"nm": "西宁市"
},
{
"nm": "海东地区"
},
{
"nm": "海北藏族自治州"
},
{
"nm": "黄南藏族自治州"
},
{
"nm": "海南藏族自治州"
},
{
"nm": "果洛藏族自治州"
},
{
"nm": "玉树藏族自治州"
},
{
"nm": "海西蒙古族藏族自治州"
}
],
"nm": "青海省"
},
{
"cl": [
{
"nm": "银川市"
},
{
"nm": "石嘴山市"
},
{
"nm": "吴忠市"
},
{
"nm": "固原市"
},
{
"nm": "中卫市"
}
],
"nm": "宁夏回族自治区"
},
{
"cl": [
{
"nm": "乌鲁木齐市"
},
{
"nm": "克拉玛依市"
},
{
"nm": "吐鲁番地区"
},
{
"nm": "哈密地区"
},
{
"nm": "昌吉回族自治州"
},
{
"nm": "博尔塔拉蒙古自治州"
},
{
"nm": "巴音郭楞蒙古自治州"
},
{
"nm": "阿克苏地区"
},
{
"nm": "克孜勒苏柯尔克孜自治州"
},
{
"nm": "喀什地区"
},
{
"nm": "和田地区"
},
{
"nm": "伊犁哈萨克自治州"
},
{
"nm": "塔城地区"
},
{
"nm": "阿勒泰地区"
},
{
"nm": "省直辖行政单位"
}
],
"nm": "新疆维吾尔自治区"
},
{
"cl": [
{
"nm": ""
}
],
"nm": "台湾省"
},
{
"cl": [
{
"nm": ""
}
],
"nm": "香港特别行政区"
},
{
"cl": [
{
"nm": ""
}
],
"nm": "澳门特别行政区"
}
]
}
\ No newline at end of file
package com.mayi.fastdevelop.util;
import android.content.Context;
import android.view.View;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.view.dialog.BaseDialog;
import com.mayi.fastdevelop.view.dialog.DialogViewHolder;
/**
* 常用对话框
*/
public class DialogUtils {
public static BaseDialog showCommonDialog(final String titel, final String left, final String right, Context context, final DefaultDialogListener dialogListener) {
return new BaseDialog(context, R.layout.dialog_default_sure) {
@Override
public void convert(DialogViewHolder holder) {
holder.setText(R.id.tv_title, titel);
holder.setText(R.id.tv_left, left);
holder.setText(R.id.tv_right, right);
holder.setOnClick(R.id.tv_right, new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
if (dialogListener != null) {
dialogListener.onClickRight();
}
}
});
holder.setOnClick(R.id.tv_left, new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
if (dialogListener != null) {
dialogListener.onClickLeft();
}
}
});
}
}.setCanceledOnTouchOutside(true)
.setCancelAble(true)
.show();
}
public static BaseDialog showCommonDialog(String title, Context context, DefaultDialogListener listener) {
return showCommonDialog(title, "取消", "确定", context, listener);
}
public static BaseDialog showTipsDialog(final String content, Context context, final TipsDialogListener listener) {
return new BaseDialog(context, R.layout.dialog_default_tips) {
@Override
public void convert(DialogViewHolder holder) {
holder.setText(R.id.tv_content, content);
holder.setOnClick(R.id.tv_ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
if (listener != null) {
listener.onClickOK();
}
}
});
}
}.setCanceledOnTouchOutside(true)
.setCancelAble(true)
.show();
}
public interface TipsDialogListener {
void onClickOK();
}
public interface DefaultDialogListener {
void onClickLeft();
void onClickRight();
}
}
...@@ -27,7 +27,7 @@ public class SpUtil { ...@@ -27,7 +27,7 @@ public class SpUtil {
* 清空所有数据 * 清空所有数据
*/ */
public static void clear() { public static void clear() {
getSp().edit().clear().apply(); getSp().edit().clear().commit();
} }
/** /**
...@@ -37,7 +37,7 @@ public class SpUtil { ...@@ -37,7 +37,7 @@ public class SpUtil {
* @param value 值(boolean). * @param value 值(boolean).
*/ */
public static void set(String key, boolean value) { public static void set(String key, boolean value) {
getSp().edit().putBoolean(key, value).apply(); getSp().edit().putBoolean(key, value).commit();
} }
/** /**
...@@ -47,7 +47,7 @@ public class SpUtil { ...@@ -47,7 +47,7 @@ public class SpUtil {
* @param value 值(float). * @param value 值(float).
*/ */
public static void set(String key, float value) { public static void set(String key, float value) {
getSp().edit().putFloat(key, value).apply(); getSp().edit().putFloat(key, value).commit();
} }
/** /**
...@@ -57,7 +57,7 @@ public class SpUtil { ...@@ -57,7 +57,7 @@ public class SpUtil {
* @param value 值(int). * @param value 值(int).
*/ */
public static void set(String key, int value) { public static void set(String key, int value) {
getSp().edit().putInt(key, value).apply(); getSp().edit().putInt(key, value).commit();
} }
/** /**
...@@ -67,7 +67,7 @@ public class SpUtil { ...@@ -67,7 +67,7 @@ public class SpUtil {
* @param value 值(long). * @param value 值(long).
*/ */
public static void set(String key, long value) { public static void set(String key, long value) {
getSp().edit().putLong(key, value).apply(); getSp().edit().putLong(key, value).commit();
} }
/** /**
...@@ -77,7 +77,7 @@ public class SpUtil { ...@@ -77,7 +77,7 @@ public class SpUtil {
* @param value 值(String). * @param value 值(String).
*/ */
public static void set(String key, String value) { public static void set(String key, String value) {
getSp().edit().putString(key, value).apply(); getSp().edit().putString(key, value).commit();
} }
/** /**
...@@ -86,7 +86,7 @@ public class SpUtil { ...@@ -86,7 +86,7 @@ public class SpUtil {
* @param key 键. * @param key 键.
*/ */
public static void remove(String key) { public static void remove(String key) {
getSp().edit().remove(key).apply(); getSp().edit().remove(key).commit();
} }
/** /**
......
package com.mayi.fastdevelop.view;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.text.Html;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.util.DisplayUtil;
/**
* 页面的顶部。
* 注意,该类包含元素:左边返回icon 文字、中间标题、右边提示文字、右边图片按钮。不符合这种顶部的UI自己写布局,符合的都用这个。
* 默认只显示返回按钮和中间标题。布局文件添加见类头部注释
*/
public class CustomTitleBar extends RelativeLayout {
private ImageView iv_left, iv_logo;
private View layout_left, layout_right, layout_close, v_right;
private TextView tv_left, tv_center, tv_right;
private OnClickListener onClickLeftView, onClickRightView, onClickRightText, onClickLeftClose, onClickCenterText;
private static String defaultTitle;//默认标题
public CustomTitleBar(Context context) {
super(context);
init();
}
public CustomTitleBar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomTitleBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
View view = LayoutInflater.from(getContext()).inflate(R.layout.view_title_bar, null);
iv_left = (ImageView) view.findViewById(R.id.iv_left);
tv_left = (TextView) view.findViewById(R.id.tv_left);
iv_logo = (ImageView) view.findViewById(R.id.iv_logo);
layout_left = view.findViewById(R.id.layout_left);
layout_right = view.findViewById(R.id.layout_right);
layout_close = view.findViewById(R.id.layout_close);
v_right = view.findViewById(R.id.v_right);
tv_center = (TextView) view.findViewById(R.id.tv_center);
tv_right = (TextView) view.findViewById(R.id.tv_right);
layout_right.setVisibility(View.GONE);
tv_right.setVisibility(View.GONE);
if (defaultTitle != null) {
setTextCenter(defaultTitle);
}
layout_left.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onClickLeftView != null)
onClickLeftView.onClick(v);
}
});
layout_right.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onClickRightView != null)
onClickRightView.onClick(v);
}
});
tv_right.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onClickRightText != null)
onClickRightText.onClick(v);
}
});
layout_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onClickLeftClose != null) {
onClickLeftClose.onClick(v);
}
}
});
iv_logo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (onClickCenterText != null) {
onClickCenterText.onClick(v);
}
}
});
addView(view);
}
/**
* 设置全局默认标题,如果没有设置默认,则默认为teamlib,所以需要在AppContext中设置默认标题
*/
public static void setDefaultTitle(String defaultTitle) {
CustomTitleBar.defaultTitle = defaultTitle;
}
/**
* 设置左上角返回按钮的图片
*/
public void setLeftImageResource(int resId) {
iv_left.setImageResource(resId);
}
/**
* 设置标题左边LOGO图片
*/
public void setLogoImageResource(int resId) {
iv_logo.setImageResource(resId);
tv_center.setEms(4);
}
/**
* 设置返回文字
*
* @param text
*/
public void setTextLeft(CharSequence text) {
if (text != null) {
tv_left.setText(Html.fromHtml(text.toString().trim()));
}
}
/**
* 隐藏返回按钮
*/
public void hideLeftView() {
layout_left.setVisibility(View.GONE);
}
public TextView getLeftText() {
return tv_left;
}
/**
* 设置返回文字
*
* @param textResId 文字id
*/
public void setTextLeft(int textResId) {
setTextLeft(getContext().getString(textResId).trim());
}
/**
* 设置返回文字颜色
*
* @param textLeftColor 颜色值ID
*/
public void setTextLeftColor(int textLeftColor) {
tv_left.setTextColor(textLeftColor);
}
/**
* 设置显隐返回文字
*
* @param hide true 隐藏
*/
public void setTextLeftVisible(boolean hide) {
tv_left.setVisibility(hide ? GONE : VISIBLE);
}
/**
* 设置中间标题文字
*
* @param text
*/
public void setTextCenter(CharSequence text) {
if (text != null) {
tv_center.setText(Html.fromHtml(text.toString().trim()));
}
}
/**
* 设置中间标题文字
*
* @param textResId
*/
public void setTextCenter(int textResId) {
setTextCenter(getContext().getString(textResId).trim());
}
/**
* 设置中间文字大小
*
* @param size
*/
public void setTextCenterSize(int size) {
tv_center.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
}
/**
* 标题右边图片
*
* @param resId
*/
public void setTextCenterDrawableRight(@DrawableRes int resId) {
Drawable drawable = getResources().getDrawable(resId);
drawable.setBounds(0, 0, DisplayUtil.dip2px(getContext(), 14), DisplayUtil.dip2px(getContext(), 14));
tv_center.setCompoundDrawables(null, null, drawable, null);
}
/**
* 标题左右两边图片
*
* @param leftResId
* @param rightResId
*/
public void setTextCenterDrawableLeftRight(@DrawableRes int leftResId, @DrawableRes int rightResId) {
Drawable drawable_l = getResources().getDrawable(leftResId);
drawable_l.setBounds(0, 0, DisplayUtil.dip2px(getContext(), 14), DisplayUtil.dip2px(getContext(), 14));
Drawable drawable_r = getResources().getDrawable(rightResId);
drawable_r.setBounds(0, 0, DisplayUtil.dip2px(getContext(), 14), DisplayUtil.dip2px(getContext(), 14));
tv_center.setCompoundDrawables(drawable_l, null, drawable_r, null);
}
/**
* 设置右边提示文字
*/
public void setTextRight(String text) {
if (TextUtils.isEmpty(text)) {
tv_right.setVisibility(View.GONE);
} else {
tv_right.setText(text.trim());
tv_right.setVisibility(View.VISIBLE);
}
}
/**
* 设置右边提示文字
*/
public void setTextRight(int textResId) {
setTextRight(getContext().getString(textResId).trim());
}
/**
* 设置右边提示文字颜色
*/
public void setTextRightColor(int color) {
tv_right.setTextColor(color);
}
/**
* 设置右上角按钮图片
*/
public void setImageRight(int resId) {
v_right.setBackgroundResource(resId);
}
/**
* 点击左边图标,一般是返回按钮事件
*/
public void setOnClickLeftViewListener(OnClickListener onClickLeftView) {
this.onClickLeftView = onClickLeftView;
}
/**
* 点击右边图标,例如删除按钮事件
*/
public void setOnClickRightViewListener(OnClickListener onClickRightView) {
this.onClickRightView = onClickRightView;
}
/**
* 点击中间文字事件
*/
public void setOnClickCenterTextListener(OnClickListener onClickCenterText) {
this.onClickCenterText = onClickCenterText;
tv_center.setOnClickListener(onClickCenterText);
}
/**
* 点击右边文字,例如优惠券说明等
*/
public void setOnClickRightTextListener(OnClickListener onClickRightText) {
this.onClickRightText = onClickRightText;
}
/**
* 对于webView,显示关闭按钮,直接关闭activity
*/
public void setOnClickLeftCloseListener(OnClickListener onClickLeftClose) {
this.onClickLeftClose = onClickLeftClose;
}
/**
* 对于webView,显示关闭按钮,直接关闭activity,点击返回按钮则web.goback
*/
public void showLeftCloseView() {
layout_close.setVisibility(View.VISIBLE);
}
/**
* 隐藏右上角文字
*/
public void hideRightText() {
tv_right.setVisibility(View.GONE);
}
/**
* 显示右上角文字
*/
public void showRightText() {
tv_right.setVisibility(View.VISIBLE);
}
public TextView getRightText() {
return tv_right;
}
/**
* 显示右上角图标按钮
*/
public void showRightView() {
layout_right.setVisibility(View.VISIBLE);
}
/**
* 隐藏右上角图标按钮
*/
public void hideRightView() {
layout_right.setVisibility(View.GONE);
}
}
package com.mayi.fastdevelop.view.dialog;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.FloatRange;
import android.support.annotation.StyleRes;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import com.mayi.fastdevelop.R;
/**
* 自定义dialog {@link # https://github.com/luoshihai/XXDialog/}
* <p>
* 用法:<BR/>
* {@code new BaseDialog(this,R.layout.dialog)实现 convert()
* .setCancelable......}
* <p>
* API:<BR/>
* {@link #show()} 显示dialog <BR/>
* {@link #show(boolean)} 如果为true 就显示默认的一个缩放动画<BR/>
* {@link #showWithAnim(int)} 显示一个Dialog自定义一个弹出方式 具体怎么写 可以模仿上面的<BR/>
* {@link #dismiss()} dismiss dialog<BR/>
* {@link #backgroundLight(float light)} 弹出时背景亮度 值为0.0~1.0 1.0表示全黑 0.0表示全白<BR/>
* {@link #fromBottomToMiddle()} 从底部一直弹到中间<BR/>
* {@link #fromBottom()} 从底部弹出 显示在底部<BR/>
* {@link #fromLeftToMiddle()} 从左边一直弹到中间退出也是到左边<BR/>
* {@link #fromRightToMiddle()} 从右边一直弹到中间退出也是到右边<BR/>
* {@link #fromTop()} 从顶部弹出 从顶部弹出 保持在顶部<BR/>
* {@link #fromTopToMiddle()} 从顶部谈到中间 从顶部弹出 保持在中间<BR/>
* {@link #fullScreen()} 全屏显示<BR/>
* {@link #fullWidth()} 全屏宽度<BR/>
* {@link #fullHeight()} 全屏高度<BR/>
* {@link #setWidthAndHeight(int width, int height)} 自定义宽高<BR/>
* {@link #setOnKeyListener(DialogInterface.OnKeyListener onKeyListener)} 当dialog弹出是 按键的点击事件会被dialog获取<BR/>
* {@link #setDialogDismissListener(DialogInterface.OnDismissListener)} 设置dismiss监听<BR/>
* {@link #setOnCancelListener(DialogInterface.OnCancelListener)} 设置取消监听<BR/>
* {@link #setCancelAble(boolean)} 设置能否被取消<BR/>
* {@link #setCanceledOnTouchOutside(boolean cancel)} 设置点击其他地方能否被取消<BR/>
* Created by ludas on 2017/5/5.
*/
public abstract class BaseDialog {
private static Dialog mDialog;
private Window mDialogWindow;
private DialogViewHolder dialogHolder;
private View mRootView;
public BaseDialog(Context context, int layoutId) {
dialogHolder = DialogViewHolder.get(context, layoutId);
mRootView = dialogHolder.getConvertView();
mDialog = new Dialog(context, R.style.dialog);
mDialog.setContentView(mRootView);
mDialogWindow = mDialog.getWindow();
convert(dialogHolder);
}
/**
* 把弹出框view holder传出去
*/
public abstract void convert(DialogViewHolder holder);
public static AlertDialog.Builder creatNormalDialogBuilder(Context context, String title, String message) {
return new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message);
}
public static Dialog getDialog() {
return mDialog;
}
/**
* 显示dialog
*/
public BaseDialog show() {
if (mDialog != null && !mDialog.isShowing()) {
mDialog.show();
}
return this;
}
/**
* @param light 弹出时背景亮度 值为0.0~1.0 1.0表示全黑 0.0表示全白
* @return
*/
public BaseDialog backgroundLight(@FloatRange(from = 0, to = 1) float light) {
if (light < 0.0 || light > 1.0)
return this;
WindowManager.LayoutParams lp = mDialogWindow.getAttributes();
lp.dimAmount = light;
mDialogWindow.setAttributes(lp);
return this;
}
/**
* 从底部一直弹到中间
*/
@SuppressLint("NewApi")
public BaseDialog fromBottomToMiddle() {
mDialogWindow.setWindowAnimations(R.style.window_bottom_in_bottom_out);
return this;
}
/**
* 从底部弹出
*/
public BaseDialog fromBottom() {
fromBottomToMiddle();
mDialogWindow.setGravity(Gravity.CENTER | Gravity.BOTTOM);
return this;
}
/**
* 从左边一直弹到中间退出也是到左边
*/
public BaseDialog fromLeftToMiddle() {
mDialogWindow.setWindowAnimations(R.style.window_left_in_left_out);
mDialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
mDialogWindow.setGravity(Gravity.CENTER | Gravity.START);
return this;
}
/**
* 设置窗体的显示类型
*/
public BaseDialog setWindowType() {
mDialogWindow.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
return this;
}
/**
* 从右边一直弹到中间退出也是到右边
*
* @return
*/
public BaseDialog fromRightToMiddle() {
mDialogWindow.setWindowAnimations(R.style.window_right_in_right_out);
mDialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
mDialogWindow.setGravity(Gravity.END);
return this;
}
/**
* 从顶部弹出 从顶部弹出 保持在顶部
*
* @return
*/
public BaseDialog fromTop() {
fromTopToMiddle();
mDialogWindow.setGravity(Gravity.CENTER | Gravity.TOP);
return this;
}
/**
* 从顶部谈到中间 从顶部弹出 保持在中间
*
* @return
*/
public BaseDialog fromTopToMiddle() {
mDialogWindow.setWindowAnimations(R.style.window_top_in_top_out);
mDialogWindow.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
return this;
}
/**
* @param style 显示一个Dialog自定义一个弹出方式 具体怎么写 可以模仿上面的
* @return
*/
public BaseDialog showWithAnim(@StyleRes int style) {
mDialogWindow.setWindowAnimations(style);
mDialog.show();
return this;
}
/**
* @param isAnimation 如果为true 就显示默认的一个缩放动画
* @return
*/
public BaseDialog show(boolean isAnimation) {
mDialogWindow.setWindowAnimations(R.style.dialog_scale_animstyle);
mDialog.show();
return this;
}
/**
* 全屏显示
*/
public BaseDialog fullScreen() {
WindowManager.LayoutParams wl = mDialogWindow.getAttributes();
wl.height = ViewGroup.LayoutParams.MATCH_PARENT;
wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
mDialog.onWindowAttributesChanged(wl);
return this;
}
public BaseDialog setOnKeyListener(DialogInterface.OnKeyListener onKeyListener) {
mDialog.setOnKeyListener(onKeyListener);
return this;
}
/**
* 全屏宽度
*/
public BaseDialog fullWidth() {
WindowManager.LayoutParams wl = mDialogWindow.getAttributes();
wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
mDialog.onWindowAttributesChanged(wl);
return this;
}
/**
* 全屏高度
*/
public BaseDialog fullHeight() {
WindowManager.LayoutParams wl = mDialogWindow.getAttributes();
wl.height = ViewGroup.LayoutParams.MATCH_PARENT;
mDialog.onWindowAttributesChanged(wl);
return this;
}
/**
* @param width 自定义的宽度
* @param height 自定义的高度
* @return
*/
public BaseDialog setWidthAndHeight(int width, int height) {
WindowManager.LayoutParams wl = mDialogWindow.getAttributes();
wl.width = width;
wl.height = height;
mDialog.onWindowAttributesChanged(wl);
return this;
}
/**
* cancel dialog
*/
public void cancelDialog() {
if (mDialog != null && mDialog.isShowing())
dismiss();
}
/**
* cancel dialog
*/
public void dismiss() {
if (mDialog != null && mDialog.isShowing()) {
mDialog.dismiss();
}
}
/**
* 设置监听
*/
public BaseDialog setDialogDismissListener(DialogInterface.OnDismissListener listener) {
mDialog.setOnDismissListener(listener);
return this;
}
/**
* 设置监听
*/
public BaseDialog setOnCancelListener(DialogInterface.OnCancelListener listener) {
mDialog.setOnCancelListener(listener);
return this;
}
/**
* 设置是否能取消
*/
public BaseDialog setCancelAble(boolean cancel) {
mDialog.setCancelable(cancel);
return this;
}
/**
* 设置触摸其他地方是否能取消
*/
public BaseDialog setCanceledOnTouchOutside(boolean cancel) {
mDialog.setCanceledOnTouchOutside(cancel);
return this;
}
}
package com.mayi.fastdevelop.view.dialog;
import android.content.Context;
import android.support.annotation.StringRes;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;
public class DialogViewHolder {
private final SparseArray<View> mViews;
private View mDialogView;
private DialogViewHolder(Context context, int layoutId) {
this.mViews = new SparseArray<>();
mDialogView = View.inflate(context, layoutId, null);
}
public static DialogViewHolder get(Context context, int layoutId) {
return new DialogViewHolder(context, layoutId);
}
public View getConvertView() {
return mDialogView;
}
public DialogViewHolder setText(int viewId, CharSequence text) {
TextView view = getView(viewId);
view.setText(text);
return this;
}
public DialogViewHolder setText(int viewId, @StringRes int redId) {
TextView view = getView(viewId);
view.setText(redId);
return this;
}
/**
* 设置view 显示状态
*
* @param viewId view id
* @param viewState View.VISIBLE / GONE /INVISIBLE
* @return
*/
public DialogViewHolder setViewVisibleState(int viewId, int viewState) {
View view = getView(viewId);
view.setVisibility(viewState);
return this;
}
/**
* 设置点击事件
*/
public DialogViewHolder setOnClick(int viewId, View.OnClickListener onClick) {
View view = getView(viewId);
view.setOnClickListener(onClick);
return this;
}
/**
* Through control the Id of the access to control, if not join views
*
* @param viewId
* @return
*/
private <T extends View> T getView(int viewId) {
View view = mViews.get(viewId);
if (view == null) {
view = mDialogView.findViewById(viewId);
mViews.put(viewId, view);
}
return (T) view;
}
}
package com.mayi.fastdevelop.view.wheel;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.alibaba.fastjson.JSON;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.view.wheel.adapters.AbstractWheelTextAdapter;
import com.mayi.fastdevelop.view.wheel.views.CustomWheelView;
import com.mayi.fastdevelop.view.wheel.views.OnWheelChangedListener;
import com.mayi.fastdevelop.view.wheel.views.OnWheelScrollListener;
import com.mayi.fastdevelop.view.dialog.BaseDialog;
import com.mayi.fastdevelop.view.dialog.DialogViewHolder;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* 城市二级联动对话框
*/
public class ChangeAddressDialog extends BaseDialog implements View.OnClickListener {
private CustomWheelView wvProvince;
private CustomWheelView wvCitys;
private TextView btnSure;
private TextView btnCancel;
private Context context;
private JSONObject mJsonObj;
private String[] mProvinceDatas;
private Map<String, String[]> mCitisDatasMap = new HashMap<>();
private ArrayList<String> arrProvinces = new ArrayList<String>();
private ArrayList<String> arrCitys = new ArrayList<String>();
private AddressTextAdapter provinceAdapter;
private AddressTextAdapter cityAdapter;
private String strProvince = "上海市";
private String strCity = "黄浦区";
private OnAddressCListener onAddressCListener;
private final static int maxsize = 16;
private final static int minsize = 14;
private final static int chooicesize = 20;
public ChangeAddressDialog(Context context, OnAddressCListener onAddressCListener) {
super(context, R.layout.dialog_myinfo_changeaddress);
this.context = context;
this.onAddressCListener = onAddressCListener;
initDataAndBindEvent();
}
@Override
public void convert(DialogViewHolder holder) {
View view = holder.getConvertView();
wvProvince = (CustomWheelView) view.findViewById(R.id.wv_address_province);
wvCitys = (CustomWheelView) view.findViewById(R.id.wv_address_city);
btnSure = (TextView) view.findViewById(R.id.btn_sure);
btnCancel = (TextView) view.findViewById(R.id.btn_cancel);
btnSure.setOnClickListener(this);
btnCancel.setOnClickListener(this);
}
private void initDataAndBindEvent() {
initJsonData();
initDatas();
initProvinces();
String s= JSON.toJSONString(mCitisDatasMap);
provinceAdapter = new AddressTextAdapter(context, arrProvinces, getProvinceItem(strProvince), maxsize, minsize);
wvProvince.setVisibleItems(5);
wvProvince.setViewAdapter(provinceAdapter);
wvProvince.setCurrentItem(getProvinceItem(strProvince));
initCitys(mCitisDatasMap.get(strProvince));
cityAdapter = new AddressTextAdapter(context, arrCitys, getCityItem(strCity), maxsize, minsize);
wvCitys.setVisibleItems(5);
wvCitys.setViewAdapter(cityAdapter);
wvCitys.setCurrentItem(getCityItem(strCity));
wvProvince.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
// TODO Auto-generated method stub
String currentText = (String) provinceAdapter.getItemText(wheel.getCurrentItem());
strProvince = currentText;
setTextviewSize(currentText, provinceAdapter);
String[] citys = mCitisDatasMap.get(currentText);
initCitys(citys);
cityAdapter = new AddressTextAdapter(context, arrCitys, 0, maxsize, minsize);
wvCitys.setVisibleItems(5);
wvCitys.setViewAdapter(cityAdapter);
wvCitys.setCurrentItem(0);
}
});
wvProvince.addScrollingListener(new OnWheelScrollListener() {
@Override
public void onScrollingStarted(CustomWheelView wheel) {
// TODO Auto-generated method stub
}
@Override
public void onScrollingFinished(CustomWheelView wheel) {
// TODO Auto-generated method stub
String currentText = (String) provinceAdapter.getItemText(wheel.getCurrentItem());
setTextviewSize(currentText, provinceAdapter);
}
});
wvCitys.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
// TODO Auto-generated method stub
String currentText = (String) cityAdapter.getItemText(wheel.getCurrentItem());
strCity = currentText;
setTextviewSize(currentText, cityAdapter);
}
});
wvCitys.addScrollingListener(new OnWheelScrollListener() {
@Override
public void onScrollingStarted(CustomWheelView wheel) {
// TODO Auto-generated method stub
}
@Override
public void onScrollingFinished(CustomWheelView wheel) {
// TODO Auto-generated method stub
String currentText = (String) cityAdapter.getItemText(wheel.getCurrentItem());
setTextviewSize(currentText, cityAdapter);
}
});
}
private class AddressTextAdapter extends AbstractWheelTextAdapter {
ArrayList<String> list;
protected AddressTextAdapter(Context context, ArrayList<String> list, int currentItem, int maxsize, int minsize) {
super(context, R.layout.item_birth_year, NO_RESOURCE, currentItem, maxsize, minsize);
this.list = list;
setItemTextResource(R.id.tempValue);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
View view = super.getItem(index, cachedView, parent);
return view;
}
@Override
public int getItemsCount() {
return list.size();
}
@Override
protected CharSequence getItemText(int index) {
return list.get(index) + "";
}
}
/**
* 设置字体大小
*
* @param curriteItemText
* @param adapter
*/
private void setTextviewSize(String curriteItemText, AddressTextAdapter adapter) {
ArrayList<View> arrayList = adapter.getTestViews();
int size = arrayList.size();
String currentText;
for (int i = 0; i < size; i++) {
TextView textvew = (TextView) arrayList.get(i);
currentText = textvew.getText().toString();
if (curriteItemText.equals(currentText)) {
textvew.setTextSize(chooicesize);
} else {
textvew.setTextSize(minsize);
}
}
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.btn_sure) {
if (onAddressCListener != null) {
onAddressCListener.onClick(strProvince, strCity);
}
dismiss();
} else if (i == R.id.btn_cancel) {
dismiss();
}
}
/**
* 回调接口
*
* @author Administrator
*/
public interface OnAddressCListener {
void onClick(String province, String city);
}
/**
* 从文件中读取地址数据
*/
private void initJsonData() {
try {
InputStream is = context.getResources().getAssets().open("city.json");
int ch = 0;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((ch = is.read()) != -1) {
out.write(ch);
}
byte[] buff = out.toByteArray();
out.close();
is.close();
String content = new String(buff, "UTF-8");
mJsonObj = new JSONObject(content);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 解析数据
*/
private void initDatas() {
try {
JSONArray jsonArray = mJsonObj.optJSONArray("citylist");
mProvinceDatas = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonP = jsonArray.optJSONObject(i);
String province = jsonP.optString("nm");
mProvinceDatas[i] = province;
JSONArray jsonCs = jsonP.optJSONArray("cl");
if (jsonCs != null && jsonCs.length() > 0) {
String[] mCitiesDatas = new String[jsonCs.length()];
for (int j = 0; j < jsonCs.length(); j++) {
JSONObject jsonCity = jsonCs.optJSONObject(j);
String city = jsonCity.optString("nm");
mCitiesDatas[j] = city;
JSONArray jsonAreas = jsonCity.optJSONArray("cl");
if (jsonAreas != null && jsonAreas.length() > 0) {
String[] mAreasDatas = new String[jsonAreas.length()];
for (int k = 0; k < jsonAreas.length(); k++) {
String area = jsonAreas.optJSONObject(k).optString("nm");
mAreasDatas[k] = area;
}
}
}
mCitisDatasMap.put(province, mCitiesDatas);
}
}
} catch (Exception e) {
e.printStackTrace();
}
mJsonObj = null;
}
/**
* 初始化省会
*/
private void initProvinces() {
int length = mProvinceDatas.length;
for (int i = 0; i < length; i++) {
arrProvinces.add(mProvinceDatas[i]);
}
}
/**
* 根据省会,生成该省会的所有城市
*
* @param citys
*/
private void initCitys(String[] citys) {
if (citys != null) {
arrCitys.clear();
int length = citys.length;
for (int i = 0; i < length; i++) {
arrCitys.add(citys[i]);
}
} else {
String[] city = mCitisDatasMap.get("上海市");
arrCitys.clear();
int length = city.length;
for (int i = 0; i < length; i++) {
arrCitys.add(city[i]);
}
}
if (arrCitys != null && arrCitys.size() > 0
&& !arrCitys.contains(strCity)) {
strCity = arrCitys.get(0);
}
}
/**
* 返回省会索引,没有就返回默认“上海市”
*
* @param province
* @return
*/
private int getProvinceItem(String province) {
int size = arrProvinces.size();
int provinceIndex = 0;
for (int i = 0; i < size; i++) {
if (province.equals(arrProvinces.get(i))) {
return provinceIndex;
} else {
provinceIndex++;
}
}
strProvince = "上海市";
return 22;
}
/**
* 得到城市索引,没有返回默认“市辖区”
*
* @param city
* @return
*/
private int getCityItem(String city) {
int size = arrCitys.size();
int cityIndex = 0;
for (int i = 0; i < size; i++) {
if (city.equals(arrCitys.get(i))) {
return cityIndex;
} else {
cityIndex++;
}
}
strCity = "市辖区";
return 0;
}
}
\ No newline at end of file
package com.mayi.fastdevelop.view.wheel;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.view.wheel.adapters.AbstractWheelTextAdapter;
import com.mayi.fastdevelop.view.wheel.views.CustomWheelView;
import com.mayi.fastdevelop.view.wheel.views.OnWheelChangedListener;
import com.mayi.fastdevelop.view.wheel.views.OnWheelScrollListener;
import com.mayi.fastdevelop.view.dialog.BaseDialog;
import com.mayi.fastdevelop.view.dialog.DialogViewHolder;
import java.util.ArrayList;
import java.util.Calendar;
/**
* 日期选择对话框
*/
public class ChangeBirthDialog extends BaseDialog implements View.OnClickListener {
private Context context;
private CustomWheelView wvYear;
private CustomWheelView wvMonth;
private CustomWheelView wvDay;
private TextView btnSure;
private TextView btnCancel;
private ArrayList<String> arry_years = new ArrayList<>();
private ArrayList<String> arry_months = new ArrayList<>();
private ArrayList<String> arry_days = new ArrayList<>();
private CalendarTextAdapter mYearAdapter;
private CalendarTextAdapter mMonthAdapter;
private CalendarTextAdapter mDaydapter;
private int month;
private int day;
private int currentYear;
private int currentMonth;
private int currentDay;
private int maxTextSize = 20;
private int minTextSize = 14;
private String selectYear;
private String selectMonth;
private String selectDay;
private OnBirthListener onBirthListener;
public ChangeBirthDialog(Context context, OnBirthListener onBirthListener) {
super(context, R.layout.dialog_myinfo_changebirth);
this.context = context;
this.onBirthListener = onBirthListener;
setDate(getYear(), getMonth(), getDay());
initDataAndBindEvent();
}
@Override
public void convert(DialogViewHolder holder) {
View view = holder.getConvertView();
wvYear = (CustomWheelView) view.findViewById(R.id.wv_birth_year);
wvMonth = (CustomWheelView) view.findViewById(R.id.wv_birth_month);
wvDay = (CustomWheelView) view.findViewById(R.id.wv_birth_day);
btnSure = (TextView) view.findViewById(R.id.btn_sure);
btnCancel = (TextView) view.findViewById(R.id.btn_cancel);
btnSure.setOnClickListener(this);
btnCancel.setOnClickListener(this);
}
private void initDataAndBindEvent() {
initYears();
mYearAdapter = new CalendarTextAdapter(context, arry_years, setYear(currentYear), maxTextSize, minTextSize);
wvYear.setVisibleItems(5);
wvYear.setViewAdapter(mYearAdapter);
wvYear.setCurrentItem(setYear(currentYear));
initMonths(month);
mMonthAdapter = new CalendarTextAdapter(context, arry_months, setMonth(currentMonth), maxTextSize, minTextSize);
wvMonth.setVisibleItems(5);
wvMonth.setViewAdapter(mMonthAdapter);
wvMonth.setCurrentItem(setMonth(currentMonth));
initDays(day);
mDaydapter = new CalendarTextAdapter(context, arry_days, currentDay - 1, maxTextSize, minTextSize);
wvDay.setVisibleItems(5);
wvDay.setViewAdapter(mDaydapter);
wvDay.setCurrentItem(currentDay - 1);
wvYear.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
// TODO Auto-generated method stub
String currentText = (String) mYearAdapter.getItemText(wheel.getCurrentItem());
selectYear = currentText;
setTextviewSize(currentText, mYearAdapter);
currentYear = Integer.parseInt(currentText);
setYear(currentYear);
initMonths(month);
mMonthAdapter = new CalendarTextAdapter(context, arry_months, 0, maxTextSize, minTextSize);
wvMonth.setVisibleItems(5);
wvMonth.setViewAdapter(mMonthAdapter);
wvMonth.setCurrentItem(0);
}
});
wvYear.addScrollingListener(new OnWheelScrollListener() {
@Override
public void onScrollingStarted(CustomWheelView wheel) {
}
@Override
public void onScrollingFinished(CustomWheelView wheel) {
String currentText = (String) mYearAdapter.getItemText(wheel.getCurrentItem());
setTextviewSize(currentText, mYearAdapter);
}
});
wvMonth.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
String currentText = (String) mMonthAdapter.getItemText(wheel.getCurrentItem());
selectMonth = currentText;
setTextviewSize(currentText, mMonthAdapter);
setMonth(Integer.parseInt(currentText));
initDays(day);
mDaydapter = new CalendarTextAdapter(context, arry_days, 0, maxTextSize, minTextSize);
wvDay.setVisibleItems(5);
wvDay.setViewAdapter(mDaydapter);
wvDay.setCurrentItem(0);
}
});
wvMonth.addScrollingListener(new OnWheelScrollListener() {
@Override
public void onScrollingStarted(CustomWheelView wheel) {
}
@Override
public void onScrollingFinished(CustomWheelView wheel) {
String currentText = (String) mMonthAdapter.getItemText(wheel.getCurrentItem());
setTextviewSize(currentText, mMonthAdapter);
}
});
wvDay.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
String currentText = (String) mDaydapter.getItemText(wheel.getCurrentItem());
setTextviewSize(currentText, mDaydapter);
selectDay = currentText;
}
});
wvDay.addScrollingListener(new OnWheelScrollListener() {
@Override
public void onScrollingStarted(CustomWheelView wheel) {
}
@Override
public void onScrollingFinished(CustomWheelView wheel) {
String currentText = (String) mDaydapter.getItemText(wheel.getCurrentItem());
setTextviewSize(currentText, mDaydapter);
}
});
}
public void initYears() {
for (int i = getYear(); i > 1950; i--) {
arry_years.add(i + "");
}
}
public void initMonths(int months) {
arry_months.clear();
for (int i = 1; i <= months; i++) {
arry_months.add(i + "");
}
}
public void initDays(int days) {
arry_days.clear();
for (int i = 1; i <= days; i++) {
arry_days.add(i + "");
}
}
private class CalendarTextAdapter extends AbstractWheelTextAdapter {
ArrayList<String> list;
protected CalendarTextAdapter(Context context, ArrayList<String> list, int currentItem, int maxsize, int minsize) {
super(context, R.layout.item_birth_year, NO_RESOURCE, currentItem, maxsize, minsize);
this.list = list;
setItemTextResource(R.id.tempValue);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
View view = super.getItem(index, cachedView, parent);
return view;
}
@Override
public int getItemsCount() {
return list.size();
}
@Override
protected CharSequence getItemText(int index) {
return list.get(index) + "";
}
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.btn_sure) {
if (onBirthListener != null) {
onBirthListener.onClick(selectYear, selectMonth, selectDay);
}
dismiss();
} else if (i == R.id.btn_cancel) {
dismiss();
}
}
public interface OnBirthListener {
void onClick(String year, String month, String day);
}
/**
* 设置字体大小
*/
public void setTextviewSize(String curriteItemText, CalendarTextAdapter adapter) {
ArrayList<View> arrayList = adapter.getTestViews();
int size = arrayList.size();
String currentText;
for (int i = 0; i < size; i++) {
TextView textvew = (TextView) arrayList.get(i);
currentText = textvew.getText().toString();
if (curriteItemText.equals(currentText)) {
textvew.setTextSize(maxTextSize);
} else {
textvew.setTextSize(minTextSize);
}
}
}
public int getYear() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.YEAR);
}
public int getMonth() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.MONTH) + 1;
}
public int getDay() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.DATE);
}
/**
* 设置年月日
*/
public void setDate(int year, int month, int day) {
this.currentYear = year;
this.currentMonth = month;
this.currentDay = day;
selectYear = year + "";
selectMonth = month + "";
selectDay = day + "";
calDays(year, month);
}
/**
* 设置年份
*/
public int setYear(int year) {
int yearIndex = 0;
if (year != getYear()) {
this.month = 12;
} else {
this.month = getMonth();
}
for (int i = getYear(); i > 1950; i--) {
if (i == year) {
return yearIndex;
}
yearIndex++;
}
return yearIndex;
}
/**
* 设置月份
*/
public int setMonth(int month) {
int monthIndex = 0;
calDays(currentYear, month);
for (int i = 1; i < this.month; i++) {
if (month == i) {
return monthIndex;
} else {
monthIndex++;
}
}
return monthIndex;
}
/**
* 计算每月多少天
*/
public void calDays(int year, int month) {
boolean leayyear = false;
if (year % 4 == 0 && year % 100 != 0) {
leayyear = true;
} else {
leayyear = false;
}
for (int i = 1; i <= 12; i++) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
this.day = 31;
break;
case 2:
if (leayyear) {
this.day = 29;
} else {
this.day = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
this.day = 30;
break;
}
}
if (year == getYear() && month == getMonth()) {
this.day = getDay();
}
}
}
\ No newline at end of file
package com.mayi.fastdevelop.view.wheel;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.view.wheel.adapters.AbstractWheelTextAdapter;
import com.mayi.fastdevelop.view.wheel.views.CustomWheelView;
import com.mayi.fastdevelop.view.wheel.views.OnWheelChangedListener;
import com.mayi.fastdevelop.view.dialog.DialogViewHolder;
import com.mayi.fastdevelop.view.dialog.BaseDialog;
import java.util.ArrayList;
import java.util.Calendar;
import static java.lang.Integer.parseInt;
/**
* 选择日期dialog
*/
public class ChangeDateDialog extends BaseDialog implements View.OnClickListener {
private Context mContext;
private OnDateListener onTimeListener;
private ArrayList<String> array_years = new ArrayList<>();
private ArrayList<String> array_months = new ArrayList<>();
private ArrayList<String> array_days = new ArrayList<>();
private CalendarTextAdapter mYearAdapter;
private CalendarTextAdapter mMonthAdapter;
private CalendarTextAdapter mDaydapter;
private CalendarTextAdapter mHourAdapter;
private CalendarTextAdapter mMinuteAdapter;
private String mYear, mMonth, mDay, mHour, mMinute;
private CustomWheelView wvYear;
private CustomWheelView wvMonth;
private CustomWheelView wvDay;
private TextView btnSure;
private TextView btnCancel;
private int day;
private int currentYear, currentMonth, currentDay;
private int maxTextSize = 20;
private int minTextSize = 14;
public ChangeDateDialog(Context context, OnDateListener onTimeListener) {
super(context, R.layout.view_wheel_date);
this.mContext = context;
this.onTimeListener = onTimeListener;
getDate();
initDataAndBindEvent();
}
private void getDate() {
this.currentYear = getYear();
this.currentMonth = getMonth();
this.currentDay = getDay();
calDays(currentYear, currentMonth);/*计算当月天数*/
}
private void initDataAndBindEvent() {
initYears();
mYearAdapter = new CalendarTextAdapter(mContext, array_years, 1, maxTextSize, minTextSize);
wvYear.setVisibleItems(5);
wvYear.setViewAdapter(mYearAdapter);
wvYear.setCurrentItem(1);
mYear = array_years.get(1);
initMonths();
mMonthAdapter = new CalendarTextAdapter(mContext, array_months, currentMonth, maxTextSize, minTextSize);
wvMonth.setVisibleItems(5);
wvMonth.setViewAdapter(mMonthAdapter);
wvMonth.setCurrentItem(currentMonth - 1);
mMonth = array_months.get(currentMonth - 1);
initDays(day);
mDaydapter = new CalendarTextAdapter(mContext, array_days, currentDay - 1, maxTextSize, minTextSize);
wvDay.setVisibleItems(5);
wvDay.setViewAdapter(mDaydapter);
wvDay.setCurrentItem(currentDay - 1);
mDay = array_days.get(currentDay - 1);
wvYear.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mYear = (String) mYearAdapter.getItemText(wheel.getCurrentItem());
currentYear = parseInt(mYear);
}
});
wvMonth.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mMonth = (String) mMonthAdapter.getItemText(wheel.getCurrentItem());
currentMonth = parseInt(mMonth);
calDays(currentYear, currentMonth);
initDays(day);
mDaydapter = new CalendarTextAdapter(mContext, array_days, currentDay - 1, maxTextSize, minTextSize);
wvDay.setVisibleItems(5);
wvDay.setViewAdapter(mDaydapter);
wvDay.setCurrentItem(currentDay - 1);
}
});
wvDay.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mDay = (String) mDaydapter.getItemText(wheel.getCurrentItem());
currentDay = parseInt(mDay);
}
});
}
private void initYears() {
array_years.clear();
for (int i = currentYear - 1; i <= currentYear + 1; i++) {
array_years.add(String.valueOf(i));
}
}
private void initMonths() {
array_months.clear();
for (int i = 1; i <= 12; i++) {
array_months.add(String.valueOf(i));
}
}
private void initDays(int days) {
array_days.clear();
for (int i = 1; i <= days; i++) {
array_days.add(String.valueOf(i));
}
}
/**
* 计算每月多少天
*/
public void calDays(int yrear, int month) {
boolean leayyear;
if (currentYear % 4 == 0 && currentYear % 100 != 0) {
leayyear = true;
} else {
leayyear = false;
}
for (int i = 1; i <= 12; i++) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
this.day = 31;
break;
case 2:
if (leayyear) {
this.day = 29;
} else {
this.day = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
this.day = 30;
break;
}
}
}
private int getYear() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.YEAR);
}
private int getMonth() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.MONTH) + 1;
}
private int getDay() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.DAY_OF_MONTH);
}
public interface OnDateListener {
void onClick(String year, String month, String day);
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.txt_complete) {
if (onTimeListener != null) {
mMonth = parseInt(mMonth) > 9 ? mMonth : "0" + mMonth;
mDay = parseInt(mDay) > 9 ? mDay : "0" + mDay;
onTimeListener.onClick(mYear, mMonth, mDay);
}
dismiss();
} else if (i == R.id.txt_think) {
dismiss();
}
}
@Override
public void convert(DialogViewHolder holder) {
View view = holder.getConvertView();
wvYear = (CustomWheelView) view.findViewById(R.id.wv_year);
wvMonth = (CustomWheelView) view.findViewById(R.id.wv_month);
wvDay = (CustomWheelView) view.findViewById(R.id.wv_day);
btnSure = (TextView) view.findViewById(R.id.txt_complete);
btnCancel = (TextView) view.findViewById(R.id.txt_think);
btnSure.setOnClickListener(this);
btnCancel.setOnClickListener(this);
}
private class CalendarTextAdapter extends AbstractWheelTextAdapter {
ArrayList<String> list;
protected CalendarTextAdapter(Context context, ArrayList<String> list, int currentItem, int maxsize, int minsize) {
super(context, R.layout.item_birth_year, NO_RESOURCE, currentItem, maxsize, minsize);
this.list = list;
setItemTextResource(R.id.tempValue);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
View view = super.getItem(index, cachedView, parent);
return view;
}
@Override
public int getItemsCount() {
return list.size();
}
@Override
protected CharSequence getItemText(int index) {
return list.get(index) + "";
}
}
}
package com.mayi.fastdevelop.view.wheel;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.view.wheel.adapters.AbstractWheelTextAdapter;
import com.mayi.fastdevelop.view.wheel.views.CustomWheelView;
import com.mayi.fastdevelop.view.wheel.views.OnWheelChangedListener;
import com.mayi.fastdevelop.view.dialog.BaseDialog;
import com.mayi.fastdevelop.view.dialog.DialogViewHolder;
import java.util.ArrayList;
import java.util.Calendar;
import static java.lang.Integer.parseInt;
/**
* 日期时间对话框
*/
public class ChangeTimeDialog extends BaseDialog implements View.OnClickListener {
private Context mContext;
private OnTimeListener onTimeListener;
private ArrayList<String> array_years = new ArrayList<>();
private ArrayList<String> array_months = new ArrayList<>();
private ArrayList<String> array_days = new ArrayList<>();
private ArrayList<String> array_hours = new ArrayList<>();
private ArrayList<String> array_minutes = new ArrayList<>();
private CalendarTextAdapter mYearAdapter;
private CalendarTextAdapter mMonthAdapter;
private CalendarTextAdapter mDaydapter;
private CalendarTextAdapter mHourAdapter;
private CalendarTextAdapter mMinuteAdapter;
private String mYear, mMonth, mDay, mHour, mMinute;
private CustomWheelView wvYear;
private CustomWheelView wvMonth;
private CustomWheelView wvDay;
private CustomWheelView wvHour;
private CustomWheelView wvMinute;
private TextView btnSure;
private TextView btnCancel;
private int day;
private int currentYear, currentMonth, currentDay, currentHour, currentMinute;
private int maxTextSize = 20;
private int minTextSize = 14;
private boolean isDismiss = true;
public ChangeTimeDialog(Context context, OnTimeListener onTimeListener) {
super(context, R.layout.view_wheel_time);
this.mContext = context;
this.onTimeListener = onTimeListener;
getDate();
initDataAndBindEvent();
}
public ChangeTimeDialog(Context context, OnTimeListener onTimeListener, boolean isDismiss) {
super(context, R.layout.view_wheel_time);
this.mContext = context;
this.onTimeListener = onTimeListener;
this.isDismiss = isDismiss;
getDate();
initDataAndBindEvent();
}
public void setDismiss(boolean dismiss) {
isDismiss = dismiss;
}
private void getDate() {
this.currentYear = getYear();
this.currentMonth = getMonth();
this.currentDay = getDay();
this.currentHour = getHour();
this.currentMinute = getMinute();
calDays(currentYear, currentMonth);/*计算当月天数*/
}
private void initDataAndBindEvent() {
initYears();
mYearAdapter = new CalendarTextAdapter(mContext, array_years, 1, maxTextSize, minTextSize);
wvYear.setVisibleItems(5);
wvYear.setViewAdapter(mYearAdapter);
wvYear.setCurrentItem(1);
mYear = array_years.get(1);
initMonths();
mMonthAdapter = new CalendarTextAdapter(mContext, array_months, currentMonth, maxTextSize, minTextSize);
wvMonth.setVisibleItems(5);
wvMonth.setViewAdapter(mMonthAdapter);
wvMonth.setCurrentItem(currentMonth - 1);
mMonth = array_months.get(currentMonth - 1);
initDays(day);
mDaydapter = new CalendarTextAdapter(mContext, array_days, currentDay - 1, maxTextSize, minTextSize);
wvDay.setVisibleItems(5);
wvDay.setViewAdapter(mDaydapter);
wvDay.setCurrentItem(currentDay - 1);
mDay = array_days.get(currentDay - 1);
initHours();
mHourAdapter = new CalendarTextAdapter(mContext, array_hours, currentHour, maxTextSize, minTextSize);
wvHour.setVisibleItems(5);
wvHour.setViewAdapter(mHourAdapter);
wvHour.setCurrentItem(currentHour);
mHour = array_hours.get(currentHour);
initMinute();
mMinuteAdapter = new CalendarTextAdapter(mContext, array_minutes, currentMinute - 1, maxTextSize, minTextSize);
wvMinute.setVisibleItems(5);
wvMinute.setViewAdapter(mMinuteAdapter);
wvMinute.setCurrentItem(currentMinute);
mMinute = array_minutes.get(currentMinute);
wvYear.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mYear = (String) mYearAdapter.getItemText(wheel.getCurrentItem());
currentYear = parseInt(mYear);
}
});
wvMonth.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mMonth = (String) mMonthAdapter.getItemText(wheel.getCurrentItem());
currentMonth = parseInt(mMonth);
calDays(currentYear, currentMonth);
initDays(day);
mDaydapter = new CalendarTextAdapter(mContext, array_days, currentDay - 1, maxTextSize, minTextSize);
wvDay.setVisibleItems(5);
wvDay.setViewAdapter(mDaydapter);
wvDay.setCurrentItem(currentDay - 1);
}
});
wvDay.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mDay = (String) mDaydapter.getItemText(wheel.getCurrentItem());
currentDay = parseInt(mDay);
}
});
wvHour.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mHour = (String) mHourAdapter.getItemText(wheel.getCurrentItem());
currentHour = parseInt(mHour);
}
});
wvMinute.addChangingListener(new OnWheelChangedListener() {
@Override
public void onChanged(CustomWheelView wheel, int oldValue, int newValue) {
mMinute = (String) mMinuteAdapter.getItemText(wheel.getCurrentItem());
currentMinute = parseInt(mMinute);
}
});
}
private void initYears() {
array_years.clear();
for (int i = currentYear - 1; i <= currentYear + 1; i++) {
array_years.add(String.valueOf(i));
}
}
private void initMonths() {
array_months.clear();
for (int i = 1; i <= 12; i++) {
array_months.add(String.valueOf(i));
}
}
private void initDays(int days) {
array_days.clear();
for (int i = 1; i <= days; i++) {
array_days.add(String.valueOf(i));
}
}
private void initHours() {
array_hours.clear();
for (int i = 0; i < 24; i++) {
array_hours.add(String.valueOf(i));
}
}
private void initMinute() {
array_minutes.clear();
for (int i = 0; i < 60; i++) {
array_minutes.add(String.valueOf(i));
}
}
/**
* 计算每月多少天
*/
public void calDays(int yrear, int month) {
boolean leayyear;
if (currentYear % 4 == 0 && currentYear % 100 != 0) {
leayyear = true;
} else {
leayyear = false;
}
for (int i = 1; i <= 12; i++) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
this.day = 31;
break;
case 2:
if (leayyear) {
this.day = 29;
} else {
this.day = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
this.day = 30;
break;
}
}
}
private int getYear() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.YEAR);
}
private int getMonth() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.MONTH) + 1;
}
private int getDay() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.DAY_OF_MONTH);
}
private int getHour() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.HOUR_OF_DAY);
}
private int getMinute() {
Calendar c = Calendar.getInstance();
return c.get(Calendar.MINUTE);
}
public interface OnTimeListener {
void onClick(String year, String month, String day, String hour, String minute);
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.txt_complete) {
if (onTimeListener != null) {
mMonth = Integer.parseInt(mMonth) > 9 ? mMonth : "0" + Integer.parseInt(mMonth);
mDay = Integer.parseInt(mDay) > 9 ? mDay : "0" + Integer.parseInt(mDay);
mHour = Integer.parseInt(mHour) > 9 ? mHour : "0" + Integer.parseInt(mHour);
mMinute = Integer.parseInt(mMinute) > 9 ? mMinute : "0" + Integer.parseInt(mMinute);
onTimeListener.onClick(mYear, mMonth, mDay, mHour, mMinute);
}
if (isDismiss) {
dismiss();
}
} else if (i == R.id.txt_think) {
dismiss();
}
}
@Override
public void convert(DialogViewHolder holder) {
View view = holder.getConvertView();
wvYear = (CustomWheelView) view.findViewById(R.id.wv_year);
wvMonth = (CustomWheelView) view.findViewById(R.id.wv_month);
wvDay = (CustomWheelView) view.findViewById(R.id.wv_day);
wvHour = (CustomWheelView) view.findViewById(R.id.wv_hour);
wvMinute = (CustomWheelView) view.findViewById(R.id.wv_minute);
btnSure = (TextView) view.findViewById(R.id.txt_complete);
btnCancel = (TextView) view.findViewById(R.id.txt_think);
btnSure.setOnClickListener(this);
btnCancel.setOnClickListener(this);
}
private class CalendarTextAdapter extends AbstractWheelTextAdapter {
ArrayList<String> list;
protected CalendarTextAdapter(Context context, ArrayList<String> list, int currentItem, int maxsize, int minsize) {
super(context, R.layout.item_birth_year, NO_RESOURCE, currentItem, maxsize, minsize);
this.list = list;
setItemTextResource(R.id.tempValue);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
View view = super.getItem(index, cachedView, parent);
return view;
}
@Override
public int getItemsCount() {
return list.size();
}
@Override
protected CharSequence getItemText(int index) {
return list.get(index) + "";
}
}
}
/*
* /**
* * Copyright &copy; 2017-2020 All rights reserved.
* * Licensed under the yen License, Version 1.0 (the "License");
*
*/
package com.mayi.fastdevelop.view.wheel.adapters;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import java.util.LinkedList;
import java.util.List;
/**
* Abstract Wheel adapter.
*/
public abstract class AbstractWheelAdapter implements WheelViewAdapter {
// Observers
private List<DataSetObserver> datasetObservers;
@Override
public View getEmptyItem(View convertView, ViewGroup parent) {
return null;
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
if (datasetObservers == null) {
datasetObservers = new LinkedList<>();
}
datasetObservers.add(observer);
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
if (datasetObservers != null) {
datasetObservers.remove(observer);
}
}
/**
* Notifies observers about data changing
*/
protected void notifyDataChangedEvent() {
if (datasetObservers != null) {
for (DataSetObserver observer : datasetObservers) {
observer.onChanged();
}
}
}
/**
* Notifies observers about invalidating data
*/
protected void notifyDataInvalidatedEvent() {
if (datasetObservers != null) {
for (DataSetObserver observer : datasetObservers) {
observer.onInvalidated();
}
}
}
}
package com.mayi.fastdevelop.view.wheel.adapters;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Abstract wheel adapter provides common functionality for adapters.
*/
public abstract class AbstractWheelTextAdapter extends AbstractWheelAdapter {
/** Text view resource. Used as a default view for adapter. */
public static final int TEXT_VIEW_ITEM_RESOURCE = -1;
/** No resource constant. */
protected static final int NO_RESOURCE = 0;
/** Default text color */
public static final int DEFAULT_TEXT_COLOR = 0xFF101010;
/** Default text color */
public static final int LABEL_COLOR = 0xFF700070;
/** Default text size */
public static final int DEFAULT_TEXT_SIZE = 20;
// Text settings
private int textColor = DEFAULT_TEXT_COLOR;
private int textSize = DEFAULT_TEXT_SIZE;
// Current context
protected Context context;
// Layout inflater
protected LayoutInflater inflater;
// Items resources
protected int itemResourceId;
protected int itemTextResourceId;
// Empty items resources
protected int emptyItemResourceId;
private int currentIndex = 0;
private static int maxsize = 17;
private static int minsize = 14;
private ArrayList<View> arrayList = new ArrayList<View>();
/**
* Constructor
*
* @param context
* the current context
*/
protected AbstractWheelTextAdapter(Context context) {
this(context, TEXT_VIEW_ITEM_RESOURCE);
}
/**
* Constructor
*
* @param context
* the current context
* @param itemResource
* the resource ID for a layout file containing a TextView to use
* when instantiating items views
*/
protected AbstractWheelTextAdapter(Context context, int itemResource) {
this(context, itemResource, NO_RESOURCE, 0, maxsize, minsize);
}
/**
* Constructor
*
* @param context
* the current context
* @param itemResource
* the resource ID for a layout file containing a TextView to use
* when instantiating items views
* @param itemTextResource
* the resource ID for a text view in the item layout
*/
protected AbstractWheelTextAdapter(Context context, int itemResource, int itemTextResource, int currentIndex,
int maxsize, int minsize) {
this.context = context;
itemResourceId = itemResource;
itemTextResourceId = itemTextResource;
this.currentIndex = currentIndex;
this.maxsize = maxsize;
this.minsize = minsize;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
/**
* get the list of show textview
*
* @return the array of textview
*/
public ArrayList<View> getTestViews() {
return arrayList;
}
/**
* Gets text color
*
* @return the text color
*/
public int getTextColor() {
return textColor;
}
/**
* Sets text color
*
* @param textColor
* the text color to set
*/
public void setTextColor(int textColor) {
this.textColor = textColor;
}
/**
* Gets text size
*
* @return the text size
*/
public int getTextSize() {
return textSize;
}
/**
* Sets text size
*
* @param textSize
* the text size to set
*/
public void setTextSize(int textSize) {
this.textSize = textSize;
}
/**
* Gets resource Id for items views
*
* @return the item resource Id
*/
public int getItemResource() {
return itemResourceId;
}
/**
* Sets resource Id for items views
*
* @param itemResourceId
* the resource Id to set
*/
public void setItemResource(int itemResourceId) {
this.itemResourceId = itemResourceId;
}
/**
* Gets resource Id for text view in item layout
*
* @return the item text resource Id
*/
public int getItemTextResource() {
return itemTextResourceId;
}
/**
* Sets resource Id for text view in item layout
*
* @param itemTextResourceId
* the item text resource Id to set
*/
public void setItemTextResource(int itemTextResourceId) {
this.itemTextResourceId = itemTextResourceId;
}
/**
* Gets resource Id for empty items views
*
* @return the empty item resource Id
*/
public int getEmptyItemResource() {
return emptyItemResourceId;
}
/**
* Sets resource Id for empty items views
*
* @param emptyItemResourceId
* the empty item resource Id to set
*/
public void setEmptyItemResource(int emptyItemResourceId) {
this.emptyItemResourceId = emptyItemResourceId;
}
/**
* Returns text for specified item
*
* @param index
* the item index
* @return the text of specified items
*/
protected abstract CharSequence getItemText(int index);
@Override
public View getItem(int index, View convertView, ViewGroup parent) {
if (index >= 0 && index < getItemsCount()) {
if (convertView == null) {
convertView = getView(itemResourceId, parent);
}
TextView textView = getTextView(convertView, itemTextResourceId);
if (!arrayList.contains(textView)) {
arrayList.add(textView);
}
if (textView != null) {
CharSequence text = getItemText(index);
if (text == null) {
text = "";
}
textView.setText(text);
// if (index == currentIndex) {
// textView.setTextSize(maxsize);
// } else {
// textView.setTextSize(minsize);
// }
if (itemResourceId == TEXT_VIEW_ITEM_RESOURCE) {
configureTextView(textView);
}
}
return convertView;
}
return null;
}
@Override
public View getEmptyItem(View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getView(emptyItemResourceId, parent);
}
if (emptyItemResourceId == TEXT_VIEW_ITEM_RESOURCE && convertView instanceof TextView) {
configureTextView((TextView) convertView);
}
return convertView;
}
/**
* Configures text view. Is called for the TEXT_VIEW_ITEM_RESOURCE views.
*
* @param view
* the text view to be configured
*/
protected void configureTextView(TextView view) {
view.setTextColor(textColor);
view.setGravity(Gravity.CENTER);
view.setTextSize(textSize);
view.setLines(1);
view.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
}
/**
* Loads a text view from view
*
* @param view
* the text view or layout containing it
* @param textResource
* the text resource Id in layout
* @return the loaded text view
*/
private TextView getTextView(View view, int textResource) {
TextView text = null;
try {
if (textResource == NO_RESOURCE && view instanceof TextView) {
text = (TextView) view;
} else if (textResource != NO_RESOURCE) {
text = (TextView) view.findViewById(textResource);
}
} catch (ClassCastException e) {
Log.e("AbstractWheelAdapter", "You must supply a resource ID for a TextView");
throw new IllegalStateException("AbstractWheelAdapter requires the resource ID to be a TextView", e);
}
return text;
}
/**
* Loads view from resources
*
* @param resource
* the resource Id
* @return the loaded view or null if resource is not set
*/
private View getView(int resource, ViewGroup parent) {
switch (resource) {
case NO_RESOURCE:
return null;
case TEXT_VIEW_ITEM_RESOURCE:
return new TextView(context);
default:
return inflater.inflate(resource, parent, false);
}
}
}
package com.mayi.fastdevelop.view.wheel.adapters;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
/**
* Wheel items adapter interface
*/
public interface WheelViewAdapter {
/**
* Gets items count
*
* @return the count of wheel items
*/
int getItemsCount();
/**
* Get a View that displays the data at the specified position in the data
* set
*
* @param index the item index
* @param convertView the old view to reuse if possible
* @param parent the parent that this view will eventually be attached to
* @return the wheel item View
*/
View getItem(int index, View convertView, ViewGroup parent);
/**
* Get a View that displays an empty wheel item placed before the first or
* after the last wheel item.
*
* @param convertView the old view to reuse if possible
* @param parent the parent that this view will eventually be attached to
* @return the empty item View
*/
View getEmptyItem(View convertView, ViewGroup parent);
/**
* Register an observer that is called when changes happen to the data used
* by this adapter.
*
* @param observer the observer to be registered
*/
void registerDataSetObserver(DataSetObserver observer);
/**
* Unregister an observer that has previously been registered
*
* @param observer the observer to be unregistered
*/
void unregisterDataSetObserver(DataSetObserver observer);
}
package com.mayi.fastdevelop.view.wheel.views;
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.view.wheel.adapters.WheelViewAdapter;
import java.util.LinkedList;
import java.util.List;
/**
* Numeric wheel view.
*/
public class CustomWheelView extends View {
/**
* Top and bottom shadows colors
*/
private static final int[] SHADOWS_COLORS = new int[]{0xeeffffff, 0xeaffffff, 0x33ffffff};
/**
* Top and bottom items offset (to hide that)
*/
private static final int ITEM_OFFSET_PERCENT = 10;
/**
* Left and right padding value
*/
private static final int PADDING = 10;
/**
* Default count of visible items
*/
private static final int DEF_VISIBLE_ITEMS = 5;
// Wheel Values
private int currentItem = 0;
// Count of visible items
private int visibleItems = DEF_VISIBLE_ITEMS;
// Item height
private int itemHeight = 0;
// Center Line
private Drawable centerDrawable;
// Shadows drawables
private GradientDrawable topShadow;
private GradientDrawable bottomShadow;
// Scrolling
private WheelScroller scroller;
private boolean isScrollingPerformed;
private int scrollingOffset;
// Cyclic
boolean isCyclic = false;
// Items layout
private LinearLayout itemsLayout;
// The number of first item in layout
private int firstItem;
// View adapter
private WheelViewAdapter viewAdapter;
// Recycle
private WheelRecycle recycle = new WheelRecycle(this);
// Listeners
private List<OnWheelChangedListener> changingListeners = new LinkedList<>();
private List<OnWheelScrollListener> scrollingListeners = new LinkedList<>();
private List<OnWheelClickedListener> clickingListeners = new LinkedList<>();
public CustomWheelView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initData(context);
}
public CustomWheelView(Context context, AttributeSet attrs) {
super(context, attrs);
initData(context);
}
public CustomWheelView(Context context) {
super(context);
initData(context);
}
/**
* Initializes class data
*
* @param context the context
*/
private void initData(Context context) {
scroller = new WheelScroller(getContext(), scrollingListener);
}
// Scrolling listener
WheelScroller.ScrollingListener scrollingListener = new WheelScroller.ScrollingListener() {
@Override
public void onStarted() {
isScrollingPerformed = true;
notifyScrollingListenersAboutStart();
}
@Override
public void onScroll(int distance) {
doScroll(distance);
int height = getHeight();
if (scrollingOffset > height) {
scrollingOffset = height;
scroller.stopScrolling();
} else if (scrollingOffset < -height) {
scrollingOffset = -height;
scroller.stopScrolling();
}
}
@Override
public void onFinished() {
if (isScrollingPerformed) {
notifyScrollingListenersAboutEnd();
isScrollingPerformed = false;
}
scrollingOffset = 0;
invalidate();
}
@Override
public void onJustify() {
if (Math.abs(scrollingOffset) > WheelScroller.MIN_DELTA_FOR_SCROLLING) {
scroller.scroll(scrollingOffset, 0);
}
}
};
/**
* Set the the specified scrolling interpolator
*
* @param interpolator the interpolator
*/
public void setInterpolator(Interpolator interpolator) {
scroller.setInterpolator(interpolator);
}
/**
* Gets count of visible items
*
* @return the count of visible items
*/
public int getVisibleItems() {
return visibleItems;
}
/**
* Sets the desired count of visible items. Actual amount of visible items
* depends on wheel layout parameters. To apply changes and rebuild view
* call measure().
*
* @param count the desired count for visible items
*/
public void setVisibleItems(int count) {
visibleItems = count;
}
/**
* Gets view adapter
*
* @return the view adapter
*/
public WheelViewAdapter getViewAdapter() {
return viewAdapter;
}
// Adapter listener
private DataSetObserver dataObserver = new DataSetObserver() {
@Override
public void onChanged() {
invalidateWheel(false);
}
@Override
public void onInvalidated() {
invalidateWheel(true);
}
};
/**
* Sets view adapter. Usually new adapters contain different views, so it
* needs to rebuild view by calling measure().
*
* @param viewAdapter the view adapter
*/
public void setViewAdapter(WheelViewAdapter viewAdapter) {
if (this.viewAdapter != null) {
this.viewAdapter.unregisterDataSetObserver(dataObserver);
}
this.viewAdapter = viewAdapter;
if (this.viewAdapter != null) {
this.viewAdapter.registerDataSetObserver(dataObserver);
}
invalidateWheel(true);
}
/**
* Adds wheel changing listener
*
* @param listener the listener
*/
public void addChangingListener(OnWheelChangedListener listener) {
changingListeners.add(listener);
}
/**
* Removes wheel changing listener
*
* @param listener the listener
*/
public void removeChangingListener(OnWheelChangedListener listener) {
changingListeners.remove(listener);
}
/**
* Notifies changing listeners
*
* @param oldValue the old wheel value
* @param newValue the new wheel value
*/
protected void notifyChangingListeners(int oldValue, int newValue) {
for (OnWheelChangedListener listener : changingListeners) {
listener.onChanged(this, oldValue, newValue);
}
}
/**
* Adds wheel scrolling listener
*
* @param listener the listener
*/
public void addScrollingListener(OnWheelScrollListener listener) {
scrollingListeners.add(listener);
}
/**
* Removes wheel scrolling listener
*
* @param listener the listener
*/
public void removeScrollingListener(OnWheelScrollListener listener) {
scrollingListeners.remove(listener);
}
/**
* Notifies listeners about starting scrolling
*/
protected void notifyScrollingListenersAboutStart() {
for (OnWheelScrollListener listener : scrollingListeners) {
listener.onScrollingStarted(this);
}
}
/**
* Notifies listeners about ending scrolling
*/
protected void notifyScrollingListenersAboutEnd() {
for (OnWheelScrollListener listener : scrollingListeners) {
listener.onScrollingFinished(this);
}
}
/**
* Adds wheel clicking listener
*
* @param listener the listener
*/
public void addClickingListener(OnWheelClickedListener listener) {
clickingListeners.add(listener);
}
/**
* Removes wheel clicking listener
*
* @param listener the listener
*/
public void removeClickingListener(OnWheelClickedListener listener) {
clickingListeners.remove(listener);
}
/**
* Notifies listeners about clicking
*/
protected void notifyClickListenersAboutClick(int item) {
for (OnWheelClickedListener listener : clickingListeners) {
listener.onItemClicked(this, item);
}
}
/**
* Gets current value
*
* @return the current value
*/
public int getCurrentItem() {
return currentItem;
}
/**
* Sets the current item. Does nothing when index is wrong.
*
* @param index the item index
* @param animated the animation flag
*/
public void setCurrentItem(int index, boolean animated) {
if (viewAdapter == null || viewAdapter.getItemsCount() == 0) {
return; // throw?
}
int itemCount = viewAdapter.getItemsCount();
if (index < 0 || index >= itemCount) {
if (isCyclic) {
while (index < 0) {
index += itemCount;
}
index %= itemCount;
} else {
return; // throw?
}
}
if (index != currentItem) {
if (animated) {
int itemsToScroll = index - currentItem;
if (isCyclic) {
int scroll = itemCount + Math.min(index, currentItem) - Math.max(index, currentItem);
if (scroll < Math.abs(itemsToScroll)) {
itemsToScroll = itemsToScroll < 0 ? scroll : -scroll;
}
}
scroll(itemsToScroll, 0);
} else {
scrollingOffset = 0;
int old = currentItem;
currentItem = index;
notifyChangingListeners(old, currentItem);
invalidate();
}
}
}
/**
* Sets the current item w/o animation. Does nothing when index is wrong.
*
* @param index the item index
*/
public void setCurrentItem(int index) {
setCurrentItem(index, false);
}
/**
* Tests if wheel is cyclic. That means before the 1st item there is shown
* the last one
*
* @return true if wheel is cyclic
*/
public boolean isCyclic() {
return isCyclic;
}
/**
* Set wheel cyclic flag
*
* @param isCyclic the flag to set
*/
public void setCyclic(boolean isCyclic) {
this.isCyclic = isCyclic;
invalidateWheel(false);
}
/**
* Invalidates wheel
*
* @param clearCaches if true then cached views will be clear
*/
public void invalidateWheel(boolean clearCaches) {
if (clearCaches) {
recycle.clearAll();
if (itemsLayout != null) {
itemsLayout.removeAllViews();
}
scrollingOffset = 0;
} else if (itemsLayout != null) {
// cache all items
recycle.recycleItems(itemsLayout, firstItem, new ItemsRange());
}
invalidate();
}
/**
* Initializes resources
*/
private void initResourcesIfNecessary() {
if (centerDrawable == null) {
centerDrawable = getContext().getResources().getDrawable(R.drawable.wheel_val);
}
if (topShadow == null) {
topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
}
if (bottomShadow == null) {
bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
}
setBackgroundResource(R.drawable.wheel_bg);
}
/**
* Calculates desired height for layout
*
* @param layout the source layout
* @return the desired layout height
*/
private int getDesiredHeight(LinearLayout layout) {
if (layout != null && layout.getChildAt(0) != null) {
itemHeight = layout.getChildAt(0).getMeasuredHeight();
}
int desired = itemHeight * visibleItems - itemHeight * ITEM_OFFSET_PERCENT / 50;
return Math.max(desired, getSuggestedMinimumHeight());
}
/**
* Returns height of wheel item
*
* @return the item height
*/
private int getItemHeight() {
if (itemHeight != 0) {
return itemHeight;
}
if (itemsLayout != null && itemsLayout.getChildAt(0) != null) {
itemHeight = itemsLayout.getChildAt(0).getHeight();
return itemHeight;
}
return getHeight() / visibleItems;
}
/**
* Calculates control width and creates text layouts
*
* @param widthSize the input layout width
* @param mode the layout mode
* @return the calculated control width
*/
private int calculateLayoutWidth(int widthSize, int mode) {
initResourcesIfNecessary();
// TODO: make it static
itemsLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
itemsLayout.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int width = itemsLayout.getMeasuredWidth();
if (mode == MeasureSpec.EXACTLY) {
width = widthSize;
} else {
width += 2 * PADDING;
// Check against our minimum width
width = Math.max(width, getSuggestedMinimumWidth());
if (mode == MeasureSpec.AT_MOST && widthSize < width) {
width = widthSize;
}
}
itemsLayout.measure(MeasureSpec.makeMeasureSpec(width - 2 * PADDING, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
return width;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
buildViewForMeasuring();
int width = calculateLayoutWidth(widthSize, widthMode);
int height;
if (heightMode == MeasureSpec.EXACTLY) {
height = heightSize;
} else {
height = getDesiredHeight(itemsLayout);
if (heightMode == MeasureSpec.AT_MOST) {
height = Math.min(height, heightSize);
}
}
setMeasuredDimension(width, height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
layout(r - l, b - t);
}
/**
* Sets layouts width and height
*
* @param width the layout width
* @param height the layout height
*/
private void layout(int width, int height) {
int itemsWidth = width - 2 * PADDING;
itemsLayout.layout(0, 0, itemsWidth, height);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (viewAdapter != null && viewAdapter.getItemsCount() > 0) {
updateView();
drawItems(canvas);
drawCenterRect(canvas);
}
drawShadows(canvas);
}
/**
* Draws shadows on top and bottom of control
*
* @param canvas the canvas for drawing
*/
private void drawShadows(Canvas canvas) {
int height = (int) (1.5 * getItemHeight());
topShadow.setBounds(0, 0, getWidth(), height);
topShadow.draw(canvas);
bottomShadow.setBounds(0, getHeight() - height, getWidth(), getHeight());
bottomShadow.draw(canvas);
}
/**
* Draws items
*
* @param canvas the canvas for drawing
*/
private void drawItems(Canvas canvas) {
canvas.save();
int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2;
canvas.translate(PADDING, -top + scrollingOffset);
itemsLayout.draw(canvas);
canvas.restore();
}
/**
* Draws rect for current value
*
* @param canvas the canvas for drawing
*/
private void drawCenterRect(Canvas canvas) {
int center = getHeight() / 2;
int offset = (int) (getItemHeight() / 2 * 1.2);
centerDrawable.setBounds(0, center - offset, getWidth(), center + offset);
centerDrawable.draw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled() || getViewAdapter() == null) {
return true;
}
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_UP:
if (!isScrollingPerformed) {
int distance = (int) event.getY() - getHeight() / 2;
if (distance > 0) {
distance += getItemHeight() / 2;
} else {
distance -= getItemHeight() / 2;
}
int items = distance / getItemHeight();
if (items != 0 && isValidItemIndex(currentItem + items)) {
notifyClickListenersAboutClick(currentItem + items);
}
}
break;
}
return scroller.onTouchEvent(event);
}
/**
* Scrolls the wheel
*
* @param delta the scrolling value
*/
private void doScroll(int delta) {
scrollingOffset += delta;
int itemHeight = getItemHeight();
int count = scrollingOffset / itemHeight;
int pos = currentItem - count;
int itemCount = viewAdapter.getItemsCount();
int fixPos = scrollingOffset % itemHeight;
if (Math.abs(fixPos) <= itemHeight / 2) {
fixPos = 0;
}
if (isCyclic && itemCount > 0) {
if (fixPos > 0) {
pos--;
count++;
} else if (fixPos < 0) {
pos++;
count--;
}
// fix position by rotating
while (pos < 0) {
pos += itemCount;
}
pos %= itemCount;
} else {
//
if (pos < 0) {
count = currentItem;
pos = 0;
} else if (pos >= itemCount) {
count = currentItem - itemCount + 1;
pos = itemCount - 1;
} else if (pos > 0 && fixPos > 0) {
pos--;
count++;
} else if (pos < itemCount - 1 && fixPos < 0) {
pos++;
count--;
}
}
int offset = scrollingOffset;
if (pos != currentItem) {
setCurrentItem(pos, false);
} else {
invalidate();
}
// update offset
scrollingOffset = offset - count * itemHeight;
if (scrollingOffset > getHeight()) {
scrollingOffset = scrollingOffset % getHeight() + getHeight();
}
}
/**
* Scroll the wheel
*
* @param itemsToScroll items to scroll
* @param time scrolling duration
*/
public void scroll(int itemsToScroll, int time) {
int distance = itemsToScroll * getItemHeight() - scrollingOffset;
scroller.scroll(distance, time);
}
/**
* Calculates range for wheel items
*
* @return the items range
*/
private ItemsRange getItemsRange() {
if (getItemHeight() == 0) {
return null;
}
int first = currentItem;
int count = 1;
while (count * getItemHeight() < getHeight()) {
first--;
count += 2; // top + bottom items
}
if (scrollingOffset != 0) {
if (scrollingOffset > 0) {
first--;
}
count++;
// process empty items above the first or below the second
int emptyItems = scrollingOffset / getItemHeight();
first -= emptyItems;
count += Math.asin(emptyItems);
}
return new ItemsRange(first, count);
}
/**
* Rebuilds wheel items if necessary. Caches all unused items.
*
* @return true if items are rebuilt
*/
private boolean rebuildItems() {
boolean updated = false;
ItemsRange range = getItemsRange();
if (itemsLayout != null) {
int first = recycle.recycleItems(itemsLayout, firstItem, range);
updated = firstItem != first;
firstItem = first;
} else {
createItemsLayout();
updated = true;
}
if (!updated) {
updated = firstItem != range.getFirst() || itemsLayout.getChildCount() != range.getCount();
}
if (firstItem > range.getFirst() && firstItem <= range.getLast()) {
for (int i = firstItem - 1; i >= range.getFirst(); i--) {
if (!addViewItem(i, true)) {
break;
}
firstItem = i;
}
} else {
firstItem = range.getFirst();
}
int first = firstItem;
for (int i = itemsLayout.getChildCount(); i < range.getCount(); i++) {
if (!addViewItem(firstItem + i, false) && itemsLayout.getChildCount() == 0) {
first++;
}
}
firstItem = first;
return updated;
}
/**
* Updates view. Rebuilds items and label if necessary, recalculate items
* sizes.
*/
private void updateView() {
if (rebuildItems()) {
calculateLayoutWidth(getWidth(), MeasureSpec.EXACTLY);
layout(getWidth(), getHeight());
}
}
/**
* Creates item layouts if necessary
*/
private void createItemsLayout() {
if (itemsLayout == null) {
itemsLayout = new LinearLayout(getContext());
itemsLayout.setOrientation(LinearLayout.VERTICAL);
}
}
/**
* Builds view for measuring
*/
private void buildViewForMeasuring() {
// clear all items
if (itemsLayout != null) {
recycle.recycleItems(itemsLayout, firstItem, new ItemsRange());
} else {
createItemsLayout();
}
// add views
int addItems = visibleItems / 2;
for (int i = currentItem + addItems; i >= currentItem - addItems; i--) {
if (addViewItem(i, true)) {
firstItem = i;
}
}
}
/**
* Adds view for item to items layout
*
* @param index the item index
* @param first the flag indicates if view should be first
* @return true if corresponding item exists and is added
*/
private boolean addViewItem(int index, boolean first) {
View view = getItemView(index);
if (view != null) {
if (first) {
itemsLayout.addView(view, 0);
} else {
itemsLayout.addView(view);
}
return true;
}
return false;
}
/**
* Checks whether intem index is valid
*
* @param index the item index
* @return true if item index is not out of bounds or the wheel is cyclic
*/
private boolean isValidItemIndex(int index) {
return viewAdapter != null && viewAdapter.getItemsCount() > 0
&& (isCyclic || index >= 0 && index < viewAdapter.getItemsCount());
}
/**
* Returns view for specified item
*
* @param index the item index
* @return item view or empty view if index is out of bounds
*/
private View getItemView(int index) {
if (viewAdapter == null || viewAdapter.getItemsCount() == 0) {
return null;
}
int count = viewAdapter.getItemsCount();
if (!isValidItemIndex(index)) {
return viewAdapter.getEmptyItem(recycle.getEmptyItem(), itemsLayout);
} else {
while (index < 0) {
index = count + index;
}
}
index %= count;
return viewAdapter.getItem(index, recycle.getItem(), itemsLayout);
}
/**
* Stops scrolling
*/
public void stopScrolling() {
scroller.stopScrolling();
}
}
package com.mayi.fastdevelop.view.wheel.views;
/**
* Range for visible items.
*/
public class ItemsRange {
// First item number
private int first;
// Items count
private int count;
/**
* Default constructor. Creates an empty range
*/
public ItemsRange() {
this(0, 0);
}
/**
* Constructor
*
* @param first
* the number of first item
* @param count
* the count of items
*/
public ItemsRange(int first, int count) {
this.first = first;
this.count = count;
}
/**
* Gets number of first item
*
* @return the number of the first item
*/
public int getFirst() {
return first;
}
/**
* Gets number of last item
*
* @return the number of last item
*/
public int getLast() {
return getFirst() + getCount() - 1;
}
/**
* Get items count
*
* @return the count of items
*/
public int getCount() {
return count;
}
/**
* Tests whether item is contained by range
*
* @param index
* the item number
* @return true if item is contained
*/
public boolean contains(int index) {
return index >= getFirst() && index <= getLast();
}
}
\ No newline at end of file
/*
* /**
* * Copyright &copy; 2017-2020 All rights reserved.
* * Licensed under the yen License, Version 1.0 (the "License");
*
*/
package com.mayi.fastdevelop.view.wheel.views;
/**
* Wheel changed listener interface.
* <p>
* The onChanged() method is called whenever current wheel positions is changed:
* <li>New Wheel position is set
* <li>Wheel view is scrolled
*/
public interface OnWheelChangedListener {
/**
* Callback method to be invoked when current item changed
*
* @param wheel
* the wheel view whose state has changed
* @param oldValue
* the old value of current item
* @param newValue
* the new value of current item
*/
void onChanged(CustomWheelView wheel, int oldValue, int newValue);
}
/*
* /**
* * Copyright &copy; 2017-2020 All rights reserved.
* * Licensed under the yen License, Version 1.0 (the "License");
*
*/
package com.mayi.fastdevelop.view.wheel.views;
/**
* Wheel clicked listener interface.
* <p>
* The onItemClicked() method is called whenever a wheel item is clicked
* <li>New Wheel position is set
* <li>Wheel view is scrolled
*/
public interface OnWheelClickedListener {
/**
* Callback method to be invoked when current item clicked
*
* @param wheel
* the wheel view
* @param itemIndex
* the index of clicked item
*/
void onItemClicked(CustomWheelView wheel, int itemIndex);
}
package com.mayi.fastdevelop.view.wheel.views;
/**
* Wheel scrolled listener interface.
*/
public interface OnWheelScrollListener {
/**
* Callback method to be invoked when scrolling started.
*
* @param wheel
* the wheel view whose state has changed.
*/
void onScrollingStarted(CustomWheelView wheel);
/**
* Callback method to be invoked when scrolling ended.
*
* @param wheel
* the wheel view whose state has changed.
*/
void onScrollingFinished(CustomWheelView wheel);
}
package com.mayi.fastdevelop.view.wheel.views;
import android.view.View;
import android.widget.LinearLayout;
import java.util.LinkedList;
import java.util.List;
/**
* Recycle stores wheel items to reuse.
*/
public class WheelRecycle {
// Cached items
private List<View> items;
// Cached empty items
private List<View> emptyItems;
// Wheel view
private CustomWheelView wheel;
/**
* Constructor
*
* @param wheel
* the wheel view
*/
public WheelRecycle(CustomWheelView wheel) {
this.wheel = wheel;
}
/**
* Recycles items from specified layout. There are saved only items not
* included to specified range. All the cached items are removed from
* original layout.
*
* @param layout
* the layout containing items to be cached
* @param firstItem
* the number of first item in layout
* @param range
* the range of current wheel items
* @return the new value of first item number
*/
public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
int index = firstItem;
for (int i = 0; i < layout.getChildCount();) {
if (!range.contains(index)) {
recycleView(layout.getChildAt(i), index);
layout.removeViewAt(i);
if (i == 0) { // first item
firstItem++;
}
} else {
i++; // go to next item
}
index++;
}
return firstItem;
}
/**
* Gets item view
*
* @return the cached view
*/
public View getItem() {
return getCachedView(items);
}
/**
* Gets empty item view
*
* @return the cached empty view
*/
public View getEmptyItem() {
return getCachedView(emptyItems);
}
/**
* Clears all views
*/
public void clearAll() {
if (items != null) {
items.clear();
}
if (emptyItems != null) {
emptyItems.clear();
}
}
/**
* Adds view to specified cache. Creates a cache list if it is null.
*
* @param view
* the view to be cached
* @param cache
* the cache list
* @return the cache list
*/
private List<View> addView(View view, List<View> cache) {
if (cache == null) {
cache = new LinkedList<View>();
}
cache.add(view);
return cache;
}
/**
* Adds view to cache. Determines view type (item view or empty one) by
* index.
*
* @param view
* the view to be cached
* @param index
* the index of view
*/
private void recycleView(View view, int index) {
int count = wheel.getViewAdapter().getItemsCount();
if ((index < 0 || index >= count) && !wheel.isCyclic()) {
// empty view
emptyItems = addView(view, emptyItems);
} else {
while (index < 0) {
index = count + index;
}
index %= count;
items = addView(view, items);
}
}
/**
* Gets view from specified cache.
*
* @param cache
* the cache
* @return the first view from cache.
*/
private View getCachedView(List<View> cache) {
if (cache != null && cache.size() > 0) {
View view = cache.get(0);
cache.remove(0);
return view;
}
return null;
}
}
package com.mayi.fastdevelop.view.wheel.views;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.animation.Interpolator;
import android.widget.Scroller;
/**
* Scroller class handles scrolling events and updates the
*/
public class WheelScroller {
/**
* Scrolling listener interface
*/
public interface ScrollingListener {
/**
* Scrolling callback called when scrolling is performed.
*
* @param distance the distance to scroll
*/
void onScroll(int distance);
/**
* Starting callback called when scrolling is started
*/
void onStarted();
/**
* Finishing callback called after justifying
*/
void onFinished();
/**
* Justifying callback called to justify a view when scrolling is ended
*/
void onJustify();
}
/**
* Scrolling duration
*/
private static final int SCROLLING_DURATION = 235;
/**
* Minimum delta for scrolling
*/
public static final int MIN_DELTA_FOR_SCROLLING = 1;
// Listener
private ScrollingListener listener;
// Context
private Context context;
// Scrolling
private GestureDetector gestureDetector;
private Scroller scroller;
private int lastScrollY;
private float lastTouchedY;
private boolean isScrollingPerformed;
/**
* Constructor
*
* @param context the current context
* @param listener the scrolling listener
*/
public WheelScroller(Context context, ScrollingListener listener) {
gestureDetector = new GestureDetector(context, gestureListener);
gestureDetector.setIsLongpressEnabled(false);
scroller = new Scroller(context);
this.listener = listener;
this.context = context;
}
/**
* Set the the specified scrolling interpolator
*
* @param interpolator the interpolator
*/
public void setInterpolator(Interpolator interpolator) {
scroller.forceFinished(true);
scroller = new Scroller(context, interpolator);
}
/**
* Scroll the wheel
*
* @param distance the scrolling distance
* @param time the scrolling duration
*/
public void scroll(int distance, int time) {
scroller.forceFinished(true);
lastScrollY = 0;
scroller.startScroll(0, 0, 0, distance, time != 0 ? time : SCROLLING_DURATION);
setNextMessage(MESSAGE_SCROLL);
startScrolling();
}
/**
* Stops scrolling
*/
public void stopScrolling() {
scroller.forceFinished(true);
}
/**
* Handles Touch event
*
* @param event the motion event
* @return
*/
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastTouchedY = event.getY();
scroller.forceFinished(true);
clearMessages();
break;
case MotionEvent.ACTION_MOVE:
// perform scrolling
int distanceY = (int) (event.getY() - lastTouchedY);
if (distanceY != 0) {
startScrolling();
listener.onScroll(distanceY);
lastTouchedY = event.getY();
}
break;
}
if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
justify();
}
return true;
}
// gesture listener
private SimpleOnGestureListener gestureListener = new SimpleOnGestureListener() {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// Do scrolling in onTouchEvent() since onScroll() are not call
// immediately
// when user touch and move the wheel
return true;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
lastScrollY = 0;
final int maxY = 0x7FFFFFFF;
final int minY = -maxY;
scroller.fling(0, lastScrollY, 0, (int) -velocityY, 0, 0, minY, maxY);
setNextMessage(MESSAGE_SCROLL);
return true;
}
};
// Messages
private final int MESSAGE_SCROLL = 0;
private final int MESSAGE_JUSTIFY = 1;
/**
* Set next message to queue. Clears queue before.
*
* @param message the message to set
*/
private void setNextMessage(int message) {
clearMessages();
animationHandler.sendEmptyMessage(message);
}
/**
* Clears messages from queue
*/
private void clearMessages() {
animationHandler.removeMessages(MESSAGE_SCROLL);
animationHandler.removeMessages(MESSAGE_JUSTIFY);
}
// animation handler
private Handler animationHandler = new Handler() {
public void handleMessage(Message msg) {
scroller.computeScrollOffset();
int currY = scroller.getCurrY();
int delta = lastScrollY - currY;
lastScrollY = currY;
if (delta != 0) {
listener.onScroll(delta);
}
// scrolling is not finished when it comes to final Y
// so, finish it manually
if (Math.abs(currY - scroller.getFinalY()) < MIN_DELTA_FOR_SCROLLING) {
currY = scroller.getFinalY();
scroller.forceFinished(true);
}
if (!scroller.isFinished()) {
animationHandler.sendEmptyMessage(msg.what);
} else if (msg.what == MESSAGE_SCROLL) {
justify();
} else {
finishScrolling();
}
}
};
/**
* Justifies wheel
*/
private void justify() {
listener.onJustify();
setNextMessage(MESSAGE_JUSTIFY);
}
/**
* Starts scrolling
*/
private void startScrolling() {
if (!isScrollingPerformed) {
isScrollingPerformed = true;
listener.onStarted();
}
}
/**
* Finishes scrolling
*/
void finishScrolling() {
if (isScrollingPerformed) {
listener.onFinished();
isScrollingPerformed = false;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--从底部弹出-->
<translate
android:duration="400"
android:fromXDelta="0"
android:fromYDelta="100%p"
android:toXDelta="0"
android:toYDelta="0" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--往底部收回-->
<translate
android:duration="400"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="100%p"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--从左边弹出-->
<translate
android:duration="400"
android:fromXDelta="-100%p"
android:fromYDelta="0"
android:toXDelta="0"
android:interpolator="@android:anim/bounce_interpolator"
android:toYDelta="0"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--往左边收回-->
<translate
android:duration="400"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="-100%p"
android:toYDelta="0"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="400"
android:fromXDelta="100%p"
android:fromYDelta="0"
android:interpolator="@android:anim/bounce_interpolator"
android:toXDelta="0"
android:toYDelta="0"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="400"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100%p"
android:toYDelta="0"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--缩放淡入-->
<scale
android:duration="235"
android:fromXScale="0.8"
android:fromYScale="0.8"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="1.0"
android:toYScale="1.0"/>
<alpha
android:duration="235"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--缩放淡出-->
<scale
android:duration="150"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.6"
android:toYScale="0.6"/>
<alpha
android:duration="150"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0.0"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="@android:anim/bounce_interpolator"
android:toXDelta="0"
android:toYDelta="-100%p"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="400"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="-100%p"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/alpha_75_white">
<item
android:id="@android:id/mask"
android:drawable="@color/alpha_05_white"/>
</ripple>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple">
<item android:drawable="@color/white"/>
</ripple>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple">
<item
android:id="@android:id/mask"
android:drawable="@color/background_quanju"/>
</ripple>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充颜色 -->
<solid android:color="@color/white"/>
<!-- 矩形的圆角半径 -->
<corners android:radius="5dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"/>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:centerColor="#00ffffff"
android:endColor="#1A000000"
android:startColor="#1A000000"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/bg_dialog_shape"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/im_dp_20"
android:gravity="center"
android:text="标题"
android:textColor="@color/color_333333"
android:textSize="@dimen/txt_size_36px" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/cancel"
android:textColor="@color/color_333333"
android:textSize="@dimen/txt_size_32px" />
<View
android:layout_width="@dimen/im_dp_0.5"
android:layout_height="match_parent"
android:background="@color/color_666666" />
<TextView
android:id="@+id/tv_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/sure"
android:textColor="@color/color_333333"
android:textSize="@dimen/txt_size_32px" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/im_dp_0.5"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/im_dp_50"
android:background="@color/color_666666" />
</RelativeLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/bg_dialog_shape"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="@dimen/im_dp_10"
android:gravity="center"
android:text="内容"
android:textColor="@color/color_333333"
android:textSize="@dimen/txt_size_36px" />
<TextView
android:id="@+id/tv_ok"
android:layout_width="match_parent"
android:layout_height="@dimen/im_dp_50"
android:layout_below="@+id/tv_content"
android:gravity="center"
android:text="@string/sure"
android:textColor="@color/color_333333"
android:textSize="@dimen/txt_size_32px" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/im_dp_0.5"
android:layout_below="@+id/tv_content"
android:background="@color/color_666666" />
</RelativeLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ly_myinfo_changeaddress_child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:id="@+id/tv_share_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/space_30px"
android:gravity="center_vertical"
android:text="选择地区"
android:textColor="@color/txt_grey"
android:textSize="18sp"/>
<TextView
android:id="@+id/btn_sure"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="@string/sure"
android:textColor="@color/txt_notice_color_blue"
android:textSize="16sp"/>
<TextView
android:id="@+id/btn_cancel"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/btn_sure"
android:gravity="center"
android:text="@string/cancel"
android:textColor="@color/txt_grey"
android:textSize="16sp"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_address_province"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_address_city"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ly_myinfo_changeaddress_child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:id="@+id/btn_sure"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="@string/sure"
android:textColor="@color/txt_notice_color_blue"
android:textSize="16sp" />
<TextView
android:id="@+id/btn_cancel"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="@string/cancel"
android:textColor="@color/txt_grey"
android:textSize="16sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="175dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_birth_year"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_20px"
android:text="年" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_birth_month"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_20px"
android:text="月" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_birth_day"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_20px"
android:text="日" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="35dip"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tempValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#000000"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/title_bar_height"
android:background="@color/white">
<!--返回-->
<RelativeLayout
android:id="@+id/layout_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/llib_ripple_round_bg_quanju"
android:paddingLeft="10dp"
android:paddingRight="15dp">
<ImageView
android:id="@+id/iv_left"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_centerVertical="true"
android:src="@mipmap/icon_back" />
<TextView
android:id="@+id/tv_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="2dp"
android:layout_toRightOf="@id/iv_left"
android:text="@string/back"
android:textColor="#222222"
android:textSize="@dimen/txt_size_28px" />
</RelativeLayout>
<!--关闭按钮,针对webview,返回按钮是goback,部分需要直接关闭-->
<RelativeLayout
android:id="@+id/layout_close"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/layout_left"
android:background="@drawable/llib_ripple_round_bg_quanju"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/close"
android:textColor="#666666"
android:textSize="14sp" />
</RelativeLayout>
<!--标题-->
<TextView
android:id="@+id/tv_center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@drawable/llib_ripple_round_bg_quanju"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:maxWidth="150dp"
android:singleLine="true"
android:text="@string/app_name"
android:textColor="#222222"
android:textSize="18sp" />
<ImageView
android:id="@+id/iv_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/tv_center" />
<!--右边文字、图标-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
<TextView
android:id="@+id/tv_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/llib_ripple_round_bg_quanju"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:singleLine="true"
android:text="@string/app_name"
android:textColor="#666666"
android:textSize="14sp"
android:visibility="gone" />
<RelativeLayout
android:id="@+id/layout_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/llib_ripple_round_bg_quanju"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:visibility="gone">
<View
android:id="@+id/v_right"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true" />
</RelativeLayout>
</RelativeLayout>
<!--底部线条-->
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:layout_alignParentBottom="true"
android:background="@color/background_line" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<TextView
android:id="@+id/txt_think"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="@dimen/space_20px"
android:text="@string/cancel"
android:textSize="@dimen/txt_size_34px" />
<TextView
android:id="@+id/txt_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:padding="@dimen/space_20px"
android:textSize="@dimen/txt_size_34px" />
<!--完成-->
<TextView
android:id="@+id/txt_complete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="@dimen/space_20px"
android:text="完成"
android:textSize="@dimen/txt_size_34px" />
<View
android:id="@+id/view_line"
style="@style/line_h"
android:layout_below="@id/txt_think" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/view_line"
android:gravity="center_vertical"
android:minHeight="100dp"
android:orientation="horizontal">
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_year"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_30px"
android:text="年" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_month"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_30px"
android:text="月" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_day"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_30px"
android:text="日" />
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<!--再想想-->
<TextView
android:id="@+id/txt_think"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="@dimen/space_20px"
android:text="@string/cancel"
android:textSize="@dimen/txt_size_34px" />
<TextView
android:id="@+id/txt_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:padding="@dimen/space_20px"
android:textSize="@dimen/txt_size_34px" />
<!--完成-->
<TextView
android:id="@+id/txt_complete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:padding="@dimen/space_20px"
android:text="完成"
android:textSize="@dimen/txt_size_34px" />
<View
android:id="@+id/view_line"
style="@style/line_h"
android:layout_below="@id/txt_think" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/view_line"
android:gravity="center_vertical"
android:minHeight="100dp"
android:orientation="horizontal">
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_year"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_6px"
android:text="年" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_month"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_6px"
android:text="月" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_day"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_6px"
android:text="日" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_hour"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_6px"
android:text="时" />
<com.mayi.fastdevelop.view.wheel.views.CustomWheelView
android:id="@+id/wv_minute"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/space_6px"
android:text="分" />
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="gray">#D1D1D1</color>
<color name="black">#000</color>
<color name="title_blue">#6B7195</color>
<color name="text_color_blue">#bf9d4c</color>
<color name="green">#2bd34f</color>
<color name="title_bar_bg">#222222</color>
<color name="colorPrimary">#ff9100</color>
<color name="colorPrimaryDark">#ff9100</color>
<color name="colorAccent">#ff9100</color>
<color name="colorTheme">#ff9100</color>
<color name="white">#fff</color>
<!--透明色-->
<color name="transparent">#00000000</color>
<!--半透明-->
<color name="transparentHalf">#11000000</color>
<!--全局背景-->
<color name="background_quanju">#f4f4f4</color>
<!--内容区域底色-->
<color name="background_layout_grey">#f5f5f5</color>
<!--边框灰色-->
<color name="border_grey">#e8e8e8</color>
<!--分割线颜色-->
<color name="background_line">#e9e9e9</color>
<color name="progress">#ffb80d</color>
<!--灰色字体-->
<color name="txt_grey">#9d9d9d</color>
<!--输入提示文本颜色-->
<color name="txt_color_hint">#c8c8c8</color>
<!--重要级文字信息-->
<color name="txt_black">#333333</color>
<!--不可操作提示性文字颜色-->
<color name="txt_notice_color_yellow">#f7a735</color>
<!--可操作提示性文字蓝色-->
<color name="txt_notice_color_blue">#2f9efc</color>
<!--字体亮红 特别强调和突出的字体-->
<color name="txt_red_dark">#F00000</color>
<!--字体亮灰-->
<color name="txt_grey_light">#ffcccccc</color>
<!--按钮效果-->
<color name="ripple">#F3E5E5E5</color>
<!--按钮不可用背景颜色-->
<color name="background_enable_false">#F1F1F1</color>
<color name="tlib_psts_background_tab_pressed">#1AFFFFFF</color>
<color name="alpha_05_white">#0DFFFFFF</color>
<color name="alpha_10_white">#1AFFFFFF</color>
<color name="alpha_15_white">#26FFFFFF</color>
<color name="alpha_20_white">#33FFFFFF</color>
<color name="alpha_25_white">#40FFFFFF</color>
<color name="alpha_30_white">#4DFFFFFF</color>
<color name="alpha_35_white">#59FFFFFF</color>
<color name="alpha_40_white">#66FFFFFF</color>
<color name="alpha_45_white">#73FFFFFF</color>
<color name="alpha_50_white">#80FFFFFF</color>
<color name="alpha_55_white">#8CFFFFFF</color>
<color name="alpha_60_white">#99FFFFFF</color>
<color name="alpha_65_white">#A6FFFFFF</color>
<color name="alpha_70_white">#B3FFFFFF</color>
<color name="alpha_75_white">#BFFFFFFF</color>
<color name="alpha_80_white">#CCFFFFFF</color>
<color name="alpha_85_white">#D9FFFFFF</color>
<color name="alpha_90_white">#E6FFFFFF</color>
<color name="alpha_95_white">#F2FFFFFF</color>
<color name="alpha_05_black">#0D000000</color>
<color name="alpha_10_black">#1A000000</color>
<color name="alpha_15_black">#26000000</color>
<color name="alpha_20_black">#33000000</color>
<color name="alpha_25_black">#40000000</color>
<color name="alpha_30_black">#4D000000</color>
<color name="alpha_35_black">#59000000</color>
<color name="alpha_40_black">#66000000</color>
<color name="alpha_45_black">#73000000</color>
<color name="alpha_50_black">#80000000</color>
<color name="alpha_55_black">#8C000000</color>
<color name="alpha_60_black">#99000000</color>
<color name="alpha_65_black">#A6000000</color>
<color name="alpha_70_black">#B3000000</color>
<color name="alpha_75_black">#BF000000</color>
<color name="alpha_80_black">#CC000000</color>
<color name="alpha_85_black">#D9000000</color>
<color name="alpha_90_black">#E6000000</color>
<color name="alpha_95_black">#F2000000</color>
<color name="color_333333">#333333</color>
<color name="color_666666">#666666</color>
<color name="color_999999">#999999</color>
</resources>
<resources>
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="normal_size">14sp</dimen>
<dimen name="default_size">12sp</dimen>
<dimen name="title_height">0dp</dimen>
<!--默认圆角半径-->
<dimen name="shape_radius_default">4dp</dimen>
<!--距离 1dp-->
<dimen name="space_2px">1dp</dimen>
<!--距离 mini-->
<dimen name="space_6px">3dp</dimen>
<!--距离 小-->
<dimen name="space_10px">5dp</dimen>
<!--距离 默认-->
<dimen name="space_20px">10dp</dimen>
<!--距离 大-->
<dimen name="space_30px">15dp</dimen>
<!--距离 加大-->
<dimen name="space_40px">20dp</dimen>
<!--titlebar height-->
<dimen name="title_bar_height">50dp</dimen>
<dimen name="line_height">0.5dp</dimen>
<!--字体大小-->
<dimen name="txt_size_130px">65sp</dimen>
<dimen name="txt_size_80px">40sp</dimen>
<dimen name="txt_size_70px">35sp</dimen>
<dimen name="txt_size_60px">30sp</dimen>
<dimen name="txt_size_40px">20sp</dimen>
<dimen name="txt_size_36px">18sp</dimen>
<dimen name="txt_size_34px">17sp</dimen>
<dimen name="txt_size_32px">16sp</dimen>
<dimen name="txt_size_30px">15sp</dimen>
<dimen name="txt_size_28px">14sp</dimen>
<dimen name="txt_size_26px">13sp</dimen>
<dimen name="txt_size_24px">12sp</dimen>
<dimen name="txt_size_22px">11sp</dimen>
<dimen name="txt_size_18px">9sp</dimen>
<dimen name="txt_size_16px">8sp</dimen>
<dimen name="im_dp_0.5">0.5dp</dimen>
<dimen name="im_dp_1">1dp</dimen>
<dimen name="im_dp_2">2dp</dimen>
<dimen name="im_dp_3">3dp</dimen>
<dimen name="im_dp_4">4dp</dimen>
<dimen name="im_dp_5">5dp</dimen>
<dimen name="im_dp_6">6dp</dimen>
<dimen name="im_dp_7">7dp</dimen>
<dimen name="im_dp_8">8dp</dimen>
<dimen name="im_dp_9">9dp</dimen>
<dimen name="im_dp_10">10dp</dimen>
<dimen name="im_dp_11">11dp</dimen>
<dimen name="im_dp_12">12dp</dimen>
<dimen name="im_dp_13">13dp</dimen>
<dimen name="im_dp_14">14dp</dimen>
<dimen name="im_dp_15">15dp</dimen>
<dimen name="im_dp_16">16dp</dimen>
<dimen name="im_dp_20">20dp</dimen>
<dimen name="im_dp_25">25dp</dimen>
<dimen name="im_dp_30">30dp</dimen>
<dimen name="im_dp_33">33dp</dimen>
<dimen name="im_dp_36">36dp</dimen>
<dimen name="im_dp_40">40dp</dimen>
<dimen name="im_dp_48">48dp</dimen>
<dimen name="im_dp_50">50dp</dimen>
<dimen name="im_dp_54">54dp</dimen>
<dimen name="im_dp_60">60dp</dimen>
<dimen name="im_dp_72">72dp</dimen>
<dimen name="im_dp_80">80dp</dimen>
<dimen name="im_dp_96">96dp</dimen>
<dimen name="im_dp_120">120dp</dimen>
<dimen name="im_dp_150">150dp</dimen>
<dimen name="im_dp_200">200dp</dimen>
<dimen name="im_dp_250">250dp</dimen>
</resources>
...@@ -3,4 +3,9 @@ ...@@ -3,4 +3,9 @@
<string name="save_img_failed_2">图片地址异常,保存图片失败!</string> <string name="save_img_failed_2">图片地址异常,保存图片失败!</string>
<string name="save_img_success">保存图片成功!</string> <string name="save_img_success">保存图片成功!</string>
<string name="save_img_failed">保存图片失败!</string> <string name="save_img_failed">保存图片失败!</string>
<string name="close">关闭</string>
<string name="sure">确定</string>
<string name="cancel">取消</string>
<string name="back">返回</string>
</resources> </resources>
...@@ -11,4 +11,61 @@ ...@@ -11,4 +11,61 @@
<item name="android:windowIsFloating">true</item> <item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item> <item name="android:windowContentOverlay">@null</item>
</style> </style>
<!-- ################### dialog ################### -->
<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<!-- 是否浮现在activity之上 -->
<item name="android:windowIsFloating">true</item>
<!-- 边框 -->
<item name="android:windowIsTranslucent">false</item>
<!-- 无标题 -->
<item name="android:windowNoTitle">true</item>
<!-- 背景透明 -->
<item name="android:windowBackground">@android:color/transparent</item>
<!-- 模糊 -->
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="window_bottom_in_bottom_out">
<item name="android:windowEnterAnimation">@anim/dialog_bottom_in</item>
<item name="android:windowExitAnimation">@anim/dialog_bottom_out</item>
</style>
<style name="window_left_in_left_out">
<item name="android:windowEnterAnimation">@anim/dialog_left_in</item>
<item name="android:windowExitAnimation">@anim/dialog_left_out</item>
</style>
<style name="window_left_in_right_out">
<item name="android:windowEnterAnimation">@anim/dialog_left_in</item>
<item name="android:windowExitAnimation">@anim/dialog_right_out</item>
</style>
<style name="window_right_in_right_out">
<item name="android:windowEnterAnimation">@anim/dialog_right_in</item>
<item name="android:windowExitAnimation">@anim/dialog_right_out</item>
</style>
<style name="window_right_in_left_out">
<item name="android:windowEnterAnimation">@anim/dialog_right_in</item>
<item name="android:windowExitAnimation">@anim/dialog_left_out</item>
</style>
<style name="dialog_scale_animstyle">
<item name="android:windowEnterAnimation">@anim/dialog_scale_in</item>
<item name="android:windowExitAnimation">@anim/dialog_scale_out</item>
</style>
<style name="window_top_in_top_out">
<item name="android:windowEnterAnimation">@anim/dialog_top_in</item>
<item name="android:windowExitAnimation">@anim/dialog_top_out</item>
</style>
<!--水平分隔线-->
<style name="line_h">
<item name="android:background">@color/background_line</item>
<item name="android:layout_height">@dimen/line_height</item>
<item name="android:layout_width">match_parent</item>
</style>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment