<?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:id="@+id/popparent"
android:background="#f5f5f5"
>
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/include"
layout="@layout/activity_upgrade_beatifulin"
/>
</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="#f5f5f5" >
<RelativeLayout
android:id="@+id/title_layout_service_project_top"
android:layout_width="match_parent"
android:layout_height="@dimen/actionbar_height"
android:background="@color/white" >
<TextView
android:id="@+id/gengduo_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:text="升级美丽达人详情页"
android:textColor="@color/text_595"
android:textSize="19sp"
android:visibility="visible" />
<LinearLayout
android:id="@+id/left_back"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="center_vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:background="@drawable/fanghui"
android:contentDescription="@null"
android:gravity="center"
android:padding="5dip" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title_layout_service_project_top" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/edit_lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F5F5F5"
android:orientation="vertical" >
<View
android:id="@+id/view_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e5e5e5" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:gravity="center|left"
android:singleLine="true"
android:text="姓 名:"
android:textColor="#666666"
android:textSize="28px" />
<EditText
android:id="@+id/edit_name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@null"
android:hint="请输入你的真实姓名"
android:singleLine="true"
android:textColorHint="#b2b2b2"
android:textSize="28px" />
</LinearLayout>
<View
android:id="@+id/view_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e5e5e5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:gravity="center|left"
android:singleLine="true"
android:text="电 话:"
android:textColor="#666666"
android:textSize="28px" />
<EditText
android:id="@+id/edit_phone"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@null"
android:hint="请输入你的号码"
android:numeric="integer"
android:singleLine="true"
android:textColorHint="#b2b2b2"
android:textSize="28px" />
</LinearLayout>
<View
android:id="@+id/view_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e5e5e5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:gravity="center|left"
android:singleLine="true"
android:text="身份证:"
android:textColor="#666666"
android:textSize="28px" />
<EditText
android:id="@+id/edit_shenfenzheng"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@null"
android:hint="请准确填写身份证号"
android:singleLine="true"
android:textColorHint="#b2b2b2"
android:textSize="28px" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/view_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e5e5e5" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:singleLine="true"
android:text="请上传身份证照片"
android:textColor="#666666"
android:textSize="28px" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center" >
<TextView
android:id="@+id/upimgop1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:gravity="center"
android:text="上传"
android:textColor="#999999"
android:textSize="28px" />
<!-- <com.yidaomeib_c_kehu.wight.RoundImageView -->
<!-- android:id="@+id/upgrade_showImg1" -->
<!-- android:layout_width="match_parent" -->
<!-- android:layout_height="match_parent" -->
<!-- android:layout_gravity="center" -->
<!-- android:gravity="center" -->
<!-- /> -->
<ImageView
android:id="@+id/upgrade_showImg1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:gravity="center"
android:scaleType="fitXY" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:text="请上传身份证正面照片"
android:textColor="#999999"
android:textSize="25px" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center" >
<TextView
android:id="@+id/upimgop2"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:gravity="center"
android:text="上传"
android:textColor="#999999"
android:textSize="28px" />
<ImageView
android:id="@+id/upgrade_showImg2"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:gravity="center"
android:scaleType="fitXY" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:textColor="#999999"
android:text="请上传身份证反面照片"
android:textSize="25px" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/view_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#e5e5e5" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
android:paddingTop="20dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="提示:" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1:照片中人物五官清晰可见" />
<TextView
android:layout_width="wrap_content"
android:paddingTop="10dp"
android:layout_height="wrap_content"
android:text="2:证件信息清晰完整" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
android:paddingTop="20dp" >
<ImageView
android:id="@+id/register_select_images"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/zhuceshape" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dip"
android:text="我已阅读并同意 "
android:textColor="@color/text_999"
android:textSize="16sp" />
<TextView
android:id="@+id/yonghuxieyi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="《引导美用户协议》"
android:textColor="#4E99FA"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/bootomss"
android:layout_below="@+id/edit_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F5F5F5"
android:layout_marginTop="30dip"
android:orientation="vertical" >
<TextView
android:id="@+id/next_grade_beauful"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#80CDE5"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:gravity="center"
android:singleLine="true"
android:text="提交审核"
android:textColor="@color/white"
android:textSize="30px" />
<TextView
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
public class MyUpgradeBeaufulDetail extends Activity implements OnClickListener {
private LinearLayout left_back;
private EditText edit_name;
private EditText edit_phone;
private EditText edit_shenfenzheng;
private TextView upimgop1;
private TextView upimgop2;
private TextView next_grade_beauful;
private PopupWindow uploadImagePopWindow; // 选择头像
private TextView take_photo;
private TextView selete_picture;
private RelativeLayout popparent;
private ImageView upgrade_showImg1;
private ImageView upgrade_showImg2;
private PopupWindow surepopwindow;
private TextView dialog_down;
private TextView info1;
private TextView info2;
private TextView cancle;
public ArrayList<String> imgPathlist; // 本地保存图片路径集合
private String TAG = MyUpgradeBeaufulDetail.class.getSimpleName();
private static final int REQUEST_CODE_PICK_IMAGE = 0; // 相册
private static final int REQUEST_CODE_CAPTURE_CAMEIA = 1; // 相机
private String capturePath;
protected String type;
String idCard = "";// 身份证号
String name = "";// 真实姓名
String telephone = "";// 电话
String bankAddress = ""; // 银行地址
String bankBranchID = ""; // 支行ID
String bankCardNO = "";// 银行卡好
String bankID = "";// 银行ID
String flowerCount = "";// 粉丝数
String likeCount = "";// 点赞数
String sftj = "";// 是否推荐
String userId = "";// 用户ID
String idCardFacePicURL = "";// 身份证照片正面
String idCardConversePicURL = "";// 身份证照片反面
private String showimg = "upgrade_showImg1";
protected String imagePath;
private TextView yonghuxieyi;
private ImageView register_select_images;
private Object findViewById;
private boolean isSelect = true;
private RelativeLayout includes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upgrade_beatiful);
imgPathlist = new ArrayList<String>();
userId = PreferencesUtils.getInstance(MyUpgradeBeaufulDetail.this).getUserId();
System.out.println("userId:"+userId);
System.out.println("imgPathlist:"+imgPathlist);
initview();
initUploadImagePopWindow();
surePopupWindow();
}
/**
* view
*/
private void initview() {
popparent = (RelativeLayout) findViewById(R.id.popparent);
includes = (RelativeLayout) findViewById(R.id.include);
left_back = (LinearLayout) findViewById(R.id.left_back);
edit_name = (EditText) findViewById(R.id.edit_name);
edit_phone = (EditText) findViewById(R.id.edit_phone);
edit_shenfenzheng = (EditText) findViewById(R.id.edit_shenfenzheng);
upimgop1 = (TextView) findViewById(R.id.upimgop1);
upimgop2 = (TextView) findViewById(R.id.upimgop2);
next_grade_beauful = (TextView) findViewById(R.id.next_grade_beauful);
upgrade_showImg1 = (ImageView) findViewById(R.id.upgrade_showImg1);
upgrade_showImg2 = (ImageView) findViewById(R.id.upgrade_showImg2);
yonghuxieyi = (TextView) findViewById(R.id.yonghuxieyi);
register_select_images = (ImageView) findViewById(R.id.register_select_images);
yonghuxieyi.setOnClickListener(MyUpgradeBeaufulDetail.this);
register_select_images.setOnClickListener(MyUpgradeBeaufulDetail.this);
left_back.setOnClickListener(MyUpgradeBeaufulDetail.this);
upimgop1.setOnClickListener(MyUpgradeBeaufulDetail.this);
upimgop2.setOnClickListener(MyUpgradeBeaufulDetail.this);
upgrade_showImg1.setOnClickListener(MyUpgradeBeaufulDetail.this);
upgrade_showImg2.setOnClickListener(MyUpgradeBeaufulDetail.this);
next_grade_beauful.setOnClickListener(MyUpgradeBeaufulDetail.this);
}
@Override
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.register_select_images:
if(isSelect){
isSelect = false;
register_select_images.setBackgroundResource(R.drawable.zhuce);
}else{
isSelect = true;
register_select_images.setBackgroundResource(R.drawable.zhuceshape);
}
break;
case R.id.yonghuxieyi:
Intent intent2 = new Intent(MyUpgradeBeaufulDetail.this,Beauty_UserProtocolActivity.class);
startActivity(intent2);
break;
case R.id.left_back:
finish();
overridePendingTransition(0,R.anim.base_slide_right_out);
break;
case R.id.dialog_down:
surepopwindow.dismiss();
Intent intent = new Intent();
intent.setClass(MyUpgradeBeaufulDetail.this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("fromActivity","MyUpgradeBeaufulDetail");
this.startActivity(intent);
finish();
overridePendingTransition(0,R.anim.base_slide_right_out);
break;
case R.id.upgrade_showImg1:
if (uploadImagePopWindow.isShowing()) {
uploadImagePopWindow.dismiss();// 关闭
} else {
take_photo.setText("拍照上传");
selete_picture.setText("选择相片");
type = "photo";
showimg = "upgrade_showImg1";
uploadImagePopWindow.showAtLocation(popparent,Gravity.CENTER,0);
backgroundAlpha(0.5f);
}
break;
case R.id.upgrade_showImg2:
if (uploadImagePopWindow.isShowing()) {
uploadImagePopWindow.dismiss();// 关闭
} else {
take_photo.setText("拍照上传");
selete_picture.setText("选择相片");
type = "photo";
showimg = "upgrade_showImg2";
uploadImagePopWindow.showAtLocation(popparent,0);
backgroundAlpha(0.5f);
}
break;
case R.id.upimgop1:
if (uploadImagePopWindow.isShowing()) {
uploadImagePopWindow.dismiss();// 关闭
} else {
take_photo.setText("拍照上传");
selete_picture.setText("选择相片");
type = "photo";
uploadImagePopWindow.showAtLocation(popparent,0);
backgroundAlpha(0.5f);
}
break;
case R.id.upimgop2:
if (uploadImagePopWindow.isShowing()) {
uploadImagePopWindow.dismiss();// 关闭
} else {
take_photo.setText("拍照上传");
selete_picture.setText("选择相片");
type = "photo";
uploadImagePopWindow.showAtLocation(popparent,0);
backgroundAlpha(0.5f);
}
break;
case R.id.take_photo:
getImageFromCamera();
uploadImagePopWindow.dismiss();// 关闭
break;
case R.id.selete_picture:
getImageFromAlbum();
uploadImagePopWindow.dismiss();// 关闭
break;
case R.id.cancle:
uploadImagePopWindow.dismiss();// 关闭
break;
case R.id.next_grade_beauful:
name = edit_name.getText().toString().trim();
telephone = edit_phone.getText().toString().trim();
idCard = edit_shenfenzheng.getText().toString().trim();
if (name.length() > 20) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"您输入的名称过长,请重新输入",Toast.LENGTH_SHORT).show(); // 重新获取焦点
refocus(edit_name);
return;
}
if (name.length() < 2 && name.length() >= 1) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"您输入的名称有误,最少一个字符",Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (TextUtils.isEmpty(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"姓名为必填项,请输入",Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (isnuber(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"您输入的名称有误,不能含数字",Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (containstr(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"您输入的名称有误,不能含特殊符号",Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (!ishanzi(name) && containsEN(name) || !ishanzi(name) && containsnuber(name) || !ishanzi(name) && containstr(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"您输入的名称有误",Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (containsEN(name) && containsnuber(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (containstr(name) && containsnuber(name) || containstr(name) && containsEN(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (containsEN(name) && containsnuber(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (!zhenshiname(name)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,Toast.LENGTH_SHORT).show();
refocus(edit_name);
return;
}
if (TextUtils.isEmpty(telephone)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"手机号码为必填项,Toast.LENGTH_SHORT).show();
refocus(edit_phone);
return;
}
if (!buildephone()) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"您输入的手机号码格式有误,Toast.LENGTH_SHORT).show();
refocus(edit_phone);
return;
}
if (TextUtils.isEmpty(idCard)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"身份证号码为必填项,Toast.LENGTH_SHORT).show();
refocus(edit_shenfenzheng);
return;
}
if (!buildeshenfen()) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"您输入的身份证号格式有误,Toast.LENGTH_SHORT).show();
refocus(edit_shenfenzheng);
return;
}
if (TextUtils.isEmpty(idCardFacePicURL)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"请上传手持身份证正面照片",Toast.LENGTH_SHORT).show();
return;
} else if (TextUtils.isEmpty(idCardConversePicURL)) {
Toast.makeText(MyUpgradeBeaufulDetail.this,"请上传手持身份证反面照片",Toast.LENGTH_SHORT).show();
return;
}
//网络请求
if(isSelect){
putcustomerupgradbeauful(bankAddress,bankBranchID,bankCardNO,bankID,flowerCount,idCard,likeCount,name,sftj,telephone,userId,idCardFacePicURL,idCardConversePicURL);
}else {
Toast.makeText(MyUpgradeBeaufulDetail.this,"请先阅读引导美用户协议,并选中",Toast.LENGTH_SHORT).show();
return;
}
break;
default:
break;
}
}
/**
* 升级美丽达人
*
* @param bankAddress
* 银行地址
* @param bankBranchID
* 支行ID
* @param bankCardNO
* 银行卡号
* @param bankID
* 银行ID
* @param flowerCount
* 粉丝数
* @param idCard
* 身份证号
* @param likeCount
* 点赞数
* @param name
* 真实姓名
* @param sftj
* 是否推荐
* @param telephone
* 电话
* @param userId
* 用户ID
* @param idCardFacePicURL
* 身份证照片正面
* @param idCardConversePicURL
* 身份证照片反面
* @param customResponseHandler
*/
private void putcustomerupgradbeauful(String bankAddress1,String bankBranchID1,String bankCardNO1,String bankID1,String flowerCount1,String idCard1,String likeCount1,String name1,String sftj1,String telephone1,String userId1,String idCardFacePicURL1,String idCardConversePicURL1) {
RequstClient.customerupgradbeauful(bankAddress1,bankBranchID1,bankCardNO1,bankID1,flowerCount1,idCard1,likeCount1,name1,sftj1,telephone1,userId1,idCardFacePicURL1,idCardConversePicURL1,new CustomResponseHandler(this,true) {
@Override
public void onSuccess(int statusCode,Header[] headers,String content) {
super.onSuccess(statusCode,headers,content);
try {
String msg = null;
JSONObject obj = new JSONObject(content);
if (!obj.getString("status").equals("100")) {
msg = obj.getString("msg");
// System.out.println("msg:"+msg);
Toast.makeText(MyUpgradeBeaufulDetail.this,msg,Toast.LENGTH_LONG).show();
return;
}
// System.out.println("content:" + content);
if (surepopwindow.isShowing()) {
surepopwindow.dismiss();// 关闭
} else {
surepopwindow.showAtLocation(popparent,0);
backgroundAlpha(0.5f);
}
} catch (Exception e) {
e.getMessage();
}
}
});
}
/**
* 符号
* @param name2
* @return
*/
private boolean isfuhao(String name2) {
Pattern pattern = Pattern.compile("[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……& amp;*()——+|{}【】‘;:”“’。,、?|-]");
Matcher s = pattern.matcher(name2);
if (s.matches()) {
return true;
}
return false;
}
/**
* 中文
*
* @param name2
* @return false 是中文
*/
private boolean ishanzi(String name2) {
// Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5]+$"); //
// Matcher s = pattern.matcher(name2);
// if (s.matches()) {
// return true;
// }
// return false;
if (name2.getBytes().length == name2.length()) {
return true;
}
return false;
}
/**
* 根据Unicode编码完美的判断中文汉字和符号
* @param c
* @return
*/
private static boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) {
return true;
}
return false;
}
/**
* 完整的判断中文汉字和符号
* @param strName
* @return
*/
public static boolean isChinese(String strName) {
char[] ch = strName.tocharArray();
for (int i = 0; i < ch.length; i++) {
char c = ch[i];
if (isChinese(c)) {
return true;
}
}
return false;
}
/**
* 英文
* @param name2
* @return false 是英文
*/
private boolean isEN(String str) {
Pattern pattern = Pattern.compile("^[a-zA-Z]+"); // -?[0-9]+.?[0-9]+
Matcher isNum = pattern.matcher(str);
if (isNum.matches()) {
return true;
}
return false;
}
/**
* 英文
* @param name2
* @return false 不包含英文
*/
public boolean containsEN(String str) {
String[] s = { "Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","m","q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m" };
for (int i = 0; i < s.length; i++) {
if (str.contains(s[i])) {
return true;
}
}
return false;
}
/**
* 数字
* @param name2
* @return false 不包含数字
*/
public boolean containsnuber(String str) {
String[] s = { "1","2","3","4","5","6","7","8","9","0" };
for (int i = 0; i < s.length; i++) {
if (str.contains(s[i])) {
return true;
}
}
return false;
}
/**
* 数字
* @param name2
* @return false 是数字
*/
private boolean isnuber(String str) {
Pattern pattern = Pattern.compile("-?[0-9]+.?[0-9]+"); // -?[0-9]+.?[0-9]+
Matcher isNum = pattern.matcher(str);
if (isNum.matches()) {
return true;
}
return false;
}
/**
* 真实姓名
* @param name2
* @return false 是真实姓名
*/
private boolean zhenshiname(String str) {
Pattern pattern = Pattern.compile("^[A-Za-z0-9\u4e00-\u9fa5]+$"); // -?[0-9]+.?[0-9]+
Matcher isNum = pattern.matcher(str);
if (isNum.matches()) {
return true;
}
return false;
}
/**
* 其他字符
* @param name2
* @return false 不包含其他字符
*/
public boolean containstr(String str) {
String[] s = { "[","`","~","!","@","#","$","%","^","&","*","(",")","+","=","|","{","}","'",":",";",","\\",".","<",">","/","?","!","¥","……","amp","(",")","——+","【","】","‘",";",":","{","}","”","“","’","。",",","、","?","-","]","_" };
for (int i = 0; i < s.length; i++) {
if (str.contains(s[i])) {
return true;
}
}
return false;
}
/**
* 手机正则
* @return
*/
private boolean buildephone() {
telephone = edit_phone.getText().toString();
// String telRegex = "0?(13|14|15|18)[0-9]{9}";// [1][358]\\d{9}
String telRegex = "(13\\d|14[57]|15[^4,\\D]|17[678]|18\\d)\\d{8}|170[059]\\d{7}";// [1][358]\\d{9}
if (telephone.matches(telRegex)) {
return true;
} else {
return false;
}
}
/**
* 身份证 正则
* @return
*/
private boolean buildeshenfen() {
idCard = edit_shenfenzheng.getText().toString();
// 定义判别用户身份证号的正则表达式(要么是15位,要么是18位,最后一位可以为字母)
Pattern idNumPattern = Pattern.compile("(\\d{14}[0-9a-zA-Z])|(\\d{17}[0-9a-zA-Z])");
Matcher idNumMatcher = idNumPattern.matcher(idCard);
// 判断用户输入是否为身份证号
if (idNumMatcher.matches()) {
return true;
} else {
return false;
}
}
/**
* 失去焦点
* @param et
*/
protected void notfocus(EditText et) {
et.clearFocus();
et.setFocusable(false);
}
/**
* 聚焦
* @param et
*/
private void refocus(EditText et) {
et.setText("");
et.setFocusable(true);
et.setFocusableInTouchMode(true);
et.requestFocus();
et.findFocus();
}
/**
* 申请成功后的弹框
*/
public void surePopupWindow() {
DisplayMetrics disPlay = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(disPlay);
LayoutInflater inflater = (LayoutInflater) MyUpgradeBeaufulDetail.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.surepopwindow,null);
surepopwindow = new PopupWindow(layout);
dialog_down = (TextView) layout.findViewById(R.id.dialog_down);
info1 = (TextView) layout.findViewById(R.id.info1);
info2 = (TextView) layout.findViewById(R.id.info2);
dialog_down.setOnClickListener(MyUpgradeBeaufulDetail.this);
// surepopwindow.setBackgroundDrawable(new BitmapDrawable());
surepopwindow.setFocusable(true);// 加上这个popupwindow中的ListView才可以接收点击事件
// 控制popupwindow的宽度和高度自适应
surepopwindow.setWidth(disPlay.widthPixels * 8 / 10);
surepopwindow.setHeight(LayoutParams.WRAP_CONTENT);
// 控制popupwindow点击屏幕其他地方消失
// surepopwindow.setBackgroundDrawable(new BitmapDrawable());//
// 设置背景图片,不能在布局中设置,要通过代码来设置
// peopleNumPopWindow.setBackgroundDrawable(this.getResources().getDrawable(
// R.drawable.login_Box));// 设置背景图片,不能在布局中设置,要通过代码来设置
surepopwindow.setOutsideTouchable(false);// 触摸popupwindow外部,popupwindow消失。这个要求你的popupwindow要有背景图片才可以成功,如上
// 添加pop窗口关闭事件
surepopwindow.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
backgroundAlpha(1f);
}
});
}
/**
* 初始化上传弹框
*/
private void initUploadImagePopWindow() {
DisplayMetrics disPlay = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(disPlay);
LayoutInflater inflater2 = (LayoutInflater) MyUpgradeBeaufulDetail.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout2 = inflater2.inflate(R.layout.popupwindow_upload_image,null);
uploadImagePopWindow = new PopupWindow(layout2);
take_photo = (TextView) layout2.findViewById(R.id.take_photo);
selete_picture = (TextView) layout2.findViewById(R.id.selete_picture);
cancle = (TextView) layout2.findViewById(R.id.cancle);
take_photo.setOnClickListener(MyUpgradeBeaufulDetail.this);
selete_picture.setOnClickListener(MyUpgradeBeaufulDetail.this);
cancle.setOnClickListener(MyUpgradeBeaufulDetail.this);
uploadImagePopWindow.setFocusable(true);// 加上这个popupwindow中的ListView才可以接收点击事件
// 控制popupwindow的宽度和高度自适应
uploadImagePopWindow.setWidth(disPlay.widthPixels * 8 / 10);
uploadImagePopWindow.setHeight(LayoutParams.WRAP_CONTENT);
// 控制popupwindow点击屏幕其他地方消失
uploadImagePopWindow.setBackgroundDrawable(new BitmapDrawable());// 设置背景图片,不能在布局中设置,要通过代码来设置
// peopleNumPopWindow.setBackgroundDrawable(this.getResources().getDrawable(
// R.drawable.login_Box));// 设置背景图片,不能在布局中设置,要通过代码来设置
uploadImagePopWindow.setOutsideTouchable(true);// 触摸popupwindow外部,popupwindow消失。这个要求你的popupwindow要有背景图片才可以成功,如上
// 添加pop窗口关闭事件
uploadImagePopWindow.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
backgroundAlpha(1f);
}
});
}
protected void getImageFromAlbum() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");// 相片类型
startActivityForResult(intent,REQUEST_CODE_PICK_IMAGE);
}
protected void getImageFromCamera() {
// 外部存储的权限 获取当前状态
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
// 存储媒体已经挂载,并且挂载点可读/写
/*
* 拍照有两种方式,一是使用android.hardware.Camera,二是使用Intent(
* "android.media.action.IMAGE_CAPTURE") 调用系统的像机了。
*/
Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE");
capturePath = ImageFolder.getTempImageName().getPath();
getImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(capturePath)));
startActivityForResult(getImageByCamera,REQUEST_CODE_CAPTURE_CAMEIA);
} else {
Toast.makeText(MyUpgradeBeaufulDetail.this,"请确认已经插入SD卡",Toast.LENGTH_LONG).show();
}
}
public void backgroundAlpha(float bgAlpha) {
WindowManager.LayoutParams lp = MyUpgradeBeaufulDetail.this.getWindow().getAttributes();
lp.alpha = bgAlpha; // 0.0-1.0
MyUpgradeBeaufulDetail.this.getWindow().setAttributes(lp);
}
/**
* activity 返回的数据操作
*/
@Override
public void onActivityResult(int requestCode,int resultCode,Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_PICK_IMAGE) { // 相册
if (data == null || "".equals(data)) {
// 相册没有图片
Toast.makeText(MyUpgradeBeaufulDetail.this,"没有选择图片",Toast.LENGTH_LONG).show();
return;
}
Uri selectedImage = data.getData();
String picturePath;
if (selectedImage.getScheme().equals("file") && (data.getType() != null && data.getType().contains("image/"))) {
picturePath = selectedImage.getEncodedPath();
} else {
String[] filePathColumns = { MediaStore.Images.Media.DATA };
Cursor c = getContentResolver().query(selectedImage,filePathColumns,null,null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePathColumns[0]);
picturePath = c.getString(columnIndex);
c.close();
}
imgPathlist.add(picturePath);
// photoAdapter.notifyDataSetChanged();
uploadImage();
} else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_CAPTURE_CAMEIA) { // 照相机
if (data == null || "".equals(data)) {
File f = new File(capturePath);
if (!f.exists()) {
return;
} else {
imgPathlist.add(capturePath);
// photoAdapter.notifyDataSetChanged();
uploadImage();
return;
}
}
}
super.onActivityResult(requestCode,resultCode,data);
}
/**
* 上传图片
*/
private void uploadImage() {
new ImageUpload(MyUpgradeBeaufulDetail.this,imgPathlist,new UpLoadImageListener() {
@Override
public void UpLoadFail() {
return;
}
@Override
public void UpLoadSuccess(ArrayList<String> netimageurls) {
// imgPathlist.clear();
// String imagePath = netimageurls.get(0);
// imgResultList.add(imagePath);
imgPathlist.clear();
imagePath = netimageurls.get(0);
if (showimg.equals("upgrade_showImg2")) {
// 反面
idCardConversePicURL = imagePath;
upimgop2.setVisibility(View.GONE);
ImageManager.Load(idCardConversePicURL,upgrade_showImg2);
} else {
// 正面
idCardFacePicURL = imagePath;
upimgop1.setVisibility(View.GONE);
ImageManager.Load(idCardFacePicURL,upgrade_showImg1);
}
}
}).startLoad();
}
public void onResume() {
super.onResume();
StatService.onResume(this);
}
public void onPause() {
super.onPause();
StatService.onPause(this);
}
public class ImageUpload {
private Activity mActivity;
private ArrayList<String> hostimageurls = null;
private ArrayList<String> netimageurls = null;
private int upimage = 0;
private UpLoadImageListener mUpLoadImageListener;
private UIHelper uiHelper;
public ImageUpload(Activity mActivity,ArrayList<String> hostimageurls,
UpLoadImageListener mUpLoadImageListener) {
this.mActivity = mActivity;
this.hostimageurls = hostimageurls;
this.mUpLoadImageListener = mUpLoadImageListener;
netimageurls = new ArrayList<String>();
uiHelper = new UIHelper();
}
public void reLoad() {
if (hostimageurls != null && hostimageurls.size() > 0) {
uiHelper.showLoadDialog(mActivity,"正在上传");
if (netimageurls == null)
netimageurls = new ArrayList<String>();
imageup(hostimageurls.get(upimage));
} else if (mUpLoadImageListener != null) {
mUpLoadImageListener.UpLoadFail();
}
}
public void startLoad() {
this.reLoad();
}
private void imageup(String path) {
String data;
Bitmap temp = BitmapUtils.showimageFull(path,480,480);
data = Base64.imgToBase64(temp);
CustomResponseHandler handler = new CustomResponseHandler(mActivity,
false) {
@Override
public void onSuccess(int statusCode,
String content) {
super.onSuccess(statusCode,content);
try {
JSONObject obj = new JSONObject(content);
if (obj.getString("status").equals("100")
&& obj.getString("imgurl") != null) {
netimageurls.add(obj.getString("imgurl"));
if (hostimageurls.size() - 1 > upimage) {
upimage++;
imageup(hostimageurls.get(upimage));
} else {
uiHelper.cloesLoadDialog();
if (mUpLoadImageListener != null) {
mUpLoadImageListener
.UpLoadSuccess(netimageurls);
}
}
} else {
uiHelper.cloesLoadDialog();
Toast.makeText(mActivity,"上传失败!",Toast.LENGTH_SHORT)
.show();
if (mUpLoadImageListener != null) {
mUpLoadImageListener.UpLoadFail();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Throwable error,String content) {
super.onFailure(error,content);
uiHelper.cloesLoadDialog();
Toast.makeText(mActivity,Toast.LENGTH_SHORT).show();
if (mUpLoadImageListener != null) {
mUpLoadImageListener.UpLoadFail();
}
return;
}
};
String userId = PreferencesUtils.getInstance(mActivity).getUserId();
RequstClient.imgUpload(data,"jpg",handler);
}
public interface UpLoadImageListener {
void UpLoadSuccess(ArrayList<String> netimageurls);
void UpLoadFail();
}
}
public class BitmapUtils {
public static Bitmap getBmp(Context context,int resId) {
Resources res = context.getResources();
Bitmap bmp = BitmapFactory.decodeResource(res,resId);
return bmp;
}
public static Bitmap getBmp(Drawable drawable) {
// 取 drawable 的长宽
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
// 建立对应 bitmap
Bitmap bitmap = Bitmap.createBitmap(w,h,config);
// 建立对应 bitmap 的画布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0,w,h);
// 把 drawable 内容画到画布中
drawable.draw(canvas);
// Resources res = context.getResources();
// Bitmap bmp = BitmapFactory.decodeResource(res,resId);
return bitmap;
}
public static Bitmap zoomBitmap(Bitmap bitmap,int width,int height) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix matrix = new Matrix();
float scaleWidth = ((float) width / w);
float scaleHeight = ((float) height / h);
matrix.postScale(scaleWidth,scaleHeight);
Bitmap newbmp = Bitmap.createBitmap(bitmap,matrix,true);
return newbmp;
}
// public void saveBitmap(Bitmap bm,String name) {
// File f = new File(AppContext.getSDPath(),name);
// if (f.exists()) {
// f.delete();
// }
// try {
// FileOutputStream out = new FileOutputStream(f);
// bm.compress(Bitmap.CompressFormat.PNG,90,out);
// out.flush();
// out.close();
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
public static Bitmap showimageFull(String ImagePath,int w,int h) {
Bitmap tempBitmap;
int heightRatio = 0,widthRatio = 0;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(ImagePath,options);
heightRatio = (int) Math.ceil(options.outHeight / (float) h);
widthRatio = (int) Math.ceil(options.outWidth / (float) w);
if ((heightRatio > 1) && (widthRatio > 1)) {
if (heightRatio > widthRatio) {
options.inSampleSize = heightRatio;
} else {
options.inSampleSize = widthRatio;
}
}
options.inJustDecodeBounds = false;
tempBitmap = BitmapFactory.decodeFile(ImagePath,options);
try {
ExifInterface exif = new ExifInterface(ImagePath);
String sModel = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
if (sModel.equals("6")) {
Matrix matrix = new Matrix();
matrix.setRotate(90);
tempBitmap = Bitmap.createBitmap(tempBitmap,tempBitmap.getWidth(),tempBitmap.getHeight(),true);
}
} catch (IOException e) {
e.printStackTrace();
}
return tempBitmap;
}
public static Bitmap showimage(String ImagePath,int target) {
Bitmap tempBitmap;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(ImagePath,options);
options.inSampleSize = computeSampleSize(options,target);
options.inJustDecodeBounds = false;
tempBitmap = BitmapFactory.decodeFile(ImagePath,options);
return tempBitmap;
}
public static Bitmap watermarkBitmap(Bitmap src,Bitmap watermark,String title,int TextSize) {
if (src == null) {
return null;
}
int w = src.getWidth();
int h = src.getHeight();
// 需要处理图片太大造成的内存超过的问题,这里我的图片很小所以不写相应代码了
Bitmap tempBitmap = Bitmap.createBitmap(w,Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
Canvas cv = new Canvas(tempBitmap);
cv.drawBitmap(src,null);// 在 0,0坐标开始画入src
Paint paint = new Paint();
// 加入图片
if (watermark != null) {
int ww = watermark.getWidth();
int wh = watermark.getHeight();
paint.setAlpha(50);
cv.drawBitmap(watermark,w - ww + 5,h - wh + 5,paint);// 在src的右下角画入水印
}
// 加入文字
if (title != null) {
String familyName = "黑体";
Typeface font = Typeface.create(familyName,Typeface.BOLD);
TextPaint textPaint = new TextPaint();
textPaint.setColor(Color.RED);
textPaint.setTypeface(font);
textPaint.setTextSize(TextSize);
// 这里是自动换行的
StaticLayout layout = new StaticLayout(title,textPaint,Alignment.ALIGN_NORMAL,1.0F,0.0F,true);
layout.draw(cv);
// 文字就加左上角算了
// cv.drawText(title,50,paint);
}
cv.save(Canvas.ALL_SAVE_FLAG);// 保存
cv.restore();// 存储
return tempBitmap;
}
public static int computeSampleSize(BitmapFactory.Options options,int target) {
int w = options.outWidth;
int h = options.outHeight;
int candidateW = w / target;
int candidateH = h / target;
int candidate = Math.max(candidateW,candidateH);
if (candidate == 0)
return 1;
if (candidate > 1) {
if ((w > target) && (w / candidate) > target)
candidate += 1;
}
if (candidate > 1) {
if ((h > target) && (h / candidate) > target)
candidate += 1;
}
return candidate;
}
}
public class Base64 {
private static final char[] legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".tocharArray();
public static String encode(byte[] data) {
int start = 0;
int len = data.length;
StringBuffer buf = new StringBuffer(data.length * 3 / 2);
int end = len - 3;
int i = start;
int n = 0;
while (i <= end) {
int d = ((((int) data[i]) & 0x0ff) << 16) | ((((int) data[i + 1]) & 0x0ff) << 8) | (((int) data[i + 2]) & 0x0ff);
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append(legalChars[d & 63]);
i += 3;
if (n++ >= 14) {
n = 0;
buf.append(" ");
}
}
if (i == start + len - 2) {
int d = ((((int) data[i]) & 0x0ff) << 16) | ((((int) data[i + 1]) & 255) << 8);
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append("=");
} else if (i == start + len - 1) {
int d = (((int) data[i]) & 0x0ff) << 16;
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append("==");
}
return buf.toString();
}
private static int decode(char c) {
if (c >= 'A' && c <= 'Z')
return ((int) c) - 65;
else if (c >= 'a' && c <= 'z')
return ((int) c) - 97 + 26;
else if (c >= '0' && c <= '9')
return ((int) c) - 48 + 26 + 26;
else
switch (c) {
case '+':
return 62;
case '/':
return 63;
case '=':
return 0;
default:
throw new RuntimeException("unexpected code: " + c);
}
}
/**
* Decodes the given Base64 encoded String to a new byte array. The byte
* array holding the decoded data is returned.
*/
public static byte[] decode(String s) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
decode(s,bos);
} catch (IOException e) {
throw new RuntimeException();
}
byte[] decodedBytes = bos.toByteArray();
try {
bos.close();
bos = null;
} catch (IOException ex) {
System.err.println("Error while decoding BASE64: " + ex.toString());
}
return decodedBytes;
}
private static void decode(String s,OutputStream os) throws IOException {
int i = 0;
int len = s.length();
while (true) {
while (i < len && s.charAt(i) <= ' ')
i++;
if (i == len)
break;
int tri = (decode(s.charAt(i)) << 18) + (decode(s.charAt(i + 1)) << 12) + (decode(s.charAt(i + 2)) << 6)
+ (decode(s.charAt(i + 3)));
os.write((tri >> 16) & 255);
if (s.charAt(i + 2) == '=')
break;
os.write((tri >> 8) & 255);
if (s.charAt(i + 3) == '=')
break;
os.write(tri & 255);
i += 4;
}
}
public static String imgToBase64(Bitmap bitmap) {
ByteArrayOutputStream out = null;
try {
out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,70,out);
out.flush();
out.close();
byte[] imgBytes = out.toByteArray();
return encode(imgBytes);
} catch (Exception e) {
return null;
} finally {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class CustomResponseHandler extends AsyncHttpResponseHandler { public boolean isShowLoading = true; private Activity mActivity; private String msg = ""; private UIHelper uiHelper; public CustomResponseHandler(Activity mActivity,boolean isShowLoading) { this.isShowLoading = isShowLoading; this.mActivity = mActivity; this.uiHelper = new UIHelper(); } public CustomResponseHandler(Activity mActivity) { this.mActivity = mActivity; this.uiHelper = new UIHelper(); } public CustomResponseHandler(Activity mActivity,String msg) { this.mActivity = mActivity; this.msg = msg; this.uiHelper = new UIHelper(); } @Override public void onStart() { super.onStart(); if (isShowLoading && !mActivity.isFinishing()) { if(msg.equals("")){ uiHelper.showLoadDialog(mActivity,mActivity.getString(R.string.loading)); }else{ uiHelper.showLoadDialog(mActivity,msg); } } } @Override public void onFinish() { super.onFinish(); if (!mActivity.isFinishing()) { uiHelper.cloesLoadDialog(); } } @Override public void onFailure(Throwable error,String content) { super.onFailure(error,content); if(error instanceof HttpException) { onFailure(mActivity.getString(R.string.networkFailure));// 网络异常 }else if (error instanceof SocketTimeoutException) { onFailure(mActivity.getString(R.string.responseTimeout)); // 响应超时 }else if (error instanceof ConnectTimeoutException) { onFailure(mActivity.getString(R.string.requestTimeout));// 请求超时 }else if (error instanceof IOException) { onFailure(mActivity.getString(R.string.networkError)); // 网络异常 }else if (error instanceof JSONException) { onFailure(mActivity.getString(R.string.jsonError));//json格式转换异常 }else { onFailure(content); // 无法连接网络 } } @Override public void onSuccess(int statusCode,String content) { super.onSuccess(statusCode,content); //System.out.println("得到的返回码" + content); LogUtil.i("onSuccess",content); try { switch (statusCode) { case 200: break; default: break; } } catch (Exception e) { e.printStackTrace(); } } /** * 出错 * @param errorMessage */ public void onFailure(String errorMessage) { if (isShowLoading) { uiHelper.cloesLoadDialog(); } Toast.makeText(mActivity,errorMessage,Toast.LENGTH_SHORT).show(); } }
原文链接:https://www.f2er.com/regex/359682.html