Kaynağa Gözat

邀请赚钱图片滑动修改

zengjiebin 7 yıl önce
ebeveyn
işleme
6427986d30

+ 10 - 7
app/src/main/java/com/sheep/gamegroup/util/GlideImageLoader.java

@@ -2,16 +2,13 @@ package com.sheep.gamegroup.util;
 
 import android.content.Intent;
 import android.graphics.Bitmap;
-import android.graphics.Color;
 import android.net.Uri;
 import android.text.TextUtils;
-import android.util.Log;
 import android.widget.ImageView;
 
 import com.bumptech.glide.Glide;
 import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
 import com.bumptech.glide.request.RequestOptions;
-import com.sheep.gamegroup.model.api.BaseMessageConverter;
 import com.sheep.gamegroup.util.glide.GlideCircleTransformWithBorder;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
@@ -21,9 +18,7 @@ import com.zhy.http.okhttp.OkHttpUtils;
 import com.zhy.http.okhttp.callback.FileCallBack;
 
 import java.io.File;
-import java.util.HashMap;
 import java.util.Locale;
-import java.util.Map;
 
 import okhttp3.Call;
 import rx.functions.Action1;
@@ -82,6 +77,12 @@ public class GlideImageLoader {
                 .apply(new RequestOptions().transform(new RoundedCorners(radius)).placeholder(R.drawable.loading_01))
                 .into(imageView);
     }
