From a0c117d4568e5ee5f2792ce10e62646854ef8bfe Mon Sep 17 00:00:00 2001 From: maning <154292322@qq.com> Date: Fri, 16 Oct 2020 20:21:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=B5=8F=E8=A7=88=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E8=87=AA=E5=B7=B1=E7=9A=84=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 + .../gankmm/ui/activity/GankActivity.java | 3 +- .../ui/imagebrowser/GlideImageEngine.java | 51 ++ .../ui/imagebrowser/ImageBrowserUtils.java | 221 +++++++++ .../gankmm/ui/imagebrowser/MNGestureView.java | 134 ------ .../ui/imagebrowser/MNImageBrowser.java | 45 -- .../imagebrowser/MNImageBrowserActivity2.java | 440 ------------------ .../imagebrowser/ZoomOutPageTransformer.java | 54 --- .../ui/presenter/impl/GankPresenterImpl.java | 46 +- .../com/maning/gankmm/utils/IntentUtils.java | 8 +- app/src/main/res/layout/activity_day_show.xml | 2 +- .../res/layout/activity_mnimage_browser2.xml | 44 -- .../mn_image_browser_item_show_image2.xml | 43 -- 13 files changed, 320 insertions(+), 773 deletions(-) create mode 100644 app/src/main/java/com/maning/gankmm/ui/imagebrowser/GlideImageEngine.java create mode 100644 app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java delete mode 100644 app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNGestureView.java delete mode 100644 app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java delete mode 100644 app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity2.java delete mode 100644 app/src/main/java/com/maning/gankmm/ui/imagebrowser/ZoomOutPageTransformer.java delete mode 100644 app/src/main/res/layout/activity_mnimage_browser2.xml delete mode 100644 app/src/main/res/layout/mn_image_browser_item_show_image2.xml diff --git a/app/build.gradle b/app/build.gradle index 1e9bae8..9132c90 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -192,6 +192,8 @@ dependencies { /*-----------------------------------------*/ + /*图片浏览*/ + implementation 'com.github.maning0303:MNImageBrowser:V1.3.5-support' /*二维码扫描*/ implementation 'com.github.maning0303:MNZXingCode:V2.1.4' /*翻滚广告条TextView*/ diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/GankActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/GankActivity.java index c3b0003..b0ffb6a 100644 --- a/app/src/main/java/com/maning/gankmm/ui/activity/GankActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/activity/GankActivity.java @@ -162,8 +162,7 @@ public void showToast(String msg) { public void showImageView(String url) { RequestOptions options = new RequestOptions(); options.fitCenter(); - Glide - .with(this) + Glide.with(this) .load(url) .apply(options) .into(ivTop); diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/GlideImageEngine.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/GlideImageEngine.java new file mode 100644 index 0000000..3165e74 --- /dev/null +++ b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/GlideImageEngine.java @@ -0,0 +1,51 @@ +package com.maning.gankmm.ui.imagebrowser; + +import android.content.Context; +import android.graphics.Bitmap; +import android.support.annotation.Nullable; +import android.view.View; +import android.widget.ImageView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.GlideException; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.Target; +import com.maning.gankmm.R; +import com.maning.imagebrowserlibrary.ImageEngine; + +/** + * @author : maning + * @date : 2020-10-16 + * @desc : + */ +public class GlideImageEngine implements ImageEngine { + @Override + public void loadImage(Context context, String url, ImageView imageView, final View progressView, View customImageView) { + RequestOptions options = new RequestOptions(); + options.fitCenter(); + options.placeholder(R.drawable.pic_gray_bg); + options.error(R.drawable.pic_gray_bg); + Glide.with(context) + .asBitmap() + .load(url) + .apply(options) + .listener(new RequestListener() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + //隐藏进度View,必须设置setCustomProgressViewLayoutID + progressView.setVisibility(View.GONE); + return false; + } + + @Override + public boolean onResourceReady(Bitmap resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + //隐藏进度View,必须设置setCustomProgressViewLayoutID + progressView.setVisibility(View.GONE); + return false; + } + }) + .into(imageView); + } +} diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java new file mode 100644 index 0000000..ac47b23 --- /dev/null +++ b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ImageBrowserUtils.java @@ -0,0 +1,221 @@ +package com.maning.gankmm.ui.imagebrowser; + +import android.app.WallpaperManager; +import android.content.Context; +import android.graphics.Bitmap; +import android.support.v4.app.FragmentActivity; +import android.view.View; +import android.widget.ImageView; + +import com.maning.gankmm.R; +import com.maning.gankmm.app.MyApplication; +import com.maning.gankmm.bean.gank2.GankEntity; +import com.maning.gankmm.constant.Constants; +import com.maning.gankmm.db.GankDaoManager; +import com.maning.gankmm.listeners.OnItemClickListener; +import com.maning.gankmm.ui.dialog.ListFragmentDialog; +import com.maning.gankmm.utils.BitmapUtils; +import com.maning.gankmm.utils.IntentUtils; +import com.maning.gankmm.utils.PermissionUtils; +import com.maning.gankmm.utils.ThreadPoolUtils; +import com.maning.imagebrowserlibrary.listeners.OnLongClickListener; +import com.maning.imagebrowserlibrary.model.ImageBrowserConfig; +import com.maning.mndialoglibrary.MProgressDialog; +import com.maning.mndialoglibrary.MStatusDialog; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * @author : maning + * @date : 2020-10-16 + * @desc : + */ +public class ImageBrowserUtils { + + public static void open(FragmentActivity context, View view, int position, final ArrayList imageList, final ArrayList gankEntityList) { + if (imageList == null || imageList.size() == 0) { + return; + } + com.maning.imagebrowserlibrary.MNImageBrowser.with(context) + //指示器效果 + .setIndicatorType(ImageBrowserConfig.IndicatorType.Indicator_Number) + //设置隐藏指示器 + .setIndicatorHide(false) + //当前位置 + .setCurrentPosition(position) + //图片引擎 + .setImageEngine(new GlideImageEngine()) + //图片集合 + .setImageList(imageList) + //长按监听 + .setOnLongClickListener(new OnLongClickListener() { + @Override + public void onLongClick(final FragmentActivity activity, final View imageView, int position, String url) { + //长按事件 + if (gankEntityList != null && gankEntityList.size() == imageList.size()) { + showBottomSheet(activity, (ImageView) imageView, url, gankEntityList.get(position)); + } else { + showBottomSheet(activity, (ImageView) imageView, url, null); + } + } + }) + //全屏模式 + .setFullScreenMode(false) + //显示:传入当前View + .show(view); + } + + public static void showBottomSheet(final FragmentActivity context, final ImageView imageView, final String url, final GankEntity gankEntity) { + ArrayList mListDialogDatas = new ArrayList<>(); + mListDialogDatas.add("保存"); + mListDialogDatas.add("分享"); + mListDialogDatas.add("设置壁纸"); + + if (gankEntity != null) { + //查询是否存在收藏 + boolean isCollect = GankDaoManager.getCollectDao().queryOneCollectByID(gankEntity.get_id()); + if (isCollect) { + mListDialogDatas.add("取消收藏"); + } else { + mListDialogDatas.add("收藏"); + } + } + + ListFragmentDialog.newInstance(context).showDailog(context.getSupportFragmentManager(), mListDialogDatas, new OnItemClickListener() { + @Override + public void onItemClick(View view, int position) { + if (position == 0) { + //保存图片 + PermissionUtils.checkWritePermission(context, new PermissionUtils.PermissionCallBack() { + @Override + public void onGranted() { + saveImage(context, imageView, url); + } + + @Override + public void onDenied() { + showProgressError(context, "获取存储权限失败,请前往设置页面打开存储权限"); + } + }); + } else if (position == 1) { + IntentUtils.startAppShareText(context, "GankMM图片分享", "分享图片:" + url); + } else if (position == 2) { + setWallpaper(context, imageView); + } else if (position == 3) { + //查询是否存在收藏 + boolean isCollect = GankDaoManager.getCollectDao().queryOneCollectByID(gankEntity.get_id()); + if (isCollect) { + //取消收藏 + boolean deleteResult = GankDaoManager.getCollectDao().deleteOneCollect(gankEntity.get_id()); + if (deleteResult) { + showProgressSuccess(context, "取消收藏成功"); + } else { + showProgressError(context, "取消收藏失败"); + } + } else { + //收藏 + boolean insertResult = GankDaoManager.getCollectDao().insertOneCollect(gankEntity); + if (insertResult) { + showProgressSuccess(context, "收藏成功"); + } else { + showProgressError(context, "收藏失败"); + } + } + } + } + }); + } + + private static void saveImage(final Context context, final ImageView imageView, final String url) { + showProgressDialog(context, "正在保存图片..."); + imageView.setDrawingCacheEnabled(true); + final Bitmap bitmap = Bitmap.createBitmap(imageView.getDrawingCache()); + imageView.setDrawingCacheEnabled(false); + if (bitmap == null) { + return; + } + ThreadPoolUtils.execute(new Runnable() { + @Override + public void run() { + final boolean saveBitmapToSD = BitmapUtils.saveBitmapToSD(bitmap, Constants.BasePath, System.currentTimeMillis() + ".jpg", true); + MyApplication.getHandler().post(new Runnable() { + @Override + public void run() { + dissmissProgressDialog(); + if (saveBitmapToSD) { + showProgressSuccess(context, "保存成功"); + } else { + showProgressError(context, "保存失败"); + } + } + }); + } + }); + } + + private static void setWallpaper(final Context context, ImageView imageView) { + showProgressDialog(context, "正在设置壁纸..."); + imageView.setDrawingCacheEnabled(true); + final Bitmap bitmap = Bitmap.createBitmap(imageView.getDrawingCache()); + imageView.setDrawingCacheEnabled(false); + if (bitmap == null) { + showProgressError(context, "设置失败"); + return; + } + ThreadPoolUtils.execute(new Runnable() { + @Override + public void run() { + boolean flag = false; + WallpaperManager manager = WallpaperManager.getInstance(context); + try { + manager.setBitmap(bitmap); + flag = true; + } catch (IOException e) { + e.printStackTrace(); + flag = false; + } finally { + if (flag) { + MyApplication.getHandler().post(new Runnable() { + @Override + public void run() { + dissmissProgressDialog(); + showProgressSuccess(context, "设置成功"); + } + }); + } else { + MyApplication.getHandler().post(new Runnable() { + @Override + public void run() { + dissmissProgressDialog(); + showProgressError(context, "设置失败"); + } + }); + } + + } + } + }); + } + + public static void showProgressDialog(Context context) { + MProgressDialog.showProgress(context); + } + + public static void showProgressDialog(Context context, String message) { + MProgressDialog.showProgress(context, message); + } + + public static void showProgressSuccess(Context context, String message) { + new MStatusDialog(context).show(message, context.getResources().getDrawable(R.drawable.mn_icon_dialog_success)); + } + + public static void showProgressError(Context context, String message) { + new MStatusDialog(context).show(message, context.getResources().getDrawable(R.drawable.mn_icon_dialog_fail)); + } + + public static void dissmissProgressDialog() { + MProgressDialog.dismissProgress(); + } + +} diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNGestureView.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNGestureView.java deleted file mode 100644 index a32f357..0000000 --- a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNGestureView.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.maning.gankmm.ui.imagebrowser; - -import android.content.Context; -import android.graphics.Color; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.ViewConfiguration; -import android.widget.RelativeLayout; - -/** - * 手势View - */ -public class MNGestureView extends RelativeLayout { - - public MNGestureView(Context context) { - this(context, null); - } - - public MNGestureView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public MNGestureView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - private static final int mHeight = 500; - private float mDisplacementX; - private float mDisplacementY; - private float mInitialTy; - private float mInitialTx; - private boolean mTracking; - - @Override - public boolean onTouchEvent(MotionEvent event) { - return true; - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent event) { - switch (event.getActionMasked()) { - case MotionEvent.ACTION_DOWN: - - mDisplacementX = event.getRawX(); - mDisplacementY = event.getRawY(); - - mInitialTy = getTranslationY(); - mInitialTx = getTranslationX(); - - break; - - case MotionEvent.ACTION_MOVE: - // get the delta distance in X and Y direction - float deltaX = event.getRawX() - mDisplacementX; - float deltaY = event.getRawY() - mDisplacementY; - - - // set the touch and cancel event - if (deltaY > 0 && (Math.abs(deltaY) > ViewConfiguration.get(getContext()).getScaledTouchSlop() * 2 && Math.abs(deltaX) < Math.abs(deltaY) / 2) - || mTracking) { - - onSwipeListener.onSwiping(deltaY); - - setBackgroundColor(Color.TRANSPARENT); - - mTracking = true; - - setTranslationY(mInitialTy + deltaY); - setTranslationX(mInitialTx + deltaX); - - float mScale = 1 - deltaY / mHeight; - if (mScale < 0.3) { - mScale = 0.3f; - } - setScaleX(mScale); - setScaleY(mScale); - - } - if (deltaY < 0) { - setViewDefault(); - } - - break; - - case MotionEvent.ACTION_UP: - - if (mTracking) { - mTracking = false; - float currentTranslateY = getTranslationY(); - - if (currentTranslateY > mHeight / 3) { - onSwipeListener.downSwipe(); - break; - } - - } - setViewDefault(); - - onSwipeListener.overSwipe(); - break; - } - return false; - } - - private void setViewDefault(){ - //恢复默认 - setAlpha(1); - setTranslationX(0); - setTranslationY(0); - setScaleX(1); - setScaleY(1); - setBackgroundColor(Color.BLACK); - } - - - public interface OnSwipeListener { - //向下滑动 - void downSwipe(); - - //结束 - void overSwipe(); - - //正在滑动 - void onSwiping(float y); - } - - - private OnSwipeListener onSwipeListener; - - public void setOnSwipeListener(OnSwipeListener onSwipeListener) { - this.onSwipeListener = onSwipeListener; - } - -} diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java deleted file mode 100644 index 5bd03f7..0000000 --- a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowser.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.maning.gankmm.ui.imagebrowser; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.support.v4.app.ActivityCompat; -import android.support.v4.app.ActivityOptionsCompat; -import android.view.View; - -import com.maning.gankmm.R; -import com.maning.gankmm.bean.gank2.GankEntity; - -import java.util.ArrayList; - -/** - * Created by maning on 2017/5/25. - */ -public class MNImageBrowser { - - /** - * 打开浏览页面 - * - * @param context 上下文 - * @param view 点击的当前View - * @param position 默认打开第几个 - * @param imageList 数据源ArrayList - */ - public static void showImageBrowser(Context context, View view, int position, ArrayList imageList, ArrayList gankEntityList) { - Intent intent = new Intent(context, MNImageBrowserActivity2.class); - intent.putExtra(MNImageBrowserActivity2.IntentKey_ImageList, imageList); - intent.putExtra(MNImageBrowserActivity2.IntentKey_CurrentPosition, position); - intent.putExtra(MNImageBrowserActivity2.IntentKey_GankEntityList, gankEntityList); - - //android V4包的类,用于两个activity转场时的缩放效果实现 - ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeScaleUpAnimation(view, view.getWidth() / 2, view.getHeight() / 2, 0, 0); - try { - ActivityCompat.startActivity(context, intent, optionsCompat.toBundle()); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - context.startActivity(intent); - ((Activity) context).overridePendingTransition(R.anim.browser_enter_anim, 0); - } - } - -} diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity2.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity2.java deleted file mode 100644 index c6fee2d..0000000 --- a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/MNImageBrowserActivity2.java +++ /dev/null @@ -1,440 +0,0 @@ -package com.maning.gankmm.ui.imagebrowser; - -import android.app.WallpaperManager; -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.load.DataSource; -import com.bumptech.glide.load.engine.GlideException; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.Target; -import com.github.chrisbanes.photoview.PhotoView; -import com.maning.gankmm.R; -import com.maning.gankmm.app.MyApplication; -import com.maning.gankmm.bean.gank2.GankEntity; -import com.maning.gankmm.constant.Constants; -import com.maning.gankmm.db.GankDaoManager; -import com.maning.gankmm.listeners.OnItemClickListener; -import com.maning.gankmm.ui.dialog.ListFragmentDialog; -import com.maning.gankmm.ui.view.ProgressWheel; -import com.maning.gankmm.utils.BitmapUtils; -import com.maning.gankmm.utils.IntentUtils; -import com.maning.gankmm.utils.PermissionUtils; -import com.maning.mndialoglibrary.MProgressDialog; -import com.maning.mndialoglibrary.MStatusDialog; -import com.umeng.analytics.MobclickAgent; - -import java.io.IOException; -import java.util.ArrayList; - - -/** - * 图片浏览的页面 - */ -public class MNImageBrowserActivity2 extends AppCompatActivity { - - public final static String IntentKey_ImageList = "IntentKey_ImageList"; - public final static String IntentKey_GankEntityList = "IntentKey_GankEntityList"; - public final static String IntentKey_CurrentPosition = "IntentKey_CurrentPosition"; - - private Context context; - - private MNGestureView mnGestureView; - private ViewPager viewPagerBrowser; - private TextView tvNumShow; - private RelativeLayout rl_black_bg; - - private ImageView currentImageView; //需要保存的图片 - private int clickPosition; //需要保存的图片 - - private ArrayList imageUrlList = new ArrayList<>(); - private ArrayList welFareLists; - private int currentPosition; - - private ArrayList mListDialogDatas = new ArrayList<>(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - setWindowFullScreen(); - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_mnimage_browser2); - - context = this; - - initIntent(); - - initViews(); - - initData(); - - initViewPager(); - - } - - private void setWindowFullScreen() { - //设置全屏 - requestWindowFeature(Window.FEATURE_NO_TITLE); - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); - if (Build.VERSION.SDK_INT >= 19) { - // 虚拟导航栏透明 - getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - } - } - - private void initIntent() { - imageUrlList = getIntent().getStringArrayListExtra(IntentKey_ImageList); - welFareLists = (ArrayList) getIntent().getSerializableExtra(IntentKey_GankEntityList); - currentPosition = getIntent().getIntExtra(IntentKey_CurrentPosition, 1); - } - - private void initViews() { - viewPagerBrowser = (ViewPager) findViewById(R.id.viewPagerBrowser); - mnGestureView = (MNGestureView) findViewById(R.id.mnGestureView); - tvNumShow = (TextView) findViewById(R.id.tvNumShow); - rl_black_bg = (RelativeLayout) findViewById(R.id.rl_black_bg); - } - - private void initData() { - tvNumShow.setText(String.valueOf((currentPosition + 1) + "/" + imageUrlList.size())); - } - - private void initViewPager() { - viewPagerBrowser.setAdapter(new MyAdapter()); - viewPagerBrowser.setPageTransformer(true, new ZoomOutPageTransformer()); - viewPagerBrowser.setCurrentItem(currentPosition); - viewPagerBrowser.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - currentPosition = position; - tvNumShow.setText(String.valueOf((position + 1) + "/" + imageUrlList.size())); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - - mnGestureView.setOnSwipeListener(new MNGestureView.OnSwipeListener() { - @Override - public void downSwipe() { - finishBrowser(); - } - - @Override - public void onSwiping(float deltaY) { - tvNumShow.setVisibility(View.GONE); - - float mAlpha = 1 - deltaY / 500; - if (mAlpha < 0.3) { - mAlpha = 0.3f; - } - if (mAlpha > 1) { - mAlpha = 1; - } - rl_black_bg.setAlpha(mAlpha); - } - - @Override - public void overSwipe() { - tvNumShow.setVisibility(View.VISIBLE); - rl_black_bg.setAlpha(1); - } - }); - } - - private void finishBrowser() { - tvNumShow.setVisibility(View.GONE); - rl_black_bg.setAlpha(0); - finish(); - this.overridePendingTransition(0, R.anim.browser_exit_anim); - } - - @Override - public void onBackPressed() { - finishBrowser(); - } - - private void setWallpaper() { - showProgressDialog("正在设置壁纸..."); - currentImageView.setDrawingCacheEnabled(true); - final Bitmap bitmap = Bitmap.createBitmap(currentImageView.getDrawingCache()); - currentImageView.setDrawingCacheEnabled(false); - if (bitmap == null) { - showProgressError("设置失败"); - return; - } - new Thread(new Runnable() { - @Override - public void run() { - boolean flag = false; - WallpaperManager manager = WallpaperManager.getInstance(context); - try { - manager.setBitmap(bitmap); - flag = true; - } catch (IOException e) { - e.printStackTrace(); - flag = false; - } finally { - if (flag) { - MyApplication.getHandler().post(new Runnable() { - @Override - public void run() { - dissmissProgressDialog(); - showProgressSuccess("设置成功"); - } - }); - } else { - MyApplication.getHandler().post(new Runnable() { - @Override - public void run() { - dissmissProgressDialog(); - showProgressError("设置失败"); - } - }); - } - - } - } - }).start(); - } - - private void saveImage() { - showProgressDialog("正在保存图片..."); - currentImageView.setDrawingCacheEnabled(true); - final Bitmap bitmap = Bitmap.createBitmap(currentImageView.getDrawingCache()); - currentImageView.setDrawingCacheEnabled(false); - if (bitmap == null) { - return; - } - //save Image - new Thread(new Runnable() { - @Override - public void run() { - final boolean saveBitmapToSD = BitmapUtils.saveBitmapToSD(bitmap, Constants.BasePath, System.currentTimeMillis() + ".jpg", true); - MyApplication.getHandler().post(new Runnable() { - @Override - public void run() { - dissmissProgressDialog(); - if (saveBitmapToSD) { - showProgressSuccess("保存成功"); - } else { - showProgressError("保存失败"); - } - } - }); - } - }).start(); - } - - public void showBottomSheet() { - mListDialogDatas.clear(); - mListDialogDatas.add("保存"); - mListDialogDatas.add("分享"); - mListDialogDatas.add("设置壁纸"); - - if (welFareLists != null && welFareLists.size() > 0) { - GankEntity gankEntity = welFareLists.get(currentPosition); - //查询是否存在收藏 - boolean isCollect = GankDaoManager.getCollectDao().queryOneCollectByID(gankEntity.get_id()); - if (isCollect) { - mListDialogDatas.add("取消收藏"); - } else { - mListDialogDatas.add("收藏"); - } - } - - ListFragmentDialog.newInstance(this).showDailog(getSupportFragmentManager(), mListDialogDatas, new OnItemClickListener() { - @Override - public void onItemClick(View view, int position) { - if (position == 0) { - //保存图片 - PermissionUtils.checkWritePermission(context, new PermissionUtils.PermissionCallBack() { - @Override - public void onGranted() { - saveImage(); - } - - @Override - public void onDenied() { - showProgressError("获取存储权限失败,请前往设置页面打开存储权限"); - } - }); - } else if (position == 1) { - IntentUtils.startAppShareText(context, "GankMM图片分享", "分享图片:" + imageUrlList.get(clickPosition)); - } else if (position == 2) { - setWallpaper(); - } else if (position == 3) { - if (welFareLists != null && welFareLists.size() > 0) { - GankEntity gankEntity = welFareLists.get(currentPosition); - //查询是否存在收藏 - boolean isCollect = GankDaoManager.getCollectDao().queryOneCollectByID(gankEntity.get_id()); - if (isCollect) { - //取消收藏 - boolean deleteResult = GankDaoManager.getCollectDao().deleteOneCollect(gankEntity.get_id()); - if (deleteResult) { - new MStatusDialog(context).show("取消收藏成功", getResources().getDrawable(R.drawable.mn_icon_dialog_success)); - } else { - new MStatusDialog(context).show("取消收藏失败", getResources().getDrawable(R.drawable.mn_icon_dialog_fail)); - } - } else { - //收藏 - boolean insertResult = GankDaoManager.getCollectDao().insertOneCollect(gankEntity); - if (insertResult) { - new MStatusDialog(context).show("收藏成功", getResources().getDrawable(R.drawable.mn_icon_dialog_success)); - } else { - new MStatusDialog(context).show("收藏失败", getResources().getDrawable(R.drawable.mn_icon_dialog_fail)); - } - } - } - } - } - }); - } - - - private class MyAdapter extends PagerAdapter { - - private LayoutInflater layoutInflater; - - public MyAdapter() { - layoutInflater = LayoutInflater.from(context); - } - - @Override - public int getCount() { - return imageUrlList.size(); - } - - @Override - public boolean isViewFromObject(View view, Object object) { - return view == object; - } - - @Override - public void destroyItem(ViewGroup container, int position, Object object) { - container.removeView((View) object); - } - - @Override - public Object instantiateItem(ViewGroup container, final int position) { - View inflate = layoutInflater.inflate(R.layout.mn_image_browser_item_show_image2, container, false); - final PhotoView imageView = (PhotoView) inflate.findViewById(R.id.photoImageView); - RelativeLayout rl_browser_root = (RelativeLayout) inflate.findViewById(R.id.rl_browser_root); - final ProgressWheel progressWheel = (ProgressWheel) inflate.findViewById(R.id.progressWheel); - final RelativeLayout rl_image_placeholder_bg = (RelativeLayout) inflate.findViewById(R.id.rl_image_placeholder_bg); - final ImageView iv_fail = (ImageView) inflate.findViewById(R.id.iv_fail); - - iv_fail.setVisibility(View.GONE); - - final String url = imageUrlList.get(position); - Glide - .with(context) - .load(url) - .thumbnail(0.2f) - .listener(new RequestListener() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - progressWheel.setVisibility(View.GONE); - iv_fail.setVisibility(View.VISIBLE); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - progressWheel.setVisibility(View.GONE); - rl_image_placeholder_bg.setVisibility(View.GONE); - iv_fail.setVisibility(View.GONE); - return false; - } - }) - .into(imageView); - - - rl_browser_root.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finishBrowser(); - } - }); - - imageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finishBrowser(); - } - }); - - imageView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - clickPosition = position; - currentImageView = imageView; - //显示隐藏下面的Dialog - showBottomSheet(); - return false; - } - }); - - container.addView(inflate); - return inflate; - } - } - - public void showProgressDialog() { - MProgressDialog.showProgress(context); - } - - public void showProgressDialog(String message) { - MProgressDialog.showProgress(context,message); - } - - public void showProgressSuccess(String message) { - new MStatusDialog(context).show(message, getResources().getDrawable(R.drawable.mn_icon_dialog_success)); - } - - public void showProgressError(String message) { - new MStatusDialog(context).show(message, getResources().getDrawable(R.drawable.mn_icon_dialog_fail)); - } - - public void dissmissProgressDialog() { - MProgressDialog.dismissProgress(); - } - - @Override - protected void onResume() { - super.onResume(); - MobclickAgent.onPageStart(this.getClass().getSimpleName()); - MobclickAgent.onResume(this); //统计时长 - } - - @Override - protected void onPause() { - super.onPause(); - MobclickAgent.onPageStart(this.getClass().getSimpleName()); - MobclickAgent.onPause(this); - } - - -} diff --git a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ZoomOutPageTransformer.java b/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ZoomOutPageTransformer.java deleted file mode 100644 index d20ce51..0000000 --- a/app/src/main/java/com/maning/gankmm/ui/imagebrowser/ZoomOutPageTransformer.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.maning.gankmm.ui.imagebrowser; - -import android.annotation.SuppressLint; -import android.support.v4.view.ViewPager; -import android.view.View; - -/** - * Created by maning on 2017/5/25. - */ - -public class ZoomOutPageTransformer implements ViewPager.PageTransformer { - private static final float MIN_SCALE = 0.85f; - private static final float MIN_ALPHA = 0.5f; - - @SuppressLint("NewApi") - public void transformPage(View view, float position) - { - int pageWidth = view.getWidth(); - int pageHeight = view.getHeight(); - - if (position < -1) - { // [-Infinity,-1) - // This page is way off-screen to the left. - view.setAlpha(0); - - } else if (position <= 1) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0 - { // [-1,1] - // Modify the default slide transition to shrink the page as well - float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); - float vertMargin = pageHeight * (1 - scaleFactor) / 2; - float horzMargin = pageWidth * (1 - scaleFactor) / 2; - if (position < 0) - { - view.setTranslationX(horzMargin - vertMargin / 2); - } else - { - view.setTranslationX(-horzMargin + vertMargin / 2); - } - - // Scale the page down (between MIN_SCALE and 1) - view.setScaleX(scaleFactor); - view.setScaleY(scaleFactor); - - // Fade the page relative to its size. - view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) - / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); - - } else - { // (1,+Infinity] - // This page is way off-screen to the right. - view.setAlpha(0); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/GankPresenterImpl.java b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/GankPresenterImpl.java index 661d394..7c5c628 100644 --- a/app/src/main/java/com/maning/gankmm/ui/presenter/impl/GankPresenterImpl.java +++ b/app/src/main/java/com/maning/gankmm/ui/presenter/impl/GankPresenterImpl.java @@ -11,6 +11,7 @@ import com.maning.gankmm.http.gank.GankApi; import com.maning.gankmm.ui.iView.IGankView; import com.maning.gankmm.ui.presenter.IGankPresenter; +import com.maning.gankmm.utils.ThreadPoolUtils; import com.socks.library.KLog; import java.util.ArrayList; @@ -39,27 +40,28 @@ public void getOneDayDatas(String timeStr) { GankApi.getOneDayData(dayArray[0], dayArray[1], dayArray[2], new CommonHttpCallback() { @Override public void onSuccess(final GankDayBean result) { + if (mView == null) { + return; + } if (result != null) { GankDayBean.ResultsEntity results = result.getResults(); if (results != null) { - - List 福利 = result.getResults().get福利(); - if (福利 != null && 福利.size() > 0) { - String url = result.getResults().get福利().get(0).getUrl(); + String topImage = getTopImage(results); + if (!TextUtils.isEmpty(topImage)) { mView.setProgressBarVisility(View.GONE); - mView.showImageView(url); + mView.showImageView(topImage); } else { mView.setProgressBarVisility(View.GONE); mView.showToast("糟糕,图片没找到"); } try { //初始化数据 - new Thread(new Runnable() { + ThreadPoolUtils.execute(new Runnable() { @Override public void run() { initDatas(result); } - }).start(); + }); } catch (Exception e) { mView.showToast("抱歉,出错了..."); } @@ -85,6 +87,36 @@ public void onFail(int code, String message) { } } + private String getTopImage(GankDayBean.ResultsEntity resultsEntity) { + String imageUrl = ""; + List 福利 = resultsEntity.get福利(); + if (福利 != null && 福利.size() > 0) { + List images = 福利.get(0).getImages(); + if (images != null && images.size() > 0) { + imageUrl = images.get(0); + } + } + if (TextUtils.isEmpty(imageUrl)) { + List android = resultsEntity.getAndroid(); + if (android != null && android.size() > 0) { + List images = android.get(0).getImages(); + if (images != null && images.size() > 0) { + imageUrl = images.get(0); + } + } + } + if (TextUtils.isEmpty(imageUrl)) { + List ios = resultsEntity.getIOS(); + if (ios != null && ios.size() > 0) { + List images = ios.get(0).getImages(); + if (images != null && images.size() > 0) { + imageUrl = images.get(0); + } + } + } + return imageUrl; + } + private List dayEntityArrayList = new ArrayList<>(); diff --git a/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java b/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java index cb4fbc7..43f4ed1 100644 --- a/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java +++ b/app/src/main/java/com/maning/gankmm/utils/IntentUtils.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.support.v4.app.FragmentActivity; import android.view.View; import com.maning.gankmm.bean.gank2.GankEntity; @@ -14,7 +15,7 @@ import com.maning.gankmm.ui.activity.SettingActivity; import com.maning.gankmm.ui.activity.SupportPayActivity; import com.maning.gankmm.ui.activity.WebActivity; -import com.maning.gankmm.ui.imagebrowser.MNImageBrowser; +import com.maning.gankmm.ui.imagebrowser.ImageBrowserUtils; import java.util.ArrayList; @@ -35,11 +36,12 @@ public class IntentUtils { public static final String PushMessage = "PushMessage"; public static void startToImageShow(Context context, ArrayList mDatas, int position, View view) { - MNImageBrowser.showImageBrowser(context, view, position, mDatas, null); + startToImageShow(context, mDatas, null, position, view); } public static void startToImageShow(final Context context, ArrayList mDatas, final ArrayList gankEntityList, int position, View view) { - MNImageBrowser.showImageBrowser(context, view, position, mDatas, gankEntityList); +// MNImageBrowser.showImageBrowser(context, view, position, mDatas, gankEntityList); + ImageBrowserUtils.open((FragmentActivity) context, view, position, mDatas, gankEntityList); } public static void startToWebActivity(Context context, String titleFlag, String title, String url) { diff --git a/app/src/main/res/layout/activity_day_show.xml b/app/src/main/res/layout/activity_day_show.xml index 501826e..0936513 100644 --- a/app/src/main/res/layout/activity_day_show.xml +++ b/app/src/main/res/layout/activity_day_show.xml @@ -34,7 +34,7 @@ - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/mn_image_browser_item_show_image2.xml b/app/src/main/res/layout/mn_image_browser_item_show_image2.xml deleted file mode 100644 index 7ae644c..0000000 --- a/app/src/main/res/layout/mn_image_browser_item_show_image2.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - -