|
|
@@ -0,0 +1,532 @@
|
|
|
+package com.modular.login.activity;
|
|
|
+
|
|
|
+import android.Manifest;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Build;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Base64;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.CheckBox;
|
|
|
+import android.widget.CompoundButton;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.andreabaccega.widget.FormEditText;
|
|
|
+import com.common.LogUtil;
|
|
|
+import com.common.data.StringUtil;
|
|
|
+import com.common.system.DisplayUtil;
|
|
|
+import com.common.system.PermissionUtil;
|
|
|
+import com.common.ui.CameraUtil;
|
|
|
+import com.common.ui.ImageUtil;
|
|
|
+import com.core.app.AppConstant;
|
|
|
+import com.core.app.Constants;
|
|
|
+import com.core.app.MyApplication;
|
|
|
+import com.core.base.BaseActivity;
|
|
|
+import com.core.net.http.ViewUtil;
|
|
|
+import com.core.utils.CommonUtil;
|
|
|
+import com.core.utils.ToastUtil;
|
|
|
+import com.me.network.app.http.HttpClient;
|
|
|
+import com.me.network.app.http.Method;
|
|
|
+import com.me.network.app.http.rx.ResultListener;
|
|
|
+import com.me.network.app.http.rx.ResultSubscriber;
|
|
|
+import com.modular.login.R;
|
|
|
+import com.modular.login.model.ProfessionBean;
|
|
|
+import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
+
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by RaoMeng on 2017/9/21.
|
|
|
+ */
|
|
|
+
|
|
|
+public class EnterpriseRegisterActivity extends BaseActivity implements View.OnClickListener {
|
|
|
+ private final int ENTERPRISE_REGISTER = 0x11;
|
|
|
+
|
|
|
+ private Button mNextStepButton;
|
|
|
+ private FormEditText mEnterpriseCompanyEt;
|
|
|
+ private FormEditText mEnterpriseLicenseEt;
|
|
|
+ private FormEditText mEnterpriseRepresentEt;
|
|
|
+ private FormEditText mEnterpriseAddressEt;
|
|
|
+ private FormEditText mEnterpriseIndustryEt;
|
|
|
+ private FormEditText mEnterpriseBusinessEt;
|
|
|
+ private ImageView mEnterpriseLicenseIv;
|
|
|
+ private ImageView mTakePicImageView;
|
|
|
+ private TextView mEnterpriseClauseTv1;
|
|
|
+ private TextView mEnterpriseClauseTv2;
|
|
|
+ private TextView mEnterpriseClauseTv3;
|
|
|
+ private CheckBox mClauseCheckBox;
|
|
|
+ private PopupWindow mPopupWindow;
|
|
|
+ private Uri mNewPhotoUri;
|
|
|
+ private static final int REQUEST_CODE_CAPTURE_PHOTO = 1;// 拍照
|
|
|
+ private static final int REQUEST_CODE_PICK_PHOTO = 2;// 图库
|
|
|
+ private static final int REQUEST_CODE_CROP_PHOTO = 3;//裁剪
|
|
|
+ private String path = null;
|
|
|
+ private File mLicenseFile;
|
|
|
+ private List<ProfessionBean> mProfessionList;
|
|
|
+
|
|
|
+ private Handler mHandler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ String result = msg.getData().getString("result");
|
|
|
+ Log.d("enterpriseresponse", result);
|
|
|
+ switch (msg.what) {
|
|
|
+ case ENTERPRISE_REGISTER:
|
|
|
+ progressDialog.dismiss();
|
|
|
+ if (result != null) {
|
|
|
+ try {
|
|
|
+ JSONObject resultObject = new JSONObject(result);
|
|
|
+ if (resultObject.optBoolean("success")) {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setClass(EnterpriseRegisterActivity.this, AdminRegisterActivity.class);
|
|
|
+ startActivity(intent);
|
|
|
+ } else {
|
|
|
+ String errMsg = resultObject.optString("errMsg");
|
|
|
+ ToastUtil.showToast(EnterpriseRegisterActivity.this, errMsg);
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Constants.APP_SOCKETIMEOUTEXCEPTION:
|
|
|
+ progressDialog.dismiss();
|
|
|
+ if (result != null)
|
|
|
+ ToastMessage(result);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ private HttpClient mHttpClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_enterprise_register);
|
|
|
+ getSupportActionBar().setTitle("企业注册(1/2)");
|
|
|
+
|
|
|
+ initViews();
|
|
|
+// initProfession();
|
|
|
+
|
|
|
+ mNextStepButton.setOnClickListener(this);
|
|
|
+ mEnterpriseLicenseIv.setOnClickListener(this);
|
|
|
+ mTakePicImageView.setOnClickListener(this);
|
|
|
+ mClauseCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
+ if (isChecked) {
|
|
|
+ mNextStepButton.setEnabled(true);
|
|
|
+ } else {
|
|
|
+ mNextStepButton.setEnabled(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initViews() {
|
|
|
+
|
|
|
+ mNextStepButton = (Button) findViewById(R.id.enterprise_register_next_step_btn);
|
|
|
+ mEnterpriseCompanyEt = (FormEditText) findViewById(R.id.enterprise_register_company_et);
|
|
|
+ mEnterpriseLicenseEt = (FormEditText) findViewById(R.id.enterprise_register_license_et);
|
|
|
+ mEnterpriseRepresentEt = (FormEditText) findViewById(R.id.enterprise_register_represent_et);
|
|
|
+ mEnterpriseAddressEt = (FormEditText) findViewById(R.id.enterprise_register_address_et);
|
|
|
+ mEnterpriseIndustryEt = (FormEditText) findViewById(R.id.enterprise_register_industry_et);
|
|
|
+ mEnterpriseBusinessEt = (FormEditText) findViewById(R.id.enterprise_register_business_et);
|
|
|
+ mEnterpriseLicenseIv = (ImageView) findViewById(R.id.enterprise_register_license_iv);
|
|
|
+ mTakePicImageView = (ImageView) findViewById(R.id.enterprise_register_picture_iv);
|
|
|
+ mEnterpriseClauseTv1 = (TextView) findViewById(R.id.enterprise_register_clause_tv1);
|
|
|
+ mEnterpriseClauseTv2 = (TextView) findViewById(R.id.enterprise_register_clause_tv2);
|
|
|
+ mEnterpriseClauseTv3 = (TextView) findViewById(R.id.enterprise_register_clause_tv3);
|
|
|
+ mClauseCheckBox = (CheckBox) findViewById(R.id.enterprise_register_clause_cb);
|
|
|
+ mProfessionList = new ArrayList<>();
|
|
|
+ mHttpClient = new
|
|
|
+// HttpClient.Builder("https://account.ubtob.com/sso")
|
|
|
+ HttpClient.Builder("http://192.168.253.66:8082")
|
|
|
+// HttpClient.Builder("http://192.168.253.200:8080")
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initProfession() {
|
|
|
+ mProfessionList = new ArrayList<>();
|
|
|
+ String profession = CommonUtil.getAssetsJson(this, "profession.json");
|
|
|
+ try {
|
|
|
+ JSONObject professionObject = new JSONObject(profession);
|
|
|
+ Iterator<String> iterator = professionObject.keys();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ProfessionBean professionBean = new ProfessionBean();
|
|
|
+ String professionFirstTitle = iterator.next().toString();
|
|
|
+ professionBean.setProfessionFirstTitle(professionFirstTitle);
|
|
|
+
|
|
|
+ List<ProfessionBean.ProfessionSecondBean> professionSecondList = new ArrayList<>();
|
|
|
+
|
|
|
+ Object second = professionObject.opt(professionFirstTitle);
|
|
|
+ if (second instanceof JSONArray) {
|
|
|
+ JSONArray secondArray = (JSONArray) second;
|
|
|
+ if (secondArray != null) {
|
|
|
+ for (int i = 0; i < secondArray.length(); i++) {
|
|
|
+ ProfessionBean.ProfessionSecondBean professionSecond = new ProfessionBean.ProfessionSecondBean();
|
|
|
+ String secondTitle = secondArray.optString(i);
|
|
|
+ professionSecond.setProfessionSecondTitle(secondTitle);
|
|
|
+
|
|
|
+ professionSecondList.add(professionSecond);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (second instanceof JSONObject) {
|
|
|
+ JSONObject secondObject = (JSONObject) second;
|
|
|
+ Iterator<String> secondKeys = secondObject.keys();
|
|
|
+ while (secondKeys.hasNext()) {
|
|
|
+ ProfessionBean.ProfessionSecondBean professionSecond = new ProfessionBean.ProfessionSecondBean();
|
|
|
+ String secondTitle = iterator.next().toString();
|
|
|
+ professionSecond.setProfessionSecondTitle(secondTitle);
|
|
|
+
|
|
|
+ List<String> thirdTitles = new ArrayList<>();
|
|
|
+ Object third = secondObject.opt(secondTitle);
|
|
|
+ if (third instanceof String) {
|
|
|
+ thirdTitles.add((String) third);
|
|
|
+ } else if (third instanceof JSONArray) {
|
|
|
+ JSONArray thirdArray = (JSONArray) third;
|
|
|
+ for (int i = 0; i < thirdArray.length(); i++) {
|
|
|
+ String thirdTitle = thirdArray.optString(i);
|
|
|
+ thirdTitles.add(thirdTitle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ professionSecond.setProfessionThirdTitles(thirdTitles);
|
|
|
+
|
|
|
+ professionSecondList.add(professionSecond);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ professionBean.setProfessionSecondTitles(professionSecondList);
|
|
|
+
|
|
|
+ mProfessionList.add(professionBean);
|
|
|
+ Log.d("professionList", mProfessionList.toString());
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ int i = v.getId();
|
|
|
+ if (i == R.id.enterprise_register_next_step_btn) {
|
|
|
+
|
|
|
+ if (mClauseCheckBox.isChecked()) {
|
|
|
+ FormEditText[] allFields = {mEnterpriseAddressEt, mEnterpriseRepresentEt
|
|
|
+ , mEnterpriseCompanyEt, mEnterpriseLicenseEt};
|
|
|
+
|
|
|
+ boolean allValid = true;
|
|
|
+ for (FormEditText field : allFields) {
|
|
|
+ allValid = field.testValidity() && allValid;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (allValid) {
|
|
|
+ if (mLicenseFile == null) {
|
|
|
+ ToastUtil.showToast(this, "请选择您的营业执照");
|
|
|
+ } else {
|
|
|
+ progressDialog.show();
|
|
|
+ obtainPageToken();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // EditText are going to appear with an exclamation mark and an explicative message.
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, "请阅读并同意必读协议");
|
|
|
+ }
|
|
|
+ } else if (i == R.id.enterprise_register_license_iv) {
|
|
|
+ if (mLicenseFile != null) {
|
|
|
+ try {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setAction("com.modular.tool.SingleImagePreviewActivity");
|
|
|
+ intent.putExtra(AppConstant.EXTRA_IMAGE_URI, mLicenseFile.getCanonicalPath());
|
|
|
+ startActivity(intent);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (i == R.id.enterprise_register_picture_iv) {
|
|
|
+ CommonUtil.closeKeybord(mEnterpriseCompanyEt, this);
|
|
|
+ showPicturePopup();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void obtainPageToken() {
|
|
|
+ mHttpClient.Api().send(new HttpClient.Builder()
|
|
|
+ .url("/sso/mobile/userspace/register")
|
|
|
+// .header("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"))
|
|
|
+ .method(Method.GET).build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object s) {
|
|
|
+ if (s != null) {
|
|
|
+ try {
|
|
|
+ JSONObject resultObject = new JSONObject(s.toString());
|
|
|
+ if (resultObject.optBoolean("success")) {
|
|
|
+ JSONObject contentObject = resultObject.optJSONObject("content");
|
|
|
+ if (contentObject != null) {
|
|
|
+ String pageToken = contentObject.optString("pageToken");
|
|
|
+ String sessionId = contentObject.optString("sessionId");
|
|
|
+ CommonUtil.setSharedPreferences(ct, "sessionId", sessionId);
|
|
|
+ CommonUtil.setSharedPreferences(ct, "pageToken", pageToken);
|
|
|
+
|
|
|
+// Intent intent = new Intent();
|
|
|
+// intent.setClass(EnterpriseRegisterActivity.this, AdminRegisterActivity.class);
|
|
|
+// startActivity(intent);
|
|
|
+
|
|
|
+ enterpriseRegister(pageToken, sessionId);
|
|
|
+ } else {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ ToastUtil.showToast(EnterpriseRegisterActivity.this
|
|
|
+ , "注册失败,请重试");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String errMsg = resultObject.optString("errMsg");
|
|
|
+ ToastUtil.showToast(EnterpriseRegisterActivity.this
|
|
|
+ , TextUtils.isEmpty(errMsg) ? "注册失败,请重试" : errMsg);
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void enterpriseRegister(String pageToken, String sessionId) {
|
|
|
+
|
|
|
+ String url = "http://192.168.253.66:8082/sso/mobile/userspace/register";
|
|
|
+
|
|
|
+ String fileBytes = getFileBytes(mLicenseFile);
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("name", mEnterpriseCompanyEt.getText().toString());
|
|
|
+ params.put("businessCode", mEnterpriseLicenseEt.getText().toString());
|
|
|
+ params.put("corporation", mEnterpriseRepresentEt.getText().toString());
|
|
|
+ params.put("address", mEnterpriseAddressEt.getText().toString());
|
|
|
+ params.put("pageToken", pageToken);
|
|
|
+ if (!TextUtils.isEmpty(mEnterpriseIndustryEt.getText())) {
|
|
|
+ params.put("profession", mEnterpriseIndustryEt.getText().toString());
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(mEnterpriseBusinessEt.getText())) {
|
|
|
+ params.put("tags", mEnterpriseBusinessEt.getText().toString());
|
|
|
+ }
|
|
|
+ params.put("businessImage", fileBytes);
|
|
|
+ LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + sessionId);
|
|
|
+ ViewUtil.httpSendRequest(this, url, params, mHandler, headers, ENTERPRISE_REGISTER, null, null, "post");
|
|
|
+
|
|
|
+// String fileBytes = getFileBytes(mLicenseFile);
|
|
|
+//
|
|
|
+// String url = "http://192.168.253.192:8080/account/api/file";
|
|
|
+// Map<String, Object> params = new HashMap<>();
|
|
|
+// params.put("data", fileBytes);
|
|
|
+// LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
+// headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
+// ViewUtil.httpSendRequest(this, url, params, mHandler, headers, 111, null, null, "post");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getFileBytes(File licenseFile) {
|
|
|
+ String fileBytes = "";
|
|
|
+ FileInputStream inputStream = null;
|
|
|
+ ByteArrayOutputStream bos = null;
|
|
|
+ try {
|
|
|
+ inputStream = new FileInputStream(licenseFile);
|
|
|
+ bos = new ByteArrayOutputStream();
|
|
|
+ byte[] b = new byte[1024];
|
|
|
+ int len = -1;
|
|
|
+ while ((len = inputStream.read(b)) != -1) {
|
|
|
+ bos.write(b, 0, len);
|
|
|
+ }
|
|
|
+ byte[] bytes = bos.toByteArray();
|
|
|
+// fileBytes = new String(bytes, "UTF-8");
|
|
|
+ fileBytes = Base64.encodeToString(bytes, Base64.NO_WRAP);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (inputStream != null)
|
|
|
+ inputStream.close();
|
|
|
+ if (bos != null)
|
|
|
+ bos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showPicturePopup() {
|
|
|
+ View headSelectView = View.inflate(this, R.layout.layout_select_head, null);
|
|
|
+
|
|
|
+ mPopupWindow = new PopupWindow(headSelectView,
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ mPopupWindow.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
+ mPopupWindow.setFocusable(true);
|
|
|
+ mPopupWindow.setOutsideTouchable(true);
|
|
|
+ DisplayUtil.backgroundAlpha(this, 0.5f);
|
|
|
+ mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mPopupWindow.showAtLocation(View.inflate(this, R.layout.activity_base_info, null), Gravity.BOTTOM, 0, 0);
|
|
|
+ TextView takePicTv = (TextView) headSelectView.findViewById(R.id.head_take_picture);
|
|
|
+ TextView selectPicTv = (TextView) headSelectView.findViewById(R.id.head_select_photos);
|
|
|
+ TextView cancelTv = (TextView) headSelectView.findViewById(R.id.head_cancel);
|
|
|
+
|
|
|
+ takePicTv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ String[] permissions = new String[]{Manifest.permission.CAMERA};
|
|
|
+ if (PermissionUtil.lacksPermissions(ct, permissions)) {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ requestPermissions(permissions, PermissionUtil.DEFAULT_REQUEST);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(EnterpriseRegisterActivity.this, MyApplication.getInstance().mLoginUser.getUserId(), CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.captureImage(EnterpriseRegisterActivity.this, mNewPhotoUri, REQUEST_CODE_CAPTURE_PHOTO);
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ selectPicTv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ /*boolean is = CommonUtil.getSharedPreferencesBoolean(ct, "isImage", false);
|
|
|
+ if (!is) {
|
|
|
+ Crouton.makeText(ct, "您当前未被允许使用相册,请使用拍照");
|
|
|
+ return;
|
|
|
+ }*/
|
|
|
+ String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
+ if (PermissionUtil.lacksPermissions(ct, permissions)) {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ requestPermissions(permissions, 111);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(EnterpriseRegisterActivity.this, MyApplication.getInstance().mLoginUser.getUserId(), CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.pickImageSimple(EnterpriseRegisterActivity.this, REQUEST_CODE_PICK_PHOTO);
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ cancelTv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closePopupWindow() {
|
|
|
+ if (mPopupWindow != null) {
|
|
|
+ mPopupWindow.dismiss();
|
|
|
+ mPopupWindow = null;
|
|
|
+ DisplayUtil.backgroundAlpha(this, 1f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
+ if (requestCode == PermissionUtil.DEFAULT_REQUEST) {
|
|
|
+ if (grantResults.length != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ LogUtil.i("没有获取到权限");
|
|
|
+ } else {
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(EnterpriseRegisterActivity.this, MyApplication.getInstance().mLoginUser.getUserId(), CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.captureImage(EnterpriseRegisterActivity.this, mNewPhotoUri, REQUEST_CODE_CAPTURE_PHOTO);
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ } else if (requestCode == 111) {
|
|
|
+ if (grantResults.length != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ LogUtil.i("没有获取到权限");
|
|
|
+ } else {
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(EnterpriseRegisterActivity.this, MyApplication.getInstance().mLoginUser.getUserId(), CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.pickImageSimple(EnterpriseRegisterActivity.this, REQUEST_CODE_PICK_PHOTO);
|
|
|
+ closePopupWindow();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ if (requestCode == REQUEST_CODE_CAPTURE_PHOTO) {// 拍照返回
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (mNewPhotoUri != null) {
|
|
|
+ path = mNewPhotoUri.getPath();
|
|
|
+// path = CameraUtil.getImagePathFromUri(ct, mNewPhotoUri);
|
|
|
+ if (StringUtil.isEmpty(path)) return;
|
|
|
+
|
|
|
+ mLicenseFile = ImageUtil.compressBitmapToFile(path, 100, 300, 300);
|
|
|
+ if (StringUtil.isEmpty(path)) return;
|
|
|
+ ImageLoader.getInstance().displayImage(Uri.fromFile(mLicenseFile).toString(), mEnterpriseLicenseIv);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_take_picture_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*else if (requestCode == REQUEST_CODE_PICK_PHOTO) {// 选择一张图片,然后立即调用裁减
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (data != null && data.getData() != null) {
|
|
|
+ String path = CameraUtil.getImagePathFromUri(this, data.getData());
|
|
|
+ Uri o = Uri.fromFile(new File(path));
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ mCurrentFile = new File(mNewPhotoUri.getPath());
|
|
|
+ CameraUtil.cropImage(this, o, mNewPhotoUri, REQUEST_CODE_CROP_PHOTO, 1, 1, 300, 300);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ else if (requestCode == REQUEST_CODE_PICK_PHOTO) {
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (data != null && data.getData() != null) {
|
|
|
+ path = CameraUtil.getImagePathFromUri(ct, data.getData());
|
|
|
+ LogUtil.i("path=" + path);
|
|
|
+ if (StringUtil.isEmpty(path)) return;
|
|
|
+
|
|
|
+ mLicenseFile = ImageUtil.compressBitmapToFile(path, 100, 300, 300);
|
|
|
+ if (StringUtil.isEmpty(path)) return;
|
|
|
+ ImageLoader.getInstance().displayImage(Uri.fromFile(mLicenseFile).toString(), mEnterpriseLicenseIv);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|