Commit 59eb35cf authored by DNLDsht's avatar DNLDsht

fragment pager view

parent 6a6a3603
......@@ -46,19 +46,7 @@
</intent-filter>
</activity>
<activity android:name=".PhotoActivity"
android:label="Album"
android:parentActivityName=".PhotosActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".PhotosActivity"/>
<intent-filter>
<action android:name="android.intent.action.albumPhoto"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity"
<activity android:name=".PhotoPagerActivity"
android:label="Album"
android:parentActivityName=".PhotosActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
......
......@@ -51,7 +51,8 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
Album a = albums.get(position);
a.setPath();
Glide.clear(holder.picture);
//Glide.clear(holder.picture);
Glide.with(holder.picture.getContext())
.load(a.getPathCoverAlbum())
.asBitmap()
......
......@@ -23,18 +23,24 @@ import java.util.ArrayList;
* Created by dnld on 18/02/16.
*/
public class MyPagerAdapter extends FragmentPagerAdapter {
public class MediaPagerAdapter extends FragmentPagerAdapter {
ArrayList<Photo> photos;
View.OnTouchListener listener;
public void setOnTouchListener(View.OnTouchListener l){ listener = l; }
public MyPagerAdapter(FragmentManager fm, ArrayList<Photo> photos) {
public MediaPagerAdapter(FragmentManager fm, ArrayList<Photo> photos) {
super(fm);
this.photos=photos;
}
@Override
public Fragment getItem(int pos) {
return ImageFragment.newInstance(photos.get(pos).Path,0,0);
Photo p = photos.get(pos);
ImageFragment fragment = ImageFragment.newInstance(p.Path,300,300);
fragment.setOnTouchListener(listener);
return fragment;
}
@Override
......
package com.leafpic.app.Adapters;
import android.content.Context;
import android.graphics.Bitmap;
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.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.koushikdutta.ion.Ion;
import com.leafpic.app.Base.Photo;
import com.leafpic.app.R;
import java.util.ArrayList;
/**
* Created by dnld on 1/11/16.
*/
public class PhotosPagerAdapter extends android.support.v4.view.PagerAdapter {
Context mContext;
LayoutInflater mLayoutInflater;
ArrayList<Photo> mResources;
private View.OnClickListener onClickListener;
public PhotosPagerAdapter(Context context, ArrayList<Photo> ph) {
mContext = context;
mResources = ph;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setOnClickListener(View.OnClickListener ls) {
onClickListener = ls;
}
@Override
public int getCount() {
return mResources.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Photo f = mResources.get(position);
View itemView;
if (f.MIME.equals("image/gif")) {
itemView = mLayoutInflater.inflate(R.layout.gif_pager_layout, container, false);
ImageView picture = (ImageView) itemView.findViewById(R.id.media_view);
picture.setOnClickListener(onClickListener);
Ion.with(container.getContext())
.load(f.Path)
.intoImageView(picture);
} else {
itemView = mLayoutInflater.inflate(R.layout.image_pager_item, container, false);
final SubsamplingScaleImageView picture = (SubsamplingScaleImageView) itemView.findViewById(R.id.media_view);
Glide.with(container.getContext())
.load(mResources.get(position).Path)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
picture.setOnClickListener(onClickListener);
picture.setMaxScale(10);
}
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
\ No newline at end of file
package com.leafpic.app.Fragments;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
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.leafpic.app.MainActivity;
import com.leafpic.app.R;
import com.leafpic.app.utils.StringUtils;
/**
* Created by dnld on 18/02/16.
......@@ -29,6 +30,7 @@ public class ImageFragment extends Fragment {
private String path;
private int width;
private int height;
private View.OnTouchListener onTouchListener;
// newInstance constructor for creating fragment with arguments
public static ImageFragment newInstance(String path,int width,int height) {
......@@ -43,6 +45,8 @@ public class ImageFragment extends Fragment {
return fragmentFirst;
}
public void setOnTouchListener(View.OnTouchListener l){onTouchListener = l;}
// Store instance variables based on arguments passed
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -51,31 +55,95 @@ public class ImageFragment extends Fragment {
height = getArguments().getInt("height", 300);
path = getArguments().getString("path");
}
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.recycle();
Glide.with(container.getContext())
.load(path)
.asBitmap()
.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));
}
});
/* picture.setOnTouchListener(new View.OnTouchListener() {
times++;
//TODO load full image size when starting zooming
picture.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
@Override
public void onReady() {
}
@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)
.dontAnimate()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
picture.setImage(ImageSource.bitmap(bitmap));
}
});
times++;
}
}, 250);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
public void onPreviewLoadError(Exception e) {
}
@Override
public void onImageLoadError(Exception e) {
}
@Override
public void onTileLoadError(Exception e) {
}
});*/
});
picture.setOnTouchListener(onTouchListener);
picture.setMaxScale(10);
return view;
}
......
This diff is collapsed.
......@@ -7,15 +7,10 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
......@@ -24,8 +19,7 @@ import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import com.leafpic.app.Adapters.MyPagerAdapter;
import com.leafpic.app.Adapters.PhotosPagerAdapter;
import com.leafpic.app.Adapters.MediaPagerAdapter;
import com.leafpic.app.Animations.DepthPageTransformer;
import com.leafpic.app.Base.HandlingPhotos;
import com.leafpic.app.Base.Photo;
......@@ -37,11 +31,11 @@ import java.text.SimpleDateFormat;
/**
* Created by dnld on 18/02/16.
*/
public class MainActivity extends AppCompatActivity {
public class PhotoPagerActivity extends AppCompatActivity {
ViewPager mViewPager;
HandlingPhotos photos;
MyPagerAdapter adapter;
MediaPagerAdapter adapter;
Toolbar toolbar;
boolean fullscreenmode;
......@@ -55,41 +49,32 @@ public class MainActivity extends AppCompatActivity {
final GestureDetector gestureDetector = new GestureDetector(getApplicationContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
toggleSystemUI();
return true;
}
});
try {
Bundle data = getIntent().getExtras();
photos = data.getParcelable("album");
if(photos!=null)
photos.setContext(getApplicationContext());
mViewPager = (ViewPager) findViewById(R.id.photos_pager);
adapter = new MyPagerAdapter(getSupportFragmentManager(),photos.photos);
mViewPager.setAdapter(adapter);
mViewPager.setCurrentItem(photos.getCurrentPhotoIndex());
mViewPager.setPageTransformer(true, new DepthPageTransformer());
mViewPager.setOnTouchListener(new View.OnTouchListener() {
adapter = new MediaPagerAdapter(getSupportFragmentManager(),photos.photos);
adapter.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
mViewPager.setAdapter(adapter);
mViewPager.setCurrentItem(photos.getCurrentPhotoIndex());
mViewPager.setPageTransformer(true, new DepthPageTransformer());
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
@Override
public void onPageSelected(int position) {
......@@ -100,6 +85,7 @@ public class MainActivity extends AppCompatActivity {
public void onPageScrollStateChanged(int state) {
}
});
}catch (Exception e){e.printStackTrace();}
}
......@@ -252,7 +238,6 @@ public class MainActivity extends AppCompatActivity {
/**** ToolBar ********/
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(getColor(R.color.transparent_gray));
//setActionBar(toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
......@@ -260,12 +245,15 @@ public class MainActivity extends AppCompatActivity {
getWindow().setStatusBarColor(getColor(R.color.transparent_gray));
/**** Navigation Bar */
getWindow().setNavigationBarColor(getColor(R.color.transparent_gray));
final Handler handler = new Handler();
/*handler.postDelayed(new Runnable() {
handler.postDelayed(new Runnable() {
public void run() {
hideSystemUI();
}
}, 150);*/
}, 150);
}
public void toggleSystemUI() {
......
......@@ -11,14 +11,12 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.*;
import android.text.Html;
import android.text.InputType;
import android.transition.Slide;
import android.view.*;
import android.widget.ImageView;
......@@ -106,7 +104,7 @@ public class PhotosActivity extends AppCompatActivity {
invalidateOptionsMenu();
} else {
photos.setCurrentPhoto(is.getTag().toString());
Intent intent = new Intent(PhotosActivity.this, MainActivity.class);
Intent intent = new Intent(PhotosActivity.this, PhotoPagerActivity.class);
Bundle b = new Bundle();
b.putParcelable("album", photos);
intent.putExtras(b);
......
......@@ -7,7 +7,7 @@
android:layout_height="match_parent"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:orientation="vertical"
tools:context=".MainActivity"
tools:context=".PhotoPagerActivity"
android:background="@color/background_material_dark">
<LinearLayout
......
......@@ -2,7 +2,7 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@style/Theme.AppCompat"
android:theme="@style/ThemeOverlay.AppCompat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
......
......@@ -2,7 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
tools:context=".PhotoPagerActivity">
<item
android:id="@+id/endEditAlbumMode"
android:icon="@mipmap/ic_done_white_24dp"
......
......@@ -2,7 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
tools:context=".PhotoPagerActivity"
>
<!-- general Stuff -->
<!-- Albums Stuff -->
......
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