|
@@ -3,9 +3,12 @@ package com.edufound.reader.popwindow;
|
|
|
import android.app.Activity;
|
|
|
import android.app.Dialog;
|
|
|
import android.content.Context;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.PointF;
|
|
|
import android.net.Uri;
|
|
|
+import android.os.Build;
|
|
|
import android.view.Display;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.KeyEvent;
|
|
@@ -289,7 +292,9 @@ public class PopWindowUtil {
|
|
|
mPresenter.initRecordStatusWindow(context, record_view, bean, userread, listener);
|
|
|
recordPopupWindow = new PopupWindow(record_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
|
|
|
recordPopupWindow.setFocusable(false);
|
|
|
+ mPopupWindow.setClippingEnabled(false);
|
|
|
recordPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
|
|
|
+ hideBottomUIMenuForPopupWindow(recordPopupWindow);
|
|
|
recordPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
@Override
|
|
|
public void onDismiss() {
|
|
@@ -404,7 +409,9 @@ public class PopWindowUtil {
|
|
|
});
|
|
|
eventPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
|
|
|
eventPopupWindow.setFocusable(true);
|
|
|
+ mPopupWindow.setClippingEnabled(false);
|
|
|
eventPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
|
|
|
+ hideBottomUIMenuForPopupWindow(eventPopupWindow);
|
|
|
eventPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
@Override
|
|
|
public void onDismiss() {
|
|
@@ -493,7 +500,7 @@ public class PopWindowUtil {
|
|
|
/**
|
|
|
* 超长图popupwindow
|
|
|
*/
|
|
|
- public static void showLongSizeImg(Context context, String url, View parent) {
|
|
|
+ public static void showLongSizeImg(Activity context, String url, View parent) {
|
|
|
initPresenter();
|
|
|
if (checkWindowShoing()) {
|
|
|
return;
|
|
@@ -504,7 +511,6 @@ public class PopWindowUtil {
|
|
|
final File[] imgResource = new File[1];
|
|
|
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) dialog_view.findViewById(R.id.imageview);
|
|
|
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM);
|
|
|
- imageView.setMinScale(1.0F);
|
|
|
//下载图片保存到本地
|
|
|
GlideUtils.downloadImage(context, url, new RequestListener<File>() {
|
|
|
@Override
|
|
@@ -515,7 +521,10 @@ public class PopWindowUtil {
|
|
|
@Override
|
|
|
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
|
|
|
imgResource[0] = resource;
|
|
|
- imageView.setImage(ImageSource.uri(Uri.fromFile(resource)), new ImageViewState(1.0F, new PointF(0, 0), 0));
|
|
|
+ float initImageScale = getInitImageScale(context, resource.getPath());
|
|
|
+ imageView.setMaxScale(initImageScale);//最大显示比例
|
|
|
+ imageView.setMinScale(initImageScale);
|
|
|
+ imageView.setImage(ImageSource.uri(Uri.fromFile(resource)), new ImageViewState(initImageScale, new PointF(0, 0), 0));
|
|
|
// Uri uri = Uri.fromFile(resource);
|
|
|
// imageView.setImage(uri);
|
|
|
|
|
@@ -533,6 +542,39 @@ public class PopWindowUtil {
|
|
|
newPopupWindow(parent, true);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算出图片初次显示需要放大倍数
|
|
|
+ *
|
|
|
+ * @param imagePath 图片的绝对路径
|
|
|
+ */
|
|
|
+ public static float getInitImageScale(Activity activity, String imagePath) {
|
|
|
+ Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
|
|
|
+ WindowManager wm = activity.getWindowManager();
|
|
|
+ int width = Consts.getScreenSize()[0];
|
|
|
+ int height = Consts.getScreenSize()[1];
|
|
|
+ // 拿到图片的宽和高
|
|
|
+ int dw = bitmap.getWidth();
|
|
|
+ int dh = bitmap.getHeight();
|
|
|
+ float scale = 1.0f;
|
|
|
+ //图片宽度大于屏幕,但高度小于屏幕,则缩小图片至填满屏幕宽
|
|
|
+ if (dw > width && dh <= height) {
|
|
|
+ scale = width * 1.0f / dw;
|
|
|
+ }
|
|
|
+ //图片宽度小于屏幕,但高度大于屏幕,则放大图片至填满屏幕宽
|
|
|
+ if (dw <= width && dh > height) {
|
|
|
+ scale = width * 1.0f / dw;
|
|
|
+ }
|
|
|
+ //图片高度和宽度都小于屏幕,则放大图片至填满屏幕宽
|
|
|
+ if (dw < width && dh < height) {
|
|
|
+ scale = width * 1.0f / dw;
|
|
|
+ }
|
|
|
+ //图片高度和宽度都大于屏幕,则缩小图片至填满屏幕宽
|
|
|
+ if (dw > width && dh > height) {
|
|
|
+ scale = width * 1.0f / dw;
|
|
|
+ }
|
|
|
+ return scale;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 排行榜
|
|
@@ -612,9 +654,12 @@ public class PopWindowUtil {
|
|
|
Logger.e("newPopupWindow-parent=null");
|
|
|
return;
|
|
|
}
|
|
|
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
|
|
|
+
|
|
|
+ mPopupWindow = new PopupWindow(dialog_view, Consts.getScreenSize()[0], FrameLayout.LayoutParams.MATCH_PARENT);
|
|
|
mPopupWindow.setFocusable(nedFocus);
|
|
|
+ mPopupWindow.setClippingEnabled(false);
|
|
|
mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
|
|
|
+ hideBottomUIMenuForPopupWindow(mPopupWindow);
|
|
|
mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
@Override
|
|
|
public void onDismiss() {
|
|
@@ -624,6 +669,34 @@ public class PopWindowUtil {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 影藏PopupWindow页面弹出时的虚拟按键
|
|
|
+ */
|
|
|
+ private static void hideBottomUIMenuForPopupWindow(final PopupWindow popupWindow) {
|
|
|
+ if (popupWindow != null && popupWindow.getContentView() != null) {
|
|
|
+ popupWindow.getContentView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onSystemUiVisibilityChange(int visibility) {
|
|
|
+ // //保持布局状态
|
|
|
+ int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
|
|
+ //布局位于状态栏下方
|
|
|
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
|
|
+ //全屏
|
|
|
+ View.SYSTEM_UI_FLAG_FULLSCREEN |
|
|
|
+ //隐藏导航栏
|
|
|
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
|
|
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
|
|
+ if (Build.VERSION.SDK_INT >= 19) {
|
|
|
+ uiOptions |= 0x00001000;
|
|
|
+ } else {
|
|
|
+ uiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
|
|
|
+ }
|
|
|
+ popupWindow.getContentView().setSystemUiVisibility(uiOptions);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|