diff --git a/picture_library/src/main/java/com/luck/picture/lib/PictureExternalPreviewActivity.java b/picture_library/src/main/java/com/luck/picture/lib/PictureExternalPreviewActivity.java index 3970490df..6e548b386 100644 --- a/picture_library/src/main/java/com/luck/picture/lib/PictureExternalPreviewActivity.java +++ b/picture_library/src/main/java/com/luck/picture/lib/PictureExternalPreviewActivity.java @@ -42,7 +42,7 @@ import com.luck.picture.lib.tools.SdkVersionUtils; import com.luck.picture.lib.tools.ToastUtils; import com.luck.picture.lib.tools.ValueOf; -import com.luck.picture.lib.widget.PreviewViewPager; +import com.luck.picture.lib.widget.viewpager.PreviewViewPager; import com.luck.picture.lib.widget.longimage.ImageSource; import com.luck.picture.lib.widget.longimage.ImageViewState; import com.luck.picture.lib.widget.longimage.SubsamplingScaleImageView; diff --git a/picture_library/src/main/java/com/luck/picture/lib/PicturePreviewActivity.java b/picture_library/src/main/java/com/luck/picture/lib/PicturePreviewActivity.java index ae3b747ed..eb382d0ef 100644 --- a/picture_library/src/main/java/com/luck/picture/lib/PicturePreviewActivity.java +++ b/picture_library/src/main/java/com/luck/picture/lib/PicturePreviewActivity.java @@ -28,7 +28,7 @@ import com.luck.picture.lib.tools.ToastUtils; import com.luck.picture.lib.tools.ValueOf; import com.luck.picture.lib.tools.VoiceUtils; -import com.luck.picture.lib.widget.PreviewViewPager; +import com.luck.picture.lib.widget.viewpager.PreviewViewPager; import com.yalantis.ucrop.UCrop; import com.yalantis.ucrop.model.CutInfo; diff --git a/picture_library/src/main/java/com/luck/picture/lib/PictureSelectorActivity.java b/picture_library/src/main/java/com/luck/picture/lib/PictureSelectorActivity.java index 4e6aa2ddb..335389014 100644 --- a/picture_library/src/main/java/com/luck/picture/lib/PictureSelectorActivity.java +++ b/picture_library/src/main/java/com/luck/picture/lib/PictureSelectorActivity.java @@ -81,6 +81,7 @@ public class PictureSelectorActivity extends PictureBaseActivity implements View mTvMusicStatus, mTvMusicTotal, mTvMusicTime; protected RecyclerView mPictureRecycler; protected RelativeLayout mBottomLayout; + protected RelativeLayout mRlAlbum; protected PictureImageGridAdapter mAdapter; protected List images = new ArrayList<>(); protected List foldersList = new ArrayList<>(); @@ -155,6 +156,7 @@ protected void initWidgets() { mTvPictureImgNum = findViewById(R.id.picture_tv_img_num); mPictureRecycler = findViewById(R.id.picture_recycler); mBottomLayout = findViewById(R.id.rl_bottom); + mRlAlbum = findViewById(R.id.rlAlbum); mTvEmpty = findViewById(R.id.tv_empty); isNumComplete(numComplete); if (!numComplete) { @@ -168,8 +170,7 @@ protected void initWidgets() { mTvPictureRight.setOnClickListener(this); mTvPictureOk.setOnClickListener(this); mTvPictureImgNum.setOnClickListener(this); - mTvPictureTitle.setOnClickListener(this); - mIvArrow.setOnClickListener(this); + mRlAlbum.setOnClickListener(this); String title = config.chooseMode == PictureMimeType.ofAudio() ? getString(R.string.picture_all_audio) : getString(R.string.picture_camera_roll); mTvPictureTitle.setText(title); @@ -545,7 +546,7 @@ public void onClick(View v) { onBackPressed(); } } - if (id == R.id.picture_title || id == R.id.ivArrow) { + if (id == R.id.rlAlbum) { if (folderWindow.isShowing()) { folderWindow.dismiss(); } else { diff --git a/picture_library/src/main/java/com/luck/picture/lib/widget/FolderPopWindow.java b/picture_library/src/main/java/com/luck/picture/lib/widget/FolderPopWindow.java index d40d3b961..ba16124fa 100644 --- a/picture_library/src/main/java/com/luck/picture/lib/widget/FolderPopWindow.java +++ b/picture_library/src/main/java/com/luck/picture/lib/widget/FolderPopWindow.java @@ -12,10 +12,6 @@ import android.widget.PopupWindow; import android.widget.RelativeLayout; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - import com.luck.picture.lib.R; import com.luck.picture.lib.adapter.PictureAlbumDirectoryAdapter; import com.luck.picture.lib.config.PictureSelectionConfig; @@ -28,6 +24,10 @@ import java.util.List; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + /** * @author:luck * @date:2017-5-25 17:02 @@ -56,7 +56,7 @@ public FolderPopWindow(Context context, PictureSelectionConfig config) { this.setContentView(window); this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT); this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT); - this.setAnimationStyle(R.style.PictureThemeWindowStyle); + this.setAnimationStyle(R.style.PictureGradientAnimation); this.setFocusable(true); this.setOutsideTouchable(true); this.update(); diff --git a/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/MScroller.java b/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/MScroller.java new file mode 100644 index 000000000..ca00868ed --- /dev/null +++ b/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/MScroller.java @@ -0,0 +1,37 @@ +package com.luck.picture.lib.widget.viewpager; + +import android.content.Context; +import android.view.animation.Interpolator; +import android.widget.Scroller; + +public class MScroller extends Scroller { + private static final Interpolator sInterpolator = new Interpolator() { + public float getInterpolation(float t) { + t -= 1.0f; + return t * t * t * t * t + 1.0f; + } + }; + + public boolean noDuration; + + public void setNoDuration(boolean noDuration) { + this.noDuration = noDuration; + } + + public MScroller(Context context) { + this(context, sInterpolator); + } + + public MScroller(Context context, Interpolator interpolator) { + super(context, interpolator); + } + + @Override + public void startScroll(int startX, int startY, int dx, int dy, int duration) { + if (noDuration) + //界面滑动不需要时间间隔 + super.startScroll(startX, startY, dx, dy, 0); + else + super.startScroll(startX, startY, dx, dy, duration); + } +} diff --git a/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/MyViewPageHelper.java b/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/MyViewPageHelper.java new file mode 100644 index 000000000..d0b59695e --- /dev/null +++ b/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/MyViewPageHelper.java @@ -0,0 +1,53 @@ +package com.luck.picture.lib.widget.viewpager; + +import java.lang.reflect.Field; + +import androidx.viewpager.widget.ViewPager; + +public class MyViewPageHelper { + ViewPager viewPager; + + MScroller scroller; + + public MyViewPageHelper(ViewPager viewPager) { + this.viewPager = viewPager; + init(); + } + + public void setCurrentItem(int item) { + setCurrentItem(item, true); + } + + public MScroller getScroller() { + return scroller; + } + + + public void setCurrentItem(int item, boolean somoth) { + int current = viewPager.getCurrentItem(); + //如果页面相隔大于1,就设置页面切换的动画的时间为0 + if (Math.abs(current - item) > 1) { + scroller.setNoDuration(true); + viewPager.setCurrentItem(item, somoth); + scroller.setNoDuration(false); + } else { + scroller.setNoDuration(false); + viewPager.setCurrentItem(item, somoth); + } + } + + private void init() { + scroller = new MScroller(viewPager.getContext()); + Class cl = ViewPager.class; + try { + Field field = cl.getDeclaredField("mScroller"); + field.setAccessible(true); + //利用反射设置mScroller域为自己定义的MScroller + field.set(viewPager, scroller); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/picture_library/src/main/java/com/luck/picture/lib/widget/PreviewViewPager.java b/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/PreviewViewPager.java similarity index 61% rename from picture_library/src/main/java/com/luck/picture/lib/widget/PreviewViewPager.java rename to picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/PreviewViewPager.java index 02e7db9ae..38203e32a 100644 --- a/picture_library/src/main/java/com/luck/picture/lib/widget/PreviewViewPager.java +++ b/picture_library/src/main/java/com/luck/picture/lib/widget/viewpager/PreviewViewPager.java @@ -1,4 +1,4 @@ -package com.luck.picture.lib.widget; +package com.luck.picture.lib.widget.viewpager; import android.content.Context; import android.util.AttributeSet; @@ -7,19 +7,20 @@ import androidx.viewpager.widget.ViewPager; /** - * @author:luck - * @date:2016-12-31 22:12 - * @describe:PreviewViewPager + * */ public class PreviewViewPager extends ViewPager { + private MyViewPageHelper helper; + public PreviewViewPager(Context context) { - super(context); + this(context, null); } public PreviewViewPager(Context context, AttributeSet attrs) { super(context, attrs); + helper = new MyViewPageHelper(this); } @Override @@ -51,4 +52,22 @@ public boolean dispatchTouchEvent(MotionEvent ev) { } return false; } + + @Override + public void setCurrentItem(int item) { + setCurrentItem(item, true); + } + + @Override + public void setCurrentItem(int item, boolean smoothScroll) { + MScroller scroller = helper.getScroller(); + if (Math.abs(getCurrentItem() - item) > 1) { + scroller.setNoDuration(true); + super.setCurrentItem(item, smoothScroll); + scroller.setNoDuration(false); + } else { + scroller.setNoDuration(false); + super.setCurrentItem(item, smoothScroll); + } + } } diff --git a/picture_library/src/main/res/anim/picture_anim_gradient_in.xml b/picture_library/src/main/res/anim/picture_anim_gradient_in.xml new file mode 100644 index 000000000..8907f4c7b --- /dev/null +++ b/picture_library/src/main/res/anim/picture_anim_gradient_in.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/picture_library/src/main/res/anim/picture_anim_gradient_out.xml b/picture_library/src/main/res/anim/picture_anim_gradient_out.xml new file mode 100644 index 000000000..c6ccb047d --- /dev/null +++ b/picture_library/src/main/res/anim/picture_anim_gradient_out.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/picture_library/src/main/res/drawable/picture_item_select_bg.xml b/picture_library/src/main/res/drawable/picture_item_select_bg.xml index 6f3f095e1..f5185c714 100644 --- a/picture_library/src/main/res/drawable/picture_item_select_bg.xml +++ b/picture_library/src/main/res/drawable/picture_item_select_bg.xml @@ -1,7 +1,7 @@ - - - + + + \ No newline at end of file diff --git a/picture_library/src/main/res/layout/picture_activity_external_preview.xml b/picture_library/src/main/res/layout/picture_activity_external_preview.xml index bca5d700c..7d8eaea29 100644 --- a/picture_library/src/main/res/layout/picture_activity_external_preview.xml +++ b/picture_library/src/main/res/layout/picture_activity_external_preview.xml @@ -42,7 +42,7 @@ android:scaleType="centerInside" android:src="@drawable/picture_icon_delete" /> - - \ No newline at end of file diff --git a/picture_library/src/main/res/layout/picture_preview.xml b/picture_library/src/main/res/layout/picture_preview.xml index aa95f80de..8051427a9 100644 --- a/picture_library/src/main/res/layout/picture_preview.xml +++ b/picture_library/src/main/res/layout/picture_preview.xml @@ -61,7 +61,7 @@ - - + android:layout_centerHorizontal="true"> + + + + + + - - + android:layout_marginTop="10dp"> #FA632D #9b9b9b #F2F2F2 + #FFDBDBDB #00000000 #F0FFFFFF #E0DBDBDB diff --git a/picture_library/src/main/res/values/styles.xml b/picture_library/src/main/res/values/styles.xml index 357870d19..638b573bd 100644 --- a/picture_library/src/main/res/values/styles.xml +++ b/picture_library/src/main/res/values/styles.xml @@ -6,6 +6,12 @@ @anim/picture_anim_album_dismiss + + +