@Override
        public void onClick(View paramView) {
          String errorMessage = "";
          int litres = 0;

          try {
            // Leave breadcrumb.
            CrashReporter.leaveBreadcrumb("Trip_Stock_Load: onOK");

            // Check for product.
            if (product == null) {
              errorMessage = "Please select a product";
              return;
            }

            // Check loaded quantity.
            try {
              litres = decimalFormat.parse(etLoaded.getText().toString()).intValue();
            } catch (ParseException e) {
              e.printStackTrace();
            }

            if (litres <= 0) {
              errorMessage = "Litres missing";
              return;
            }

            // Update stock locally.
            Active.vehicle.recordLoad(product, litres);

            // Update stock on server.
            trip.sendVehicleStock();

            // Reset UI.
            etLoaded.setText("");

            // Notify user.
            Toast t = Toast.makeText(trip, litres + " loaded", Toast.LENGTH_SHORT);
            t.setGravity(Gravity.CENTER, 0, 0);
            t.show();
          } catch (Exception e) {
            CrashReporter.logHandledException(e);
          } finally {
            // Show error message?
            if (errorMessage.length() > 0) {
              Toast t = Toast.makeText(trip, errorMessage, Toast.LENGTH_SHORT);
              t.setGravity(Gravity.CENTER, 0, 0);
              t.show();
            }
          }
        }
  @SuppressLint("SetTextI18n")
  @Override
  public boolean resumeView() {
    try {
      CrashReporter.leaveBreadcrumb("Trip_Stock_Load: resumeView");

      // Clear product.
      product = null;

      // Load products.
      products = dbProduct.getAllMeteredAndNonMetered();

      // Resume updating.
      infoview.resume();

      // Clear litres & focus.
      etLoaded.setText("");
      etLoaded.requestFocus();

      // Reset buttons.
      btnOK.setEnabled(false);
      btnCancel.setText("Close");
      btnCancel.setEnabled(true);

      // Make sure that the required products Hashtable is populated
      getRequiredProducts();

      // Make sure that the stock levels Hashtable is populated
      getStockLevels();

      return true;
    } catch (Exception e) {
      CrashReporter.logHandledException(e);
      return false;
    }
  }
        @Override
        public void onClick(View paramView) {
          try {
            // Leave breadcrumb.
            CrashReporter.leaveBreadcrumb("Trip_Stock_Load: onCancel");

            if (btnCancel.getText().equals("Close")) {
              // Close view.
              btnCancel.setEnabled(false);

              // Switch back to previous view.
              trip.selectView(previousViewName, -1);
            } else {
              // Cancel input.
              etLoaded.setText("");
            }
          } catch (Exception e) {
            CrashReporter.logHandledException(e);
          }
        }
  private void init(Context context) {
    try {
      // Leave breadcrumb.
      CrashReporter.leaveBreadcrumb("Trip_Stock_Load: init");

      // Store reference to Trip activity.
      trip = (Trip) context;

      // Setup a standard decimal format.
      decimalFormat = new DecimalFormat("#,##0");

      // Inflate layout.
      LayoutInflater inflater =
          (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      inflater.inflate(R.layout.trip_stock_load, this, true);

      // Find UI controls.
      infoview = (MyInfoView1Line) this.findViewById(R.id.trip_stock_load_infoview);

      etLoaded = (MyEditText) this.findViewById(R.id.trip_stock_load_litres);

      tvProduct = (TextView) this.findViewById(R.id.trip_stock_load_product);

      Button btnChange = (Button) this.findViewById(R.id.trip_stock_load_change);

      btnOK = (Button) this.findViewById(R.id.trip_stock_load_ok);

      btnCancel = (Button) this.findViewById(R.id.trip_stock_load_cancel);

      etLoaded.addTextChangedListener(onLitresChanged);

      btnChange.setOnClickListener(onChange);
      btnOK.setOnClickListener(onOK);
      btnCancel.setOnClickListener(onCancel);
    } catch (Exception e) {
      CrashReporter.logHandledException(e);
    }
  }
  private void validate() {
    try {
      CrashReporter.leaveBreadcrumb("Trip_Stock_Load: validate");

      int litres = 0;

      // Check if value is valid.
      try {
        String text = etLoaded.getText().toString();

        if (text.length() > 0) {
          litres = decimalFormat.parse(text).intValue();
        }
      } catch (ParseException e) {
        e.printStackTrace();
      }

      btnOK.setEnabled(litres > 0);
      btnCancel.setText(litres > 0 ? "Cancel" : "Close");
    } catch (Exception e) {
      CrashReporter.logHandledException(e);
    }
  }