예제 #1
0
 @Override
 public void setImageURI(Uri uri) {
   super.setImageURI(uri);
   if (null != mAttacher) {
     mAttacher.update();
   }
 }
예제 #2
0
 @Override
 public void setImageResource(int resId) {
   super.setImageResource(resId);
   if (null != mAttacher) {
     mAttacher.update();
   }
 }
예제 #3
0
 @Override
 protected boolean setFrame(int l, int t, int r, int b) {
   boolean changed = super.setFrame(l, t, r, b);
   if (null != mAttacher) {
     mAttacher.update();
   }
   return changed;
 }
예제 #4
0
 @Override
 // setImageBitmap calls through to this method
 public void setImageDrawable(Drawable drawable) {
   super.setImageDrawable(drawable);
   if (null != mAttacher) {
     mAttacher.update();
   }
 }
예제 #5
0
  @Override
  public void setScaleType(ScaleType scaleType) {
    if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
      mScaleType = scaleType;

      // Finally update
      update();
    }
  }
예제 #6
0
 private void setupPhotoAttacher() {
   mPhotoViewAttacher = new PhotoViewAttacher(mImageView);
   mPhotoViewAttacher.setOnViewTapListener(
       new PhotoViewAttacher.OnViewTapListener() {
         @Override
         public void onViewTap(View view, float v, float v1) {
           onBackPressed();
         }
       });
   mPhotoViewAttacher.update();
 }
  @Override
  public void initialize() {
    loadBitmapFromTemporaryStorage();

    mImageView.setImageBitmap(babeBitMap);

    // The MAGIC happens here!
    mAttacher = new PhotoViewAttacher(mImageView);

    mAttacher.update();
  }
  @Override
  public void setZoomable(boolean zoomable) {
    mZoomEnabled = zoomable;
    update();

    View v = getImageView();

    if (!zoomable && v != null) {
      ViewParent parent = v.getParent();
      if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(false);
      }
    }
  }
예제 #9
0
 @Override
 public void setZoomable(boolean zoomable) {
   mZoomEnabled = zoomable;
   update();
 }
예제 #10
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
예제 #11
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);
      }
    }
  }
예제 #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_r);
    toolbar.setTitleTextColor(getResources().getColor(R.color.white));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");
    InstagramDatum instagramDatum =
        new Gson().fromJson(getIntent().getStringExtra(Constants.INSTA_DATA), InstagramDatum.class);
    mImageView = (ImageView) findViewById(R.id.image_view);
    final LinearLayout imageDataLinearLayout =
        (LinearLayout) findViewById(R.id.image_data_linear_layout);
    TextView imageUserTextView = (TextView) findViewById(R.id.image_user_text_view);
    TextView imageLikeTextView = (TextView) findViewById(R.id.image_like_text_view);
    TextView imageCommentTextView = (TextView) findViewById(R.id.image_comment_text_view);
    final ProgressBar imageProgressBar = (ProgressBar) findViewById(R.id.image_progress_bar);

    Picasso.with(getApplicationContext())
        .load(instagramDatum.getImages().getStandardResolution().getUrl())
        .into(
            mImageView,
            new Callback() {
              @Override
              public void onSuccess() {
                imageProgressBar.setVisibility(View.GONE);
              }

              @Override
              public void onError() {
                setContentView(R.layout.no_connection_layout);
                imageProgressBar.setVisibility(View.GONE);
              }
            });
    imageCommentTextView.setText("" + instagramDatum.getComments().getCount());
    imageLikeTextView.setText("" + instagramDatum.getLikes().getCount());
    imageUserTextView.setText("@" + instagramDatum.getUser().getUsername());

    mImageView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Animation fadeOutAnimation =
                AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation_fade_out);
            Animation fadeInAnimation =
                AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation_fade_in);
            if (isVisible) {
              imageDataLinearLayout.startAnimation(fadeOutAnimation);
              imageDataLinearLayout.setVisibility(View.GONE);
              getSupportActionBar().hide();
            } else {

              imageDataLinearLayout.startAnimation(fadeInAnimation);
              imageDataLinearLayout.setVisibility(View.VISIBLE);
              getSupportActionBar().show();
            }
            isVisible = !isVisible;
          }
        });

    PhotoViewAttacher photoViewAttacher = new PhotoViewAttacher(mImageView);
    photoViewAttacher.update();
  }