Exemplo n.º 1
0
  @Override
  public void onClick(View view) {

    if (view.getId() == productName.getId()) {
      Bundle bundle = new Bundle();
      bundle.putString("selectedJobNo", productName.getText().toString());
      Fragment productIssue = new F_ProductIssue();
      productIssue.setArguments(bundle);
      ((A_Entry) getActivity()).transferTo(productIssue, true);
    } else if (view.getId() == jobCompany.getId()) {
      Bundle bundle = new Bundle();
      bundle.putString("comName", jobCompany.getText().toString());
      Fragment companyDetails = new F_CompanyDetails();
      companyDetails.setArguments(bundle);
      ((A_Entry) getActivity()).transferTo(companyDetails, true);
    } else if (view.getId() == btn_photo.getId()) {
      try {
        ((BitmapDrawable) image_preview.getDrawable()).getBitmap().recycle();
      } catch (NullPointerException e) {

      }
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      // fileURI = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
      fileURI = getImageUri();
      intent.putExtra(MediaStore.EXTRA_OUTPUT, fileURI); // set the image file name
      startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    } else if (view.getId() == btn_postpone.getId()) {
      for (int i = 0; i < jobStatusItem.length; i++)
        if (jobStatusItem[i].equals("postponed")) {
          jobStatus.setSelection(i);
          DatabaseView.exec(
              "UPDATE ServiceJob SET jobStatus = 'postponed' WHERE jobNo ='"
                  + jobNo.getText().toString()
                  + "'");
          Toast.makeText(
                  getActivity(), "Successful change the status to postpone!", Toast.LENGTH_SHORT)
              .show();
        }
    } else if (view.getId() == btn_cancelJob.getId()) {
      for (int i = 0; i < jobStatusItem.length; i++)
        if (jobStatusItem[i].equals("cancelled")) {
          jobStatus.setSelection(i);
          DatabaseView.exec(
              "UPDATE ServiceJob SET jobStatus = 'cancelled' WHERE jobNo ='"
                  + jobNo.getText().toString()
                  + "'");
          Toast.makeText(
                  getActivity(), "Successful change the status to cancel!", Toast.LENGTH_SHORT)
              .show();
        }
    } else if (view.getId() == btn_viewImage.getId()) {

      final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
      final ImageView iv = new ImageView(getActivity());

      try {
        final Bitmap bm = convertJPG(getImageUri());
        if (bm == null) return;
        iv.setImageBitmap(bm);
        ab.setView(iv);
        ab.setPositiveButton(
            "OK",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {}
            });
        ab.show();
      } catch (OutOfMemoryError e) {
        try {
          ((BitmapDrawable) iv.getDrawable()).getBitmap().recycle();
          Toast.makeText(getActivity(), "Sorry, try again", Toast.LENGTH_SHORT).show();
          e.printStackTrace();
        } catch (Exception ee) {

        }
      }

    } else if (view.getId() == btn_viewSign.getId()) {
      final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
      final ImageView iv = new ImageView(getActivity());
      try {
        final Bitmap bm = _signView.loadFromStorage(getActivity(), getSignViewFileName());
        if (bm == null) return;
        iv.setImageBitmap(bm);
        ab.setView(iv);
        ab.setPositiveButton(
            "OK",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {}
            });
        ab.show();
      } catch (OutOfMemoryError e) {
        try {
          ((BitmapDrawable) iv.getDrawable()).getBitmap().recycle();
          Toast.makeText(getActivity(), "Sorry, try again", Toast.LENGTH_SHORT).show();
          e.printStackTrace();
        } catch (Exception ee) {

        }
      }
    }
  }