Skip to content

Commit

Permalink
添加查看原图demo
Browse files Browse the repository at this point in the history
  • Loading branch information
iielse committed Nov 19, 2018
1 parent c65a937 commit b13027e
Show file tree
Hide file tree
Showing 20 changed files with 482 additions and 67 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.2'
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "ch.ielse.demo.p02"
minSdkVersion 14
targetSdkVersion 27
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -19,8 +19,8 @@ android {
}

dependencies {
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'

Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/ch/ielse/demo/p02/CustomLoadingUIProvider2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ch.ielse.demo.p02;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.github.ielse.imagewatcher.ImageWatcher;


public class CustomLoadingUIProvider2 implements ImageWatcher.LoadingUIProvider {
private final FrameLayout.LayoutParams lpCenterInParent = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
private final Handler mHandler = new Handler();

private Runnable runDelayDisplay;

@Override
public View initialView(Context context) {
ImageView load = new ImageView(context);
lpCenterInParent.gravity = Gravity.CENTER;
load.setLayoutParams(lpCenterInParent);
load.setImageResource(R.mipmap.loading);
return load;
}

@Override
public void start(final View loadView) {
if (runDelayDisplay != null) mHandler.removeCallbacks(runDelayDisplay);
runDelayDisplay = new Runnable() {
@Override
public void run() {
loadView.setVisibility(View.VISIBLE);
}
};
mHandler.postDelayed(runDelayDisplay, 500);
}

@Override
public void stop(View loadView) {
if (runDelayDisplay != null) mHandler.removeCallbacks(runDelayDisplay);
runDelayDisplay = null;
loadView.setVisibility(View.GONE);
}
}
93 changes: 93 additions & 0 deletions app/src/main/java/ch/ielse/demo/p02/DecorationLayout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package ch.ielse.demo.p02;

import android.content.Context;
import android.net.Uri;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.ielse.imagewatcher.ImageWatcher;
import com.github.ielse.imagewatcher.ImageWatcherHelper;

public class DecorationLayout extends FrameLayout implements ViewPager.OnPageChangeListener, View.OnClickListener {

private ImageWatcherHelper mHolder;
private TextView vDisplayOrigin;
private View vDownload;
private int currentPosition;
private int mPagerPositionOffsetPixels;

public DecorationLayout(Context context) {
super(context);
final FrameLayout vContainer = (FrameLayout) LayoutInflater.from(context).inflate(R.layout.layout_watcher_decoration, this);
vDisplayOrigin = vContainer.findViewById(R.id.vDisplayOrigin);
vDisplayOrigin.setOnClickListener(this);
vDownload = vContainer.findViewById(R.id.vDownload);
vDownload.setOnClickListener(this);

}

public void attachImageWatcher(ImageWatcherHelper iwHelper) {
mHolder = iwHelper;
}


@Override
public void onClick(View v) {
if (mPagerPositionOffsetPixels != 0) return;

if (v.getId() == R.id.vDownload) {
final int clickPosition = currentPosition;
Toast.makeText(v.getContext().getApplicationContext(), "download [" + clickPosition + "] ", Toast.LENGTH_SHORT).show();
} else if (v.getId() == R.id.vDisplayOrigin) {
final int clickPosition = currentPosition;
Toast.makeText(v.getContext().getApplicationContext(), "display origin [" + clickPosition + "]", Toast.LENGTH_SHORT).show();
Uri newUri = Uri.parse("https://pub-static.haozhaopian.net/static/web/site/features/cn/crop/images/crop_20a7dc7fbd29d679b456fa0f77bd9525d.jpg");
notifyAdapterItemChanged(clickPosition, newUri);

}
}

@Override
public void onPageScrolled(int i, float v, int i1) {
mPagerPositionOffsetPixels = i1;
notifyAlphaChanged(v);
// setAlpha(1 - v);
}

@Override
public void onPageSelected(int i) {
currentPosition = i;
}

@Override
public void onPageScrollStateChanged(int i) {

}

private void notifyAdapterItemChanged(int position, Uri newUri) {
if (mHolder != null) {
final ImageWatcher iw = mHolder.getImageWatcher();
if (iw != null) {
iw.notifyItemChanged(position, newUri);
}
}
}

private void notifyAlphaChanged(float p) {
if (0 < p && p <= 0.2f) {
float r = (0.2f - p) * 5;
setAlpha(r);
} else if (0.8f <= p && p < 1) {
float r = (p - 0.8f) * 5;
setAlpha(r);
} else if (p == 0) {
setAlpha(1f);
} else {
setAlpha(0f);
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/ch/ielse/demo/p02/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onClick(View v) {
// 长按图片的回调,你可以显示一个框继续提供一些复制,发送等功能
vImageWatcher.setOnPictureLongPressListener(this);
vImageWatcher.setLoader(new GlideSimpleLoader());
vImageWatcher.setOnStateChangedListener(new ImageWatcher.OnStateChangedListener() {
vImageWatcher.addOnStateChangedListener(new ImageWatcher.OnStateChangedListener() {
@Override
public void onStateChangeUpdate(ImageWatcher imageWatcher, ImageView clicked, int position, Uri uri, float animatedValue, int actionTag) {
Log.e("IW", "onStateChangeUpdate [" + position + "][" + uri + "][" + animatedValue + "][" + actionTag + "]");
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/ch/ielse/demo/p02/MainActivity2.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class MainActivity2 extends Activity implements MessagePicturesLayout.Cal
private RecyclerView vRecycler;
private MessageAdapter adapter;

private DecorationLayout layDecoration;

@Override
protected void onCreate(Bundle savedInstanceState) {
boolean isTranslucentStatus = false;
Expand All @@ -40,6 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
layDecoration = new DecorationLayout(this);

vRecycler = (RecyclerView) findViewById(R.id.v_recycler);
vRecycler.setLayoutManager(new LinearLayoutManager(this));
Expand Down Expand Up @@ -74,7 +77,12 @@ public void onStateChanged(ImageWatcher imageWatcher, int position, Uri uri, int
}
}
})
.setLoadingUIProvider(new CustomLoadingUIProvider()); // 自定义LoadingUI
.setOtherView(layDecoration)
.addOnPageChangeListener(layDecoration)
.setLoadingUIProvider(new CustomLoadingUIProvider2()); // 自定义LoadingUI


layDecoration.attachImageWatcher(iwHelper);


Utils.fitsSystemWindows(isTranslucentStatus, findViewById(R.id.v_fit));
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ch/ielse/demo/p02/MainActivity4.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public void onClick(View v) {


iwHelper = ImageWatcherHelper.with(this, new GlideSimpleLoader()) // 一般来讲, ImageWatcher 需要占据全屏的位置
.setIndexProvider(new CustomDotIndexProvider()); // 自定义index
.setIndexProvider(new CustomDotIndexProvider()) // 自定义index
.setLoadingUIProvider(new CustomLoadingUIProvider()); // 骰子loading

}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/b_white_ffffff_stroke_round_3_shape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="3dp" />
<stroke
android:width="0.5dp"
android:color="#fff" />

<solid android:color="#88000000" />

</shape>
32 changes: 32 additions & 0 deletions app/src/main/res/layout/layout_watcher_decoration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/vDisplayOrigin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="15dp"
android:background="@drawable/b_white_ffffff_stroke_round_3_shape"
android:includeFontPadding="false"
android:paddingLeft="7dp"
android:paddingTop="4dp"
android:paddingRight="7dp"
android:paddingBottom="4dp"
android:text="查看原图"
android:textColor="#fff"
android:textSize="12sp" />


<ImageView
android:id="@+id/vDownload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="5dp"
android:padding="10dp"
android:src="@mipmap/download" />

</FrameLayout>
Binary file added app/src/main/res/mipmap-xxhdpi/download.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxhdpi/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<string name="app_name">ImageWatcher</string>


</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Loading

0 comments on commit b13027e

Please sign in to comment.