Java tutorial
package com.df.dfcarchecker.CarCheck; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.support.v4.app.Fragment; import android.text.Editable; import android.text.InputFilter; import android.text.Spanned; import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.Toast; import com.df.dfcarchecker.LoginActivity; import com.df.dfcarchecker.MainActivity; import com.df.dfcarchecker.R; import com.df.entry.Brand; import com.df.entry.CarSettings; import com.df.entry.Country; import com.df.entry.Model; import com.df.entry.Manufacturer; import com.df.entry.PhotoEntity; import com.df.entry.Series; import com.df.entry.VehicleModel; import com.df.service.Common; import com.df.service.EncryptDecryptFile; import com.df.service.Helper; import com.df.service.SoapService; import com.df.service.VehicleModelParser; import com.df.service.XmlHandler; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Random; import java.util.UUID; import static com.df.service.Helper.SetSpinnerData; import static com.df.service.Helper.enableView; import static com.df.service.Helper.getDateString; import static com.df.service.Helper.getEditText; import static com.df.service.Helper.getSpinnerSelectedIndex; import static com.df.service.Helper.getSpinnerSelectedText; import static com.df.service.Helper.setEditText; import static com.df.service.Helper.setEditWeight; import static com.df.service.Helper.setSpinnerSelectionWithString; import static com.df.service.Helper.showView; public class CarCheckBasicInfoFragment extends Fragment implements View.OnClickListener { private static View rootView; private LayoutInflater inflater; // TableLayout private TableLayout tableLayout; private LinearLayout contentLayout; // ??spinner private Spinner countrySpinner; private Spinner brandSpinner; private Spinner manufacturerSpinner; private Spinner seriesSpinner; private Spinner modelSpinner; private int lastCountryIndex = 0; private int lastBrandIndex = 0; private int lastManufacturerIndex = 0; private int lastSeriesIndex = 0; private int lastModelIndex = 0; // ???view private Button brandOkButton; private Button brandSelectButton; private EditText vin_edit; private EditText brandEdit; private EditText displacementEdit; private EditText carNumberEdit; private Spinner transmissionSpinner; private EditText transmissionEdit; private EditText runEdit; private Spinner firstLogYearSpinner; private Spinner manufactureYearSpinner; private Spinner ticketSpinner; private Spinner lastTransferCountSpinner; private Spinner compulsoryInsuranceSpinner; private Spinner businessInsuranceSpinner; private EditText licencePhotoMatchEdit; private TableRow portedProcedureRow; public static CarSettings mCarSettings; private FileInputStream fis = null; private VehicleModel vehicleModel = null; // ?? private boolean isPorted; // ? private boolean match; // soapservice private SoapService soapService; // ??? private GetCarSettingsTask mGetCarSettingsTask = null; // public static String uniqueId; // ?? private String result; // ? private ProgressDialog mProgressDialog; // ?? public static List<PhotoEntity> sketchPhotoEntities; // private String jsonData = ""; private boolean modifyMode = false; private JSONObject procedures; private JSONObject options; // ViewPagerActivity OnHeadlineSelectedListener mCallback; // public CarCheckBasicInfoFragment(String jsonData) { this.jsonData = jsonData; } // ViewPager public interface OnHeadlineSelectedListener { public void onUpdateIntegratedUi(); } @Override public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (OnHeadlineSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnHeadlineSelectedListener"); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Random r=new Random(); // int uniqueNumber =(r.nextInt(999) + 100); // uniqueId = Integer.toString(uniqueNumber); // ?uniqueId UUID uuid = UUID.randomUUID(); uniqueId = uuid.toString(); this.inflater = inflater; rootView = inflater.inflate(R.layout.fragment_car_check_basic_info, container, false); // <editor-fold defaultstate="collapsed" desc="??View?"> tableLayout = (TableLayout) rootView.findViewById(R.id.bi_content_table); contentLayout = (LinearLayout) rootView.findViewById(R.id.brand_input); Button vinButton = (Button) rootView.findViewById(R.id.bi_vin_button); vinButton.setOnClickListener(this); brandOkButton = (Button) rootView.findViewById(R.id.bi_brand_ok_button); brandOkButton.setEnabled(false); brandOkButton.setOnClickListener(this); brandSelectButton = (Button) rootView.findViewById(R.id.bi_brand_select_button); brandSelectButton.setEnabled(false); brandSelectButton.setOnClickListener(this); // ?? sketchPhotoEntities = new ArrayList<PhotoEntity>(); // Button matchButton = (Button) rootView.findViewById(R.id.ct_licencePhotoMatch_button); matchButton.setOnClickListener(this); // vin??? InputFilter alphaNumericFilter = new InputFilter() { @Override public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) { for (int k = arg1; k < arg2; k++) { if (!Character.isLetterOrDigit(arg0.charAt(k))) { return ""; } } return null; } }; vin_edit = (EditText) rootView.findViewById(R.id.bi_vin_edit); vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps() }); brandEdit = (EditText) rootView.findViewById(R.id.bi_brand_edit); displacementEdit = (EditText) rootView.findViewById(R.id.csi_displacement_edit); transmissionEdit = (EditText) rootView.findViewById(R.id.csi_transmission_edit); runEdit = (EditText) rootView.findViewById(R.id.bi_mileage_edit); // // transmissionSpinner = (Spinner)rootView.findViewById(R.id.csi_transmission_spinner); // transmissionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { // @Override // public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // transmissionEdit.setText(adapterView.getSelectedItem().toString()); // } // // @Override // public void onNothingSelected(AdapterView<?> adapterView) { // // } // }); // ?????? ScrollView view = (ScrollView) rootView.findViewById(R.id.root); view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.requestFocusFromTouch(); return false; } }); // ????????2? runEdit.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable edt) { String temp = edt.toString(); if (temp.contains(".")) { int posDot = temp.indexOf("."); if (posDot <= 0) return; if (temp.length() - posDot - 1 > 2) { edt.delete(posDot + 3, posDot + 4); } } else { if (temp.length() > 2) { edt.clear(); edt.append(temp.substring(0, 2)); } } } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); licencePhotoMatchEdit = (EditText) rootView.findViewById(R.id.ct_licencePhotoMatch_edit); licencePhotoMatchEdit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { licencePhotoMatchEdit.setError(null); } @Override public void afterTextChanged(Editable editable) { licencePhotoMatchEdit.setError(null); } }); // ?? carNumberEdit = (EditText) rootView.findViewById(R.id.ci_plateNumber_edit); carNumberEdit.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) }); // ? portedProcedureRow = (TableRow) rootView.findViewById(R.id.ct_ported_procedure); // ?Spinner setRegLocationSpinner(); setCarColorSpinner(); setFirstLogTimeSpinner(); setManufactureTimeSpinner(); setTransferCountSpinner(); setLastTransferTimeSpinner(); setYearlyCheckAvailableDateSpinner(); setAvailableDateYearSpinner(); setBusinessInsuranceAvailableDateYearSpinner(); setOtherSpinners(); // </editor-fold> mCarSettings = new CarSettings(); // ??xml if (vehicleModel == null) { mProgressDialog = ProgressDialog.show(rootView.getContext(), null, "?..", false, false); Thread thread = new Thread(new Runnable() { @Override public void run() { try { ParseXml(); // jsonData?? if (!jsonData.equals("")) { modifyMode = true; letsEnterModifyMode(); } } catch (Exception e) { e.printStackTrace(); } } }); thread.start(); } return rootView; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bi_vin_button: checkVinAndGetCarSettings(); break; case R.id.bi_brand_ok_button: showContent(); break; case R.id.ct_licencePhotoMatch_button: PictureMatch(); break; case R.id.bi_brand_select_button: selectCarManually(); break; } } // VIN?? private void checkVinAndGetCarSettings() { final String vinString = vin_edit.getText().toString(); // ? if (vinString.equals("")) { Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show(); vin_edit.requestFocus(); return; } // VIN? if (!Helper.isVin(vinString)) { AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setTitle(R.string.alert_title) .setMessage("VIN?: " + vinString + "\n" + "VIN?????\n") .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { brandEdit.setText(""); brandOkButton.setEnabled(false); brandSelectButton.setEnabled(false); // ???VIN getCarSettingsFromServer(""); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { vin_edit.requestFocus(); } }).create(); dialog.show(); return; } brandEdit.setText(""); brandOkButton.setEnabled(false); brandSelectButton.setEnabled(false); // ???VIN getCarSettingsFromServer(""); } // ??? private void getCarSettingsFromServer(String seriesId) { mGetCarSettingsTask = new GetCarSettingsTask(rootView.getContext()); mGetCarSettingsTask.execute(seriesId); } // UI private void updateUi() { // ?EditText setEditText(rootView, R.id.bi_brand_edit, mCarSettings.getBrandString()); // ?EditText setEditText(rootView, R.id.csi_displacement_edit, mCarSettings.getDisplacement()); // ?EditText transmissionEdit.setText(mCarSettings.getTransmissionText()); // ? TODO: ????? brandOkButton.setEnabled(true); brandSelectButton.setEnabled(true); // ??? portedProcedureRow.setVisibility(isPorted ? View.VISIBLE : View.GONE); // ??Spinner String carConfigs = mCarSettings.getCarConfigs(); String configArray[] = carConfigs.split(","); for (int i = 0; i < configArray.length; i++) { int selection = Integer.parseInt(configArray[i]); setSpinnerSelection(Common.carSettingsSpinnerMap[i][0], selection); } // ?? if (!mCarSettings.getFigure().equals("")) CarCheckFrameFragment.setFigureImage(Integer.parseInt(mCarSettings.getFigure())); // ??? CarCheckIntegratedFragment.setGearType(mCarSettings.getTransmissionText()); // ???? if (!jsonData.equals("")) { mCallback.onUpdateIntegratedUi(); } } // ??Spinner?Spinner? private void setSpinnerSelection(final int spinnerId, int selection) { final Spinner spinner = (Spinner) rootView.findViewById(spinnerId); spinner.setSelection(selection); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { CarCheckIntegratedFragment.updateAssociatedSpinners(spinnerId, adapterView.getSelectedItem().toString()); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); } // ?? private void showContent() { if (tableLayout.getVisibility() != View.VISIBLE) { tableLayout.setVisibility(View.VISIBLE); CarCheckIntegratedFragment.showContent(); CarCheckFrameFragment.showContent(); } } // ? private void selectCarManually() { View view = this.inflater.inflate(R.layout.dialog_vehiclemodel_select, null); countrySpinner = (Spinner) view.findViewById(R.id.country_spinner); brandSpinner = (Spinner) view.findViewById(R.id.brand_spinner); manufacturerSpinner = (Spinner) view.findViewById(R.id.production_spinner); seriesSpinner = (Spinner) view.findViewById(R.id.serial_spinner); modelSpinner = (Spinner) view.findViewById(R.id.model_spinner); AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setView(view).setTitle("") .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // // ?? if (countrySpinner.getSelectedItemPosition() > 1) { isPorted = true; } else { isPorted = false; } // ? lastCountryIndex = countrySpinner.getSelectedItemPosition(); lastBrandIndex = brandSpinner.getSelectedItemPosition(); lastManufacturerIndex = manufacturerSpinner.getSelectedItemPosition(); lastSeriesIndex = seriesSpinner.getSelectedItemPosition(); lastModelIndex = modelSpinner.getSelectedItemPosition(); // ?Spinner? if (lastCountryIndex == 0 || lastBrandIndex == 0 || lastManufacturerIndex == 0 || lastSeriesIndex == 0 || lastModelIndex == 0) { Toast.makeText(rootView.getContext(), "", Toast.LENGTH_SHORT) .show(); return; } Country country = vehicleModel.countries.get(lastCountryIndex - 1); Brand brand = country.brands.get(lastBrandIndex - 1); Manufacturer manufacturer = brand.manufacturers.get(lastManufacturerIndex - 1); Series series = manufacturer.serieses.get(lastSeriesIndex - 1); Model model = series.models.get(lastModelIndex - 1); // ?seriesIdmodelId??? getCarSettingsFromServer(series.id + "," + model.id); // String brandString = manufacturerSpinner.getSelectedItem().toString() + " " + seriesSpinner.getSelectedItem().toString() + " " + modelSpinner.getSelectedItem().toString(); // ? String displacementString = modelSpinner.getSelectedItem().toString(); if (displacementString.length() > 3) { displacementString = displacementString.substring(0, 3); } mCarSettings.setBrandString(brandString); mCarSettings.setDisplacement(displacementString); mCarSettings.setCountry(country); mCarSettings.setBrand(brand); mCarSettings.setManufacturer(manufacturer); mCarSettings.setSeries(series); mCarSettings.setModel(model); setCarSettings(model.getName()); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // ? lastCountryIndex = countrySpinner.getSelectedItemPosition(); lastBrandIndex = brandSpinner.getSelectedItemPosition(); lastManufacturerIndex = manufacturerSpinner.getSelectedItemPosition(); lastSeriesIndex = seriesSpinner.getSelectedItemPosition(); lastModelIndex = modelSpinner.getSelectedItemPosition(); } }).create(); setCountrySpinner(vehicleModel); dialog.show(); } // ?XML public void ParseXml() { try { String path = Environment.getExternalStorageDirectory().getPath() + "/.cheyipai/"; String zippedFile = path + "df001"; EncryptDecryptFile.decryptFile(zippedFile, "pdAFstScKvwO0o!D"); XmlHandler.unzip(zippedFile + ".d", path); File f = new File(path + "vm"); fis = new FileInputStream(f); if (fis == null) { Toast.makeText(rootView.getContext(), "SD?!", Toast.LENGTH_LONG).show(); Log.d(Common.TAG, "SD?!"); } else { // ? VehicleModelParser parser = new VehicleModelParser(); vehicleModel = parser.parseVehicleModelXml(fis); // delete vm f.delete(); // delete df001.d f = new File(zippedFile + ".d"); f.delete(); } } catch (FileNotFoundException e) { Toast.makeText(rootView.getContext(), "?!", Toast.LENGTH_LONG).show(); Log.d(Common.TAG, "?!"); } catch (GeneralSecurityException e) { e.printStackTrace(); } catch (IOException e) { Log.d(Common.TAG, "?!"); } mProgressDialog.dismiss(); } // <editor-fold defaultstate="collapsed" desc="?JsonString"> // ???jsonString public JSONObject generateOptionsJsonObject() { JSONObject options = new JSONObject(); try { options.put("vin", vin_edit.getText().toString()); options.put("country", mCarSettings.getCountry().name); options.put("countryId", Integer.parseInt(mCarSettings.getCountry().id)); options.put("brand", mCarSettings.getBrand().name); options.put("brandId", Integer.parseInt(mCarSettings.getBrand().id)); options.put("manufacturer", mCarSettings.getManufacturer().name); options.put("manufacturerId", Integer.parseInt(mCarSettings.getManufacturer().id)); options.put("series", mCarSettings.getSeries().name); options.put("seriesId", Integer.parseInt(mCarSettings.getSeries().id)); options.put("model", mCarSettings.getModel().name); options.put("modelId", Integer.parseInt(mCarSettings.getModel().id)); options.put("displacement", displacementEdit.getText().toString()); options.put("category", mCarSettings.getCategory()); options.put("driveType", getSpinnerSelectedText(rootView, R.id.csi_driveType_spinner)); options.put("transmission", getSpinnerSelectedText(rootView, R.id.csi_transmission_spinner)); options.put("airBags", getSpinnerSelectedText(rootView, R.id.csi_airbag_spinner)); // if (!getSpinnerSelectedText(rootView, R.id.csi_abs_spinner).equals("")) options.put("abs", getSpinnerSelectedText(rootView, R.id.csi_abs_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_powerSteering_spinner).equals("")) options.put("powerSteering", getSpinnerSelectedText(rootView, R.id.csi_powerSteering_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_powerWindows_spinner).equals("")) options.put("powerWindows", getSpinnerSelectedText(rootView, R.id.csi_powerWindows_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_sunroof_spinner).equals("")) options.put("sunroof", getSpinnerSelectedText(rootView, R.id.csi_sunroof_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_airConditioning_spinner).equals("")) options.put("airConditioning", getSpinnerSelectedText(rootView, R.id.csi_airConditioning_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_leatherSeats_spinner).equals("")) options.put("leatherSeats", getSpinnerSelectedText(rootView, R.id.csi_leatherSeats_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_powerSeats_spinner).equals("")) options.put("powerSeats", getSpinnerSelectedText(rootView, R.id.csi_powerSeats_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_powerMirror_spinner).equals("")) options.put("powerMirror", getSpinnerSelectedText(rootView, R.id.csi_powerMirror_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_reversingRadar_spinner).equals("")) options.put("reversingRadar", getSpinnerSelectedText(rootView, R.id.csi_reversingRadar_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_reversingCamera_spinner).equals("")) options.put("reversingCamera", getSpinnerSelectedText(rootView, R.id.csi_reversingCamera_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_ccs_spinner).equals("")) options.put("ccs", getSpinnerSelectedText(rootView, R.id.csi_ccs_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_softCloseDoors_spinner).equals("")) options.put("softCloseDoors", getSpinnerSelectedText(rootView, R.id.csi_softCloseDoors_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_rearPowerSeats_spinner).equals("")) options.put("rearPowerSeats", getSpinnerSelectedText(rootView, R.id.csi_rearPowerSeats_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_ahc_spinner).equals("")) options.put("ahc", getSpinnerSelectedText(rootView, R.id.csi_ahc_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_parkAssist_spinner).equals("")) options.put("parkAssist", getSpinnerSelectedText(rootView, R.id.csi_parkAssist_spinner)); if (!getSpinnerSelectedText(rootView, R.id.csi_clapboard_spinner).equals("")) options.put("clapboard", getSpinnerSelectedText(rootView, R.id.csi_clapboard_spinner)); } catch (JSONException e) { } return options; } //??jsonString public JSONObject generateProceduresJsonObject() { JSONObject procedures = new JSONObject(); try { procedures.put("regArea", getSpinnerSelectedText(rootView, R.id.ci_regArea_spinner)); procedures.put("plateNumber", getEditText(rootView, R.id.ci_plateNumber_edit)); procedures.put("licenseModel", getEditText(rootView, R.id.ci_licenseModel_edit)); procedures.put("vehicleType", getSpinnerSelectedText(rootView, R.id.ci_vehicleType_spinner)); procedures.put("useCharacter", getSpinnerSelectedText(rootView, R.id.ci_useCharacter_spinner)); // if (getEditText(rootView, R.id.bi_mileage_edit).equals("")) procedures.put("mileage", 0); else procedures.put("mileage", getEditText(rootView, R.id.bi_mileage_edit)); procedures.put("exteriorColor", getSpinnerSelectedText(rootView, R.id.ci_exteriorColor_spinner)); procedures.put("regDate", getDateString(getSpinnerSelectedText(rootView, R.id.ci_regYear_spinner), getSpinnerSelectedText(rootView, R.id.ci_regMonth_spinner))); procedures.put("builtDate", getDateString(getSpinnerSelectedText(rootView, R.id.ci_builtYear_spinner), getSpinnerSelectedText(rootView, R.id.ci_builtMonth_spinner))); procedures.put("invoice", getSpinnerSelectedText(rootView, R.id.ct_invoice_spinner)); // ? if (getSpinnerSelectedIndex(rootView, R.id.ct_invoice_spinner) > 1) { procedures.put("invoicePrice", 0); } else { // ? if (getEditText(rootView, R.id.ct_invoice_edit).equals("")) procedures.put("invoicePrice", 0); else procedures.put("invoicePrice", getEditText(rootView, R.id.ct_invoice_edit)); } procedures.put("surtax", getSpinnerSelectedText(rootView, R.id.ct_surtax_spinner)); procedures.put("transferCount", getSpinnerSelectedText(rootView, R.id.ci_transferCount_spinner)); // 0 if (getSpinnerSelectedText(rootView, R.id.ci_transferCount_spinner).equals("0")) { procedures.put("transferLastDate", ""); } else { procedures.put("transferLastDate", getDateString(getSpinnerSelectedText(rootView, R.id.ci_transferLastYear_spinner), getSpinnerSelectedText(rootView, R.id.ci_transferLastMonth_spinner))); } procedures.put("annualInspection", getDateString(getSpinnerSelectedText(rootView, R.id.ct_annualInspectionYear_spinner), getSpinnerSelectedText(rootView, R.id.ct_annualInspectionMonth_spinner))); if (getSpinnerSelectedIndex(rootView, R.id.ct_compulsoryInsurance_spinner) == 0) { procedures.put("compulsoryInsurance", getDateString(getSpinnerSelectedText(rootView, R.id.ct_compulsoryInsuranceYear_spinner), getSpinnerSelectedText(rootView, R.id.ct_compulsoryInsuranceMonth_spinner))); } else { procedures.put("compulsoryInsurance", ""); } procedures.put("licensePhotoMatch", getEditText(rootView, R.id.ct_licencePhotoMatch_edit)); procedures.put("insurance", getSpinnerSelectedText(rootView, R.id.ct_insurance_spinner)); // if (getSpinnerSelectedText(rootView, R.id.ct_insurance_spinner).equals("")) { procedures.put("insuranceRegion", ""); procedures.put("insuranceAmount", 0); procedures.put("insuranceExpiryDate", ""); procedures.put("insuranceCompany", ""); } else { procedures.put("insuranceRegion", getSpinnerSelectedText(rootView, R.id.ct_insuranceRegion_spinner)); // ? if (getEditText(rootView, R.id.ct_insuranceAmount_edit).equals("")) procedures.put("insuranceAmount", 0); else procedures.put("insuranceAmount", getEditText(rootView, R.id.ct_insuranceAmount_edit)); procedures.put("insuranceExpiryDate", getDateString(getSpinnerSelectedText(rootView, R.id.ct_insuranceExpiryYear_spinner), getSpinnerSelectedText(rootView, R.id.ct_insuranceExpiryMonth_spinner))); procedures.put("insuranceCompany", getSpinnerSelectedText(rootView, R.id.ct_insuranceCompany_spinner)); } procedures.put("importProcedures", getSpinnerSelectedText(rootView, R.id.ct_importProcedures_spinner)); procedures.put("spareTire", getSpinnerSelectedText(rootView, R.id.ct_spareTire_spinner)); procedures.put("spareKey", getSpinnerSelectedText(rootView, R.id.ct_spareKey_spinner)); procedures.put("ownerName", getEditText(rootView, R.id.ci_ownerName_edit)); procedures.put("ownerIdNumber", getEditText(rootView, R.id.ci_ownerIdNumber_edit)); procedures.put("ownerPhone", getEditText(rootView, R.id.ci_ownerPhone_edit)); } catch (JSONException e) { } return procedures; } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="???Task"> private class GetCarSettingsTask extends AsyncTask<String, Void, Boolean> { Context context; String seriesId; String modelId; String modelName = ""; List<String> modelNames; JSONObject jsonObject; List<JSONObject> jsonObjects; Country country = null; Brand brand = null; Manufacturer manufacturer = null; Series series = null; Model model = null; String config = null; String category = null; String figure = null; private GetCarSettingsTask(Context context) { this.context = context; this.seriesId = null; } @Override protected void onPreExecute() { mProgressDialog = ProgressDialog.show(rootView.getContext(), null, "???", false, false); model = null; modelName = ""; modelNames = null; jsonObject = null; jsonObjects = null; } @Override protected Boolean doInBackground(String... params) { boolean success = false; // seriesIdmodelId if (!params[0].equals("")) { // ??seriesIdmodelId String temp[] = params[0].split(","); seriesId = temp[0]; modelId = temp[1]; try { JSONObject jsonObject = new JSONObject(); // SeriesId + userID + key jsonObject.put("SeriesId", seriesId); jsonObject.put("ModelId", modelId); jsonObject.put("UserId", MainActivity.userInfo.getId()); jsonObject.put("Key", MainActivity.userInfo.getKey()); soapService = new SoapService(); // soap? soapService.setUtils(Common.SERVER_ADDRESS + Common.REPORT_SERVICE, "http://cheyipai/IReportService/GetOptionsBySeriesIdAndModelId", "GetOptionsBySeriesIdAndModelId"); success = soapService.communicateWithServer(jsonObject.toString()); // ?? if (!success) { Log.d("DFCarChecker", "???" + soapService.getErrorMessage()); } else { result = soapService.getResultMessage(); } } catch (JSONException e) { Log.d("DFCarChecker", "Json?" + e.getMessage()); return false; } } // VIN else { try { JSONObject jsonObject = new JSONObject(); // vin + userID + key jsonObject.put("Vin", vin_edit.getText().toString()); jsonObject.put("UserId", MainActivity.userInfo.getId()); jsonObject.put("Key", MainActivity.userInfo.getKey()); soapService = new SoapService(); // soap? soapService.setUtils(Common.SERVER_ADDRESS + Common.REPORT_SERVICE, "http://cheyipai/IReportService/GetCarConfigInfoByVin", "GetCarConfigInfoByVin"); success = soapService.communicateWithServer(jsonObject.toString()); // ?? if (!success) { Log.d("DFCarChecker", "???" + soapService.getErrorMessage()); } else { result = soapService.getResultMessage(); } } catch (JSONException e) { Log.d("DFCarChecker", "Json?" + e.getMessage()); return false; } } return success; } @Override protected void onPostExecute(final Boolean success) { mGetCarSettingsTask = null; mProgressDialog.dismiss(); // ? if (success) { try { // ?[? if (result.startsWith("[")) { JSONArray jsonArray = new JSONArray(result); // ???jsonobject list jsonObjects = new ArrayList<JSONObject>(); // ??string list modelNames = new ArrayList<String>(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); jsonObjects.add(jsonObject); // ?ID? if (jsonObject.has("countryId")) country = vehicleModel.getCountryById(jsonObject.getString("countryId")); else country = vehicleModel.countries.get(0); if (jsonObject.has("brandId")) brand = country.getBrandById(jsonObject.getString("brandId")); else brand = country.brands.get(0); if (jsonObject.has("manufacturerId")) manufacturer = brand.getProductionById(jsonObject.getString("manufacturerId")); else manufacturer = brand.manufacturers.get(0); if (jsonObject.has("seriesId")) series = manufacturer.getSerialById(jsonObject.getString("seriesId")); else series = manufacturer.serieses.get(0); if (jsonObject.has("modelId")) model = series.getModelById(jsonObject.getString("modelId")); else model = series.models.get(0); // ?? // config:powerSteering,powerWindows,powerSeats config = jsonObject.getString("config"); // ??????? category = jsonObject.getString("category"); // figure = jsonObject.getString("figure"); modelNames.add(manufacturer.name + " " + series.name + " " + model.name); } // ? AlertDialog.Builder builder = new AlertDialog.Builder(rootView.getContext()); builder.setTitle(R.string.bi_select_model); String[] tempArray = new String[modelNames.size() + 1]; for (int i = 0; i < modelNames.size(); i++) { tempArray[i] = modelNames.get(i); } // ??? tempArray[modelNames.size()] = ""; builder.setItems(tempArray, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // ????? if (i == modelNames.size()) { selectCarManually(); } else { modelName = modelNames.get(i); jsonObject = jsonObjects.get(i); try { country = vehicleModel.getCountryById(jsonObject.getString("countryId")); brand = country.getBrandById(jsonObject.getString("brandId")); manufacturer = brand .getProductionById(jsonObject.getString("manufacturerId")); series = manufacturer.getSerialById(jsonObject.getString("seriesId")); model = series.getModelById(jsonObject.getString("modelId")); config = jsonObject.getString("config"); category = jsonObject.getString("category"); figure = jsonObject.getString("figure"); // ?idspinner? lastCountryIndex = vehicleModel.getCountryNames().indexOf(country.name); lastBrandIndex = country.getBrandNames().indexOf(brand.name); lastManufacturerIndex = brand.getManufacturerNames() .indexOf(manufacturer.name); lastSeriesIndex = manufacturer.getSerialNames().indexOf(series.name); lastModelIndex = series.getModelNames().indexOf(model.name); } catch (JSONException e) { e.printStackTrace(); } // ? mCarSettings.setBrandString(modelName); mCarSettings.setCountry(country); mCarSettings.setBrand(brand); mCarSettings.setManufacturer(manufacturer); mCarSettings.setSeries(series); mCarSettings.setModel(model); // ?? mCarSettings.setConfig(config); // String categoryArray[] = getResources() .getStringArray(R.array.csi_category_item); if (Integer.parseInt(category) > 0) mCarSettings.setCategory(categoryArray[Integer.parseInt(category) - 1]); else mCarSettings.setCategory(categoryArray[Integer.parseInt(category)]); mCarSettings.setFigure(figure); setCarSettings(model.getName()); // UI updateUi(); } } }); AlertDialog dialog = builder.create(); dialog.show(); contentLayout.setVisibility(View.VISIBLE); } // ?{?? else { JSONObject jsonObject = new JSONObject(result); config = jsonObject.getString("config"); category = jsonObject.getString("category"); figure = jsonObject.getString("figure"); // ?? mCarSettings.setConfig(config); // mCarSettings.setCategory(category); mCarSettings.setFigure(figure); // UI updateUi(); } } catch (JSONException e) { Log.d("DFCarChecker", "Json?" + e.getMessage()); } } // else { if (soapService.getErrorMessage() .equals("??Key?IdKey")) { AlertDialog.Builder builder = new AlertDialog.Builder(rootView.getContext()); builder.setTitle(R.string.bi_select_model).setMessage("??"); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Intent intent = new Intent(rootView.getContext(), LoginActivity.class); startActivity(intent); } }); AlertDialog dialog = builder.create(); dialog.show(); } else if (soapService.getErrorMessage() .equals("VIN??")) { AlertDialog dialog = new AlertDialog.Builder(this.context).setTitle(R.string.alert_title) .setMessage("?") .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { selectCarManually(); contentLayout.setVisibility(View.VISIBLE); } }).create(); dialog.show(); updateUi(); } else { Toast.makeText(context, soapService.getErrorMessage(), Toast.LENGTH_LONG).show(); } } } @Override protected void onCancelled() { mGetCarSettingsTask = null; } } // </editor-fold> // ??? public boolean runOverAllCheck() { int id2Check[] = { R.id.ci_licenseModel_edit, R.id.bi_mileage_edit, R.id.ct_invoice_edit, R.id.ct_licencePhotoMatch_edit, R.id.ct_insuranceAmount_edit, R.id.ci_ownerName_edit, R.id.ci_ownerIdNumber_edit, R.id.ci_ownerPhone_edit }; for (int i = 0; i < id2Check.length; i++) { if (id2Check[i] == R.id.ct_invoice_edit) { // ? if (ticketSpinner.getSelectedItemPosition() > 1) continue; } if (id2Check[i] == R.id.ct_insuranceAmount_edit) { // if (businessInsuranceSpinner.getSelectedItemPosition() >= 1) continue; } if (Helper.getEditText(rootView, id2Check[i]).equals("")) { Helper.setEditError(rootView, id2Check[i]); Helper.setEditFocus(rootView, id2Check[i]); return false; } } return true; } // <editor-fold defaultstate="collapsed" desc="??Spinner"> // Spinner private void setCountrySpinner(final VehicleModel vehicleModel) { ArrayAdapter<String> adapter; if (vehicleModel == null) { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, Helper.getEmptyStringList()); } else { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, vehicleModel.getCountryNames()); } countrySpinner.setAdapter(adapter); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // ?Spinner Adapter countrySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (i == 0) { setBrandSpinner(null); } else if (i >= 1) { setBrandSpinner(vehicleModel.countries.get(i - 1)); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); countrySpinner.setSelection(lastCountryIndex); lastCountryIndex = 0; } // ?Spinner private void setBrandSpinner(final Country country) { ArrayAdapter<String> adapter; if (country == null) { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, Helper.getEmptyStringList()); } else { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, country.getBrandNames()); } brandSpinner.setAdapter(adapter); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // ?Spinner Adapter brandSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (country == null || i == 0) { setManufacturerSpinner(null); } else if (i >= 1) { setManufacturerSpinner(country.brands.get(i - 1)); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // ??? if (country != null && country.getBrandNames().size() == 2) { brandSpinner.setSelection(1); } else { brandSpinner.setSelection(lastBrandIndex); } lastBrandIndex = 0; } // Spinner private void setManufacturerSpinner(final Brand brand) { ArrayAdapter<String> adapter; if (brand == null) { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, Helper.getEmptyStringList()); } else { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, brand.getManufacturerNames()); } manufacturerSpinner.setAdapter(adapter); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Spinner Adapter manufacturerSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (brand == null || i == 0) { setSeriesSpinner(null); } else if (i >= 1) { setSeriesSpinner(brand.manufacturers.get(i - 1)); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // ??? if (brand != null && brand.getManufacturerNames().size() == 2) { manufacturerSpinner.setSelection(1); } else { manufacturerSpinner.setSelection(lastManufacturerIndex); } lastManufacturerIndex = 0; } // Spinner private void setSeriesSpinner(final Manufacturer manufacturer) { ArrayAdapter<String> adapter; if (manufacturer == null) { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, Helper.getEmptyStringList()); } else { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, manufacturer.getSerialNames()); } seriesSpinner.setAdapter(adapter); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // ?Spinner Adapter seriesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (manufacturer == null || i == 0) { setModelSpinner(null); } else if (i >= 1) { setModelSpinner(manufacturer.serieses.get(i - 1)); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // ??? if (manufacturer != null && manufacturer.getSerialNames().size() == 2) { seriesSpinner.setSelection(1); } else { seriesSpinner.setSelection(lastSeriesIndex); } lastSeriesIndex = 0; } // Spinner private void setModelSpinner(final Series series) { ArrayAdapter<String> adapter; if (series == null) { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, Helper.getEmptyStringList()); } else { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item, series.getModelNames()); } modelSpinner.setAdapter(adapter); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // ??? if (series != null && series.getModelNames().size() == 2) { modelSpinner.setSelection(1); } else { modelSpinner.setSelection(lastModelIndex); } lastModelIndex = 0; } // ?? private void setCarSettings(String modelString) { // ? if (modelString.length() >= 3) { mCarSettings.setDisplacement(modelString.substring(0, 3)); } // ?Spinner if (modelString.contains("")) { mCarSettings.setDriveType(""); } else { mCarSettings.setDriveType(""); } // ??Spinner if (modelString.contains("A/MT")) { mCarSettings.setTransmission("A/MT"); } else if (modelString.contains("MT")) { mCarSettings.setTransmission("MT"); } else if (modelString.contains("CVT") || modelString.contains("DSG")) { mCarSettings.setTransmission("CVT"); } else { mCarSettings.setTransmission("AT"); } } // private void setRegLocationSpinner() { String[] provinceArray = getResources().getStringArray(R.array.ci_province); List<String> province = Helper.StringArray2List(provinceArray); SetSpinnerData(R.id.ci_regArea_spinner, province, rootView); String[] provinceAbbreviationArray = getResources().getStringArray(R.array.ci_province_abbreviation); final List<String> provinceAbbreviation = Helper.StringArray2List(provinceAbbreviationArray); Spinner regLocationSpinner = (Spinner) rootView.findViewById(R.id.ci_regArea_spinner); regLocationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (!modifyMode) { carNumberEdit.setText(provinceAbbreviation.get(i)); } modifyMode = false; } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); } // ??spinner?? // ?vin public void littleFixAboutRegArea() { try { setEditText(rootView, R.id.ci_plateNumber_edit, procedures.getString("plateNumber")); } catch (Exception e) { } } // private void setCarColorSpinner() { String[] colorArray = getResources().getStringArray(R.array.ci_car_color_arrays); List<String> colorList = Helper.StringArray2List(colorArray); SetSpinnerData(R.id.ci_exteriorColor_spinner, colorList, rootView); } // ? private void setFirstLogTimeSpinner() { SetSpinnerData(R.id.ci_regYear_spinner, Helper.GetYearList(20), rootView); SetSpinnerData(R.id.ci_regMonth_spinner, Helper.GetMonthList(), rootView); firstLogYearSpinner = (Spinner) rootView.findViewById(R.id.ci_regYear_spinner); firstLogYearSpinner.setSelection(17); firstLogYearSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // ? List<String> temp = Helper.GetYearList(20); SetSpinnerData(R.id.ci_builtYear_spinner, temp.subList(0, i + 1), rootView); manufactureYearSpinner.setSelection(i); // ?? SetSpinnerData(R.id.ci_transferLastYear_spinner, temp.subList(i, temp.size()), rootView); // ??? int from = Integer.parseInt(temp.get(i)); int to = Calendar.getInstance().get(Calendar.YEAR) + 2; SetSpinnerData(R.id.ct_annualInspectionYear_spinner, Helper.GetNumbersList(from, to), rootView); SetSpinnerData(R.id.ct_compulsoryInsuranceYear_spinner, Helper.GetNumbersList(from, to), rootView); SetSpinnerData(R.id.ct_insuranceExpiryYear_spinner, Helper.GetNumbersList(from, to), rootView); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); } // private void setManufactureTimeSpinner() { SetSpinnerData(R.id.ci_builtYear_spinner, Helper.GetYearList(20), rootView); SetSpinnerData(R.id.ci_builtMonth_spinner, Helper.GetMonthList(), rootView); } // private void setTransferCountSpinner() { SetSpinnerData(R.id.ci_transferCount_spinner, Helper.GetNumbersList(0, 15), rootView); } // ? private void setLastTransferTimeSpinner() { SetSpinnerData(R.id.ci_transferLastYear_spinner, Helper.GetYearList(17), rootView); SetSpinnerData(R.id.ci_transferLastMonth_spinner, Helper.GetMonthList(), rootView); } // private void setYearlyCheckAvailableDateSpinner() { SetSpinnerData(R.id.ct_annualInspectionYear_spinner, Helper.GetYearList(2), rootView); SetSpinnerData(R.id.ct_annualInspectionMonth_spinner, Helper.GetMonthList(), rootView); } // private void setAvailableDateYearSpinner() { SetSpinnerData(R.id.ct_compulsoryInsuranceYear_spinner, Helper.GetYearList(2), rootView); SetSpinnerData(R.id.ct_compulsoryInsuranceMonth_spinner, Helper.GetMonthList(), rootView); } // private void setBusinessInsuranceAvailableDateYearSpinner() { SetSpinnerData(R.id.ct_insuranceExpiryYear_spinner, Helper.GetYearList(19), rootView); SetSpinnerData(R.id.ct_insuranceExpiryMonth_spinner, Helper.GetMonthList(), rootView); } // spinner private void setOtherSpinners() { // ? ticketSpinner = (Spinner) rootView.findViewById(R.id.ct_invoice_spinner); ticketSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // ? if (i <= 1) { Helper.showView(true, rootView, R.id.ct_invoice_edit); Helper.showView(true, rootView, R.id.yuan); Helper.showView(false, rootView, R.id.placeholder); } else { // ? Helper.showView(false, rootView, R.id.ct_invoice_edit); Helper.showView(false, rootView, R.id.yuan); Helper.showView(true, rootView, R.id.placeholder); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // ? lastTransferCountSpinner = (Spinner) rootView.findViewById(R.id.ci_transferCount_spinner); lastTransferCountSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // 0 if (i > 0) { Helper.showView(true, rootView, R.id.ci_last_transfer_row); } else { Helper.showView(false, rootView, R.id.ci_last_transfer_row); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // ? businessInsuranceSpinner = (Spinner) rootView.findViewById(R.id.ct_insurance_spinner); businessInsuranceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // ?? if (i == 0) { Helper.showView(true, rootView, R.id.ct_insurance_table); } else { Helper.showView(false, rootView, R.id.ct_insurance_table); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // compulsoryInsuranceSpinner = (Spinner) rootView.findViewById(R.id.ct_compulsoryInsurance_spinner); compulsoryInsuranceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { if (i == 0) { showView(true, rootView, R.id.ct_compulsoryInsurance_table); } else { showView(false, rootView, R.id.ct_compulsoryInsurance_table); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); // manufactureYearSpinner = (Spinner) rootView.findViewById(R.id.ci_builtYear_spinner); } // ? public void PictureMatch() { View view = this.inflater.inflate(R.layout.ci_dialog, null); AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setTitle("?").setView(view) .setPositiveButton(R.string.ci_attention_match, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // setPictureMatchEdit(true); } }).setNegativeButton(R.string.ci_attention_notmatch, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // ? setPictureMatchEdit(false); } }).create(); dialog.show(); } private void setPictureMatchEdit(boolean match) { String matches = getResources().getString(R.string.ci_attention_match); String notMatch = getResources().getString(R.string.ci_attention_notmatch); setEditText(rootView, R.id.ct_licencePhotoMatch_edit, match ? matches : notMatch); } // </editor-fold> // ? private void letsEnterModifyMode() { try { JSONObject features = new JSONObject(jsonData).getJSONObject("features"); options = features.getJSONObject("options"); procedures = features.getJSONObject("procedures"); String brandString = options.getString("manufacturer") + " " + options.getString("series") + " " + options.getString("model"); mCarSettings.setBrandString(brandString); mCarSettings.setDisplacement(options.getString("displacement")); mCarSettings.setCategory(options.getString("category")); Country country = vehicleModel.getCountryById(Integer.toString(options.getInt("countryId"))); Brand brand = country.getBrandById(Integer.toString(options.getInt("brandId"))); Manufacturer manufacturer = brand.getProductionById(Integer.toString(options.getInt("manufacturerId"))); Series series = manufacturer.getSerialById(Integer.toString(options.getInt("seriesId"))); Model model = series.getModelById(Integer.toString(options.getInt("modelId"))); mCarSettings.setCountry(country); mCarSettings.setBrand(brand); mCarSettings.setManufacturer(manufacturer); mCarSettings.setSeries(series); mCarSettings.setModel(model); mCarSettings.setCarSettings(options.toString()); // mCarSettings.setCategory(options.getString("category")); mCarSettings.setFigure("1"); setCarSettings(model.getName()); this.getActivity().runOnUiThread(new Runnable() { public void run() { //stuff that updates ui contentLayout.setVisibility(View.VISIBLE); tableLayout.setVisibility(View.VISIBLE); CarCheckFrameFragment.showContent(); CarCheckIntegratedFragment.showContent(); // UI updateUi(); } }); this.getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { // vin setEditText(rootView, R.id.bi_vin_edit, options.getString("vin")); enableView(false, rootView, R.id.bi_vin_edit); showView(false, rootView, R.id.bi_vin_button); showView(false, rootView, R.id.bi_brand_ok_button); setEditWeight(rootView, R.id.bi_vin_edit, 4f); setEditWeight(rootView, R.id.bi_brand_edit, 3f); // setSpinnerSelectionWithString(rootView, R.id.ci_regArea_spinner, procedures.getString("regArea")); setEditText(rootView, R.id.ci_licenseModel_edit, procedures.getString("licenseModel")); setSpinnerSelectionWithString(rootView, R.id.ci_vehicleType_spinner, procedures.getString("vehicleType")); setSpinnerSelectionWithString(rootView, R.id.ci_useCharacter_spinner, procedures.getString("useCharacter")); setEditText(rootView, R.id.bi_mileage_edit, procedures.getString("mileage")); setSpinnerSelectionWithString(rootView, R.id.ci_exteriorColor_spinner, procedures.getString("exteriorColor")); setSpinnerSelectionWithString(rootView, R.id.ci_regYear_spinner, procedures.getString("regDate").substring(0, 4)); setSpinnerSelectionWithString(rootView, R.id.ci_regMonth_spinner, procedures.getString("regDate").substring(6, 7)); setSpinnerSelectionWithString(rootView, R.id.ci_builtYear_spinner, procedures.getString("builtDate").substring(0, 4)); setSpinnerSelectionWithString(rootView, R.id.ci_builtMonth_spinner, procedures.getString("builtDate").substring(6, 7)); setSpinnerSelectionWithString(rootView, R.id.ct_invoice_spinner, procedures.getString("invoice")); setEditText(rootView, R.id.ct_invoice_edit, procedures.getString("invoicePrice")); setSpinnerSelectionWithString(rootView, R.id.ct_surtax_spinner, procedures.getString("surtax")); setSpinnerSelectionWithString(rootView, R.id.ci_transferCount_spinner, procedures.getString("transferCount")); // ?0? if (!procedures.getString("transferCount").equals("0")) { setSpinnerSelectionWithString(rootView, R.id.ci_transferLastYear_spinner, procedures.getString("transferLastDate").substring(0, 4)); setSpinnerSelectionWithString(rootView, R.id.ci_transferLastMonth_spinner, procedures.getString("transferLastDate").substring(6, 7)); } setEditText(rootView, R.id.ct_licencePhotoMatch_edit, procedures.getString("licensePhotoMatch")); setSpinnerSelectionWithString(rootView, R.id.ct_insurance_spinner, procedures.getString("insurance")); // ??? if (!procedures.getString("insurance").equals("")) { setSpinnerSelectionWithString(rootView, R.id.ct_insuranceRegion_spinner, procedures.getString("insuranceRegion")); setEditText(rootView, R.id.ct_insuranceAmount_edit, procedures.getString("insuranceAmount")); setSpinnerSelectionWithString(rootView, R.id.ct_insuranceCompany_spinner, procedures.getString("insuranceCompany")); setSpinnerSelectionWithString(rootView, R.id.ct_insuranceExpiryYear_spinner, procedures.getString("insuranceExpiryDate").substring(0, 4)); setSpinnerSelectionWithString(rootView, R.id.ct_insuranceExpiryMonth_spinner, procedures.getString("insuranceExpiryDate").substring(6, 7)); } setSpinnerSelectionWithString(rootView, R.id.ct_importProcedures_spinner, procedures.getString("importProcedures")); setSpinnerSelectionWithString(rootView, R.id.ct_spareTire_spinner, procedures.getString("spareTire")); setSpinnerSelectionWithString(rootView, R.id.ct_spareKey_spinner, procedures.getString("spareKey")); setEditText(rootView, R.id.ci_ownerName_edit, procedures.getString("ownerName")); setEditText(rootView, R.id.ci_ownerIdNumber_edit, procedures.getString("ownerIdNumber")); setEditText(rootView, R.id.ci_ownerPhone_edit, procedures.getString("ownerPhone")); setSpinnerSelectionWithString(rootView, R.id.ct_annualInspectionYear_spinner, procedures.getString("annualInspection").substring(0, 4)); setSpinnerSelectionWithString(rootView, R.id.ct_annualInspectionMonth_spinner, procedures.getString("annualInspection").substring(6, 7)); if (procedures.getString("compulsoryInsurance").equals("")) { setSpinnerSelectionWithString(rootView, R.id.ct_compulsoryInsurance_spinner, ""); } else { setSpinnerSelectionWithString(rootView, R.id.ct_compulsoryInsuranceYear_spinner, procedures.getString("compulsoryInsurance").substring(0, 4)); setSpinnerSelectionWithString(rootView, R.id.ct_compulsoryInsuranceMonth_spinner, procedures.getString("compulsoryInsurance").substring(6, 7)); } mProgressDialog.dismiss(); } catch (JSONException e) { } } }); } catch (Exception e) { Log.d(Common.TAG, e.getMessage()); } } }