+    public static void roundedCornersImage1(ImageView imageView, String url, int radius) {
+        Glide.with(SheepApp.getInstance())
+                .load(url)
+                .apply(new RequestOptions().centerCrop().transform(new RoundedCorners(radius)))
+                .into(imageView);
+    }
     public static void setGameImage(ImageView imageView, String url) {
         if(url.endsWith(".gif")){//gif图片不做任务处理
             Glide.with(SheepApp.getInstance())
@@ -109,7 +110,6 @@ public class GlideImageLoader {
      * @param w
      */
     public static void saveAndSetRqImage(final ImageView imageView, String link, int w) {
-        LogUtil.logI("二维码链接-----"+link);
         String fileName = String.format(Locale.CHINA, "%d.png", link.hashCode());
         File file = new File(ClassFileHelper.DIR, fileName);
         if(!file.exists()){
@@ -117,7 +117,10 @@ public class GlideImageLoader {
             if(mBitmap != null) {
                 ViewUtil.saveImage(mBitmap, ClassFileHelper.DIR, fileName);
                 if(imageView != null)
-                    imageView.setImageBitmap(mBitmap);
+                    Glide.with(SheepApp.getInstance())
+                            .load(file)
+                            .apply(new RequestOptions().override(w, w))
+                            .into(imageView);
             }
         }
         if(file.exists()){

+ 0 - 3
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -112,9 +112,6 @@ public class ViewUtil {
     public static final int REQUEST_CODE_TASK_LIST = 110;
     private static ViewUtil viewUtil;
     static RobTask mRobTask;
-    private static int mLastPos = -1;
-    private static CardScaleHelper mCardScaleHelper = new CardScaleHelper();
-    private static Runnable mBlurRunnable;
 
     public static ViewUtil newInstance() {
         if (viewUtil == null) {

+ 29 - 89
app/src/main/java/com/sheep/gamegroup/view/activity/InvitationActivity.java

@@ -1,19 +1,11 @@
 package com.sheep.gamegroup.view.activity;
 
-import android.annotation.SuppressLint;
 import android.app.Activity;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
 import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.Message;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.GridLayoutManager;
 import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.OrientationHelper;
 import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
 import android.util.Log;
@@ -22,10 +14,12 @@ import android.widget.ImageView;
 import android.widget.TextView;
 
 import com.alibaba.fastjson.JSONObject;
-import com.google.gson.Gson;
-import com.sheep.gamegroup.helper.DownloadUtil;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
+import com.bumptech.glide.request.RequestOptions;
+import com.kfzs.appstore.utils.adapter.recyclerview.RecyclerViewAdapter;
 import com.sheep.gamegroup.helper.ScalableCardHelper;
-import com.sheep.gamegroup.helper.ZXingHelper;
+import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.DialogConfig;
 import com.sheep.gamegroup.model.entity.FriendAndAwardEntity;
@@ -37,12 +31,10 @@ import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.FastJsonUtils;
 import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.ListUtil;
-import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.StringUtils;
 import com.sheep.gamegroup.util.ViewHolder;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
-import com.sheep.gamegroup.view.adapter.MyAdapter;
 import com.sheep.gamegroup.view.dialog.DialogShare;
 import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
@@ -88,10 +80,6 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
     private String description;
     private File file;
     private List<PictureInvitationEntity> mPictureList = new ArrayList<>();
-    private int position = 0;
-    private List<Bitmap> listBitmap1 = new ArrayList<>();
-    private List<Bitmap> listBitmap2 = new ArrayList<>();
-    private MyAdapter adapter;
 
     @Override
 
@@ -100,8 +88,8 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
         setContentView(R.layout.activity_invitation);
         ButterKnife.bind(this);
         initView();
+        initListener();
         initData();
-        createAdapter(listBitmap1, this);
         getPictureList();
     }
 
@@ -114,18 +102,22 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
             }
         });
     }
+    private RecyclerViewAdapter<PictureInvitationEntity> mRecyclerViewAdapter;
+    private void initListener() {
+        mRecyclerView.setLayoutManager(new LinearLayoutManager(mRecyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
+        mRecyclerView.setNestedScrollingEnabled(false);
 
-    /**
-     * @param list    Bitmap集合
-     * @param context
-     */
-    private void createAdapter(List<Bitmap> list, Context context) {
-        adapter = new MyAdapter(context, list, listBitmap2);
-        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
-        layoutManager.setOrientation(OrientationHelper.HORIZONTAL);
-        mRecyclerView.setLayoutManager(layoutManager);
-        // recyclerView.addItemDecoration(new InvitationPictureAdapter.SpacesItemDecoration(15));
-        mRecyclerView.setAdapter(adapter);
+        mRecyclerViewAdapter = new RecyclerViewAdapter<PictureInvitationEntity>(mRecyclerView.getContext(), R.layout.item_image2, mPictureList) {
+            @Override
+            public void convert(com.kfzs.appstore.utils.adapter.recyclerview.ViewHolder viewHolder, PictureInvitationEntity item, int i) {
+                ImageView image_full = viewHolder.getView(R.id.image_full);
+                ImageView image_bottom = viewHolder.getView(R.id.image_bottom);
+                GlideImageLoader.roundedCornersImage1(image_full, item.getPicture(), (int) getResources().getDimension(R.dimen.content_padding_8));
+                GlideImageLoader.saveAndSetRqImage(image_bottom, item.getLink(), 800);
+            }
+
+        };
+        mRecyclerView.setAdapter(mRecyclerViewAdapter);
         ScalableCardHelper cardHelper = new ScalableCardHelper(this);
         cardHelper.attachToRecyclerView(mRecyclerView);
     }
@@ -345,6 +337,7 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
                     @Override
                     public void onNext(BaseMessage baseMessage) {
                         mPictureList.addAll(baseMessage.getDataList(PictureInvitationEntity.class));
+                        mRecyclerViewAdapter.notifyDataSetChanged();
                     }
 
                     @Override
@@ -352,67 +345,14 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
                     }
                 });
     }
+//    private void createBitmapList(int y) {
+//        for (int i = 0; i < mPictureList.size(); i++) {
+//            listBitmap1.add(BitmapFactory.decodeFile(getSavePath(mPictureList.get(i).getPicture())));
+//            Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.sheep_logo);
+//            Bitmap bitmap = ZXingHelper.createQRCodeWithLogo(mPictureList.get(y).getLink(), logo);
+//        }
+//    }
 
-    /**
-     * @param url ,,图片地址
-     * @return /storage/emulated/0/sheep/aaa
-     */
-    private String getSavePath(String url) {
-        return Environment.getExternalStorageDirectory() + "/sheep/" + url.substring(url.lastIndexOf("/") + 1);
-    }
-    private void downloadPictures() {
-        for (int i = 0; i < mPictureList.size(); i++) {
-            position = i;
-            DownloadUtil.get().download(mPictureList.get(position).getPicture(), "sheep", new DownloadUtil.OnDownloadListener() {
-                @Override
-                public void onDownloadSuccess() {
-                    if (position == mPictureList.size()-1) {
-                        createBitmapList(position);
-                    }
-                }
-
-                @Override
-                public void onDownloading(int progress) {
-                }
-
-                @Override
-                public void onDownloadFailed() {
-                }
-            });
-        }
-    }
-
-    private void createBitmapList(int y) {
-        for (int i = 0; i < mPictureList.size(); i++) {
-            listBitmap1.add(BitmapFactory.decodeFile(getSavePath(mPictureList.get(i).getPicture())));
-            Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.sheep_logo);
-            Bitmap bitmap = ZXingHelper.createQRCodeWithLogo(mPictureList.get(y).getLink(), logo);
-            listBitmap2.add(bitmap);
-        }
-        handler.sendEmptyMessage(1);
-    }
-
-    @SuppressLint("HandlerLeak")
-    private Handler handler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            super.handleMessage(msg);
-            switch (msg.what) {
-                case 1:
-                  /*  for (int i = 0; i < size; i++) {
-                        listBitmap.add(mergeBitmap(listBitmap1.get(i), listBitmap2.get(i)));
-                    }*/
-                    adapter.notifyDataSetChanged();
-
-                    break;
-                case 2:
-                    break;
-                default:
-
-                    break;
-            }
-        }
-    };
 
     private File getViewFile(View addViewContent) {
         if (addViewContent==null){

+ 5 - 1
app/src/main/res/layout/activity_invitation.xml

@@ -30,12 +30,16 @@
         <android.support.v7.widget.RecyclerView
             android:id="@+id/recyclerView"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content" />
+            android:layout_height="0dp"
+            android:layout_weight="1"
+            android:clipChildren="true"/>
 
         <TextView
             android:id="@+id/tv_flags"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/content_padding_16"
+            android:layout_marginBottom="@dimen/content_padding_16"
             android:text="左右滑动选择推广页" />
 
     </LinearLayout>

+ 1 - 1
app/src/main/res/layout/item_image.xml

@@ -8,6 +8,6 @@
         android:id="@+id/img_detail"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
-        android:layout_marginRight="12dp" />
+        android:layout_marginEnd="12dp" />
 
 </LinearLayout>

+ 31 - 0
app/src/main/res/layout/item_image2.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <ImageView
+        android:id="@+id/image_full"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_centerHorizontal="true"
+        android:adjustViewBounds="true"
+        android:scaleType="fitXY" />
+
+    <ImageView
+        android:id="@+id/image_bottom"
+        android:layout_width="100dp"
+        android:layout_height="100dp"
+        android:layout_alignParentBottom="true"
+        android:layout_centerHorizontal="true"
+        android:src="@drawable/loading_01" />
+
+    <ImageView
+        android:layout_width="100dp"
+        android:layout_height="100dp"
+        android:layout_alignParentBottom="true"
+        android:layout_centerHorizontal="true"
+        android:padding="40dp"
+        android:src="@mipmap/sheep_logo" />
+
+
+</RelativeLayout>