Commit 6d68f8c0 authored by jianglx's avatar jianglx

修改分享模块

parent 91aa6dc0
......@@ -95,7 +95,7 @@ public class ReativeBillActivity extends BaseStatusActivity<ReativeBillPresenter
} else if (id == R.id.btn_save_bill) {
mPresenter.saveBill(llContent);
} else if (id == R.id.btn_share) {
mPresenter.saveShare(llContent);
mPresenter.shareCircle(llContent);
}
}
}
......@@ -117,7 +117,7 @@ public class ShareActivity extends BaseStatusActivity<SharePresenter> {
if (id == R.id.tv_weixin) {
mPresenter.shareWx(shareUrl, "新人专享大礼包,快去领!", " ");
} else if (id == R.id.tv_weixin_circle) {
mPresenter.shareWxC(shareUrl, "新人专享大礼包,快去领!", " ");
mPresenter.shareWxC(shareUrl, "【滴房车】新人专享大礼包,快去领!", " ");
} else if (id == R.id.tv_bill) {
startActivity(ReativeBillActivity.getIntent(this, shareUrl));
} else if (id == R.id.tv_more) {
......
......@@ -100,23 +100,30 @@ public class BillPresenter extends CommonPresenter {
return bmp;
}
public File saveBitmapFile(Bitmap bitmap) {
private File saveBitmapFile(Bitmap bitmap) {
File parent = new File(StorageUtils.getPhotoSavePath(getPresenterContext()));
if (!parent.exists()) {
parent.mkdirs();
}
File file = new File(parent, System.currentTimeMillis() + ".jpg");//将要保存图片的路径
BufferedOutputStream bos = null;
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
StorageUtils.notifyImageChange(getPresenterContext(), file.getPath());
return file;
}
......
package com.rv.share.presenter;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
import android.widget.Toast;
import com.base.utils.ui.datetime.picker.Utils;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.rv.share.utils.ShareUtils;
import com.rv.share.utils.StorageUtils;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
......@@ -20,7 +23,6 @@ import java.io.IOException;
public class ReativeBillPresenter extends CommonPresenter {
private UMImage image = null;
private ShareAction shareAction = null;
/*****
......@@ -29,10 +31,10 @@ public class ReativeBillPresenter extends CommonPresenter {
*/
public void saveBill(View view) {
if (view != null) {
Bitmap bitmap = viewConversionBitmap(view);
Bitmap bitmap = ShareUtils.viewConversionBitmap(view);
File file = null;
if (bitmap != null) {
file = saveBitmapFile(bitmap);
file = ShareUtils.saveBitmapFile(getPresenterContext(),bitmap);
}
if (file != null) {
Toast.makeText(getPresenterContext(), "海报保存在" + file.getAbsolutePath(), Toast.LENGTH_LONG).show();
......@@ -40,19 +42,19 @@ public class ReativeBillPresenter extends CommonPresenter {
}
}
/*****
* 保存海报
/****
* 分享到朋友圈
* @param view
*/
public void saveShare(View view) {
public void shareCircle(View view) {
if (view != null) {
Bitmap bitmap = viewConversionBitmap(view);
Bitmap bitmap = ShareUtils.viewConversionBitmap(view);
File file = null;
if (bitmap != null) {
file = saveBitmapFile(bitmap);
file = ShareUtils.saveBitmapFile(getPresenterContext(), bitmap);
}
if (file != null) {
image = new UMImage(getPresenterContext(), file);//bitmap文件
UMImage image = new UMImage(getPresenterContext(), file);//bitmap文件
image.compressStyle = UMImage.CompressStyle.SCALE;//大小压缩,默认为大小压缩,适合普通很大的图
image.compressStyle = UMImage.CompressStyle.QUALITY;//质量压缩,适合长图的分享
image.compressFormat = Bitmap.CompressFormat.PNG;
......@@ -75,51 +77,4 @@ public class ReativeBillPresenter extends CommonPresenter {
.withMedia(var2);//分享内容
shareAction.share();
}
/**
* view转bitmap
*/
private Bitmap viewConversionBitmap(View v) {
int w = v.getWidth();
int h = v.getHeight();
int startX = (int) v.getX();
int startY = (int) v.getY();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
Canvas c = new Canvas(bmp);
c.drawColor(Color.WHITE);
v.layout(startX, startY, w + startX, h + startY);
v.draw(c);
return bmp;
}
private File saveBitmapFile(Bitmap bitmap) {
File parent = new File(StorageUtils.getPhotoSavePath(getPresenterContext()));
if (!parent.exists()) {
parent.mkdirs();
}
File file = new File(parent, ((int) (System.currentTimeMillis() / 1000000)) + ".jpg");//将要保存图片的路径
if (file.exists()) {
return file;
}
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
StorageUtils.notifyImageChange(getPresenterContext(), file.getPath());
return file;
}
}
......@@ -17,6 +17,7 @@ import com.rv.component.utils.DisplayUtil;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.rv.share.R;
import com.rv.share.ReativeBillActivity;
import com.rv.share.utils.ShareUtils;
import com.rv.share.view.ShareChoiceDialog;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
......@@ -59,7 +60,7 @@ public class SharePresenter extends CommonPresenter {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
UMImage image = new UMImage(getPresenterContext(), R.drawable.share_logo);
UMImage image = new UMImage(getPresenterContext(), R.drawable.icon_share);
UMWeb web = new UMWeb(mUrl);
web.setTitle(mTitle);//标题
web.setThumb(image); //缩略图
......@@ -78,7 +79,7 @@ public class SharePresenter extends CommonPresenter {
if (shareAction == null) {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
UMImage image = new UMImage(getPresenterContext(), R.drawable.share_logo);
UMImage image = new UMImage(getPresenterContext(), R.drawable.icon_share);
UMWeb web = new UMWeb(mUrl);
web.setTitle(mTitle + " " + mDescript);//标题
web.setThumb(image); //缩略图
......@@ -134,7 +135,7 @@ public class SharePresenter extends CommonPresenter {
@Override
public void copyShare() {
if (!TextUtils.isEmpty(mUrl)) {
copy(mUrl);
ShareUtils.copy(getPresenterContext(), mUrl);
}
}
......@@ -167,16 +168,4 @@ public class SharePresenter extends CommonPresenter {
public void close() {
}
};
/*******
* 复制地址
* @param url
*/
private void copy(String url) {
ClipboardManager cm = (ClipboardManager) getPresenterContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData mClipData = ClipData.newRawUri("Label", Uri.parse(url));
cm.setPrimaryClip(mClipData);
Toast.makeText(getPresenterContext(), "复制成功", Toast.LENGTH_SHORT).show();
}
}
......@@ -63,7 +63,7 @@ public class WebViewPresenter extends CommonPresenter {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
UMImage image = new UMImage(getPresenterContext(), R.drawable.share_logo);
UMImage image = new UMImage(getPresenterContext(), R.drawable.icon_share);
UMWeb web = new UMWeb(mUrl);
web.setTitle(mTitle);//标题
web.setThumb(image); //缩略图
......@@ -82,7 +82,7 @@ public class WebViewPresenter extends CommonPresenter {
if (shareAction == null) {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
UMImage image = new UMImage(getPresenterContext(), R.drawable.share_logo);
UMImage image = new UMImage(getPresenterContext(), R.drawable.icon_share);
UMWeb web = new UMWeb(mUrl);
web.setTitle(mTitle);//标题
web.setThumb(image); //缩略图
......
package com.rv.share.utils;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.net.Uri;
import android.view.View;
import android.widget.Toast;
import com.rv.share.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class ShareUtils {
/*******
* 复制地址
* @param url
*/
public static void copy(Context context, String url) {
ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData mClipData = ClipData.newRawUri("Label", Uri.parse(url));
cm.setPrimaryClip(mClipData);
Toast.makeText(context, "复制成功", Toast.LENGTH_SHORT).show();
}
/**
* view转bitmap
*/
public static Bitmap viewConversionBitmap(View v) {
int w = v.getWidth();
int h = v.getHeight();
int startX = (int) v.getX();
int startY = (int) v.getY();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
Canvas c = new Canvas(bmp);
c.drawColor(Color.WHITE);
v.layout(startX, startY, w + startX, h + startY);
v.draw(c);
return bmp;
}
public static File saveBitmapFile(Context context, Bitmap bitmap) {
File parent = new File(StorageUtils.getPhotoSavePath(context));
if (!parent.exists()) {
parent.mkdirs();
}
File file = new File(parent, System.currentTimeMillis() + ".jpg");//将要保存图片的路径
if (file.exists()) {
return file;
}
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
StorageUtils.notifyImageChange(context, file.getPath());
return file;
}
}
......@@ -61,15 +61,15 @@ public class PromotionDialog extends Dialog {
// 为对话框添加布局和设置大小
dialog.addContentView(layout, new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT));
this.button = layout.findViewById(R.id.button);
if (this.act != null && !TextUtils.isEmpty(this.act.getButtonImages())) {
GlideManager.getInstance(mContext).loadImage2(this.act.getButtonImages(), this.button);
}
// if (this.act != null && !TextUtils.isEmpty(this.act.getButtonImages())) {
// GlideManager.getInstance(mContext).loadImage2(this.act.getButtonImages(), this.button);
// }
this.imgBg = layout.findViewById(R.id.img_bg);
if (this.act != null && !TextUtils.isEmpty(this.act.getBackground())) {
GlideManager.getInstance(mContext).loadImage2(this.act.getBackground(), this.imgBg);
}
this.imgClose = layout.findViewById(R.id.img_close);
this.button.setOnClickListener(mListener);
layout.setOnClickListener(mListener);
this.imgClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......
......@@ -6,16 +6,17 @@
android:orientation="vertical">
<FrameLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:minWidth="300dp"
android:layout_width="@dimen/dialog_width"
android:layout_height="wrap_content"
android:minHeight="@dimen/dialog_min_height"
android:orientation="vertical">
<ImageView
android:id="@+id/img_bg"
android:scaleType="fitXY"
android:layout_width="300dp"
android:layout_height="300dp" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/dialog_min_height"
android:scaleType="fitXY" />
<ImageView
......@@ -27,7 +28,8 @@
android:layout_marginTop="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:layout_marginBottom="@dimen/size_10"
android:gravity="center" />
android:gravity="center"
android:visibility="gone" />
</FrameLayout>
......@@ -38,5 +40,4 @@
android:layout_marginTop="10dp"
android:src="@drawable/home_icon_close" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dialog_width">150dp</dimen>
<dimen name="dialog_min_height">150dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dialog_width">200dp</dimen>
<dimen name="dialog_min_height">200dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dialog_width">300dp</dimen>
<dimen name="dialog_min_height">300dp</dimen>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment