Exemplo n.º 1
0
 private void setUpPhotoAttacher() {
   mPhotoViewAttacher = new PhotoViewAttacher(mImageView);
   mPhotoViewAttacher.setOnViewTapListener((view, v, v1) -> hideOrShowToolbar());
   mPhotoViewAttacher.setOnLongClickListener(
       v -> {
         new AlertDialog.Builder(PictureActivity.this)
             .setMessage(getString(R.string.ask_saving_picture))
             .setNegativeButton(
                 android.R.string.cancel,
                 (dialog, which) -> {
                   dialog.dismiss();
                 })
             .setPositiveButton(
                 android.R.string.ok,
                 (dialog, which) -> {
                   saveImageToGallery();
                   dialog.dismiss();
                 })
             .show();
         return true;
       });
 }
Exemplo n.º 2
0
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    LinearLayout.LayoutParams lparams_img =
        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1000);
    lparams_img.gravity = Gravity.CENTER_HORIZONTAL;
    ImageKeepAspectRatio iv = new ImageKeepAspectRatio(this);
    iv.setLayoutParams(lparams_img);

    Log.d("QA_APP", "RETURN...");
    if (requestCode == 1) {
      if (resultCode == RESULT_OK) {

        // A LOT OF RE-WRITTEN CODE THAT MUST BE REFACTORED
        Log.d("QA_APP", "RETURN SUCCESS");
        questionDataLayout.removeViewAt(chooserIndex);
        Bitmap tempBitmap = PicUtil.loadFromCacheFile();

        iv.setImageBitmap(PicUtil.loadFromCacheFile());

        PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(iv);
        photoViewAttacher.setOnLongClickListener(questionItemLongClickListener);
        photoViewAttacher.setOnViewTapListener(
            new PhotoViewAttacher.OnViewTapListener() {
              @Override
              public void onViewTap(View view, float x, float y) {
                int index = questionDataLayout.indexOfChild(view);
                //                           scrollView.scrollTo(0,
                // questionDataLayout.getChildAt(index).getTop());

                // reset colors/boxes
                for (int i = 0; i < elements.size(); i++) {
                  circleIndex.get(i).setBorderColor(getResources().getColor(R.color.blue));
                  questionDataLayout.getChildAt(i).setBackground(null);
                }
                circleIndex.get(index).setBorderColor(Color.WHITE);
                // TODO: WORKAROUND FOR API 16 CALL BELOW
                questionDataLayout.getChildAt(index).setBackground(rectShapeDrawable);
                selectedIndex = index;
              }
            });
        photoViewAttacher.update();

        elements.add(new QData(tempBitmap));

        questionDataLayout.addView(iv);
        addElementCircles();
        createScrollView();
      }
      if (resultCode == RESULT_CANCELED) {
        Log.d("QA_APP", "RETURN FAIL");
      }
    } else if (requestCode == 2) {
      if (resultCode == RESULT_OK) {
        Uri selectedImage = data.getData();
        InputStream imageStream = null;
        try {
          imageStream = getContentResolver().openInputStream(selectedImage);
        } catch (FileNotFoundException e) {
          e.printStackTrace();
        }
        Bitmap selectedImg = BitmapFactory.decodeStream(imageStream);
        iv.setImageBitmap(selectedImg);
        PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(iv);
        photoViewAttacher.setOnLongClickListener(questionItemLongClickListener);
        photoViewAttacher.setOnViewTapListener(
            new PhotoViewAttacher.OnViewTapListener() {
              @Override
              public void onViewTap(View view, float x, float y) {
                int index = questionDataLayout.indexOfChild(view);
                //                           scrollView.scrollTo(0,
                // questionDataLayout.getChildAt(index).getTop());

                // reset colors/boxes
                for (int i = 0; i < elements.size(); i++) {
                  circleIndex.get(i).setBorderColor(getResources().getColor(R.color.blue));
                  questionDataLayout.getChildAt(i).setBackground(null);
                }
                circleIndex.get(index).setBorderColor(Color.WHITE);
                // TODO: WORKAROUND FOR API 16 CALL BELOW
                questionDataLayout.getChildAt(index).setBackground(rectShapeDrawable);
                selectedIndex = index;
              }
            });
        photoViewAttacher.update();

        elements.add(new QData(selectedImg));

        addElementCircles();
        createScrollView();
      }
    }
  } // onActivityResult
Exemplo n.º 3
0
  public void createScrollView() {
    // LayoutParams (Reuseable)
    LinearLayout.LayoutParams lparams_text =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout.LayoutParams lparams_img =
        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1000);

    RelativeLayout.LayoutParams rparams_text =
        new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams rparams_img =
        new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1000);

    lparams_text.gravity = Gravity.CENTER_HORIZONTAL;
    lparams_img.gravity = Gravity.CENTER_HORIZONTAL;

    if (questionDataLayout.getChildCount() != 0) {
      questionDataLayout.removeAllViewsInLayout();
    }
    QData data;
    for (int position = 0; position < elements.size(); position++) {
      data = elements.get(position);
      RelativeLayout rl = new RelativeLayout(getApplicationContext());

      if (data.isText()) {
        TextView tv = new TextView(this);
        tv.setLayoutParams(lparams_text);
        tv.setText(data.getText());
        tv.setTextSize(20);
        tv.setTextColor(Color.DKGRAY);
        tv.setOnClickListener(questionItemClickListener);
        tv.setOnLongClickListener(questionItemLongClickListener);
        rl.addView(tv, rparams_text);
        questionDataLayout.addView(rl, lparams_text);
      } else if (!data.isText()) {
        // ADD IMAGEVIEW
        ImageKeepAspectRatio iv = new ImageKeepAspectRatio(this);
        iv.setLayoutParams(lparams_img);
        iv.setImageBitmap(data.getImageBitmap());

        PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(iv);
        photoViewAttacher.setOnLongClickListener(questionItemLongClickListener);
        photoViewAttacher.setOnViewTapListener(
            new PhotoViewAttacher.OnViewTapListener() {
              @Override
              public void onViewTap(View view, float x, float y) {
                int index = questionDataLayout.indexOfChild(view);
                //                           scrollView.scrollTo(0,
                // questionDataLayout.getChildAt(index).getTop());

                // reset colors/boxes
                for (int i = 0; i < elements.size(); i++) {
                  circleIndex.get(i).setBorderColor(getResources().getColor(R.color.blue));
                  questionDataLayout.getChildAt(i).setBackground(null);
                }
                //                        circleIndex.get(index).setBorderColor(Color.WHITE);
                // TODO: WORKAROUND FOR API 16 CALL BELOW
                view.setBackground(rectShapeDrawable);
                selectedIndex = index;
              }
            });
        photoViewAttacher.update();

        rl.addView(iv, rparams_img);
        questionDataLayout.addView(rl, lparams_img);
      }
    }
  }
Exemplo n.º 4
0
 @Override
 public void setOnLongClickListener(OnLongClickListener l) {
   mAttacher.setOnLongClickListener(l);
 }