@Override protected void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); setContentView(R.layout.activity_vehicle_manager); mVehicleNoIndicatorText = (IndicatorTextView) findViewById(R.id.vehicle_no_indicator_text); mVehicleModelIndicatorText = (IndicatorTextView) findViewById(R.id.vehicle_model_indicator_text); mOilPriceIndicatorEdit = (IndicatorEditText) findViewById(R.id.oil_price_indicator_edit); mCurrentMileageIndicatorEdit = (IndicatorEditText) findViewById(R.id.current_mileage_indicator_edit); mMaintainPeriodIndicatorEdit = (IndicatorEditText) findViewById(R.id.maintain_period_indicator_edit); mLastMaintainMileageIndicatorEdit = (IndicatorEditText) findViewById(R.id.last_maintain_mileage_indicator_edit); mNextMaintainTimeIndicatorText = (IndicatorTextView) findViewById(R.id.next_maintain_time_indicator_text); mNextExaminationTimeIndicatorText = (IndicatorTextView) findViewById(R.id.next_examination_time_indicator_text); mOilPriceIndicatorEdit.requestFocus(); mOilpriceMinValue = getResources().getInteger(R.integer.oilprice_min_value); mOilpriceMaxValue = getResources().getInteger(R.integer.oilprice_max_value); mOilPriceIndicatorEdit .getEditText() .setHint( getString(R.string.txt_hint_oil_price_range, mOilpriceMinValue, mOilpriceMaxValue)); mNextMaintainTimeIndicatorText.setImageIndicator( R.drawable.ic_calendar, new OnClickListener() { @Override public void onClick(View v) { showDatePickerDialog(mNextMaintainTimeIndicatorText); } }); mNextExaminationTimeIndicatorText.setImageIndicator( R.drawable.ic_calendar, new OnClickListener() { @Override public void onClick(View v) { showDatePickerDialog(mNextExaminationTimeIndicatorText); } }); if (restoreExtras(savedInstance)) { } else { restoreIntentExtras(); } }
@Override protected void onSaveInstanceState(Bundle outState) { outState.putString(EXTRA_VEHICLE_NO, mVehicleNoIndicatorText.getTextValue()); outState.putString(EXTRA_VEHICLE_MODEL, mVehicleModelIndicatorText.getTextValue()); outState.putString(EXTRA_OIL_PRICE, mOilPriceIndicatorEdit.getEditTextValue()); outState.putString(EXTRA_CURRENT_MILEAGE, mCurrentMileageIndicatorEdit.getEditTextValue()); outState.putString(EXTRA_MATINTAIN_PERIOD, mMaintainPeriodIndicatorEdit.getEditTextValue()); outState.putString( EXTRA_LAST_MAINTAIN_MILEAGE, mLastMaintainMileageIndicatorEdit.getEditTextValue()); outState.putString(EXTRA_NEXT_MAINTAIN_TIME, mNextMaintainTimeIndicatorText.getTextValue()); outState.putString( EXTRA_NEXT_EXAMINATION_TIME, mNextExaminationTimeIndicatorText.getTextValue()); super.onSaveInstanceState(outState); }
@Override protected boolean restoreExtras(Bundle extra) { if (isBundleEmpty(extra) || !extra.containsKey(EXTRA_VEHICLE_NO)) { return false; } mVehicleNoIndicatorText.setTextValue(extra.getString(EXTRA_VEHICLE_NO)); mVehicleModelIndicatorText.setTextValue(extra.getString(EXTRA_VEHICLE_MODEL)); mOilPriceIndicatorEdit.setEditTextValue(extra.getString(EXTRA_OIL_PRICE)); int currentMileage = Integer.valueOf(extra.getString(EXTRA_CURRENT_MILEAGE)); mCurrentMileageIndicatorEdit.setEditTextValue( currentMileage <= 0 ? "" : String.valueOf(currentMileage)); mMaintainPeriodIndicatorEdit.setEditTextValue(extra.getString(EXTRA_MATINTAIN_PERIOD)); mLastMaintainMileageIndicatorEdit.setEditTextValue( extra.getString(EXTRA_LAST_MAINTAIN_MILEAGE)); mNextMaintainTimeIndicatorText.setTextValue(extra.getString(EXTRA_NEXT_MAINTAIN_TIME)); mNextExaminationTimeIndicatorText.setTextValue(extra.getString(EXTRA_NEXT_EXAMINATION_TIME)); return true; }