-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
482 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/ch/ielse/demo/p02/CustomLoadingUIProvider2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/res/drawable/b_white_ffffff_stroke_round_3_shape.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<resources> | ||
<string name="app_name">ImageWatcher</string> | ||
|
||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.