Ejemplo n.º 1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.fragment_sale_skidkaonline, container, false);
    setHasOptionsMenu(true);
    setRetainInstance(true);

    sale = getArguments().getParcelable(CURRENT_SALE_TAG);

    progressBar = (CircularProgressView) rootView.findViewById(R.id.fragment_sale_progressbar);
    imageView = (SubsamplingScaleImageView) rootView.findViewById(R.id.fragment_sale_imageview);
    imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM);
    imageView.setMaxScale(getResources().getDimension(R.dimen.image_maximum_scale));

    File smallFile = ImageLoader.getInstance().getDiskCache().get(sale.getSmallImageUrl());
    if (smallFile != null) {
      imageView.setImage(ImageSource.uri(smallFile.getAbsolutePath()));
      loadBigImage();
    } else {
      ImageLoader.getInstance()
          .loadImage(
              sale.getSmallImageUrl(),
              null,
              UIL.getScaleImageOptions(),
              new ImageLoadingListener() {
                @Override
                public void onLoadingStarted(String s, View view) {
                  progressBar.setVisibility(View.VISIBLE);
                }

                @Override
                public void onLoadingFailed(String s, View view, FailReason failReason) {
                  progressBar.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                  File smallFile =
                      ImageLoader.getInstance().getDiskCache().get(sale.getSmallImageUrl());
                  if (smallFile != null) {
                    imageView.setImage(ImageSource.uri(smallFile.getAbsolutePath()));
                  }
                  bitmap.recycle();
                  loadBigImage();
                }

                @Override
                public void onLoadingCancelled(String s, View view) {}
              },
              new ImageLoadingProgressListener() {
                @Override
                public void onProgressUpdate(String s, View view, int progress, int size) {
                  progressBar.setProgress(progress * 500 / size);
                }
              });
    }
    return rootView;
  }
  private void updateNotes() {
    if (position > notes.size() - 1) {
      return;
    }
    getActionBar().setSubtitle(notes.get(position).subtitle);
    ((TextView) findViewById(id.note)).setText(notes.get(position).text);
    findViewById(id.next)
        .setVisibility(position >= notes.size() - 1 ? View.INVISIBLE : View.VISIBLE);
    findViewById(id.previous).setVisibility(position <= 0 ? View.INVISIBLE : View.VISIBLE);

    SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) findViewById(id.imageView);
    if (position == 2) {
      imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_CENTER);
    } else {
      imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
    }
  }
