@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    m_context = MainActivity.this;

    m_btnSelectImage = (Button) findViewById(R.id.btn_image);
    m_btnTakePhoto = (Button) findViewById(R.id.btn_photo);
    m_ivImage = (ImageView) findViewById(R.id.ivCardView);
    m_absolutelayout = (AbsoluteLayout) findViewById(R.id.relative1);
    m_llTopLayout = (LinearLayout) findViewById(R.id.llBottomLayout);
    m_arrSignObjects = new ArrayList<ViewsVo>();

    // Set the layout parameters to the Absolute layout for adding images.
    RelativeLayout.LayoutParams rl_pr =
        new LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    rl_pr.addRule(RelativeLayout.ABOVE, R.id.llBottomLayout);
    rl_pr.addRule(RelativeLayout.BELOW, R.id.layout_title);

    m_absolutelayout.setLayoutParams(rl_pr);

    m_screen = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    m_DisplayWidth = m_screen.getWidth();
    m_AddedViewsHeightText = m_llTopLayout.getHeight();

    // Get the absoulte layout height according to the device screen density
    // to set the layout.
    m_vtoTree = m_absolutelayout.getViewTreeObserver();
    m_vtoTree.addOnGlobalLayoutListener(
        new OnGlobalLayoutListener() {

          @Override
          public void onGlobalLayout() {

            m_absHeight = m_absolutelayout.getHeight();
            m_absolutelayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
        });

    m_dialog = new Dialog(this, R.style.Dialog);
    m_dialog.setCancelable(true);

    m_btnSelectImage.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            //                Intent i = new Intent(
            //                        Intent.ACTION_PICK,
            //
            // android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            //                startActivityForResult(i, 0);

            m_bitmap = null;

            Uri selectedImages = resIdToUri(m_context, R.drawable.mario);

            System.err.println("Image Path =====>" + selectedImages.getPath());
            m_bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mario);
            getImageLayout(m_bitmap);
          }
        });

    m_btnTakePhoto.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            // Launch camera
            // create new Intent
            intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); // create a file to save the video
            intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
            intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, fileUri.toString());
            intent.putExtra(
                MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high

            // start the Video Capture Intent
            startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
          }
        });
  }
  /**
   * Method to add the image by setting and creating the views dynamically with delete and zoom
   * option.
   */
  @SuppressWarnings("deprecation")
  private void getImageLayout(Bitmap p_bitmap) {
    ViewsVo m_signVo;
    // Check for images count .Set the count for limiting the number of images to add on screen.
    if (m_ImageCount < 1) {
      m_viewsAddedHeightEmotions = m_viewsAddedHeightEmotions + 90;
      m_ImageCount++;
    } /*
       * else { Toast.makeText(m_context, "No enough space for images.",
       * Toast.LENGTH_LONG).show(); }
       */
    m_btnSDeleteImage = new Button(m_context);
    m_btnZoom = new Button(m_context);
    m_ivtmpImage = new ImageView(m_context);

    setViewsHeightDynamically();
    // System.err.println("Height of Layout------" + m_absHeight);
    m_btnSDeleteImage.setLayoutParams(m_layoutparamsDelete);
    m_btnSDeleteImage.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_deletered));
    m_btnSDeleteImage.setId(0);
    m_btnSDeleteImage.setOnClickListener(new ImageDeleteListener());

    m_btnZoom.setLayoutParams(m_layoutParamsEdit);
    m_btnZoom.setBackgroundDrawable(getResources().getDrawable(R.drawable.right_arrow));
    m_btnZoom.setId(0);

    m_absTextlayout = new AbsoluteLayout(m_context);
    m_absZoomlayout = new AbsoluteLayout(m_context);
    m_ivtmpImage.setImageBitmap(Bitmap.createScaledBitmap(p_bitmap, 400, 180, true));
    m_absTextlayout.setLayoutParams(
        new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            0,
            0));
    m_absZoomlayout.setLayoutParams(
        new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            0,
            0));

    if (m_absHeight >= 900) m_ivtmpImage.setLayoutParams(new FrameLayout.LayoutParams(400, 200));
    else m_ivtmpImage.setLayoutParams(new FrameLayout.LayoutParams(80, 80));

    m_ivtmpImage.setBackgroundColor(Color.TRANSPARENT);
    m_absTextlayout.addView(m_btnSDeleteImage);
    if (m_absHeight >= 900) m_absZoomlayout.setPadding(0, 0, 0, 0);
    else m_absZoomlayout.setPadding(0, 0, 0, 0);

    m_absZoomlayout.setBackgroundResource(R.drawable.dashedbordersmall);
    m_absZoomlayout.addView(m_ivtmpImage);

    m_absTextlayout.addView(m_absZoomlayout);
    m_absTextlayout.addView(m_btnZoom);
    m_absTextlayout.setDrawingCacheEnabled(true);
    m_absTextlayout.setClickable(true);
    m_absTextlayout.setId(0);
    m_ivtmpImage.setId(0);

    m_vtoTree = m_absTextlayout.getViewTreeObserver();
    m_vtoTree.addOnGlobalLayoutListener(
        new OnGlobalLayoutListener() {

          @Override
          public void onGlobalLayout() {
            m_absTextlayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
        });

    /**
     * Add all the views into arraylist which are added into the screen for further to perform
     * deletion of each views.
     */
    m_signVo = new ViewsVo();
    m_arrSignObjects.add(0, m_signVo);
    m_absolutelayout.addView(m_absTextlayout);

    // Image touch listener to move image onTouch event on screen.
    m_touchImagListener =
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                m_oldX = event.getX();
                m_oldY = event.getY();
                break;
              case MotionEvent.ACTION_UP:

              case MotionEvent.ACTION_POINTER_UP:
                break;

              case MotionEvent.ACTION_MOVE:
                m_dX = event.getX() - m_oldX;
                m_dY = event.getY() - m_oldY;

                m_posX = m_prevX + m_dX;
                m_posY = m_prevY + m_dY;

                if (m_posX > 0
                    && m_posY > 0
                    && (m_posX + v.getWidth()) < m_absolutelayout.getWidth()
                    && (m_posY + v.getHeight()) < m_absolutelayout.getHeight()) {
                  v.setLayoutParams(
                      new AbsoluteLayout.LayoutParams(
                          v.getMeasuredWidth(), v.getMeasuredHeight(), (int) m_posX, (int) m_posY));

                  m_prevX = m_posX;
                  m_prevY = m_posY;
                }
                break;
            }
            return false;
          }
        };

    // Listener for the arrow ontouch of arrow ZoomIn and ZoomOut the image.
    m_strecthArrowListener =
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            View view;
            // RemoveBorders();
            view = v;
            v.setClickable(true);
            v.setDrawingCacheEnabled(true);
            AbsoluteLayout m_absLayout = null;
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                m_oldX = event.getX();
                m_oldY = event.getY();
                break;
              case MotionEvent.ACTION_UP:

              case MotionEvent.ACTION_POINTER_UP:
                break;

              case MotionEvent.ACTION_MOVE:
                m_newX = event.getX();
                m_newY = event.getY();

                float newDist = m_newX - m_oldX;
                if (m_newX > m_oldX && m_newY > m_oldY) {
                  if (newDist > 0.0f) {
                    m_scale = 1;
                    m_absLayout = (AbsoluteLayout) v.getParent();
                    int m_hightOfImage =
                        (int)
                            (m_scale
                                + (((ImageView)
                                        ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                    .getHeight()));
                    int m_widthOfImage =
                        (int)
                            (m_scale
                                + (((ImageView)
                                        ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                    .getWidth()));
                    m_widthDelete =
                        (int)
                            (m_scale + ((((AbsoluteLayout) m_absLayout.getChildAt(1))).getWidth()));
                    m_heightDelete =
                        (int)
                            (m_scale
                                + ((((AbsoluteLayout) m_absLayout.getChildAt(1)).getHeight())));
                    if (m_absLayout.getBottom() <= (m_ivImage.getBottom())
                        && m_absLayout.getRight() <= (m_DisplayWidth)) {
                      m_layoutparams =
                          new AbsoluteLayout.LayoutParams(m_widthOfImage, m_hightOfImage, 0, 0);
                      ((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                          .setLayoutParams(m_layoutparams);

                      m_layoutparams =
                          new AbsoluteLayout.LayoutParams(
                              AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                              AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                              m_absLayout.getLeft(),
                              m_absLayout.getTop());
                      m_absLayout.setLayoutParams(m_layoutparams);
                      ((Button) m_absLayout.getChildAt(0))
                          .setLayoutParams(
                              new AbsoluteLayout.LayoutParams(
                                  m_deleteEditHeightwidth,
                                  m_deleteEditHeightwidth,
                                  m_widthDelete,
                                  0));
                      ((Button) m_absLayout.getChildAt(2))
                          .setLayoutParams(
                              new AbsoluteLayout.LayoutParams(
                                  m_deleteEditHeightwidth,
                                  m_deleteEditHeightwidth,
                                  m_widthDelete,
                                  m_heightDelete));

                      m_hightOfImage =
                          (int)
                              (m_scale
                                  + (((AbsoluteLayout) m_absLayout.getChildAt(1)).getHeight()));
                      m_widthOfImage =
                          (int)
                              (m_scale + (((AbsoluteLayout) m_absLayout.getChildAt(1)).getWidth()));
                      m_layoutparams =
                          new AbsoluteLayout.LayoutParams(
                              m_widthOfImage,
                              m_hightOfImage,
                              ((AbsoluteLayout) m_absLayout.getChildAt(1)).getLeft(),
                              ((AbsoluteLayout) m_absLayout.getChildAt(1)).getTop());
                      ((AbsoluteLayout) m_absLayout.getChildAt(1)).setLayoutParams(m_layoutparams);
                    }
                  }
                }
                if (m_newX < m_oldX && m_newY < m_oldY) {
                  m_absLayout = (AbsoluteLayout) view.getParent();

                  int m_hightOfImage =
                      (int)
                          (((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                  .getHeight()
                              - m_scale);
                  int m_widthOfImage =
                      (int)
                          (((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                                  .getWidth()
                              - m_scale);

                  m_widthDelete =
                      (int) (((AbsoluteLayout) m_absLayout.getChildAt(1)).getWidth() - m_scale);
                  m_layoutparams =
                      new AbsoluteLayout.LayoutParams(m_widthOfImage, m_hightOfImage, 0, 0);
                  ((ImageView) ((AbsoluteLayout) m_absLayout.getChildAt(1)).getChildAt(0))
                      .setLayoutParams(m_layoutparams);

                  m_layoutparams =
                      new AbsoluteLayout.LayoutParams(
                          AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                          AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                          m_absLayout.getLeft(),
                          m_absLayout.getTop());
                  m_absLayout.setLayoutParams(m_layoutparams);

                  ((Button) m_absLayout.getChildAt(0))
                      .setLayoutParams(
                          new AbsoluteLayout.LayoutParams(
                              m_deleteEditHeightwidth, m_deleteEditHeightwidth, m_widthDelete, 0));
                  ((Button) m_absLayout.getChildAt(2))
                      .setLayoutParams(
                          new AbsoluteLayout.LayoutParams(
                              m_deleteEditHeightwidth,
                              m_deleteEditHeightwidth,
                              m_widthDelete,
                              m_widthDelete));

                  m_hightOfImage =
                      (int) ((((AbsoluteLayout) m_absLayout.getChildAt(1)).getHeight()) - m_scale);
                  m_widthOfImage =
                      (int) ((((AbsoluteLayout) m_absLayout.getChildAt(1)).getWidth()) - m_scale);
                  m_layoutparams =
                      new AbsoluteLayout.LayoutParams(
                          m_widthOfImage,
                          m_hightOfImage,
                          ((AbsoluteLayout) m_absLayout.getChildAt(1)).getLeft(),
                          ((AbsoluteLayout) m_absLayout.getChildAt(1)).getTop());
                  ((AbsoluteLayout) m_absLayout.getChildAt(1)).setLayoutParams(m_layoutparams);
                }

                break;
            }

            return false;
          }
        };
    m_absTextlayout.setOnTouchListener(m_touchImagListener);
    m_btnZoom.setOnTouchListener(m_strecthArrowListener);
  }