protected void onResume() { super.onResume(); try { storage = new SharedStorage(this); // populate data but only for the first time ! if (firstRun) { // populate with the values loadInfo(); firstRun = false; } } catch (Exception ex) { DKDialog.ShowMessage( this, Translate.translate("Error"), Translate.translate("Reading settings activitiy failed!"), Translate.translate("OK"), Translate.translate("Cancel")); LogWriter.writeException(this, ex.getMessage(), ex); } }
/** Loads detailed tax payer info */ public void loadInfo() { // try to connect try { // Get TaxPayer Income first: HTTPConnection connection = new HTTPConnection(storage.getServerURL()); JSONObject response = connection.connectJSON(Engine.getTaxPayerInfo(TaxPayerID)); storage.setLastServerResponse(response.toString()); if (!response.getString("result").equals("OK")) { throw new Exception("Invalid response from server = " + response.getString("data")); } // read results JSONObject data = response.getJSONArray("data").getJSONObject(0); // Fill the activity with results TaxIncome = data.getDouble("Income"); tbTaxYearIncome.setText(String.valueOf(TaxIncome) + " \u20AC"); // Get Tax stats: response = connection.connectJSON(Engine.TaxProgramGrid(TaxYearID, TaxPayerID)); storage.setLastServerResponse(response.toString()); // retrieve the array of items array = response.getJSONArray("data"); recalculateTaxRate(); // only after array is loaded - show the list adapter = new TaxYearProgramsAdapter(this); tableTaxProgramManage.setAdapter(adapter); } catch (Exception ex) { DKDialog.ShowMessage( this, Translate.translate("Error"), Translate.translate("Connection failed: " + ex.getMessage()), Translate.translate("OK"), Translate.translate("Cancel")); LogWriter.writeException(this, ex.getMessage(), ex); storage.setLastServerResponse(ex.toString()); } }
/** Called when activity is created */ public void onCreated() { try { // find ui elements on the form: tbTaxYearIncome = (TextView) this.getElementById(R.id.tbTaxYearIncome); tbTaxYearStats = (TextView) this.getElementById(R.id.tbTaxYearStats); tbTaxYearTax = (TextView) this.getElementById(R.id.tbTaxYearTax); tableTaxProgramManage = (ListView) this.getElementById(R.id.listViewTaxPayerProgramManage); btnCancel = (Button) this.getElementById(R.id.btnCancel); btnSubmit = (Button) this.getElementById(R.id.btnSubmit); btnCancel.setVisibility(View.GONE); // only when it was submitted first time btnSubmit.setVisibility(View.GONE); // only when there is anything to submit btnSubmit.setOnClickListener(submitClicked); btnCancel.setOnClickListener(cancelClicked); // tbTaxYearIncome = (ListView)this.getElementById(R.id.listViewTaxPayerYears); // lvTaxYearGrid.setOnItemClickListener( clickListener ); TaxPayerID = getIntent().getExtras().getInt(TaxYearStatsActivity.EXTRA_INT_TAX_PAYER_ID); TaxYearID = getIntent().getExtras().getInt(TaxYearStatsActivity.EXTRA_INT_TAX_YEAR_ID); YearValue = getIntent().getExtras().getInt(TaxYearStatsActivity.EXTRA_INT_TAX_YEAR_VALUE); // specify changes // lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items )); tbTaxYearStats.setText("Manage year: " + YearValue); } catch (Exception e) { DKDialog.ShowMessage( this, Translate.translate("Error"), Translate.translate("Loading default activitiy failed!"), Translate.translate("OK"), Translate.translate("Cancel")); LogWriter.writeException(this, e.getMessage(), e); } }
public void handleMessage(Message msg) { Bundle data = msg.getData(); if (data.containsKey("error")) { // error has occured - show it: DKDialog.ShowMessage( TaxProgramsManageActivity.this, Translate.translate("Error"), Translate.translate(data.getString("error")), Translate.translate("OK"), Translate.translate("Cancel")); removeDialog(typeBar); progThread.setState(ProgressThread.DONE); } else { // Get the current value of the variable total from the message data // and update the progress bar. int total = data.getInt("total"); progDialog.setProgress(total); if (total >= (maxBarValue)) { removeDialog(typeBar); progThread.setState(ProgressThread.DONE); presentResults(); try { recalculateTaxRate(); } catch (JSONException e) { DKDialog.ShowMessage( TaxProgramsManageActivity.this, Translate.translate("Error"), Translate.translate("Failed to recalculate tax rate!"), Translate.translate("OK"), Translate.translate("Cancel")); } } } }
public void onClick(View arg0) { if (btnCancel.getVisibility() == View.VISIBLE) { // Confirmation of existing programs try { for (int i = 0; i < array.length(); i++) { JSONObject object = (JSONObject) array.get(i); if (object.getInt("IsSelected") > 0) { // Get TaxPayer Income first: HTTPConnection connection = new HTTPConnection(storage.getServerURL()); JSONObject response = connection.connectJSON( Engine.ApproveProgramPrice( TaxYearID, TaxPayerID, object.getInt("ID"), object.getDouble("TaxRate"))); storage.setLastServerResponse(response.toString()); if (!response.getString("result").equals("OK")) { throw new Exception( "Invalid response from server = " + response.getString("data")); } // read results int result = (Integer) response.getInt("data"); } } Intent resultIntent = new Intent(); setResult(Activity.RESULT_OK, resultIntent); TaxProgramsManageActivity.this.finish(); /* DKDialog.ShowMessage( TaxProgramsManageActivity.this, Translate.translate("Thank you") , Translate.translate("All programs have been confirmed!"), Translate.translate("OK"), Translate.translate("Cancel")); */ } catch (Exception ex) { DKDialog.ShowMessage( TaxProgramsManageActivity.this, Translate.translate("Error"), Translate.translate("Connection failed: " + ex.getMessage()), Translate.translate("OK"), Translate.translate("Cancel")); LogWriter.writeException(TaxProgramsManageActivity.this, ex.getMessage(), ex); storage.setLastServerResponse(ex.toString()); } } else { // 1-st submit selected = new ArrayList<Integer>(); try { for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); if (object.getInt("IsSelected") > 0) { selected.add(object.getInt("ID")); } else { // clear the price object.put("TaxRate", 0.0); } } if (selected.size() == 0) { DKDialog.ShowMessage( TaxProgramsManageActivity.this, Translate.translate("Error"), Translate.translate("Nothing to submit, no programs selected!"), Translate.translate("OK"), Translate.translate("Cancel")); } else { typeBar = 1; showDialog(typeBar); } } catch (Exception ex) { DKDialog.ShowMessage( TaxProgramsManageActivity.this, Translate.translate("Error"), Translate.translate("Failed to count selected values! " + ex.getMessage()), Translate.translate("OK"), Translate.translate("Cancel")); LogWriter.writeException(TaxProgramsManageActivity.this, ex.getMessage(), ex); } } }