Ejemplo n.º 3
0
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      final ViewGroup rootView =
          (ViewGroup) inflater.inflate(R.layout.submission_imagecard_album, container, false);

      String url;

      if (gallery) {
        url = ("https://imgur.com/" + user.getAsJsonObject().get("hash").getAsString() + ".png");

      } else {
        url = (user.getAsJsonObject().getAsJsonObject("links").get("original").getAsString());
      }

      final SubsamplingScaleImageView image =
          (SubsamplingScaleImageView) rootView.findViewById(R.id.image);
      TitleTextView title = (TitleTextView) rootView.findViewById(R.id.title);
      SpoilerRobotoTextView desc = (SpoilerRobotoTextView) rootView.findViewById(R.id.desc);
      ImageView fakeImage = new ImageView(getActivity());
      fakeImage.setLayoutParams(new LinearLayout.LayoutParams(image.getWidth(), image.getHeight()));
      fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);

      ((Reddit) getActivity().getApplication())
          .getImageLoader()
          .displayImage(
              url,
              new ImageViewAware(fakeImage),
              ImageLoaderUtils.options,
              new ImageLoadingListener() {
                private View mView;

                @Override
                public void onLoadingStarted(String imageUri, View view) {
                  mView = view;
                }

                @Override
                public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                  Log.v("Slide", "LOADING FAILED");
                }

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                  image.setImage(ImageSource.bitmap(loadedImage));
                  (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
                }

                @Override
                public void onLoadingCancelled(String imageUri, View view) {
                  Log.v("Slide", "LOADING CANCELLED");
                }
              },
              new ImageLoadingProgressListener() {
                @Override
                public void onProgressUpdate(String imageUri, View view, int current, int total) {
                  ((ProgressBar) rootView.findViewById(R.id.progress))
                      .setProgress(Math.round(100.0f * current / total));
                }
              });
      title.setVisibility(View.VISIBLE);
      desc.setVisibility(View.VISIBLE);
      if (user.getAsJsonObject().has("image")) {
        if (!user.getAsJsonObject().getAsJsonObject("image").get("title").isJsonNull()) {
          List<String> text =
              SubmissionParser.getBlocks(
                  user.getAsJsonObject().getAsJsonObject("image").get("title").getAsString());
          title.setTextHtml(text.get(0));
          if (desc.getText().toString().isEmpty()) {
            desc.setVisibility(View.GONE);
          }
        } else {
          desc.setVisibility(View.GONE);
        }

        if (!user.getAsJsonObject().getAsJsonObject("image").get("caption").isJsonNull()) {
          List<String> text =
              SubmissionParser.getBlocks(
                  user.getAsJsonObject().getAsJsonObject("image").get("caption").getAsString());
          title.setText(Html.fromHtml(text.get(0)));
          if (title.getText().toString().isEmpty()) {
            title.setVisibility(View.GONE);
          }
        } else {
          title.setVisibility(View.GONE);
        }
      } else {
        if (user.getAsJsonObject().has("title")) {
          List<String> text =
              SubmissionParser.getBlocks(user.getAsJsonObject().get("title").getAsString());
          title.setText(Html.fromHtml(text.get(0)));
          if (desc.getText().toString().isEmpty()) {
            desc.setVisibility(View.GONE);
          }
        } else {
          desc.setVisibility(View.GONE);
        }

        if (user.getAsJsonObject().has("description")) {
          List<String> text =
              SubmissionParser.getBlocks(user.getAsJsonObject().get("description").getAsString());
          title.setText(Html.fromHtml(text.get(0)));
          if (title.getText().toString().isEmpty()) {
            title.setVisibility(View.GONE);
          }
        } else {
          title.setVisibility(View.GONE);
        }
      }
      return rootView;
    }
  private void initialiseImage() {
    final SubsamplingScaleImageView imageView =
        (SubsamplingScaleImageView) findViewById(id.imageView);
    final GestureDetector gestureDetector =
        new GestureDetector(
            this,
            new GestureDetector.SimpleOnGestureListener() {
              @Override
              public boolean onSingleTapConfirmed(MotionEvent e) {
                if (imageView.isReady()) {
                  PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                  Toast.makeText(
                          getApplicationContext(),
                          "Single tap: " + ((int) sCoord.x) + ", " + ((int) sCoord.y),
                          Toast.LENGTH_SHORT)
                      .show();
                } else {
                  Toast.makeText(
                          getApplicationContext(),
                          "Single tap: Image not ready",
                          Toast.LENGTH_SHORT)
                      .show();
                }
                return true;
              }

              @Override
              public void onLongPress(MotionEvent e) {
                if (imageView.isReady()) {
                  PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                  Toast.makeText(
                          getApplicationContext(),
                          "Long press: " + ((int) sCoord.x) + ", " + ((int) sCoord.y),
                          Toast.LENGTH_SHORT)
                      .show();
                } else {
                  Toast.makeText(
                          getApplicationContext(),
                          "Long press: Image not ready",
                          Toast.LENGTH_SHORT)
                      .show();
                }
              }

              @Override
              public boolean onDoubleTap(MotionEvent e) {
                if (imageView.isReady()) {
                  PointF sCoord = imageView.viewToSourceCoord(e.getX(), e.getY());
                  Toast.makeText(
                          getApplicationContext(),
                          "Double tap: " + ((int) sCoord.x) + ", " + ((int) sCoord.y),
                          Toast.LENGTH_SHORT)
                      .show();
                } else {
                  Toast.makeText(
                          getApplicationContext(),
                          "Double tap: Image not ready",
                          Toast.LENGTH_SHORT)
                      .show();
                }
                return true;
              }
            });

    imageView.setImage(ImageSource.asset("squirrel.jpg"));
    imageView.setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent motionEvent) {
            return gestureDetector.onTouchEvent(motionEvent);
          }
        });
  }
 private void initialiseImage() {
   SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) findViewById(id.imageView);
   imageView.setImage(ImageSource.asset("squirrel.jpg"));
 }
Ejemplo n.º 6
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.submission_imagecard, container, false);

    final SubsamplingScaleImageView image =
        (SubsamplingScaleImageView) rootView.findViewById(R.id.image);
    TextView title = (TextView) rootView.findViewById(R.id.title);
    TextView desc = (TextView) rootView.findViewById(R.id.desc);

    title.setText(s.getTitle());
    desc.setText(s.getAuthor() + " " + TimeUtils.getTimeAgo(s.getCreatedUtc().getTime()));
    ContentType.ImageType type = ContentType.getImageType(s);

    String url;

    if (type.toString().toLowerCase().contains("image")) {
      addClickFunctions(image, rootView, type, getActivity(), s);

      url = ContentType.getFixedUrl(s.getUrl());
      ((Reddit) getContext().getApplicationContext())
          .getImageLoader()
          .loadImage(
              url,
              new SimpleImageLoadingListener() {

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                  image.setImage(ImageSource.bitmap(loadedImage));
                }
              });
    } else if (s.getDataNode().has("preview")
        && s.getDataNode().get("preview").get("images").get(0).get("source").has("height")
        && s.getDataNode().get("preview").get("images").get(0).get("source").get("height").asInt()
            > 200) {

      url = s.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
      ((Reddit) getContext().getApplicationContext())
          .getImageLoader()
          .loadImage(
              url,
              new SimpleImageLoadingListener() {

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                  image.setImage(ImageSource.bitmap(loadedImage));
                }
              });

    } else {
      addClickFunctions(image, rootView, type, getActivity(), s);
      Log.v("Slide", "NO IMAGE");
      image.recycle();
    }

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (Reddit.tabletUI
                    && getActivity().getResources().getConfiguration().orientation
                        == Configuration.ORIENTATION_LANDSCAPE) {
                  Intent i2 = new Intent(getActivity(), CommentsScreenPopup.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);

                } else {
                  Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);
                }
              }
            });
    return rootView;
  }