Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改查看图片详情,滑动viewpager切换问题 #1315

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocalMedia> images = new ArrayList<>();
protected List<LocalMediaFolder> foldersList = new ArrayList<>();
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<ViewPager> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 10 additions & 0 deletions picture_library/src/main/res/anim/picture_anim_gradient_in.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="200"
android:fillAfter="true"
android:fillBefore="false"
android:fromAlpha="0"
android:toAlpha="1.0"/>

</set>
10 changes: 10 additions & 0 deletions picture_library/src/main/res/anim/picture_anim_gradient_out.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="200"
android:fillAfter="true"
android:fillBefore="false"
android:fromAlpha="1.0"
android:toAlpha="0"/>

</set>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/picture_color_transparent_e0db" android:state_pressed="true" />
<item android:drawable="@color/picture_color_transparent_e0db" android:state_selected="true" />
<item android:drawable="@color/picture_color_transparent_white" />
<item android:drawable="@color/picture_color_db" android:state_pressed="true" />
<item android:drawable="@color/picture_color_db" android:state_selected="true" />
<item android:drawable="@color/picture_color_white" />
</selector>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:scaleType="centerInside"
android:src="@drawable/picture_icon_delete" />

<com.luck.picture.lib.widget.PreviewViewPager
<com.luck.picture.lib.widget.viewpager.PreviewViewPager
android:id="@+id/preview_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/first_image"
android:text="@string/picture_camera_roll_num"
android:textColor="@color/picture_color_4d"
android:textSize="16sp" />



</RelativeLayout>
2 changes: 1 addition & 1 deletion picture_library/src/main/res/layout/picture_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</RelativeLayout>


<com.luck.picture.lib.widget.PreviewViewPager
<com.luck.picture.lib.widget.viewpager.PreviewViewPager
android:id="@+id/preview_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
45 changes: 27 additions & 18 deletions picture_library/src/main/res/layout/picture_title_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,36 @@
android:layout_height="48dp"
android:background="?colorPrimary" />

<TextView
android:id="@+id/picture_title"
<RelativeLayout
android:id="@+id/rlAlbum"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_centerHorizontal="true"
android:ellipsize="end"
android:gravity="center"
android:maxEms="11"
android:text="@string/picture_camera_roll"
android:textColor="?picture.title.textColor"
android:textSize="17sp" />
android:layout_centerHorizontal="true">

<TextView
android:id="@+id/picture_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ellipsize="end"
android:gravity="center"
android:maxEms="11"
android:text="@string/picture_camera_roll"
android:textColor="?picture.title.textColor"
android:textSize="17sp" />

<ImageView
android:id="@+id/ivArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/picture_title"
android:layout_alignBottom="@id/picture_title"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/picture_title"
android:scaleType="centerInside"
android:src="?attr/picture.arrow_down.icon" />

</RelativeLayout>

<ImageView
android:id="@+id/ivArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/picture_title"
android:layout_alignBottom="@id/picture_title"
android:layout_toRightOf="@id/picture_title"
android:scaleType="centerInside"
android:src="?attr/picture.arrow_down.icon" />

<TextView
android:id="@+id/picture_right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<include layout="@layout/picture_wechat_style_preview_title_bar" />


<com.luck.picture.lib.widget.PreviewViewPager
<com.luck.picture.lib.widget.viewpager.PreviewViewPager
android:id="@+id/preview_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
android:id="@+id/rlAlbum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
android:layout_marginTop="10dp">

<TextView
android:id="@+id/picture_title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:id="@+id/folder_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none" />

<View
Expand Down
1 change: 1 addition & 0 deletions picture_library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<color name="picture_color_fa632d">#FA632D</color>
<color name="picture_color_9b">#9b9b9b</color>
<color name="picture_color_f2">#F2F2F2</color>
<color name="picture_color_db">#FFDBDBDB</color>
<color name="picture_color_transparent">#00000000</color>
<color name="picture_color_transparent_white">#F0FFFFFF</color>
<color name="picture_color_transparent_e0db">#E0DBDBDB</color>
Expand Down
Loading