@Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_document_upload);
    super.initWidgets();
    mContext = this;
    documentBundle = getIntent().getExtras();

    documentList = new ArrayList<String>();
    ivBack.setVisibility(View.GONE);
    llPhotoRow = (LinearLayout) findViewById(R.id.llLicencingDocumentRow);
    textAddImage = (TextView) findViewById(R.id.tvAddImage);
    tvUpload = (TextView) findViewById(R.id.tvUpload);
    tvSkip = (TextView) findViewById(R.id.tvSkip);
    tvSkip.setVisibility(View.GONE);
    tvLicensingDocument = (TextView) findViewById(R.id.tvLicensingDocument);
    rlTopPoint = (RelativeLayout) findViewById(R.id.rlTopPoint);
    tvLicensingDocumentText = (TextView) findViewById(R.id.tvLicensingDocumentText);

    relProgress = (RelativeLayout) findViewById(R.id.rel_progress_sync);
    progressBar = (ProgressBar) findViewById(R.id.progress_sync);
    progressText = (TextView) findViewById(R.id.tv_progress);

    tvUpload.setText("Complete registration");

    progressText = (TextView) findViewById(R.id.tv_progress);

    txtEdit = (TextView) findViewById(R.id.tvEdit);
    txtEdit.setVisibility(View.GONE);
    if (((LinearLayout) llPhotoRow).getChildCount() > 0)
      ((LinearLayout) llPhotoRow).removeAllViews();

    if (AppValues.driverSettings != null && AppValues.driverSettings.getDriverDocuments() != null)
      szDriverDocument = AppValues.driverSettings.getDriverDocuments();

    if (AppValues.driverSettings != null
        && AppValues.driverSettings.getDriverDocumentsList() != null)
      szDriverDocumentsList = AppValues.driverSettings.getDriverDocumentsList();
    tvLicensingDocumentText.setText(" " + szDriverDocumentsList + " ");

    if (mContext != null) {
      szDriverDocument = Util.getDriverDocument(mContext);
      szDriverDocumentsList = Util.getDriverDocumentsList(mContext);
      if (!szDriverDocumentsList.toString().isEmpty())
        tvLicensingDocumentText.setText(" " + szDriverDocumentsList + " ");
    }

    if (documentBundle != null) {
      if (documentBundle.containsKey(Constants.FROM_REGISTRATION_COMPLETE)
          && documentBundle.getBoolean(Constants.FROM_REGISTRATION_COMPLETE)) {
        bIsFromRegistration = documentBundle.getBoolean(Constants.FROM_REGISTRATION_COMPLETE);
      }

      if (documentBundle.containsKey(Constants.FROM_EDIT_MY_ACC_VECHILE_DETAILS)) {
        isComingFromEditMyAccount =
            documentBundle.getBoolean(Constants.FROM_EDIT_MY_ACC_VECHILE_DETAILS);

        if (isComingFromEditMyAccount) {
          tvSkip.setVisibility(View.GONE);
          ivBack.setVisibility(View.VISIBLE);
          rlTopPoint.setVisibility(View.GONE);
          tvUpload.setText("Save");
          tvLicensingDocument.setText("* LICENSING DOCUMENT");

          AlertDialog PendingAlertDialog =
              new AlertDialog.Builder(mContext)
                  .setMessage(
                      "Adding or deleting documents will put your account in pending state.")
                  .setPositiveButton(
                      "OK",
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface argDialog, int argWhich) {}
                      })
                  .create();
          PendingAlertDialog.setCanceledOnTouchOutside(false);
          PendingAlertDialog.show();

          List<Document> documentDetails = AppValues.driverDetails.getDocument();

          if (AppValues.driverDetails != null
              && documentDetails != null
              && documentDetails.size() > 0) {
            for (int i = 0; i < documentDetails.size(); i++) {

              LayoutInflater inflater = LayoutInflater.from(getBaseContext());
              viewAddPhoto = inflater.inflate(R.layout.row_attached_files, null);

              TextView tvAttachedFileName =
                  (TextView) viewAddPhoto.findViewById(R.id.tvAttachedFileName);
              // TextView tvFileSize = (TextView) viewAddPhoto
              // .findViewById(R.id.tvFileSize);

              ImageView ivCancel = (ImageView) viewAddPhoto.findViewById(R.id.ivCancel);
              ImageView ivThumbnail = (ImageView) viewAddPhoto.findViewById(R.id.ivThumbnail);

              ImageLoader.getInstance()
                  .displayImage(documentDetails.get(i).getThumbnail(), ivThumbnail);

              if (Constants.isDebug)
                Log.e(
                    "DocumentUploadActivity", "Filename:: " + documentDetails.get(i).getFilename());
              tvAttachedFileName.setText(documentDetails.get(i).getFilename());
              // tvFileSize.setText("");// + " kb"

              DocumentDetails details = new DocumentDetails();
              details.szFilePath = "";
              details.view = viewAddPhoto;
              details.szDocumentID = documentDetails.get(i).getId();
              documentList.add(details.szDocumentID);
              ivCancel.setTag(details);

              ivCancel.setOnClickListener(
                  new OnClickListener() {

                    @Override
                    public void onClick(final View v) {
                      // TODO Auto-generated method stub
                      AlertDialog.Builder builder =
                          new AlertDialog.Builder(DocumentUploadActivity.this);
                      builder
                          .setMessage("Are you sure you want to delete document?")
                          .setCancelable(false)
                          .setPositiveButton(
                              getString(android.R.string.ok),
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                  DeleteDocumentTask deleteTask = new DeleteDocumentTask();
                                  deleteTask.documentView = v;
                                  deleteTask.execute();
                                }
                              })
                          .setNegativeButton(
                              getString(android.R.string.cancel),
                              new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                  dialog.cancel();
                                }
                              });
                      builder.setTitle("Alert");
                      AlertDialog alert = builder.create();
                      alert.show();
                    }
                  });

              llPhotoRow.addView(viewAddPhoto);
            }
          }
        }
      }
    }
    tvSkip.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
            // Intent tutorialIntent = new Intent(mContext,
            // TutorialActivity.class);
            // startActivity(tutorialIntent);
          }
        });

    textAddImage.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            int maxUpload = 0;
            maxUpload = Integer.valueOf(szDriverDocument);
            if (llPhotoRow.getChildCount() < maxUpload) {

              AlertDialog.Builder builder = new AlertDialog.Builder(DocumentUploadActivity.this);
              builder.setItems(R.array.add_image_options_upload_documents, mDialogListener);
              AlertDialog dialog = builder.create();
              dialog.show();
            } else {
              Util.showToastMessage(
                  DocumentUploadActivity.this,
                  "Maximum document limit is " + maxUpload,
                  Toast.LENGTH_LONG);
            }
          }
        });

    tvUpload.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            // code for upload
            if (isComingFromEditMyAccount) { // tvUpload.getText().equals("Save")

              if (llPhotoRow.getChildCount() <= 0 && documentList.size() <= 0) {

                Util.showToastMessage(
                    mContext, "Please upload a document first", Toast.LENGTH_LONG);

              } else {
                UploadDocument();

                // final Dialog dialog = new Dialog(mContext,
                // R.style.mydialogstyle);
                // dialog.setContentView(R.layout.confirmation_dialog);
                // dialog.setCanceledOnTouchOutside(false);
                // // dialog.setTitle("Alert!!");
                // dialog.setCancelable(false);
                // dialog.show();
                //
                // TextView tvAlertText = (TextView) dialog
                // .findViewById(R.id.tvAlertText);
                // tvAlertText.setText("");
                // textYes = (TextView) dialog.findViewById(R.id.tvYes);
                // textNo = (TextView) dialog.findViewById(R.id.tvNo);
                // textNo.setOnClickListener(new OnClickListener() {
                //
                // @Override
                // public void onClick(View v) {
                // // TODO Auto-generated method stub
                // dialog.dismiss();
                // }
                // });
                // textYes.setOnClickListener(new OnClickListener() {
                //
                // @Override
                // public void onClick(View v) {
                // // TODO Auto-generated method stub
                // dialog.dismiss();
                // UploadDocument();
                // }
                // });
              }
            } else {
              UploadDocument();
            }
          }
        });
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    String imagePath = "";
    String fileName = "";
    long file_size = 0;
    if (resultCode == RESULT_OK) {
      if (requestCode == TAKE_PHOTO_REQUEST) {
        // camera picture
        imagePath = cameraFile.getPath();
        file_size = Integer.parseInt(String.valueOf(cameraFile.length() / 1024));
        if (Constants.isDebug) Log.i(TAG, "Camera Path::>  " + imagePath);

      } else if (requestCode == PICK_PHOTO_REQUEST) {
        // gallery
        Uri selectedImageUri = intent.getData();
        imagePath = getPath(selectedImageUri);
        if (Constants.isDebug) Log.i(TAG, "Gallery Path::>  " + imagePath);

        // File galleryFile = new File(imagePath);
        // file_size = Integer.parseInt(String.valueOf(galleryFile
        // .length() / 1024));

        if (imagePath != null
            && (imagePath.endsWith("mp4")
                || imagePath.endsWith("wmv")
                || imagePath.endsWith("avi"))) {
          Util.showToastMessage(
              DocumentUploadActivity.this, "Video file not supported!", Toast.LENGTH_LONG);
          return;
        }
      }

      if (documentList == null) documentList = new ArrayList<String>();

      if (documentList != null
          && documentList.size() > 0
          && documentList.get(0) != null
          && !documentList.get(0).contains("/")) documentList.clear();

      fileName = extractFileNameFromString(imagePath);

      // Adding new row:
      LayoutInflater inflater = LayoutInflater.from(getBaseContext());
      viewAddPhoto = inflater.inflate(R.layout.row_attached_files, null);

      TextView tvAttachedFileName = (TextView) viewAddPhoto.findViewById(R.id.tvAttachedFileName);
      // TextView tvFileSize = (TextView) viewAddPhoto
      // .findViewById(R.id.tvFileSize);

      ImageView ivCancel = (ImageView) viewAddPhoto.findViewById(R.id.ivCancel);
      ImageView ivThumbnail = (ImageView) viewAddPhoto.findViewById(R.id.ivThumbnail);

      ImageLoader.getInstance().displayImage("file://" + imagePath, ivThumbnail);

      DocumentDetails details = new DocumentDetails();
      details.szFilePath = imagePath;
      details.view = viewAddPhoto;

      ivCancel.setTag(details);

      ivCancel.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              DocumentDetails details = (DocumentDetails) v.getTag();
              llPhotoRow.removeView(details.view);
              documentList.remove(details.szFilePath);
            }
          });

      tvAttachedFileName.setText(fileName);
      // if (file_size > 0) {
      // tvFileSize.setText(String.valueOf(file_size) + " kb");
      // } else {
      // tvFileSize.setText("0 kb");
      // }

      llPhotoRow.addView(viewAddPhoto);
      documentList.add(imagePath);

    } else if (resultCode != RESULT_CANCELED) {
      Util.showToastMessage(mContext, "Sorry, there was an error", Toast.LENGTH_LONG);
    }
  }