Java tutorial
package com.uddchina.youdingdan; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.provider.MediaStore; import android.support.v4.content.FileProvider; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.CardView; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.bumptech.glide.Glide; import com.google.gson.Gson; import com.lzy.okgo.OkGo; import com.lzy.okgo.callback.StringCallback; import com.lzy.okgo.request.PostRequest; import com.uddchina.youdingdan.adapter.AreaAdapter; import com.uddchina.youdingdan.entity.AreaInfor; import com.uddchina.youdingdan.entity.ImagsInfor; import com.uddchina.youdingdan.entity.UserTypeInfor; import com.uddchina.youdingdan.popwindow.ChangeAddressPopwindow; import com.uddchina.youdingdan.utils.BitmapUtils; import com.uddchina.youdingdan.utils.InforUtils; import com.uddchina.youdingdan.utils.ShowToast; import com.uddchina.youdingdan.utils.Utils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import okhttp3.Call; import okhttp3.Response; import top.zibin.luban.Luban; import top.zibin.luban.OnCompressListener; public class MyDateActivity extends BaseActivity { @BindView(R.id.mbackground) LinearLayout mbackground; @BindView(R.id.mydateheadpic) ImageView mydateheadpic; @BindView(R.id.mydatename) EditText mydatename; @BindView(R.id.mStore_Name) TextView mStoreName; @BindView(R.id.mBusiness_license_pic) ImageView mBusinessLicensePic; @BindView(R.id.mBusiness_license) LinearLayout mBusinessLicense; @BindView(R.id.mIdCard_pic) ImageView mIdCardPic; @BindView(R.id.mIdCard) LinearLayout mIdCard; @BindView(R.id.mBusiness_license_LL_pic) ImageView mBusinessLicenseLLPic; @BindView(R.id.mBusiness_license_LL) LinearLayout mBusinessLicenseLL; @BindView(R.id.mIdCard_LL_picz) ImageView mIdCardLLPicz; @BindView(R.id.mIdCard_LL_picf) ImageView mIdCardLLPicf; @BindView(R.id.mIdCard_LL) LinearLayout mIdCardLL; @BindView(R.id.mSotrearea_content) TextView mSotreareaContent; @BindView(R.id.mStoreArea) LinearLayout mStoreArea; @BindView(R.id.mstoreAddress) EditText mstoreAddress; @BindView(R.id.mstorePhone) EditText mstorePhone; @BindView(R.id.mToRegister) TextView mToRegister; @BindView(R.id.myDatechanggeheadimg) RelativeLayout myDatechanggeheadimg; @BindView(R.id.mydate_storetext) TextView mydateStoretext; @BindView(R.id.mydatestoreheadpic) ImageView mydatestoreheadpic; @BindView(R.id.mydatestoreheadcardview) CardView mydatestoreheadcardview; @BindView(R.id.mydate_storepic) LinearLayout mydateStorepic; @BindView(R.id.datashow) LinearLayout datashow; private int pic_position = 0;//? private String path;// private Bitmap imageThumbnail; private boolean TAG_IMG = false; private PopupWindow popupwindowShow; private boolean tagone = true; private PopupWindow popuwindowArea; private ListView wv_address_province; private ListView wv_address_city; private ListView wv_address_area; private List<AreaInfor> provience = new ArrayList<>(); private boolean[] tagprovience; private String pri = "";//? private List<AreaInfor> city = new ArrayList<>(); private boolean[] tagcity; private String ci = "";// private List<AreaInfor> area = new ArrayList<>(); private String ar = "";// private String dictid = "";//?id private boolean[] tagarea; private AreaAdapter adapter1; private AreaAdapter adapter2; private AreaAdapter adapter3; private String showImags_resourt_id; private List<UserTypeInfor> userTypeInfors = new ArrayList<>(); private String authTypeid;//??id private String yingyeid;//?id private String idcardidone;//s???id private String idcardidtwo;//?????id private boolean checkingChanged;//??? @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_date); MyApp.getInstance().addActivity(this); ButterKnife.bind(this); init(); initData(); } private void initData() { //??? new Thread(new Runnable() { @Override public void run() { OkGo.get(InforUtils.URL + "dictionary/getSubDictList").params("dictTypeId", "authType") .params("parentDictId", null).execute(new StringCallback() { @Override public void onSuccess(String s, Call call, Response response) { userTypeInfors = UserTypeInfor.arrayUserTypeInforFromData(s); for (int i = 0; i < userTypeInfors.size(); i++) { if (InforUtils.identityAuth_authType.equals("")) { InforUtils.identityAuth_authType = "?"; } if (userTypeInfors.get(i).getDictName() .equals(InforUtils.identityAuth_authType)) { authTypeid = userTypeInfors.get(i).getId() + ""; } } } }); } }).start(); } Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 1: for (int i = 0; i < tagprovience.length; i++) { tagprovience[i] = false; } adapter1 = new AreaAdapter(provience, MyDateActivity.this, tagprovience); wv_address_province.setAdapter(adapter1); break; case 2: for (int i = 0; i < tagcity.length; i++) { tagcity[i] = false; } adapter2 = new AreaAdapter(city, MyDateActivity.this, tagcity); wv_address_city.setAdapter(adapter2); break; case 3: for (int i = 0; i < tagarea.length; i++) { tagarea[i] = false; } adapter3 = new AreaAdapter(area, MyDateActivity.this, tagarea); wv_address_area.setAdapter(adapter3); break; } } }; private void init() { if (null != InforUtils.customtx && !InforUtils.customtx.equals("") && !InforUtils.customtx.equals("null")) { Glide.with(getApplicationContext()).load(InforUtils.URL + InforUtils.customtx).asBitmap() .override(Utils.dp2px(50, getApplicationContext()), Utils.dp2px(50, getApplicationContext())) .centerCrop().error(R.mipmap.two).placeholder(R.mipmap.two).into(mydateheadpic); } if (!InforUtils.customname.equals("") && !InforUtils.customname.equals("null") && null != InforUtils.customname) { mydatename.setText(InforUtils.customname); } if (!InforUtils.customdq.equals("") && !InforUtils.customdq.equals("null") && null != InforUtils.customdq) { mSotreareaContent.setText(InforUtils.customdq); dictid = InforUtils.locateid; } if (!InforUtils.customdz.equals("") && !InforUtils.customdz.equals("null") && null != InforUtils.customdz) { mstoreAddress.setText(InforUtils.customdz); } if (!InforUtils.usertel.equals("") && !InforUtils.usertel.equals("null") && null != InforUtils.usertel) { mstorePhone.setText(InforUtils.usertel); } else { mstorePhone.setText(InforUtils.telnumber); } if (null != InforUtils.custommdxx && !InforUtils.custommdxx.equals("") && !InforUtils.custommdxx.equals("null")) { mStoreName.setVisibility(View.GONE); mydatestoreheadcardview.setVisibility(View.VISIBLE); Glide.with(getApplicationContext()).load(InforUtils.URL + InforUtils.custommdxx).asBitmap() .override(Utils.dp2px(60, getApplicationContext()), Utils.dp2px(30, getApplicationContext())) .error(R.mipmap.two).centerCrop().placeholder(R.mipmap.two).into(mydatestoreheadpic); showImags_resourt_id = InforUtils.custommdxxid; } if (!InforUtils.identityAuth_authType.equals("")) { if (InforUtils.identityAuth_authType.equals("?")) { for (int i = 0; i < userTypeInfors.size(); i++) { if (userTypeInfors.get(i).getDictName().equals("?")) { authTypeid = userTypeInfors.get(i).getId() + ""; } } yingyeid = InforUtils.STORE_YZID; tagone = true; mBusinessLicensePic.setImageResource(R.mipmap.chosed); mIdCardPic.setImageResource(R.mipmap.unchoosed); mBusinessLicenseLL.setVisibility(View.VISIBLE); mIdCardLL.setVisibility(View.GONE); } else { for (int i = 0; i < userTypeInfors.size(); i++) { if (userTypeInfors.get(i).getDictName().equals("?")) { authTypeid = userTypeInfors.get(i).getId() + ""; } } idcardidone = InforUtils.ID_PATHZID; idcardidtwo = InforUtils.ID_PATHFID; tagone = false; mBusinessLicensePic.setImageResource(R.mipmap.unchoosed); mIdCardPic.setImageResource(R.mipmap.chosed); mIdCardLL.setVisibility(View.VISIBLE); mBusinessLicenseLL.setVisibility(View.GONE); } } if (!InforUtils.customyy.equals("") && !InforUtils.customyy.equals("null") && null != InforUtils.customyy) { String[] split = InforUtils.customyy.split(","); if (null != split && split.length > 1) { Glide.with(getApplicationContext()).load(InforUtils.URL + split[0]).asBitmap() .override(Utils.dp2px(140, getApplicationContext()), Utils.dp2px(80, getApplicationContext())) .centerCrop().error(R.mipmap.idcard_z).placeholder(R.mipmap.idcard_z).into(mIdCardLLPicz); Glide.with(getApplicationContext()).load(InforUtils.URL + split[1]).asBitmap() .override(Utils.dp2px(140, getApplicationContext()), Utils.dp2px(80, getApplicationContext())) .centerCrop().error(R.mipmap.idcard_f).placeholder(R.mipmap.idcard_f).into(mIdCardLLPicf); } else { Glide.with(getApplicationContext()).load(InforUtils.URL + InforUtils.customyy).asBitmap() .override(Utils.dp2px(140, getApplicationContext()), Utils.dp2px(80, getApplicationContext())) .centerCrop().error(R.mipmap.store).placeholder(R.mipmap.store).into(mBusinessLicenseLLPic); } } } private void listenter() { wv_address_province.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { for (int i = 0; i < tagprovience.length; i++) { if (i == position) { tagprovience[position] = true; } else { tagprovience[i] = false; } } pri = provience.get(position).getDictName(); adapter1.notifyDataSetChanged(); getCityDate(provience.get(position).getId() + ""); } }); wv_address_city.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { for (int i = 0; i < tagcity.length; i++) { if (i == position) { tagcity[position] = true; } else { tagcity[i] = false; } } ci = city.get(position).getDictName(); adapter2.notifyDataSetChanged(); getCityDate1(city.get(position).getId() + ""); } }); wv_address_area.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { for (int i = 0; i < tagarea.length; i++) { if (i == position) { tagarea[position] = true; } else { tagarea[i] = false; } } ar = area.get(position).getDictName(); dictid = area.get(position).getId() + ""; adapter3.notifyDataSetChanged(); } }); } private void getCityDate1(final String dictId) { new Thread(new Runnable() { @Override public void run() { OkGo.get(InforUtils.URL + "dictionary/getSubDictList").params("dictTypeId", "area") .params("parentDictId", dictId).execute(new StringCallback() { @Override public void onSuccess(String s, Call call, Response response) { area = AreaInfor.arrayAreaInforFromData(s); tagarea = new boolean[area.size()]; handler.sendEmptyMessage(3); } }); } }).start(); } private void getCityDate(final String dictId) { new Thread(new Runnable() { @Override public void run() { OkGo.get(InforUtils.URL + "dictionary/getSubDictList").params("dictTypeId", "area") .params("parentDictId", dictId).execute(new StringCallback() { @Override public void onSuccess(String s, Call call, Response response) { city = AreaInfor.arrayAreaInforFromData(s); tagcity = new boolean[city.size()]; handler.sendEmptyMessage(2); } }); } }).start(); } @Override protected void onDestroy() { super.onDestroy(); MyApp.getInstance().removeActivity(this); } public void back(View view) { finish(); } @OnClick({ R.id.mBusiness_license, R.id.mIdCard, R.id.mBusiness_license_LL_pic, R.id.mIdCard_LL_picz, R.id.mIdCard_LL_picf, R.id.mStoreArea, R.id.mToRegister, R.id.myDatechanggeheadimg, R.id.mydate_storepic }) public void onClick(View view) { switch (view.getId()) { case R.id.mBusiness_license: for (int i = 0; i < userTypeInfors.size(); i++) { if (userTypeInfors.get(i).getDictName().equals("?")) { authTypeid = userTypeInfors.get(i).getId() + ""; } } tagone = true; mBusinessLicensePic.setImageResource(R.mipmap.chosed); mIdCardPic.setImageResource(R.mipmap.unchoosed); mBusinessLicenseLL.setVisibility(View.VISIBLE); mIdCardLL.setVisibility(View.GONE); break; case R.id.mIdCard: for (int i = 0; i < userTypeInfors.size(); i++) { if (userTypeInfors.get(i).getDictName().equals("?")) { authTypeid = userTypeInfors.get(i).getId() + ""; } } tagone = false; mBusinessLicensePic.setImageResource(R.mipmap.unchoosed); mIdCardPic.setImageResource(R.mipmap.chosed); mIdCardLL.setVisibility(View.VISIBLE); mBusinessLicenseLL.setVisibility(View.GONE); break; case R.id.mBusiness_license_LL_pic: pic_position = 0;//? show(mBusinessLicenseLL); break; case R.id.mIdCard_LL_picz: pic_position = 1;//?? show(mIdCard); break; case R.id.mIdCard_LL_picf: pic_position = 2;//???? show(mIdCard); break; case R.id.mStoreArea: /* ChangeAddressPopwindow mChangeAddressPopwindow = new ChangeAddressPopwindow(MyDateActivity.this); mChangeAddressPopwindow.setAddress("?", "?", "?"); mChangeAddressPopwindow.showAtLocation(mSotreareaContent, Gravity.BOTTOM, 0, 0); mChangeAddressPopwindow .setAddresskListener(new ChangeAddressPopwindow.OnAddressCListener() { @Override public void onClick(String province, String city, String area) { // TODO Auto-generated method stub userprovince = province; usercity = city; userarea = area; mSotreareaContent.setText(province + city + area); } });*/ getAreaDate(); showArea(mStoreArea); break; case R.id.mToRegister: sendData(); break; case R.id.myDatechanggeheadimg: pic_position = 3;//? show(mIdCard); break; case R.id.mydate_storepic: pic_position = 4;//? show(mIdCard); break; } } private void getAreaDate() { new Thread(new Runnable() { @Override public void run() { OkGo.get(InforUtils.URL + "dictionary/getSubDictList").params("dictTypeId", "area") .execute(new StringCallback() { @Override public void onSuccess(String s, Call call, Response response) { provience = AreaInfor.arrayAreaInforFromData(s); Log.e("...", provience.size() + ""); tagprovience = new boolean[provience.size()]; handler.sendEmptyMessage(1); } }); } }).start(); } private void sendData() { if (InforUtils.STORE_YZID.equals(yingyeid) && InforUtils.ID_PATHZID.equals(idcardidone) && InforUtils.ID_PATHFID.equals(idcardidtwo) && InforUtils.customname.equals(mydatename.getText().toString())) { checkingChanged = false; } else { checkingChanged = true; } PostRequest params = OkGo.post(InforUtils.URL + "user/perfectUser") .params("enterpriseName", mydatename.getText().toString()) .params("address", mstoreAddress.getText().toString()) .params("contactPhone", mstorePhone.getText().toString()) .params("phoneNumber", InforUtils.telnumber).params("id", InforUtils.customid) .params("avatar", InforUtils.NETHEAD_PATH).params("registStep", 1) .params("shopImages[0].resource.id", showImags_resourt_id) .params("shopImages[0].user.id", InforUtils.customid).params("locate.id", dictid) .params("checkingChanged", checkingChanged).params("identityAuth.authType.id", authTypeid); if (tagone) { Log.e("...", yingyeid); InforUtils.identityAuth_authType = "?"; params.params("identityAuth.resources[0].resource.id", yingyeid); params.params("identityAuth.resources[0].user.id", InforUtils.customid); } else { params.params("identityAuth.resources[0].resource.id", idcardidone); params.params("identityAuth.resources[0].user.id", InforUtils.customid); params.params("identityAuth.resources[1].resource.id", idcardidtwo); params.params("identityAuth.resources[1].user.id", InforUtils.customid); InforUtils.identityAuth_authType = "?"; } params.execute(new StringCallback() { @Override public void onSuccess(String s, Call call, Response response) { try { JSONObject object1 = new JSONObject(s); InforUtils.custommdxxid = showImags_resourt_id; if (object1.optBoolean("flag")) { if (tagone) { InforUtils.STORE_YZID = yingyeid; InforUtils.locateid = dictid; if (InforUtils.NETSTORE_YZ != null) { InforUtils.customyy = InforUtils.NETSTORE_YZ; Log.e("...", InforUtils.customyy); } } else { InforUtils.ID_PATHZID = idcardidone; InforUtils.ID_PATHFID = idcardidtwo; if (InforUtils.NETID_PATHF != null) { InforUtils.customyy = InforUtils.NETID_PATHZ + "," + InforUtils.NETID_PATHF; } else { } } InforUtils.registStep = "1"; if (null != InforUtils.NETHEAD_PATH) { InforUtils.customtx = InforUtils.NETHEAD_PATH; } if (null != InforUtils.NETSTORE_HEAD_PATH) { InforUtils.custommdxx = InforUtils.NETSTORE_HEAD_PATH; } if (!mSotreareaContent.getText().toString().equals("")) { InforUtils.customdq = mSotreareaContent.getText() + ""; } if (!mstoreAddress.getText().toString().equals("")) { InforUtils.customdz = mstoreAddress.getText().toString(); } if (!mydatename.getText().toString().equals("")) { InforUtils.customname = mydatename.getText().toString(); } if (!mstorePhone.getText().toString().equals("")) { InforUtils.usertel = mstorePhone.getText().toString(); } sendBroadcast(new Intent("flashPerson")); setResult(10, new Intent()); finish(); } /* ShowToast.ToToast(MyDateActivity.this,object1.optString("info"));*/ } catch (JSONException e) { e.printStackTrace(); } } }); } /** * popupWindow * * @param linearLayout */ private void show(LinearLayout linearLayout) { popupwindowShow = new PopupWindow(linearLayout, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.picture_popupwindow_layout, null); popupwindowShow.setContentView(view); popupwindowShow.setFocusable(true); popupwindowShow.setOutsideTouchable(true); popupwindowShow.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null)); popupwindowShow.showAtLocation(linearLayout, Gravity.BOTTOM, 0, 0); TextView doPhoto = (TextView) view.findViewById(R.id.doPhoto); TextView choicePicture = (TextView) view.findViewById(R.id.choicePicture); TextView cansol = (TextView) view.findViewById(R.id.cansol); //? doPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { doPhoto(); popupwindowShow.dismiss(); } }); // choicePicture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { doPicture(); popupwindowShow.dismiss(); } }); //? cansol.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popupwindowShow.dismiss(); } }); } /** * popupWindow * * @param linearLayout */ private void showArea(LinearLayout linearLayout) { popuwindowArea = new PopupWindow(linearLayout, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.editone_changeaddress_pop_layout, null); popuwindowArea.setContentView(view); popuwindowArea.setFocusable(true); popuwindowArea.setOutsideTouchable(true); popuwindowArea.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null)); popuwindowArea.showAtLocation(linearLayout, Gravity.BOTTOM, 0, 0); TextView btn_myinfo_cancel = (TextView) view.findViewById(R.id.btn_myinfo_cancel); TextView btn_myinfo_sure = (TextView) view.findViewById(R.id.btn_myinfo_sure); wv_address_province = (ListView) view.findViewById(R.id.wv_address_province); wv_address_city = (ListView) view.findViewById(R.id.wv_address_city); wv_address_area = (ListView) view.findViewById(R.id.wv_address_area); listenter(); //? btn_myinfo_cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popuwindowArea.dismiss(); } }); //? btn_myinfo_sure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!dictid.equals("")) { mSotreareaContent.setText(pri + ci + ar); popuwindowArea.dismiss(); } else { ShowToast.ToToast(MyDateActivity.this, ""); } } }); } public void doPicture() { Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*");// startActivityForResult(intent, 3); } /** * ? */ public void doPhoto() { // Uri uri = null; String saveDir = Environment.getExternalStorageDirectory() + "/youdingdan"; File dir = new File(saveDir); if (!dir.exists()) { dir.mkdir(); } String filename = "ydd_register" + pic_position + ".PNG"; path = saveDir + "/" + filename; File file = new File(path); try { if (file.exists()) { file.delete(); } file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } if (Build.VERSION.SDK_INT >= 24) { uri = FileProvider.getUriForFile(MyDateActivity.this, "com.example.cameraalbumtest.fileprovider", file); } else { uri = Uri.fromFile(file); } Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); // ?? intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, 2); /* String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, 2); } else { Toast.makeText(this, "SD?", Toast.LENGTH_LONG).show(); }*/ } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case 2: //? if (requestCode == 2 && resultCode == RESULT_OK) { Luban.get(this).load(new File(path)) //? .putGear(Luban.THIRD_GEAR) // .setCompressListener(new OnCompressListener() { // @Override public void onStart() { // TODO ??? loading UI } @Override public void onSuccess(File file) { // TODO ??? } @Override public void onError(Throwable e) { // TODO } }).launch(); //? /* Bitmap photo = null; Bitmap imageThumbnail = null; if (photo == null) { Bundle bundle = data.getExtras(); if (bundle != null) { File file = null; photo = (Bitmap) bundle.get("data"); FileOutputStream fileOutputStream = null; try { String saveDir = Environment.getExternalStorageDirectory() + "/youdingdan"; File dir = new File(saveDir); if (!dir.exists()) { dir.mkdir(); } String filename = "ydd_register" + pic_position + ".PNG"; path = saveDir + "/" + filename; file = new File(path); fileOutputStream = new FileOutputStream(file); photo.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); } catch (Exception e) { e.printStackTrace(); } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (Exception e) { e.printStackTrace(); } } }*/ Bitmap imageThumbnail1 = BitmapUtils.createImageThumbnail(path, 240, 160); switch (pic_position) { case 0: mBusinessLicenseLLPic.setImageBitmap(imageThumbnail1); InforUtils.STORE_YZ = path; break; case 1: InforUtils.ID_PATHZ = path; mIdCardLLPicz.setImageBitmap(imageThumbnail1); break; case 2: InforUtils.ID_PATHF = path; mIdCardLLPicf.setImageBitmap(imageThumbnail1); break; case 3: InforUtils.HEAD_PATH = path; mydateheadpic.setImageBitmap(imageThumbnail1); break; case 4: mStoreName.setVisibility(View.GONE); mydatestoreheadcardview.setVisibility(View.VISIBLE); InforUtils.STORE_HEAD_PATH = path; mydatestoreheadpic.setImageBitmap(imageThumbnail1); break; } upImg(path); /*} else { Toast.makeText(MyDateActivity.this, "?", Toast.LENGTH_LONG).show(); return; }*/ } break; case 3: // if (requestCode == 3 && resultCode == RESULT_OK && null != data) { if (data != null) { Uri uri = data.getData(); String res = null; String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, proj, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); res = cursor.getString(column_index); } cursor.close(); path = res; Bitmap photo = BitmapUtils.createImageThumbnail(path, 240, 160); switch (pic_position) { case 0: mBusinessLicenseLLPic.setImageBitmap(photo); InforUtils.STORE_YZ = path; break; case 1: InforUtils.ID_PATHZ = path; mIdCardLLPicz.setImageBitmap(photo); break; case 2: InforUtils.ID_PATHF = path; mIdCardLLPicf.setImageBitmap(photo); break; case 3: InforUtils.HEAD_PATH = path; mydateheadpic.setImageBitmap(photo); break; case 4: mStoreName.setVisibility(View.GONE); mydatestoreheadcardview.setVisibility(View.VISIBLE); InforUtils.STORE_HEAD_PATH = path; mydatestoreheadpic.setImageBitmap(photo); break; } upImg(path); } else { Toast.makeText(MyDateActivity.this, "", Toast.LENGTH_LONG).show(); return; } } break; } } // private void upImg(final String path1) { new Thread(new Runnable() { @Override public void run() { OkGo.post(InforUtils.URL + "resource/saveImage").params("image", new File(path1)) .execute(new StringCallback() { @Override public void onSuccess(String s, Call call, Response response) { ImagsInfor imagsInfor = new Gson().fromJson(s, ImagsInfor.class); try { JSONObject object = new JSONObject(s); if (object.optBoolean("flag")) { String content = imagsInfor.getData().getPath(); switch (pic_position) { case 0: InforUtils.NETSTORE_YZ = content; yingyeid = imagsInfor.getData().getId() + ""; break; case 1: InforUtils.NETID_PATHZ = content; idcardidone = imagsInfor.getData().getId() + ""; break; case 2: InforUtils.NETID_PATHF = content; idcardidtwo = imagsInfor.getData().getId() + ""; break; case 3: InforUtils.NETHEAD_PATH = content; break; case 4: InforUtils.NETSTORE_HEAD_PATH = content; showImags_resourt_id = imagsInfor.getData().getId() + ""; break; } } } catch (JSONException e) { e.printStackTrace(); } } }); } }).start(); } }