summaryrefslogtreecommitdiff
path: root/org.fox.ttrss/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'org.fox.ttrss/src/main/java/org')
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPager.java39
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java50
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java33
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/util/EnlargingImageView.java260
-rw-r--r--org.fox.ttrss/src/main/java/org/fox/ttrss/util/ForegroundImageView.java121
5 files changed, 34 insertions, 469 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPager.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPager.java
deleted file mode 100644
index 62522775..00000000
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPager.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.fox.ttrss;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.View;
-
-import it.sephiroth.android.library.imagezoom.ImageViewTouch;
-
-public class ArticleImagesPager extends android.support.v4.view.ViewPager {
- public ArticleImagesPager(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- @Override
- protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
- if (v instanceof ImageViewTouch) {
- ImageViewTouch ivt = (ImageViewTouch) v;
- try {
- return ivt.canScroll(dx);
- } catch (NullPointerException e) {
- // bad image, etc
- return false;
- }
- } else {
- return super.canScroll(v, checkV, dx, x, y);
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- return super.onTouchEvent(event);
- }
-
- @Override
- public boolean onInterceptTouchEvent(MotionEvent event) {
- return super.onInterceptTouchEvent(event);
- }
-} \ No newline at end of file
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java
index 1e33b559..e58cdc5c 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java
@@ -22,10 +22,12 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
+import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import com.ToxicBakery.viewpager.transforms.DepthPageTransformer;
+import com.bogdwellers.pinchtozoom.ImageMatrixTouchHandler;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
@@ -42,10 +44,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
-import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import me.relex.circleindicator.CircleIndicator;
-public class ArticleImagesPagerActivity extends CommonActivity implements GestureDetector.OnDoubleTapListener {
+public class ArticleImagesPagerActivity extends CommonActivity {
private final String TAG = this.getClass().getSimpleName();
private ArrayList<String> m_urls;
@@ -53,25 +54,9 @@ public class ArticleImagesPagerActivity extends CommonActivity implements Gestur
private String m_title;
private ArticleImagesPagerAdapter m_adapter;
private String m_content;
- private GestureDetector m_detector;
private ProgressBar m_progress;
private ViewPager m_pager;
- @Override
- public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
- return false;
- }
-
- @Override
- public boolean onDoubleTap(MotionEvent motionEvent) {
- return false;
- }
-
- @Override
- public boolean onDoubleTapEvent(MotionEvent motionEvent) {
- return false;
- }
-
private class ArticleImagesPagerAdapter extends PagerAdapter {
private List<String> m_urls;
@@ -101,21 +86,11 @@ public class ArticleImagesPagerActivity extends CommonActivity implements Gestur
View view = inflater.inflate(R.layout.article_images_image, null);
- m_detector = new GestureDetector(ArticleImagesPagerActivity.this, new GestureDetector.SimpleOnGestureListener());
+ ImageView imgView = (ImageView) view.findViewById(R.id.flavor_image);
- m_detector.setOnDoubleTapListener(ArticleImagesPagerActivity.this);
+ ImageMatrixTouchHandler touchHandler = new ImageMatrixTouchHandler(view.getContext());
- ImageViewTouch imgView = (ImageViewTouch) view.findViewById(R.id.flavor_image);
-
- imgView.setFitToScreen(true);
- //imgView.setFitToWidth(true);
-
- imgView.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent event) {
- return m_detector.onTouchEvent(event);
- }
- });
+ imgView.setOnTouchListener(touchHandler);
// shared element transitions stop GIFs from playing
if (position == 0 && url.toLowerCase().indexOf(".gif") == -1) {
@@ -174,10 +149,6 @@ public class ArticleImagesPagerActivity extends CommonActivity implements Gestur
})
.into(glideImage);
- /*if (position == 0) {
- ActivityCompat.startPostponedEnterTransition(ArticleImagesPagerActivity.this);
- }*/
-
return view;
}
@@ -196,15 +167,6 @@ public class ArticleImagesPagerActivity extends CommonActivity implements Gestur
if (!isCancelled()) {
position++;
- //Log.d(TAG, "checking: " + url);
-
- /*DisplayImageOptions options = new DisplayImageOptions.Builder()
- .cacheInMemory(true)
- .cacheOnDisk(true)
- .build();
-
- Bitmap bmp = ImageLoader.getInstance().loadImageSync(url, options); */
-
try {
Bitmap bmp = Glide.with(ArticleImagesPagerActivity.this)
.load(url)
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java
index 3bea1665..69f2b728 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java
@@ -1312,12 +1312,16 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
@Override
public void onClick(View view) {
- if (m_mediaPlayer != null) {
- m_mediaPlayer.release();
- }
+ try {
+ if (m_mediaPlayer != null) {
+ m_mediaPlayer.release();
+ }
- if (m_activeSurface != null) {
- m_activeSurface.setVisibility(View.GONE);
+ if (m_activeSurface != null) {
+ m_activeSurface.setVisibility(View.GONE);
+ }
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
}
m_mediaPlayer = new MediaPlayer();
@@ -1807,4 +1811,23 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
m_articles.addAll(articles);
m_adapter.notifyDataSetChanged();
}
+
+ @Override
+ public void onPause() {
+ super.onPause();
+
+ try {
+ if (m_mediaPlayer != null) {
+ m_mediaPlayer.release();
+ }
+
+ if (m_activeSurface != null) {
+ m_activeSurface.setVisibility(View.GONE);
+ }
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+
+ }
+
}
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/EnlargingImageView.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/EnlargingImageView.java
deleted file mode 100644
index 0f419a4c..00000000
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/EnlargingImageView.java
+++ /dev/null
@@ -1,260 +0,0 @@
-package org.fox.ttrss.util;
-
-/*
- * Copyright (C) 2013 Tomáš Procházka
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.View;
-
-import java.lang.reflect.Field;
-
-/**
- * Special version of ImageView which allow enlarge width of image if android:adjustViewBounds is true.
- *
- * <p>It simulate HTML behaviour &lt;img src="" widh="100" /&gt;</p>
- * <p><a href="http://stackoverflow.com/questions/6202000/imageview-one-dimension-to-fit-free-space-and-second-evaluate-to-keep-aspect-rati">Stackoverflow question link</a></p>
- *
- * <p>It also allow set related view which will be used as reference for size measure.</p>
- *
- * @author Tomáš Procházka &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;
- * @version $Revision: 0$ ($Date: 6.6.2011 18:16:52$)
- */
-public class EnlargingImageView extends ForegroundImageView {
-
- private int mDrawableWidth;
- private int mDrawableHeight;
- private boolean mAdjustViewBoundsL;
- private int mMaxWidthL = Integer.MAX_VALUE;
- private int mMaxHeightL = Integer.MAX_VALUE;
- private View relatedView;
-
- public EnlargingImageView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- // hack for acces some private field of parent :-(
- Field f;
- try {
- f = android.widget.ImageView.class.getDeclaredField("mAdjustViewBounds");
- f.setAccessible(true);
- setAdjustViewBounds((Boolean) f.get(this));
-
- f = android.widget.ImageView.class.getDeclaredField("mMaxWidth");
- f.setAccessible(true);
- setMaxWidth((Integer) f.get(this));
-
- f = android.widget.ImageView.class.getDeclaredField("mMaxHeight");
- f.setAccessible(true);
- setMaxHeight((Integer) f.get(this));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public EnlargingImageView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public EnlargingImageView(Context context) {
- super(context);
- }
-
- public void setAdjustViewBounds(boolean adjustViewBounds) {
- super.setAdjustViewBounds(adjustViewBounds);
- mAdjustViewBoundsL = adjustViewBounds;
- }
-
- public void setMaxWidth(int maxWidth) {
- super.setMaxWidth(maxWidth);
- mMaxWidthL = maxWidth;
- }
-
- public void setMaxHeight(int maxHeight) {
- super.setMaxHeight(maxHeight);
- mMaxHeightL = maxHeight;
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-
- if (getDrawable() == null) {
- setMeasuredDimension(0, 0);
- return;
- }
-
- mDrawableWidth = getDrawable().getIntrinsicWidth();
- mDrawableHeight = getDrawable().getIntrinsicHeight();
-
- int w = 0;
- int h = 0;
-
- // Desired aspect ratio of the view's contents (not including padding)
- float desiredAspect = 0.0f;
-
- // We are allowed to change the view's width
- boolean resizeWidth = false;
-
- // We are allowed to change the view's height
- boolean resizeHeight = false;
-
- if (mDrawableWidth > 0) {
- w = mDrawableWidth;
- h = mDrawableHeight;
- if (w <= 0) w = 1;
- if (h <= 0) h = 1;
-
- // We are supposed to adjust view bounds to match the aspect
- // ratio of our drawable. See if that is possible.
- if (mAdjustViewBoundsL) {
-
- int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
- int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
-
- resizeWidth = widthSpecMode != MeasureSpec.EXACTLY;
- resizeHeight = heightSpecMode != MeasureSpec.EXACTLY;
-
- desiredAspect = (float) w / (float) h;
- }
- }
-
- int pleft = getPaddingLeft();
- int pright = getPaddingRight();
- int ptop = getPaddingTop();
- int pbottom = getPaddingBottom();
-
- int widthSize;
- int heightSize;
-
- if (resizeWidth || resizeHeight) {
- /* If we get here, it means we want to resize to match the
- drawables aspect ratio, and we have the freedom to change at
- least one dimension.
- */
-
- // Get the max possible width given our constraints
- widthSize = resolveAdjustedSize(w + pleft + pright,
- mMaxWidthL, widthMeasureSpec);
-
- // Get the max possible height given our constraints
- heightSize = resolveAdjustedSize(h + ptop + pbottom,
- mMaxHeightL, heightMeasureSpec);
-
- if (desiredAspect != 0.0f) {
- // See what our actual aspect ratio is
- float actualAspect = (float) (widthSize - pleft - pright) /
- (heightSize - ptop - pbottom);
-
- if (Math.abs(actualAspect - desiredAspect) > 0.0000001) {
-
- // Try adjusting width to be proportional to height
- if (resizeWidth) {
- int newWidth = (int) (desiredAspect * (heightSize - ptop - pbottom)) + pleft + pright;
-
- if (newWidth > 0 && widthSize > 0 && newWidth / widthSize > 2)
- newWidth = widthSize * 2;
-
- if (/*newWidth <= widthSize &&*/ newWidth > 0) {
- widthSize = Math.min(newWidth, mMaxWidthL);
- heightSize = (int) ((widthSize - pleft - pright) / desiredAspect) + ptop + pbottom;
- }
- }
-
- // Try adjusting height to be proportional to width
- if (resizeHeight) {
- int newHeight = (int) ((widthSize - pleft - pright) / desiredAspect) + ptop + pbottom;
-
- if (newHeight > 0 && heightSize > 0 && newHeight / heightSize > 2)
- newHeight = heightSize * 2;
-
- if (/* newHeight <= heightSize && */ newHeight > 0) {
- heightSize = Math.min(newHeight, mMaxHeightL);
- widthSize = (int) (desiredAspect * (heightSize - ptop - pbottom)) + pleft + pright;
- }
- }
- }
- }
- } else {
- /* We are either don't want to preserve the drawables aspect ratio,
- or we are not allowed to change view dimensions. Just measure in
- the normal way.
- */
- w += pleft + pright;
- h += ptop + pbottom;
-
- w = Math.max(w, getSuggestedMinimumWidth());
- h = Math.max(h, getSuggestedMinimumHeight());
-
- widthSize = resolveSize(w, widthMeasureSpec);
- heightSize = resolveSize(h, heightMeasureSpec);
- }
-
- //Log.d(Constants.LOGTAG, mDrawableWidth + ":" + mDrawableHeight + " to " + widthSize + ":" + heightSize);
-
- setMeasuredDimension(widthSize, heightSize);
-
- if (relatedView != null) {
- //Log.i(Constants.LOGTAG, getTag() + " onMeasure:" + widthSize + ", " + heightSize + " update size of related view!");
- relatedView.getLayoutParams().width = widthSize;
- relatedView.getLayoutParams().height = heightSize;
- }
-
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- super.onLayout(changed, left, top, right, bottom);
- //Log.d(Constants.LOGTAG, getTag() + " onLayout:" + left + ", " + top + ", " + right + ", " + bottom);
- }
-
- /**
- * Experimental. This view will be set to the same size as this image.
- */
- public void setRelatedView(View view) {
- relatedView = view;
- }
-
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- //Log.d(Constants.LOGTAG, getTag() + " onSizeChanged:" + w + ", " + h + ", " + oldw + ", " + oldh);
- }
-
- private int resolveAdjustedSize(int desiredSize, int maxSize, int measureSpec) {
- int result = desiredSize;
- int specMode = MeasureSpec.getMode(measureSpec);
- int specSize = MeasureSpec.getSize(measureSpec);
- switch (specMode) {
- case MeasureSpec.UNSPECIFIED:
- /* Parent says we can be as big as we want. Just don't be larger
- than max size imposed on ourselves.
- */
- result = Math.min(desiredSize, maxSize);
- break;
- case MeasureSpec.AT_MOST:
- // Parent says we can be as big as we want, up to specSize.
- // Don't be larger than specSize, and don't be larger than
- // the max size imposed on ourselves.
- result = Math.min(Math.min(desiredSize, specSize), maxSize);
- break;
- case MeasureSpec.EXACTLY:
- // No choice. Do what we are told.
- result = specSize;
- break;
- }
- return result;
- }
-} \ No newline at end of file
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/ForegroundImageView.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/util/ForegroundImageView.java
deleted file mode 100644
index f02158e9..00000000
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/util/ForegroundImageView.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package org.fox.ttrss.util;
-
-// https://gist.github.com/JakeWharton/0a251d67649305d84e8a
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
-import android.util.AttributeSet;
-import android.widget.ImageView;
-
-import org.fox.ttrss.R;
-
-public class ForegroundImageView extends ImageView {
- private Drawable foreground;
-
- public ForegroundImageView(Context context) {
- this(context, null);
- }
-
- public ForegroundImageView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public ForegroundImageView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundImageView);
- Drawable foreground = a.getDrawable(R.styleable.ForegroundImageView_android_foreground);
- if (foreground != null) {
- setForeground(foreground);
- }
- a.recycle();
- }
-
- /**
- * Supply a drawable resource that is to be rendered on top of all of the child
- * views in the frame layout.
- *
- * @param drawableResId The drawable resource to be drawn on top of the children.
- */
- public void setForegroundResource(int drawableResId) {
- setForeground(getContext().getResources().getDrawable(drawableResId));
- }
-
- /**
- * Supply a Drawable that is to be rendered on top of all of the child
- * views in the frame layout.
- *
- * @param drawable The Drawable to be drawn on top of the children.
- */
- public void setForeground(Drawable drawable) {
- if (foreground == drawable) {
- return;
- }
- if (foreground != null) {
- foreground.setCallback(null);
- unscheduleDrawable(foreground);
- }
-
- foreground = drawable;
-
- if (drawable != null) {
- drawable.setCallback(this);
- if (drawable.isStateful()) {
- drawable.setState(getDrawableState());
- }
- }
- requestLayout();
- invalidate();
- }
-
- @Override protected boolean verifyDrawable(Drawable who) {
- return super.verifyDrawable(who) || who == foreground;
- }
-
- @Override public void jumpDrawablesToCurrentState() {
- super.jumpDrawablesToCurrentState();
- if (foreground != null) foreground.jumpToCurrentState();
- }
-
- @Override protected void drawableStateChanged() {
- super.drawableStateChanged();
- if (foreground != null && foreground.isStateful()) {
- foreground.setState(getDrawableState());
- }
- }
-
- @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- if (foreground != null) {
- foreground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
- invalidate();
- }
- }
-
- @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- if (foreground != null) {
- foreground.setBounds(0, 0, w, h);
- invalidate();
- }
- }
-
- @Override public void draw(Canvas canvas) {
- super.draw(canvas);
-
- if (foreground != null) {
- foreground.draw(canvas);
- }
- }
-
- @Override public void drawableHotspotChanged(float x, float y) {
- super.drawableHotspotChanged(x, y);
-
- if (foreground != null && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- foreground.setHotspot(x, y);
- }
- }
-} \ No newline at end of file