Java tutorial
package com.minsheng.app.xunchedai.loan.activities; import android.content.Intent; import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.util.Log; import android.view.MotionEvent; import android.view.View; 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 com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.lidroid.xutils.DbUtils; import com.lidroid.xutils.HttpUtils; import com.lidroid.xutils.ViewUtils; import com.lidroid.xutils.exception.HttpException; import com.lidroid.xutils.http.RequestParams; import com.lidroid.xutils.http.ResponseInfo; import com.lidroid.xutils.http.callback.RequestCallBack; import com.lidroid.xutils.http.client.HttpRequest; import com.lidroid.xutils.view.annotation.ViewInject; import com.minsheng.app.xunchedai.R; import com.minsheng.app.xunchedai.base.BaseActivity; import com.minsheng.app.xunchedai.base.whell.TimePopupWindow; import com.minsheng.app.xunchedai.home.bean.Scheme; import com.minsheng.app.xunchedai.loan.adapters.SchemeAdapter; import com.minsheng.app.xunchedai.loan.bean.Loan; import com.minsheng.app.xunchedai.utils.APIUtils; import com.minsheng.app.xunchedai.utils.CheckFormatUtils; import com.minsheng.app.xunchedai.utils.DBManager; import com.minsheng.app.xunchedai.utils.DateUtils; import com.minsheng.app.xunchedai.utils.LoanUtils; import com.minsheng.app.xunchedai.utils.PopupWindowUtils; import com.minsheng.app.xunchedai.utils.PreferenceUtils; import com.minsheng.app.xunchedai.utils.T; import com.minsheng.app.xunchedai.utils.WebServiceUrl; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * Created by Administrator on 2016/8/5. * //? */ public class AddLoanActivity extends BaseActivity implements View.OnClickListener, AdapterView.OnItemClickListener { public static final int STATE_NEW = -1; // -1 = public static final int STATE_WAITING = 0; // 0= public static final int STATE_PASSED = 1; // 1= public static final int STATE_REBUT = 2; // 2= public static final int STATE_REJECT = 3; // 3=? public static final int STATE_PAID = 4; // 4=? public static final int STATE_BACK = 5; // 5=? public static final int STATE_OVERDUE = 6; // 6=? public static final int STATE_HANDLED = 7; // 7=? @ViewInject(R.id.activity_concat_back) private ImageView iv_back; @ViewInject(R.id.tv_activity_concat_title) private TextView tv_title; @ViewInject(R.id.comment_sure) private TextView tv_save; @ViewInject(R.id.add_warranty) private LinearLayout ll_add_warranty; @ViewInject(R.id.add_invoice) private LinearLayout ll_add_invoice; @ViewInject(R.id.add_care_card) private LinearLayout ll_add_care_card; @ViewInject(R.id.add_idcard1) private LinearLayout ll_add_idcard1; @ViewInject(R.id.add_idcard2) private LinearLayout ll_add_idcard2; @ViewInject(R.id.add_bankcard1) private LinearLayout ll_add_bankcard1; @ViewInject(R.id.add_bankcard2) private LinearLayout ll_add_bankcard2; @ViewInject(R.id.add_agreement_entrust) private LinearLayout ll_add_agreement_entrust; @ViewInject(R.id.add_agreement_transfer) private LinearLayout ll_add_agreement_transfer; @ViewInject(R.id.add_license) private LinearLayout ll_add_license; @ViewInject(R.id.add_agreement_apply) private LinearLayout ll_add_agreement_apply; @ViewInject(R.id.upload_warranty) private TextView tv_upload_warranty; @ViewInject(R.id.upload_invoice) private TextView tv_upload_invoice; @ViewInject(R.id.upload_care_card) private TextView tv_upload_care_card; @ViewInject(R.id.upload_idcard1) private TextView tv_upload_idcard1; @ViewInject(R.id.upload_idcard2) private TextView tv_upload_idcard2; @ViewInject(R.id.upload_bankcard1) private TextView tv_upload_bankcard1; @ViewInject(R.id.upload_bankcard2) private TextView tv_upload_bankcard2; @ViewInject(R.id.upload_license) private TextView tv_upload_license; @ViewInject(R.id.upload_agreement_apply) private TextView tv_upload_agreement_apply; @ViewInject(R.id.upload_agreement_entrust) private TextView tv_upload_agreement_entrust; @ViewInject(R.id.upload_agreement_transfer) private TextView tv_upload_agreement_transfer; @ViewInject(R.id.apply_name) private EditText et_apply_name; @ViewInject(R.id.apply_phone) private EditText et_apply_phone; @ViewInject(R.id.iv_update_logo) private ImageView iv_update_logo; @ViewInject(R.id.tv_update_txt) private TextView tv_update_txt; @ViewInject(R.id.insurance_amount) private EditText et_insurance_amount; @ViewInject(R.id.rl_date) private RelativeLayout rl_date; @ViewInject(R.id.select_installment) private RelativeLayout rl_select_installment; @ViewInject(R.id.select_loan_object) private RelativeLayout rl_select_loan_object; @ViewInject(R.id.parent) private LinearLayout ll_parent; @ViewInject(R.id.protection_date) private TextView tv_protection_date; @ViewInject(R.id.installment) private TextView tv_installment; @ViewInject(R.id.loan_amount) private TextView tv_loan_amount; @ViewInject(R.id.loan_object) private TextView tv_loan_object; private HttpUtils httpUtils; private String loan_id; private Loan loan; private String str_name, str_phone, str_warranty, str_idcard1, str_idcard2, str_bankcard1, str_bankcard2, str_license, str_agreement_apply, str_agreement_entrust, str_agreement_transfer, str_insurance_amount, str_protection_date, str_installment, str_loan_amount, str_loan_object, str_invoice, str_care_card, str_reason; private SimpleDateFormat format; private boolean is_new, is_from_index, is_draft; private int state; private List<Scheme> list_scheme; private PopupWindow popupWindow; private SchemeAdapter adapter; private TimePopupWindow pwTime; private Intent intent_before; private DbUtils db; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_loan); ViewUtils.inject(this); initView(); } /** * ? */ private void initView() { httpUtils = new HttpUtils(); loan = new Loan(); db = DBManager.dbUtils(this); pwTime = new TimePopupWindow(this, TimePopupWindow.Type.YEAR_MONTH_DAY, this); format = new SimpleDateFormat("yyyy-MM-dd"); format.setLenient(false); list_scheme = new ArrayList<>(); intent_before = getIntent(); loan_id = intent_before.getStringExtra("loan_id"); str_installment = intent_before.getStringExtra("installment"); //loan_id, is_new = TextUtils.isEmpty(loan_id); //?? is_from_index = !TextUtils.isEmpty(str_installment); //???? is_draft = intent_before.getBooleanExtra("is_draft", false); showView(); iv_back.setVisibility(View.VISIBLE); ll_add_warranty.setOnClickListener(this); ll_add_invoice.setOnClickListener(this); ll_add_care_card.setOnClickListener(this); ll_add_idcard1.setOnClickListener(this); ll_add_idcard2.setOnClickListener(this); ll_add_bankcard1.setOnClickListener(this); ll_add_bankcard2.setOnClickListener(this); ll_add_license.setOnClickListener(this); ll_add_agreement_apply.setOnClickListener(this); ll_add_agreement_entrust.setOnClickListener(this); ll_add_agreement_transfer.setOnClickListener(this); tv_save.setOnClickListener(this); //et_insurance_amount ll_parent.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { ll_parent.setFocusable(true); ll_parent.setFocusableInTouchMode(true); ll_parent.requestFocus(); return false; } }); //???? et_insurance_amount.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { countLoanMount(); } } }); //???? tv_protection_date.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { countLoanMount(); } }); //? pwTime.setOnTimeSelectListener(new TimePopupWindow.OnTimeSelectListener() { @Override public void onTimeSelect(Date date) { tv_protection_date.setText(getTime(date)); tv_protection_date.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); } }); } //? public static String getTime(Date date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); return format.format(date); } /** * */ public void showView() { if (is_new) { tv_title.setText(""); tv_save.setText("??"); tv_save.setVisibility(View.VISIBLE); iv_update_logo.setImageResource(R.mipmap.seal_new); tv_update_txt.setText("?"); setFilesTip(""); APIUtils.getScheme(this); rl_select_installment.setOnClickListener(this); rl_date.setOnClickListener(this); rl_select_loan_object.setOnClickListener(this); state = STATE_NEW; if (is_from_index) { str_loan_amount = intent_before.getStringExtra("loan"); str_protection_date = intent_before.getStringExtra("date"); str_insurance_amount = intent_before.getStringExtra("insurance"); et_insurance_amount.setText(str_insurance_amount); tv_protection_date.setText(str_protection_date); tv_protection_date.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); tv_installment.setText(str_installment); tv_installment.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); tv_loan_amount.setText("?? " + str_loan_amount); } else if (is_draft) { showDraft(); } } else { tv_title.setText(""); setFilesTip(""); queryDetail(); } } //? public void queryDetail() { RequestParams params = new RequestParams(); params.addBodyParameter("id", loan_id); httpUtils.send(HttpRequest.HttpMethod.POST, WebServiceUrl.WEBSERVICE_URL + WebServiceUrl.LOAN_DETAIL_URL, params, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String json = responseInfo.result; Log.i("123", "json:" + json); JSONObject obj = JSON.parseObject(json); loan = JSON.parseObject(obj.toJSONString(), Loan.class); state = loan.getState(); str_phone = loan.getPhone(); str_name = loan.getName(); str_insurance_amount = loan.getInsurance_amount(); str_protection_date = loan.getProtection_date(); str_installment = loan.getInstallment(); str_loan_amount = loan.getLoan_amount(); str_loan_object = loan.getLoan_object(); et_apply_phone.setText(str_phone); et_apply_name.setText(str_name); et_insurance_amount.setText(str_insurance_amount); tv_protection_date.setText(str_protection_date); tv_installment.setText(str_installment); tv_loan_object.setText(loanObjectString(str_loan_object)); tv_loan_amount.setText("?? " + str_loan_amount); str_warranty = loan.getWarranty(); str_invoice = loan.getInvoice(); str_care_card = loan.getCare_card(); str_idcard1 = loan.getIdcard1(); str_idcard2 = loan.getIdcard2(); str_bankcard1 = loan.getBankcard1(); str_bankcard2 = loan.getBankcard2(); str_license = loan.getLicense(); str_agreement_apply = loan.getAgreement_apply(); str_agreement_entrust = loan.getAgreement_entrust(); str_agreement_transfer = loan.getAgreement_transfer(); str_reason = loan.getReason(); showState(); } @Override public void onFailure(HttpException e, String s) { T.show(AddLoanActivity.this, "?" + s); } }); } /** * ??? */ public String loanObjectString(String str) { String re; switch (str) { case "0": re = ""; break; case "1": re = ""; break; case "": re = "0"; break; case "": re = "1"; break; default: re = ""; break; } return re; } /** * ?loan??? * */ public void showState() { int img_seal; String title; boolean editable = false; switch (state) { case STATE_WAITING: img_seal = R.mipmap.seal_waiting; title = "???"; break; case STATE_PASSED: img_seal = R.mipmap.seal_passed; title = "??"; break; case STATE_REBUT: img_seal = R.mipmap.seal_rebut; title = "??" + str_reason; tv_save.setText("??"); tv_save.setVisibility(View.VISIBLE); setFilesTip(""); APIUtils.getScheme(this); rl_select_installment.setOnClickListener(this); rl_date.setOnClickListener(this); rl_select_loan_object.setOnClickListener(this); editable = true; break; case STATE_REJECT: img_seal = R.mipmap.seal_reject; title = "??" + str_reason; break; case STATE_PAID: img_seal = R.mipmap.seal_paid; title = ""; break; case STATE_BACK: img_seal = R.mipmap.seal_back; title = ""; break; case STATE_OVERDUE: img_seal = R.mipmap.seal_overdue; title = "???"; break; case STATE_HANDLED: img_seal = R.mipmap.seal_handled; title = "?"; break; default: img_seal = R.mipmap.seal_handled; title = ""; break; } iv_update_logo.setImageResource(img_seal); tv_update_txt.setText(title); et_apply_name.setEnabled(editable); et_apply_phone.setEnabled(editable); et_insurance_amount.setEnabled(editable); } //?? public void showDraft() { loan = (Loan) intent_before.getSerializableExtra("loan"); if (!TextUtils.isEmpty(loan.getName())) { str_name = loan.getName(); et_apply_name.setText(str_name); } if (!TextUtils.isEmpty(loan.getPhone())) { str_phone = loan.getPhone(); et_apply_phone.setText(str_phone); } if (!TextUtils.isEmpty(loan.getInsurance_amount())) { str_insurance_amount = loan.getInsurance_amount(); et_insurance_amount.setText(str_insurance_amount); } if (!TextUtils.isEmpty(loan.getProtection_date())) { str_protection_date = loan.getProtection_date(); tv_protection_date.setText(str_protection_date); tv_protection_date.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); } if (!TextUtils.isEmpty(loan.getInstallment())) { str_installment = loan.getInstallment(); tv_installment.setText(str_installment); tv_installment.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); } if (!TextUtils.isEmpty(loan.getLoan_object())) { str_loan_object = loan.getLoan_object(); tv_loan_object.setText(loanObjectString(str_loan_object)); tv_loan_object.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); } if (!TextUtils.isEmpty(loan.getLoan_amount())) { str_loan_amount = loan.getLoan_amount(); tv_loan_amount.setText("?? " + str_loan_amount); } if (!TextUtils.isEmpty(loan.getWarranty())) { tv_upload_warranty.setText(""); tv_upload_warranty.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_warranty = loan.getWarranty(); } if (!TextUtils.isEmpty(loan.getInvoice())) { tv_upload_invoice.setText(""); tv_upload_invoice.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_invoice = loan.getInvoice(); } if (!TextUtils.isEmpty(loan.getCare_card())) { tv_upload_care_card.setText(""); tv_upload_care_card.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_care_card = loan.getCare_card(); } if (!TextUtils.isEmpty(loan.getIdcard1())) { tv_upload_idcard1.setText(""); tv_upload_idcard1.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_idcard1 = loan.getIdcard1(); } if (!TextUtils.isEmpty(loan.getIdcard2())) { tv_upload_idcard2.setText(""); tv_upload_idcard2.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_idcard2 = loan.getIdcard2(); } if (!TextUtils.isEmpty(loan.getBankcard1())) { tv_upload_bankcard1.setText(""); tv_upload_bankcard1.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_bankcard1 = loan.getBankcard1(); } if (!TextUtils.isEmpty(loan.getBankcard2())) { tv_upload_bankcard2.setText(""); tv_upload_bankcard2.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_bankcard2 = loan.getBankcard2(); } if (!TextUtils.isEmpty(loan.getLicense())) { tv_upload_license.setText(""); tv_upload_license.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_license = loan.getLicense(); } if (!TextUtils.isEmpty(loan.getAgreement_apply())) { tv_upload_agreement_apply.setText(""); tv_upload_agreement_apply.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_agreement_apply = loan.getAgreement_apply(); } if (!TextUtils.isEmpty(loan.getAgreement_entrust())) { tv_upload_agreement_entrust.setText(""); tv_upload_agreement_entrust.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_agreement_entrust = loan.getAgreement_entrust(); } if (!TextUtils.isEmpty(loan.getAgreement_transfer())) { tv_upload_agreement_transfer.setText(""); tv_upload_agreement_transfer.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_agreement_transfer = loan.getAgreement_apply(); } } /* * ??? */ public void setFilesTip(String tip) { tv_upload_warranty.setText(tip); tv_upload_invoice.setText(tip); tv_upload_care_card.setText(tip); tv_upload_idcard1.setText(tip); tv_upload_idcard2.setText(tip); tv_upload_bankcard1.setText(tip); tv_upload_bankcard2.setText(tip); tv_upload_license.setText(tip); tv_upload_agreement_apply.setText(tip); tv_upload_agreement_entrust.setText(tip); tv_upload_agreement_transfer.setText(tip); } /* * ?PopupWindowScheme */ protected void initPopupWindowScheme(View v) { popupWindow = PopupWindowUtils.newPop(this, R.layout.pop_add_loan_activity_scheme, v); adapter = new SchemeAdapter(list_scheme, this); ListView lv_scheme = (ListView) popupWindow.getContentView().findViewById(R.id.scheme_list); TextView tv_cancel = (TextView) popupWindow.getContentView().findViewById(R.id.cancel); lv_scheme.setAdapter(adapter); lv_scheme.setOnItemClickListener(this); tv_cancel.setOnClickListener(this); } /** * ??? */ public void initPopupWindowSubmit(View v) { popupWindow = PopupWindowUtils.newPop(this, R.layout.pop_add_loan_activity_submit, v); TextView tv_submit = (TextView) popupWindow.getContentView().findViewById(R.id.submit); TextView tv_cancel = (TextView) popupWindow.getContentView().findViewById(R.id.cancel); tv_submit.setOnClickListener(this); tv_cancel.setOnClickListener(this); } /* * ??? */ public void initPopupWindowDraft(View v) { popupWindow = PopupWindowUtils.newPop(this, R.layout.pop_add_loan_activity_draft, v); TextView tv_save_draft = (TextView) popupWindow.getContentView().findViewById(R.id.save_draft); TextView tv_save_no = (TextView) popupWindow.getContentView().findViewById(R.id.save_no); TextView tv_cancel = (TextView) popupWindow.getContentView().findViewById(R.id.cancel); if (is_draft) { tv_save_draft.setText("?"); } tv_save_draft.setOnClickListener(this); tv_save_no.setOnClickListener(this); tv_cancel.setOnClickListener(this); } /** * ?? */ public void initPopupWindowObject(View v) { popupWindow = PopupWindowUtils.newPop(this, R.layout.pop_add_loan_activity_object, v); TextView tv_borrower = (TextView) popupWindow.getContentView().findViewById(R.id.borrower); TextView tv_salesman = (TextView) popupWindow.getContentView().findViewById(R.id.salesman); TextView tv_cancel = (TextView) popupWindow.getContentView().findViewById(R.id.cancel); tv_borrower.setOnClickListener(this); tv_salesman.setOnClickListener(this); tv_cancel.setOnClickListener(this); } /** * ??? */ public boolean checkMount() { str_insurance_amount = et_insurance_amount.getText().toString(); if (TextUtils.isEmpty(str_insurance_amount)) { return false; } else { Double amount = Double.parseDouble(str_insurance_amount); if (amount > 0) { str_insurance_amount = String.format("%.2f", amount); et_insurance_amount.setText(str_insurance_amount); return true; } else { et_insurance_amount.setText(""); T.show(this, "?"); return false; } } } /** * ??? */ public boolean checkDate() { str_protection_date = tv_protection_date.getText().toString(); if (TextUtils.isEmpty(str_protection_date) || str_protection_date.equals("???")) { return false; } return true; } /** * ?? */ public void countLoanMount() { if (checkDate() && checkMount()) { str_loan_amount = LoanUtils.count(str_insurance_amount, str_protection_date); tv_loan_amount.setText("?? " + str_loan_amount); } } /** * ? */ public Boolean checkData() { str_name = et_apply_name.getText().toString(); if (TextUtils.isEmpty(str_name)) { T.show(this, "???"); return false; } str_phone = et_apply_phone.getText().toString(); if (TextUtils.isEmpty(str_phone)) { T.show(this, "?"); return false; } else { if (!CheckFormatUtils.check(CheckFormatUtils.PHONE, str_phone)) { T.show(this, "????"); return false; } } str_insurance_amount = et_insurance_amount.getText().toString(); if (TextUtils.isEmpty(str_insurance_amount)) { T.show(this, "??"); return false; } str_protection_date = tv_protection_date.getText().toString(); if (TextUtils.isEmpty(str_protection_date) || str_protection_date.equals("???")) { T.show(this, "??"); return false; } str_installment = tv_installment.getText().toString(); if (TextUtils.isEmpty(str_installment)) { T.show(this, "?"); return false; } if (TextUtils.isEmpty(str_warranty)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_invoice)) { T.show(this, "??"); return false; } if (TextUtils.isEmpty(str_care_card)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_idcard1)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_idcard2)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_bankcard1)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_bankcard2)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_license)) { T.show(this, "??"); return false; } if (TextUtils.isEmpty(str_agreement_apply)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_agreement_entrust)) { T.show(this, "???"); return false; } if (TextUtils.isEmpty(str_agreement_transfer)) { T.show(this, "???"); return false; } return true; } //??? public void saveLoan(DbUtils db) { loan.setPhone(str_phone); loan.setWarranty(str_warranty); loan.setInvoice(str_invoice); loan.setCare_card(str_care_card); loan.setBankcard1(str_bankcard1); loan.setBankcard2(str_bankcard2); loan.setIdcard1(str_idcard1); loan.setIdcard2(str_idcard2); loan.setAgreement_apply(str_agreement_apply); loan.setAgreement_entrust(str_agreement_entrust); loan.setAgreement_transfer(str_agreement_transfer); loan.setLicense(str_license); loan.setName(str_name); loan.setLoan_amount(str_loan_amount); loan.setInsurance_amount(str_insurance_amount); loan.setEdit_date(DateUtils.formatPhotoDate(System.currentTimeMillis())); if ("???".equals(str_protection_date)) { str_protection_date = ""; } loan.setProtection_date(str_protection_date); if ("".equals(str_installment)) { str_installment = ""; } loan.setInstallment(str_installment); if ("".equals(str_loan_object)) { str_loan_object = ""; } loan.setLoan_object(str_loan_object); DBManager.saveLoan(db, loan); } /** * */ public void addApply() { RequestParams params = new RequestParams(); params.addBodyParameter("staffid", PreferenceUtils.loadUser(this, PreferenceUtils.STAFFID)); params.addBodyParameter("name", str_name); params.addBodyParameter("phone", str_phone); params.addBodyParameter("installment", str_installment); params.addBodyParameter("insurance_amount", str_insurance_amount); params.addBodyParameter("protection_date", str_protection_date); params.addBodyParameter("loan_amount", str_loan_amount); params.addBodyParameter("loan_object", str_loan_object); params.addBodyParameter("warranty", str_warranty); params.addBodyParameter("invoice", str_invoice); params.addBodyParameter("care_card", str_care_card); params.addBodyParameter("idcard1", str_idcard1); params.addBodyParameter("idcard2", str_idcard2); params.addBodyParameter("bankcard1", str_bankcard1); params.addBodyParameter("bankcard2", str_bankcard2); params.addBodyParameter("license", str_license); params.addBodyParameter("agreement_apply", str_agreement_apply); params.addBodyParameter("agreement_entrust", str_agreement_entrust); params.addBodyParameter("agreement_transfer", str_agreement_transfer); httpUtils.send(HttpRequest.HttpMethod.POST, WebServiceUrl.WEBSERVICE_URL + WebServiceUrl.ADD_LOAN_URL, params, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String json = responseInfo.result; Log.i("123", "json:" + json); int result = -1; JSONObject obj = JSON.parseObject(json); result = obj.getInteger("result"); String message = obj.getString("message"); if (result == 1) { //????? if (is_draft) { DBManager.deleteLoan(db, loan); } T.show(AddLoanActivity.this, "???"); finish(); } else { // T.show(AddLoanActivity.this, message); } } @Override public void onFailure(HttpException e, String s) { T.show(AddLoanActivity.this, "?" + s); } }); } /** * ?????? */ public boolean isDraft() { str_name = et_apply_name.getText().toString(); str_phone = et_apply_phone.getText().toString(); str_insurance_amount = et_insurance_amount.getText().toString(); str_protection_date = tv_protection_date.getText().toString(); str_installment = tv_installment.getText().toString(); str_loan_object = tv_loan_object.getText().toString(); if (TextUtils.isEmpty(str_name) && TextUtils.isEmpty(str_phone) && TextUtils.isEmpty(str_insurance_amount) && TextUtils.isEmpty(str_loan_amount) && "???".equals(str_protection_date) && "".equals(str_installment) && "".equals(str_loan_object) && TextUtils.isEmpty(str_warranty) && TextUtils.isEmpty(str_invoice) && TextUtils.isEmpty(str_care_card) && TextUtils.isEmpty(str_idcard1) && TextUtils.isEmpty(str_idcard2) && TextUtils.isEmpty(str_bankcard1) && TextUtils.isEmpty(str_bankcard2) && TextUtils.isEmpty(str_license) && TextUtils.isEmpty(str_agreement_apply) && TextUtils.isEmpty(str_agreement_entrust) && TextUtils.isEmpty(str_agreement_transfer)) { return false; } else { return true; } } @Override public void onClick(View v) { Intent intent = new Intent(this, UploadActivity.class); Bundle bundle = new Bundle(); bundle.putInt("state", state); switch (v.getId()) { case R.id.add_warranty: bundle.putInt("file", UploadActivity.FILE_WARRANTY); bundle.putString("imgUrl", str_warranty); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_WARRANTY); break; case R.id.add_invoice: bundle.putInt("file", UploadActivity.FILE_INVOICE); bundle.putString("imgUrl", str_invoice); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_INVOICE); break; case R.id.add_care_card: bundle.putInt("file", UploadActivity.FILE_CARE_CARD); bundle.putString("imgUrl", str_care_card); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_CARE_CARD); break; case R.id.add_idcard1: bundle.putInt("file", UploadActivity.FILE_IDCARD1); bundle.putString("imgUrl", str_idcard1); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_IDCARD1); break; case R.id.add_idcard2: bundle.putInt("file", UploadActivity.FILE_IDCARD2); bundle.putString("imgUrl", str_idcard2); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_IDCARD2); break; case R.id.add_bankcard1: bundle.putInt("file", UploadActivity.FILE_BANKCARD1); bundle.putString("imgUrl", str_bankcard1); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_BANKCARD1); break; case R.id.add_bankcard2: bundle.putInt("file", UploadActivity.FILE_BANKCARD2); bundle.putString("imgUrl", str_bankcard2); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_BANKCARD2); break; case R.id.add_license: bundle.putInt("file", UploadActivity.FILE_LICENSE); if (!TextUtils.isEmpty(str_license)) { bundle.putString("imgUrl", str_license); } intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_LICENSE); break; case R.id.add_agreement_apply: bundle.putInt("file", UploadActivity.FILE_AGREEMENT_APPLY); bundle.putString("imgUrl", str_agreement_apply); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_AGREEMENT_APPLY); break; case R.id.add_agreement_entrust: bundle.putInt("file", UploadActivity.FILE_AGREEMENT_ENTRUST); bundle.putString("imgUrl", str_agreement_entrust); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_AGREEMENT_ENTRUST); break; case R.id.add_agreement_transfer: bundle.putInt("file", UploadActivity.FILE_AGREEMENT_TRANSFER); bundle.putString("imgUrl", str_agreement_transfer); intent.putExtras(bundle); startActivityForResult(intent, UploadActivity.FILE_AGREEMENT_TRANSFER); break; case R.id.comment_sure: if (checkData()) { initPopupWindowSubmit(v); } break; case R.id.select_installment: list_scheme = APIUtils.list_scheme; if (list_scheme.size() > 0) { initPopupWindowScheme(v); } break; case R.id.select_loan_object: initPopupWindowObject(v); break; case R.id.cancel: PopupWindowUtils.destroy(popupWindow); break; case R.id.submit: addApply(); PopupWindowUtils.destroy(popupWindow); break; case R.id.save_draft: saveLoan(db); finish(); PopupWindowUtils.destroy(popupWindow); break; case R.id.save_no: finish(); PopupWindowUtils.destroy(popupWindow); break; case R.id.borrower: str_loan_object = "0"; tv_loan_object.setText(loanObjectString(str_loan_object)); tv_loan_object.setTextColor(ContextCompat.getColor(this, R.color.gray_3)); PopupWindowUtils.destroy(popupWindow); break; case R.id.salesman: str_loan_object = "1"; tv_loan_object.setText(loanObjectString(str_loan_object)); tv_loan_object.setTextColor(ContextCompat.getColor(this, R.color.gray_3)); PopupWindowUtils.destroy(popupWindow); break; case R.id.rl_date: pwTime.showAtLocation(this, v, new Date()); break; default: break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // ?????? if (resultCode == RESULT_OK) { switch (requestCode) { case UploadActivity.FILE_WARRANTY: tv_upload_warranty.setText(""); tv_upload_warranty.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_warranty = data.getStringExtra("path"); break; case UploadActivity.FILE_INVOICE: tv_upload_invoice.setText(""); tv_upload_invoice.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_invoice = data.getStringExtra("path"); break; case UploadActivity.FILE_CARE_CARD: tv_upload_care_card.setText(""); tv_upload_care_card.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_care_card = data.getStringExtra("path"); break; case UploadActivity.FILE_IDCARD1: tv_upload_idcard1.setText(""); tv_upload_idcard1.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_idcard1 = data.getStringExtra("path"); break; case UploadActivity.FILE_IDCARD2: tv_upload_idcard2.setText(""); tv_upload_idcard2.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_idcard2 = data.getStringExtra("path"); break; case UploadActivity.FILE_BANKCARD1: tv_upload_bankcard1.setText(""); tv_upload_bankcard1.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_bankcard1 = data.getStringExtra("path"); break; case UploadActivity.FILE_BANKCARD2: tv_upload_bankcard2.setText(""); tv_upload_bankcard2.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_bankcard2 = data.getStringExtra("path"); break; case UploadActivity.FILE_LICENSE: tv_upload_license.setText(""); tv_upload_license.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_license = data.getStringExtra("path"); break; case UploadActivity.FILE_AGREEMENT_APPLY: tv_upload_agreement_apply.setText(""); tv_upload_agreement_apply.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_agreement_apply = data.getStringExtra("path"); break; case UploadActivity.FILE_AGREEMENT_ENTRUST: tv_upload_agreement_entrust.setText(""); tv_upload_agreement_entrust.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_agreement_entrust = data.getStringExtra("path"); break; case UploadActivity.FILE_AGREEMENT_TRANSFER: tv_upload_agreement_transfer.setText(""); tv_upload_agreement_transfer.setTextColor(ContextCompat.getColor(this, R.color.qing)); str_agreement_transfer = data.getStringExtra("path"); break; default: break; } } } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //?? Scheme scheme = list_scheme.get(position); str_installment = String.valueOf(scheme.getInstallment()); tv_installment.setText(str_installment); tv_installment.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); PopupWindowUtils.destroy(popupWindow); } @Override public void btnClick(View v) { if (is_new && isDraft()) { initPopupWindowDraft(v); } else { finish(); } } @Override public void onBackPressed() { if (is_new && isDraft()) { initPopupWindowDraft(tv_installment); } else { finish(); } } }