|
|
@@ -7,6 +7,7 @@ import android.graphics.Bitmap;
|
|
|
import android.graphics.BitmapFactory;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Matrix;
|
|
|
+import android.graphics.Paint;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Environment;
|
|
|
import android.os.Handler;
|
|
|
@@ -24,8 +25,17 @@ import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.zxing.BarcodeFormat;
|
|
|
+import com.google.zxing.EncodeHintType;
|
|
|
+import com.google.zxing.WriterException;
|
|
|
+import com.google.zxing.common.BitMatrix;
|
|
|
+import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
|
import com.kfzs.duanduan.cardview.CardScaleHelper;
|
|
|
+import com.sheep.gamegroup.helper.DownloadUtil;
|
|
|
import com.sheep.gamegroup.helper.ScalableCardHelper;
|
|
|
+import com.sheep.gamegroup.helper.ZXingHelper;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
import com.sheep.gamegroup.model.entity.FriendAndAwardEntity;
|
|
|
@@ -37,6 +47,7 @@ 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;
|
|
|
@@ -55,6 +66,7 @@ import com.umeng.socialize.media.UMWeb;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Hashtable;
|
|
|
import java.util.List;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
@@ -79,6 +91,10 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
RecyclerView mRecyclerView;
|
|
|
@BindView(R.id.blurView)
|
|
|
ImageView mBlurView;
|
|
|
+ @BindView(R.id.img_baseactivity_title)
|
|
|
+ ImageView ivBack;
|
|
|
+ @BindView(R.id.txt_baseactivity_title)
|
|
|
+ TextView tvTitle;
|
|
|
private List<Integer> mList = new ArrayList<>();
|
|
|
private CardScaleHelper mCardScaleHelper = null;
|
|
|
private Runnable mBlurRunnable;
|
|
|
@@ -103,8 +119,9 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
private List<Bitmap> listBitmap = new ArrayList<>();
|
|
|
private List<Bitmap> listBitmap1 = new ArrayList<>();
|
|
|
private List<Bitmap> listBitmap2 = new ArrayList<>();
|
|
|
- private MyAdapter adapter;
|
|
|
-
|
|
|
+ private MyAdapter adapter;
|
|
|
+ private int size = 0;
|
|
|
+ private View view = null;
|
|
|
|
|
|
@Override
|
|
|
|
|
|
@@ -112,36 +129,29 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_invitation);
|
|
|
ButterKnife.bind(this);
|
|
|
+ initView();
|
|
|
initData();
|
|
|
- // initPicture();
|
|
|
- cerateAdapter(listBitmap,this);
|
|
|
+ // initPicture();
|
|
|
+ cerateAdapter(listBitmap1, this);
|
|
|
getPicetureList();
|
|
|
}
|
|
|
|
|
|
- private void initPicture() {
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
- mList.add(R.drawable.kaipin);
|
|
|
- mList.add(R.drawable.kaipin);
|
|
|
- mList.add(R.drawable.kaipin);
|
|
|
- }
|
|
|
-
|
|
|
- // final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
|
|
|
- // mRecyclerView.setLayoutManager(linearLayoutManager);
|
|
|
- //mRecyclerView.setAdapter(new CardAdapter(mList));
|
|
|
- // mRecyclerView绑定scale效果
|
|
|
- // mCardScaleHelper = new CardScaleHelper();
|
|
|
- // mCardScaleHelper.setCurrentItemPos(1);
|
|
|
- // mCardScaleHelper.attachToRecyclerView(mRecyclerView);
|
|
|
-
|
|
|
-
|
|
|
+ private void initView() {
|
|
|
+ tvTitle.setText("邀请赚钱");
|
|
|
+ ivBack.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ InvitationActivity.this.finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param list Bitmap集合
|
|
|
+ * @param list Bitmap集合
|
|
|
* @param context
|
|
|
*/
|
|
|
- private void cerateAdapter( List<Bitmap> list, Context context) {
|
|
|
- adapter = new MyAdapter(context, list);
|
|
|
+ private void cerateAdapter(List<Bitmap> list, Context context) {
|
|
|
+ adapter = new MyAdapter(context, list, listBitmap2);
|
|
|
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
|
|
layoutManager.setOrientation(OrientationHelper.HORIZONTAL);
|
|
|
mRecyclerView.setLayoutManager(layoutManager);
|
|
|
@@ -193,8 +203,6 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
if (position == 1 || position == 2) {
|
|
|
- mBitmap = getBitmap();
|
|
|
- mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.kaipin);
|
|
|
popShare(InvitationActivity.this, url, item, description, mBitmap);
|
|
|
} else {
|
|
|
popShare(InvitationActivity.this, url, item, description, null);
|
|
|
@@ -206,9 +214,6 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
ask_share_list.setAdapter(adapter);
|
|
|
}
|
|
|
|
|
|
- private Bitmap getBitmap() {
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 分享 url type 拼接
|
|
|
@@ -352,12 +357,12 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
|
|
|
@Override
|
|
|
public void onPageSelected(int position) {
|
|
|
+ mBitmap=getViewBitmap(adapter.getView());
|
|
|
Log.i("aaaa", "当前位置" + position);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 来获取邀请图片,
|
|
|
- *
|
|
|
*/
|
|
|
private void getPicetureList() {
|
|
|
ArrayList<PictureInvitationEntity> list = new ArrayList<>();
|
|
|
@@ -371,38 +376,57 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
.subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
@Override
|
|
|
public void onNext(BaseMessage baseMessage) {
|
|
|
+ LogUtil.logI("onNext__getPicetureList--" + new Gson().toJson(baseMessage));
|
|
|
mPictureList.addAll(baseMessage.getDataList(PictureInvitationEntity.class));
|
|
|
downloadPictures();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(BaseMessage baseMessage) {
|
|
|
-
|
|
|
+ LogUtil.logI("onError__getPicetureList--" + new Gson().toJson(baseMessage));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @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;
|
|
|
- GlideImageLoader.downLoadImage("pic" + i, mPictureList.get(i).getPicture(), new Action1<File>() {
|
|
|
+ DownloadUtil.get().download(mPictureList.get(position).getPicture(), "sheep", new DownloadUtil.OnDownloadListener() {
|
|
|
@Override
|
|
|
- public void call(File file) {
|
|
|
- if (file == null) {
|
|
|
- listBitmap1.add(BitmapFactory.decodeFile(ClassFileHelper.DIR + "pic" + position + ".png"));
|
|
|
+ public void onDownloadSuccess() {
|
|
|
+ Log.i("aaaa", "下载成功");
|
|
|
+ if (position == mPictureList.size()-1) {
|
|
|
+ Log.i("aaaa", "下载成功"+"---"+size+"-----"+mPictureList.size());
|
|
|
+ createBitmapList(position);
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
- GlideImageLoader.downLoadImage("rx" + i, mPictureList.get(i).getLink(), new Action1<File>() {
|
|
|
+
|
|
|
@Override
|
|
|
- public void call(File file) {
|
|
|
- if (file == null) {
|
|
|
- listBitmap2.add(BitmapFactory.decodeFile(ClassFileHelper.DIR + "rx" + position + ".png"));
|
|
|
+ public void onDownloading(int progress) {
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onDownloadFailed() {
|
|
|
+ Log.i("aaaa", "下载失败");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 bitmapx = ZXingHelper.createQRCodeWithLogo(mPictureList.get(y).getLink(), logo);
|
|
|
+ listBitmap2.add(bitmapx);
|
|
|
+ }
|
|
|
handler.sendEmptyMessage(1);
|
|
|
}
|
|
|
|
|
|
@@ -411,22 +435,76 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
super.handleMessage(msg);
|
|
|
- if (msg.what == 1) {
|
|
|
- for (int i = 0; i < mPictureFileList.size(); i++) {
|
|
|
- if (!listBitmap1.isEmpty() && !listBitmap2.isEmpty()) {
|
|
|
+ switch (msg.what) {
|
|
|
+ case 1:
|
|
|
+ /* for (int i = 0; i < size; i++) {
|
|
|
listBitmap.add(mergeBitmap(listBitmap1.get(i), listBitmap2.get(i)));
|
|
|
- }
|
|
|
- }
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
+ }*/
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * @param addViewContent
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Bitmap getViewBitmap(View addViewContent) {
|
|
|
+ if (addViewContent==null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ addViewContent.setDrawingCacheEnabled(true);
|
|
|
+ addViewContent.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
|
|
|
+ addViewContent.layout(0, 0, addViewContent.getMeasuredWidth(), addViewContent.getMeasuredHeight());
|
|
|
+ addViewContent.buildDrawingCache();
|
|
|
+ Bitmap cacheBitmap = addViewContent.getDrawingCache();
|
|
|
+ Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
|
|
|
+ return bitmap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合成图片
|
|
|
+ * @param firstBitmap
|
|
|
+ * @param secondBitmap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private Bitmap mergeBitmap(Bitmap firstBitmap, Bitmap secondBitmap) {
|
|
|
Bitmap bitmap = Bitmap.createBitmap(firstBitmap.getWidth(), firstBitmap.getHeight(), firstBitmap.getConfig());
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
+ float w = firstBitmap.getWidth();
|
|
|
+ float h = firstBitmap.getHeight();
|
|
|
+ Matrix matrix = new Matrix();
|
|
|
+ //确定secondBitmap大小比例
|
|
|
+ matrix.setScale(secondBitmap.getWidth(), h / secondBitmap.getHeight());
|
|
|
canvas.drawBitmap(firstBitmap, new Matrix(), null);
|
|
|
- canvas.drawBitmap(secondBitmap, 30, 30, null);
|
|
|
+ canvas.drawBitmap(zoomImage(secondBitmap, 50, 50), 320, 320, null);
|
|
|
+ LogUtil.logI("bitmap----first---" + firstBitmap.getWidth() + "--" + firstBitmap.getHeight());
|
|
|
+ LogUtil.logI("bitmap----secound---" + secondBitmap.getWidth() + "--" + secondBitmap.getHeight());
|
|
|
return bitmap;
|
|
|
}
|
|
|
+
|
|
|
+ public static Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) {
|
|
|
+ // 获取这个图片的宽和高
|
|
|
+ float width = bgimage.getWidth();
|
|
|
+ float height = bgimage.getHeight();
|
|
|
+ // 创建操作图片用的matrix对象
|
|
|
+ Matrix matrix = new Matrix();
|
|
|
+ // 计算宽高缩放率
|
|
|
+ float scaleWidth = ((float) newWidth) / width;
|
|
|
+ float scaleHeight = ((float) newHeight) / height;
|
|
|
+ // 缩放图片动作
|
|
|
+ matrix.postScale(scaleWidth, scaleHeight);
|
|
|
+ Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width,
|
|
|
+ (int) height, matrix, true);
|
|
|
+ return bitmap;
|
|
|
+ }
|
|
|
+
|
|
|
}
|