1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
package org.fox.ttrss;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
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;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
import com.bumptech.glide.request.target.Target;
public class ArticleImageFragment extends GalleryBaseFragment {
private final String TAG = this.getClass().getSimpleName();
String m_url;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_article_image, container, false);
if (savedInstanceState != null) {
m_url = savedInstanceState.getString("url");
}
Log.d(TAG, "called for URL: " + m_url);
ImageView imgView = (ImageView) view.findViewById(R.id.flavor_image);
ImageMatrixTouchHandler touchHandler = new ImageMatrixTouchHandler(view.getContext());
imgView.setOnTouchListener(touchHandler);
// shared element transitions stop GIFs from playing
if (m_url.toLowerCase().indexOf(".gif") == -1) {
ViewCompat.setTransitionName(imgView, "gallery:" + m_url);
}
//registerForContextMenu(imgView);
view.findViewById(R.id.flavor_image_overflow).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(getContext(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.context_article_content_img, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return onImageMenuItemSelected(item, m_url);
}
});
popup.show();
}
});
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.flavor_image_progress);
final View errorMessage = view.findViewById(R.id.flavor_image_error);
final GlideDrawableImageViewTarget glideImage = new GlideDrawableImageViewTarget(imgView);
Glide.with(this)
.load(m_url)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(false)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
errorMessage.setVisibility(View.VISIBLE);
ActivityCompat.startPostponedEnterTransition(m_activity);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
errorMessage.setVisibility(View.GONE);
ActivityCompat.startPostponedEnterTransition(m_activity);
return false;
}
})
.into(glideImage);
return view;
}
public void initialize(String url) {
m_url = url;
}
/*@Override
public boolean onContextItemSelected(MenuItem item) {
int position = m_pager.getCurrentItem();
String url = m_checkedUrls.get(position);
if (!onImageMenuItemSelected(item, url))
return super.onContextItemSelected(item);
else
return true;
}*/
@Override
public void onSaveInstanceState (Bundle out) {
super.onSaveInstanceState(out);
out.setClassLoader(getClass().getClassLoader());
out.putString("url", m_url);
}
}
|