Commit 9eaf35db authored by DNLDsht's avatar DNLDsht

gif viewer

improved photo full size view?
fixer jibe reported bug [select single album]
parent 9ece7d38
......@@ -9,7 +9,8 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
android:largeHeap="true">
<activity android:name=".IntroActivity"
android:label="Intro Activity"
......
......@@ -14,6 +14,7 @@ import android.widget.ListView;
import android.widget.TextView;
import com.leafpic.app.Base.Photo;
import com.leafpic.app.Fragments.GifFragment;
import com.leafpic.app.Fragments.ImageFragment;
import com.leafpic.app.R;
......@@ -27,6 +28,7 @@ public class MediaPagerAdapter extends FragmentPagerAdapter {
ArrayList<Photo> photos;
View.OnTouchListener listener;
public void setOnTouchListener(View.OnTouchListener l){ listener = l; }
public MediaPagerAdapter(FragmentManager fm, ArrayList<Photo> photos) {
......@@ -38,9 +40,15 @@ public class MediaPagerAdapter extends FragmentPagerAdapter {
public Fragment getItem(int pos) {
Photo p = photos.get(pos);
ImageFragment fragment = ImageFragment.newInstance(p.Path,300,300);
fragment.setOnTouchListener(listener);
return fragment;
if (p.isGif()){
GifFragment fragment = GifFragment.newInstance(p.Path);
fragment.setOnTouchListener(listener);
return fragment;
} else {
ImageFragment fragment = ImageFragment.newInstance(p.Path, 300, 300);
fragment.setOnTouchListener(listener);
return fragment;
}
}
@Override
......
......@@ -45,15 +45,13 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
Photo f = photos.get(position);
Glide.clear(holder.imageView);//fix corruption
if (f.MIME.equals("image/gif")) {
if (f.isGif()) {
Ion.with(holder.imageView.getContext())
.load(f.Path)
.intoImageView(holder.imageView);
holder.gifIcon.setVisibility(View.VISIBLE);
} else {
holder.gifIcon.setVisibility(View.INVISIBLE);
Glide.with(holder.imageView.getContext())
.load(f.Path)
.asBitmap()
......@@ -91,7 +89,7 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
public void removeItemAt(int pos) {
//Log.wtf("asdasd",getItemCount()+"");
photos.remove(pos);
// photos.remove(pos);
//notifyItemRemoved(pos);
//Log.wtf("asdasd",getItemCount()+"");
// notifyDataSetChanged();
......
......@@ -521,7 +521,7 @@ public class AlbumsActivity extends AppCompatActivity /*implements FolderChooser
@Override
public boolean onLongClick(View v) {
TextView a = (TextView) v.findViewById(R.id.album_name);
adapt.notifyItemChanged(albums.selectAlbum(a.getTag().toString(), true));
adapt.notifyItemChanged(albums.toggleSelectAlbum(a.getTag().toString()));
editmode = true;
invalidateOptionsMenu();
return true;
......
......@@ -24,6 +24,11 @@ public class Photo implements Parcelable {
public String FolderPath;
boolean selected = false;
public boolean isGif(){
if(MIME.equals("image/gif")) return true;
return false;
}
public Photo(String path) {
Path = path;
}
......
package com.leafpic.app.Fragments;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.koushikdutta.ion.Ion;
import com.leafpic.app.R;
/**
* Created by dnld on 18/02/16.
*/
public class GifFragment extends Fragment {
// Store instance variables
ImageView picture;
private String path;
private View.OnTouchListener onTouchListener;
// newInstance constructor for creating fragment with arguments
public static GifFragment newInstance(String path) {
GifFragment fragmentFirst = new GifFragment();
Bundle args = new Bundle();
args.putString("path", path);
fragmentFirst.setArguments(args);
return fragmentFirst;
}
public void setOnTouchListener(View.OnTouchListener l){ onTouchListener = l;}
// Store instance variables based on arguments passed
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
path = getArguments().getString("path");
}
// Inflate the view for the fragment based on layout XML
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.gif_pager_layout, container, false);
picture = (ImageView) view.findViewById(R.id.media_view);
Ion.with(getContext())
.load(path)
.intoImageView(picture);
picture.setOnTouchListener(onTouchListener);
return view;
}
}
\ No newline at end of file
package com.leafpic.app.Fragments;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
......@@ -30,6 +31,8 @@ public class ImageFragment extends Fragment {
private String path;
private int width;
private int height;
SubsamplingScaleImageView picture;
private View.OnTouchListener onTouchListener;
// newInstance constructor for creating fragment with arguments
......@@ -55,94 +58,63 @@ public class ImageFragment extends Fragment {
height = getArguments().getInt("height", 300);
path = getArguments().getString("path");
}
int times=0;
@Override
public void onDestroy(){
picture.recycle();
super.onDestroy();
}
// int times=0;
// Inflate the view for the fragment based on layout XML
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.image_pager_item, container, false);
final SubsamplingScaleImageView picture = (SubsamplingScaleImageView) view.findViewById(R.id.media_view);
// if (picture!=null)
// Glide.clear(picture);
picture = (SubsamplingScaleImageView) view.findViewById(R.id.media_view);
Glide.with(container.getContext())
.load(path)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
//.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.IMMEDIATE)
.dontAnimate()
.override(width, height)
.listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
if (!isFromMemoryCache) {
Log.e("ViewerPager", "Image not from cache:" + model + " " + target.toString());
} else {
Log.e("ViewerPager", "Image from cache:" + model + " " + target.toString());
}
return false;
}
})
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
times++;
//TODO load full image size when starting zooming
picture.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
@Override
public void onReady() {
// times++;
//picture.setImage(ImageSource.bitmap(BitmapFactory.decodeFile(path)));
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void onImageLoaded() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (times == 1)
Glide.with(getContext())
.load(path)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.IMMEDIATE)
public void run() {
//final BitmapFactory.Options options = new BitmapFactory.Options();
//options.inJustDecodeBounds = true;
//Log.wtf("asdasdasdasdas","fulllllllll");
// Glide.get(getActivity()).clearDiskCache();
Glide.get(getActivity()).clearMemory();
Glide.with(getContext())
.load(path)
.asBitmap()
.skipMemoryCache(true)
//.skipMemoryCache(true)
.priority(Priority.IMMEDIATE)
//.diskCacheStrategy(DiskCacheStrategy.NONE)
.dontAnimate()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
times++;
}
}, 250);
}
@Override
public void onPreviewLoadError(Exception e) {
}
@Override
public void onImageLoadError(Exception e) {
}
@Override
public void onTileLoadError(Exception e) {
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
}
});
picture.setOnTouchListener(onTouchListener);
picture.setMaxScale(10);
return view;
......
......@@ -36,7 +36,7 @@ public class SelectAlbumActivity extends AppCompatActivity {
String photosIndexes;
boolean hidden=false;
int code;
HandlingPhotos p;//= new HandlingPhotos(SelectAlbumActivity.this);
HandlingPhotos p;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -48,8 +48,8 @@ public class SelectAlbumActivity extends AppCompatActivity {
photosIndexes = getIntent().getStringExtra("photos_indexes");
p = new HandlingPhotos(SelectAlbumActivity.this);
if (code == 69) setTitle("Move to");
else if (code == 23) setTitle("Copy to");
if (code == MOVE_TO_ACTION) setTitle("Move to");
else if (code == COPY_TO_ACTION) setTitle("Copy to");
setResult(Activity.RESULT_CANCELED);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
......@@ -89,7 +89,7 @@ public class SelectAlbumActivity extends AppCompatActivity {
}
private void loadAlbumPreview(){
if (hidden) albums.loadPreviewHiddenAlbums();
if (hidden) albums.loadPreviewHiddenAlbums();
else albums.loadPreviewAlbums();
hidden=!hidden;
......@@ -101,16 +101,20 @@ public class SelectAlbumActivity extends AppCompatActivity {
public void onClick(View v) {
TextView a = (TextView) v.findViewById(R.id.album_name);
String newAlbumPath = a.getTag().toString();
if (code == MOVE_TO_ACTION) {
Intent result = new Intent();
result.putExtra("photos_indexes", photosIndexes);
p.moveSelectedPhotos(photoPaths, newAlbumPath);
setResult(Activity.RESULT_OK, result);
}
if (code == COPY_TO_ACTION) {
Intent result = new Intent();
p.copySelectedPhotos(photoPaths, newAlbumPath);
setResult(Activity.RESULT_OK, result);
Intent result;
switch (code){
case MOVE_TO_ACTION:
result = new Intent();
result.putExtra("photos_indexes", photosIndexes);
p.moveSelectedPhotos(photoPaths, newAlbumPath);
setResult(Activity.RESULT_OK, result);
break;
case COPY_TO_ACTION:
result = new Intent();
p.copySelectedPhotos(photoPaths, newAlbumPath);
setResult(Activity.RESULT_OK, result);
break;
default: break;
}
finish();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment