Skip to content

Commit

Permalink
#45 fixed #46
Browse files Browse the repository at this point in the history
  • Loading branch information
ielse committed Sep 14, 2018
1 parent 69c3f73 commit 9d4b910
Show file tree
Hide file tree
Showing 19 changed files with 404 additions and 142 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

<activity android:name=".MainActivity" />
<activity android:name=".MainActivity2" />
<activity android:name=".MainActivity3" />
<activity
android:name=".MainActivity3"
android:hardwareAccelerated="false" />
<activity android:name=".MainActivity4" />
<activity android:name=".MainActivity5" />
<activity android:name=".MainActivity6" />
Expand Down
32 changes: 0 additions & 32 deletions app/src/main/java/ch/ielse/demo/p02/CustomFuncUIProvider.java

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/java/ch/ielse/demo/p02/Fragment1.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

if (getActivity() instanceof ImageWatcherHelper.Provider) {
iwHelper = ((ImageWatcherHelper.Provider) getActivity()).iwh();
iwHelper = ((ImageWatcherHelper.Provider) getActivity()).iwHelper();
}

List<Uri> tmp = new ArrayList<>();
Expand Down
29 changes: 28 additions & 1 deletion app/src/main/java/ch/ielse/demo/p02/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.ielse.demo.p02;

import android.app.Activity;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
Expand Down Expand Up @@ -41,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.vRefresh).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext().getApplicationContext(), "刷新列表内容 adapter.reset()" , Toast.LENGTH_SHORT).show();
Toast.makeText(v.getContext().getApplicationContext(), "刷新列表内容 adapter.reset()", Toast.LENGTH_SHORT).show();
adapter.set(Data.get());
}
});
Expand Down Expand Up @@ -90,6 +91,32 @@ public void onThumbPictureClick(ImageView i, SparseArray<ImageView> imageGroupLi
@Override
public void onPictureLongPress(ImageView v, Uri uri, int pos) {
Toast.makeText(v.getContext().getApplicationContext(), "长按了第" + (pos + 1) + "张图片", Toast.LENGTH_SHORT).show();

new SheetDialog.Builder(this)
.addSheet("发送给好友", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.addSheet("转载到空间相册", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.addSheet("保存到手机", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.addSheet("收藏", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
}

@Override
Expand Down
18 changes: 2 additions & 16 deletions app/src/main/java/ch/ielse/demo/p02/MainActivity4.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package ch.ielse.demo.p02;

import android.app.Activity;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
Expand All @@ -24,16 +20,6 @@ public class MainActivity4 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
boolean isTranslucentStatus = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);
isTranslucentStatus = true;
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);

Expand Down Expand Up @@ -80,8 +66,8 @@ public void onClick(View v) {


iwHelper = ImageWatcherHelper.with(this, new SimpleLoader()) // 一般来讲, ImageWatcher 需要占据全屏的位置
.setIndexProvider(new CustomDotIndexProvider()) // 自定义index
.setOthersUIProvider(new CustomFuncUIProvider());
.setIndexProvider(new CustomDotIndexProvider()); // 自定义index

}

private void show(ImageView clickedImage) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ch/ielse/demo/p02/MainActivity6.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void onBackPressed() {
}

@Override
public ImageWatcherHelper iwh() {
public ImageWatcherHelper iwHelper() {
return iwHelper;
}
}
Expand Down
186 changes: 186 additions & 0 deletions app/src/main/java/ch/ielse/demo/p02/SheetDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package ch.ielse.demo.p02;


import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class SheetDialog extends Dialog {

public SheetDialog(Context context, int themeResId) {
super(context, themeResId);
}

public static class Params {
private final List<Sheet> menuList = new ArrayList<>();
private DialogInterface.OnClickListener cancelListener;
private String menuTitle;
private String cancelText;
private Context context;
}

public static class Builder {
private boolean canCancel = true;
private boolean shadow = true;
private final Params p;

public Builder(Context context) {
p = new Params();
p.context = context;
}

public Builder setTitle(String title) {
this.p.menuTitle = title;
return this;
}

public Builder addSheet(String text, DialogInterface.OnClickListener listener) {
if (listener == null || text == null)
throw new NullPointerException("text or listener null");

Sheet bm = new Sheet(text, listener);
this.p.menuList.add(bm);
return this;
}

public Builder setCancelListener(DialogInterface.OnClickListener cancelListener) {
p.cancelListener = cancelListener;
return this;
}

public Builder setCancelText(String text) {
p.cancelText = text;
return this;
}

public SheetDialog create() {
final SheetDialog dialog = new SheetDialog(p.context, shadow ? R.style.Theme_Light_NoTitle_Dialog : R.style.Theme_Light_NoTitle_NoShadow_Dialog);
Window window = dialog.getWindow();
window.setWindowAnimations(R.style.Animation_Bottom_Rising);
window.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
window.setGravity(Gravity.BOTTOM);

View view = LayoutInflater.from(p.context).inflate(R.layout.sheet_dialog, null);

TextView vCancel = (TextView) view.findViewById(R.id.vCancel);
ViewGroup layContainer = (ViewGroup) view.findViewById(R.id.layContainer);
LinearLayout.LayoutParams lpItem = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams lpDivider = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
int dip1 = (int) (1 * p.context.getResources().getDisplayMetrics().density + 0.5f);
int spacing = dip1 * 12;

boolean hasTitle = !TextUtils.isEmpty(p.menuTitle);
if (hasTitle) {
TextView tTitle = new TextView(p.context);
tTitle.setLayoutParams(lpItem);
tTitle.setGravity(Gravity.CENTER);
tTitle.setTextColor(0xFF8F8F8F);
tTitle.setText(p.menuTitle);
tTitle.setTextSize(17);
tTitle.setPadding(0, spacing, 0, spacing);
tTitle.setBackgroundResource(R.drawable.sheet_dialog_top_selector);
layContainer.addView(tTitle);

View viewDivider = new View(p.context);
viewDivider.setLayoutParams(lpDivider);
viewDivider.setBackgroundColor(0xFFCED2D6);
layContainer.addView(viewDivider);
}

for (int i = 0; i < p.menuList.size(); i++) {
final Sheet sheet = p.menuList.get(i);
TextView bbm = new TextView(p.context);
bbm.setLayoutParams(lpItem);
int backgroundResId = R.drawable.sheet_dialog_center_selector;
if (p.menuList.size() > 1) {
if (i == 0) {
if (hasTitle) {
backgroundResId = R.drawable.sheet_dialog_center_selector;
} else {
backgroundResId = R.drawable.sheet_dialog_top_selector;
}
} else if (i == p.menuList.size() - 1) {
backgroundResId = R.drawable.sheet_dialog_bottom_selector;
}
} else if (p.menuList.size() == 1) {
backgroundResId = R.drawable.sheet_dialog_singleton_selector;
}
bbm.setBackgroundResource(backgroundResId);
bbm.setPadding(0, spacing, 0, spacing);
bbm.setGravity(Gravity.CENTER);
bbm.setText(sheet.funName);
bbm.setTextColor(0xFF007AFF);
bbm.setTextSize(19);
final int finalI = i;
bbm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sheet.listener.onClick(dialog, finalI);
}
});

layContainer.addView(bbm);

if (i != p.menuList.size() - 1) {
View viewDivider = new View(p.context);
viewDivider.setLayoutParams(lpDivider);
viewDivider.setBackgroundColor(0xFFCED2D6);
layContainer.addView(viewDivider);
}
}

if (!TextUtils.isEmpty(p.cancelText)) {
vCancel.setText(p.cancelText);
}

if (p.cancelListener != null) {
vCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p.cancelListener.onClick(dialog, 0);
}
});
} else {
vCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}

