Skip to content

Commit

Permalink
不带imageView show 方法 添加初始pos设置
Browse files Browse the repository at this point in the history
  • Loading branch information
ielse committed Sep 20, 2018
1 parent 74253dc commit a1b98df
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
14 changes: 13 additions & 1 deletion app/src/main/java/ch/ielse/demo/p02/Fragment1.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -37,12 +39,14 @@ public class Fragment1 extends Fragment {
private ImageWatcherHelper iwHelper;
private final List<Uri> pictureList = new ArrayList<>();
private TextView vPictureUris;
private EditText vIdx;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View itemView = inflater.inflate(R.layout.fragment, container, false);

vIdx = itemView.findViewById(R.id.vIdx);
vPictureUris = itemView.findViewById(R.id.vPictureUris);
View vAddLocal = itemView.findViewById(R.id.vAddLocal);

Expand All @@ -58,7 +62,15 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
if (iwHelper != null) {
iwHelper.show(pictureList);
int currIdx = 0;
try {
if (!TextUtils.isEmpty(vIdx.getText())) {
currIdx = Integer.parseInt(vIdx.getText().toString());
}
} catch (Exception e) {
e.printStackTrace();
}
iwHelper.show(pictureList, currIdx);
}
}
});
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/res/layout/fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#f00"
android:text="这里开始是fragment区域" />
android:text="这里开始是fragment区域"
android:textColor="#f00" />


<Button
Expand All @@ -29,6 +29,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<EditText
android:id="@+id/vIdx"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入初始化位置,默认0"
android:minHeight="20dp" />

<Button
android:id="@+id/vNoInitPicture"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,15 @@ public interface OnPictureLongPressListener {
void onPictureLongPress(ImageView v, Uri uri, int pos); // 当前展示图片长按的回调
}

public void show(List<Uri> urlList) {
show(null, null, urlList);
public void show(List<Uri> urlList, int initPos) {
if (urlList == null) {
throw new NullPointerException("urlList[null]");
}
if (initPos >= urlList.size() || initPos < 0) {
throw new IndexOutOfBoundsException("initPos[" + initPos + "] urlList.size[" + urlList.size() + "]");
}
initPosition = initPos;
showInternal(null, null, urlList);
}

/**
Expand All @@ -249,12 +256,26 @@ public void show(List<Uri> urlList) {
* @param urlList 被加载的图片url列表,数量必须大于等于 imageGroupList.size。 且顺序应当和imageGroupList保持一致
*/
public void show(ImageView i, SparseArray<ImageView> imageGroupList, final List<Uri> urlList) {
if (i == null || imageGroupList == null || urlList == null) {
throw new NullPointerException("i[" + i + "] imageGroupList[" + imageGroupList + "] urlList[" + urlList + "]");
}
initPosition = -1;
for (int x = 0; x < imageGroupList.size(); x++) {
if (imageGroupList.get(imageGroupList.keyAt(x)) == i) {
initPosition = imageGroupList.keyAt(x);
break;
}
}
if (initPosition < 0) {
throw new IllegalArgumentException("param ImageView i must be a member of the List <ImageView> imageGroupList!");
}
showInternal(i, imageGroupList, urlList);
}

private void showInternal(ImageView i, SparseArray<ImageView> imageGroupList, final List<Uri> urlList) {
if (loader == null) {
throw new NullPointerException("please invoke `setLoader` first [loader == null]");
}
if ((i == null && imageGroupList != null) || (i != null && imageGroupList == null)) {
throw new IllegalArgumentException("666");
}

if (i != null && i.getDrawable() == null) return;

Expand All @@ -265,23 +286,6 @@ public void show(ImageView i, SparseArray<ImageView> imageGroupList, final List<
return;
}

initPosition = -1;
if (imageGroupList != null) {
for (int x = 0; x < imageGroupList.size(); x++) {
if (imageGroupList.get(imageGroupList.keyAt(x)) == i) {
initPosition = imageGroupList.keyAt(x);
break;
}
}
}

if (initPosition < 0) {
if (imageGroupList != null) {
throw new IllegalArgumentException("param ImageView i must be a member of the List <ImageView> imageGroupList!");
}
initPosition = 0;
}

currentPosition = initPosition;

if (animImageTransform != null) animImageTransform.cancel();
Expand Down Expand Up @@ -1147,7 +1151,7 @@ protected void onSizeChanged(int w, int h, int oldW, int oldH) {

private void internalDisplayDataAfterLayout() {
if (initUrlList != null) {
show(initI, initImageGroupList, initUrlList);
showInternal(initI, initImageGroupList, initUrlList);
}
}

Expand Down Expand Up @@ -1205,7 +1209,7 @@ private void animBackgroundTransform(final int colorResult, final int tag) {
if (colorResult == mBackgroundColor) return;
if (animBackground != null) animBackground.cancel();
final int mCurrentBackgroundColor = mBackgroundColor;
animBackground = ValueAnimator.ofFloat(0, 1).setDuration(300);
animBackground = ValueAnimator.ofFloat(0, 1).setDuration(200);
animBackground.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void show(ImageView i, SparseArray<ImageView> imageGroupList, List<Uri> u
mImageWatcher.show(i, imageGroupList, urlList);
}

public void show(List<Uri> urlList) {
public void show(List<Uri> urlList, int initPos) {
init();
mImageWatcher.show(urlList);
mImageWatcher.show(urlList, initPos);
}

private void init() {
Expand Down

0 comments on commit a1b98df

Please sign in to comment.