dialog.setContentView(view);
dialog.setCanceledOnTouchOutside(canCancel);
dialog.setCancelable(canCancel);
return dialog;
}


}

static class Sheet {
public String funName;
public DialogInterface.OnClickListener listener;

public Sheet(String funName, DialogInterface.OnClickListener listener) {
this.funName = funName;
this.listener = listener;
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/anim/slide_in_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:shareInterpolator="true">

<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromYDelta="100%p"
android:toYDelta="0" />

<alpha
android:duration="@android:integer/config_shortAnimTime"
android:fromAlpha="0.95"
android:toAlpha="1" />

</set>
16 changes: 16 additions & 0 deletions app/src/main/res/anim/slide_out_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:shareInterpolator="true">

<translate
android:duration="@android:integer/config_shortAnimTime"
android:fromYDelta="0"
android:toYDelta="100%p" />

<alpha
android:duration="@android:integer/config_shortAnimTime"
android:fromAlpha="1"
android:toAlpha="0.95" />

</set>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/sheet_dialog_bottom_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<corners android:bottomLeftRadius="8dip" android:bottomRightRadius="8dip" />
<solid android:color="#FFF4F4F4" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="8dip" android:bottomRightRadius="8dip" />
<solid android:color="#FFFFFFFF" />
</shape>
</item>
</selector>
Loading

0 comments on commit 9d4b910

Please sign in to comment.