Commit 87fe641a authored by jianglx's avatar jianglx

分享初次提交

parent a8ba5f7b
......@@ -107,8 +107,9 @@
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="shareinstall为当前应用分配的scheme" />
</intent-filter>
</activity> <!-- 百度地图相关 -->
<!-- 声明service组件 -->
......
......@@ -2,6 +2,8 @@ package com.xxfc.rv;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.os.StrictMode;
import com.alibaba.android.arouter.launcher.ARouter;
......@@ -17,6 +19,7 @@ import com.frame.base.bean.BeanHeartbeat;
import com.frame.base.manager.MyFrameManager;
import com.frame.rv.config.RvFrameConfig;
import com.ruiwenliu.wrapper.util.LogUtils;
import com.sh.sdk.shareinstall.ShareInstall;
import com.tencent.bugly.crashreport.CrashReport;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
......@@ -46,6 +49,9 @@ public class RvClientApplication extends FrameApp {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
if (isMainProcess()) {
ShareInstall.getInstance().init(getApplicationContext());
}
CrashHandler.getInstance().init(this);
......@@ -95,6 +101,22 @@ public class RvClientApplication extends FrameApp {
}
/**
* 判断当前进程是否是应用的主进程
*
* @return
*/
public boolean isMainProcess() {
int pid = android.os.Process.myPid();
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
if (appProcess.pid == pid) {
return getApplicationInfo().packageName.equals(appProcess.processName);
}
}
return false;
}
@Override
public void onTerminate() {
super.onTerminate();
......
......@@ -3,6 +3,7 @@ package com.xxfc.rv;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.ruiwenliu.wrapper.base.BaseActivity;
import com.ruiwenliu.wrapper.base.BaseBean;
......@@ -10,8 +11,13 @@ import com.ruiwenliu.wrapper.util.UtilsManager;
import com.ruiwenliu.wrapper.weight.TitleView;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.sh.sdk.shareinstall.ShareInstall;
import com.sh.sdk.shareinstall.listener.AppGetInfoListener;
import com.yuyife.okgo.OkGoUtil;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;
import io.reactivex.Flowable;
......@@ -37,6 +43,22 @@ public class WelcomeActivity extends BaseActivity<CommonPresenter> {
protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
showTitle(false);//隐藏菜单栏
interval();
ShareInstall.getInstance().getInfo(getIntent(), new AppGetInfoListener() {
@Override
public void onGetInfoFinish(String info) {
// 客户端获取到的参数是json字符串格式
Log.d("ShareInstall", "info = " + info);
try {
JSONObject object = new JSONObject(info);
// 通过该方法拿到设置的渠道值,剩余值为自定义的其他参数
String channel = object.optString("channel");
Log.d("ShareInstall", "channel = " + channel);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
@Override
......
......@@ -43,7 +43,6 @@ public class FileUtil {
* 在程序入口时就建立了
*/
public static void setAppFileDir() {
File sd = Environment.getExternalStorageDirectory();
String rootPath = sd.getPath() + Config.appDir;
File rootFile = new File(rootPath);
......
......@@ -30,4 +30,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.zxing:core:3.3.0'
}
package com.rv.component.utils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
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 java.util.HashMap;
import java.util.Map;
public class ZxingUtils {
public static Bitmap createQRImage(String content, int widthPix, int heightPix,
Bitmap logoBm) {
try {
//配置参数
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//容错级别
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
//设置空白边距的宽度
hints.put(EncodeHintType.MARGIN, 1); //default is 4
// 图像数据转换,使用了矩阵转换
BitMatrix bitMatrix = null;
try {
bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix,
heightPix, hints);
} catch (WriterException e) {
e.printStackTrace();
}
int[] pixels = new int[widthPix * heightPix];
// 下面这里按照二维码的算法,逐个生成二维码的图片,
// 两个for循环是图片横列扫描的结果
for (int y = 0; y < heightPix; y++) {
for (int x = 0; x < widthPix; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * widthPix + x] = 0xff000000;
} else {
pixels[y * widthPix + x] = 0xffffffff;
}
}
}
// 生成二维码图片的格式,使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
if (logoBm != null) {
bitmap = Logo(bitmap, logoBm);
}
//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,
// 内存消耗巨大!
return bitmap;
// return bitmap != null && bitmap.compress(Bitmap.CompressFormat.JPEG, 100);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static Bitmap Logo(Bitmap src, Bitmap logo) {
if (src == null) {
return null;
}
if (logo == null) {
return src;
}
//获取图片的宽高
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int logoWidth = logo.getWidth();
int logoHeight = logo.getHeight();
if (srcWidth == 0 || srcHeight == 0) {
return null;
}
if (logoWidth == 0 || logoHeight == 0) {
return src;
}
//logo大小为二维码整体大小的1/5
float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
try {
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(src, 0, 0, null);
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
canvas.save();
canvas.restore();
} catch (Exception e) {
bitmap = null;
e.getStackTrace();
}
return bitmap;
}
}
......@@ -22,6 +22,7 @@ import com.ruiwenliu.wrapper.base.BaseBean;
import com.ruiwenliu.wrapper.util.TimeManager;
import com.ruiwenliu.wrapper.util.glide.GlideManager;
import com.ruiwenliu.wrapper.weight.TitleView;
import com.rv.component.utils.ZxingUtils;
import com.rv.home.R;
import com.rv.home.R2;
import com.rv.home.rv.module.basic.BaseStatusActivity;
......@@ -83,15 +84,15 @@ public class PickUpTheCarQRCodeActivity extends BaseStatusActivity<PickerPresent
showTitle(false);
dataBean = (OrderListBean.DataBeanX.DataBean) intent.getSerializableExtra("dataBean");
if (dataBean != null){
if (4==dataBean.getStatusX()){
if (dataBean != null) {
if (4 == dataBean.getStatusX()) {
tvCenter.setText("出示取车二维码");
}else if (5==dataBean.getStatusX()){
} else if (5 == dataBean.getStatusX()) {
tvCenter.setText("出示还车二维码");
}
tvCarType.setText(dataBean.getName());
OrderListBean.DataBeanX.DataBean.OrderRentVehicleDetail detail = dataBean.getOrderRentVehicleDetail();
if (detail !=null){
if (detail != null) {
tvGetAddress.setText(detail.getStart_addr());
tvGetTime.setText(TimeManager.stampToDate(String.valueOf(detail.getStart_time())));
tvOutAddress.setText(detail.getEnd_addr());
......@@ -102,7 +103,7 @@ public class PickUpTheCarQRCodeActivity extends BaseStatusActivity<PickerPresent
}
//生成带中间图标的二维码
Bitmap success =createQRImage(dataBean.getQrcodeStr(), 100, 100,
Bitmap success = ZxingUtils.createQRImage(dataBean.getQrcodeStr(), 100, 100,
BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
ivZxing.setImageBitmap(success);
}
......@@ -128,97 +129,4 @@ public class PickUpTheCarQRCodeActivity extends BaseStatusActivity<PickerPresent
showToast("该功能还在开发中...");
}
}
public static Bitmap createQRImage(String content, int widthPix, int heightPix,
Bitmap logoBm) {
try {
//配置参数
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//容错级别
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
//设置空白边距的宽度
hints.put(EncodeHintType.MARGIN, 1); //default is 4
// 图像数据转换,使用了矩阵转换
BitMatrix bitMatrix = null;
try {
bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix,
heightPix, hints);
} catch (WriterException e) {
e.printStackTrace();
}
int[] pixels = new int[widthPix * heightPix];
// 下面这里按照二维码的算法,逐个生成二维码的图片,
// 两个for循环是图片横列扫描的结果
for (int y = 0; y < heightPix; y++) {
for (int x = 0; x < widthPix; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * widthPix + x] = 0xff000000;
} else {
pixels[y * widthPix + x] = 0xffffffff;
}
}
}
// 生成二维码图片的格式,使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
if (logoBm != null) {
bitmap = Logo(bitmap, logoBm);
}
//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,
// 内存消耗巨大!
return bitmap;
// return bitmap != null && bitmap.compress(Bitmap.CompressFormat.JPEG, 100);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static Bitmap Logo(Bitmap src, Bitmap logo) {
if (src == null) {
return null;
}
if (logo == null) {
return src;
}
//获取图片的宽高
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int logoWidth = logo.getWidth();
int logoHeight = logo.getHeight();
if (srcWidth == 0 || srcHeight == 0) {
return null;
}
if (logoWidth == 0 || logoHeight == 0) {
return src;
}
//logo大小为二维码整体大小的1/5
float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
try {
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(src, 0, 0, null);
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
canvas.save();
canvas.restore();
} catch (Exception e) {
bitmap = null;
e.getStackTrace();
}
return bitmap;
}
}
......@@ -47,4 +47,5 @@ dependencies {
//动态权限申请库
implementation 'pub.devrel:easypermissions:1.3.0'
implementation 'com.alibaba:fastjson:1.2.21'
api project(':plugin_share')
}
......@@ -33,6 +33,7 @@ import com.rv.home.rv.module.ApiConfig;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.rv.home.rv.module.ui.login.LoginRvActivity;
import com.rv.home.rv.module.ui.main.home.DrivingListActivity;
import com.rv.home.rv.module.ui.main.home.ShareImageActivity;
import com.rv.home.rv.module.ui.main.home.bean.BeanHomeBanner;
import com.rv.home.rv.module.ui.main.home.order.OrderListActivity;
import com.rv.member.MemberCenterActivity;
......@@ -43,6 +44,7 @@ import com.rv.rvmine.traveler.ChooseAVisitorActivity;
import com.rv.rvmine.traveler.CollectionActivity;
import com.rv.rvmine.traveler.PersonalInformationActivity;
import com.rv.rvmine.traveler.SettingActivity;
import com.rv.share.ShareActivity;
import com.yuyife.banner.Banner;
import com.yuyife.banner.BannerConfig;
import com.yuyife.banner.listener.OnBannerListener;
......@@ -60,6 +62,7 @@ import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.reactivex.schedulers.Schedulers;
/**
* 我的
*/
......@@ -109,7 +112,8 @@ public class MineFragment extends BaseFragment<CommonPresenter> implements Simpl
SimpleRefreshLayout mSimpleRefreshLayout;
@BindView(R2.id.tv_user_identity)
TextView tvUserIdentity;
@BindView(R2.id.rl_item_share)
RelativeLayout rlItemShare;
Unbinder unbinder;
......@@ -190,7 +194,7 @@ public class MineFragment extends BaseFragment<CommonPresenter> implements Simpl
@OnClick({R2.id.iv_avatar, R2.id.tv_login, R2.id.tv_verified, R2.id.rl_item_to_be_paid, R2.id.rl_item_staying,
R2.id.rl_item_traveling, R2.id.rl_item_completed, R2.id.rl_item_all, R2.id.rl_item_collection, R2.id.rl_item_personal_information,
R2.id.rl_item_setting, R2.id.rl_item_driver, R2.id.rl_item_traveler, R2.id.rl_item_my_pat, R2.id.tv_view_privileges})
R2.id.rl_item_setting, R2.id.rl_item_driver, R2.id.rl_item_traveler, R2.id.tv_view_privileges, R2.id.rl_item_share})
public void onViewClicked(View view) {
int id = view.getId();
if (id == R.id.iv_avatar) {
......@@ -259,10 +263,10 @@ public class MineFragment extends BaseFragment<CommonPresenter> implements Simpl
//出游人
if (isLogin()) return;
startActivity(new Intent(_mActivity, ChooseAVisitorActivity.class));
} else if (id == R.id.rl_item_my_pat) {
//我的拍拍
} else if (id == R.id.tv_view_privileges) {
startActivity(MemberCenterActivity.getIntent(_mActivity));
} else if (id == R.id.rl_item_share) {
startActivity(new Intent(_mActivity,ShareActivity.class));
}
}
......@@ -394,9 +398,9 @@ public class MineFragment extends BaseFragment<CommonPresenter> implements Simpl
if (!TextUtils.isEmpty(info.getIcon()))
GlideManager.getInstance(getContext()).loadImage(info.getIcon(), ivMember);
if (TextUtils.isEmpty(info.getPositionName())){
if (TextUtils.isEmpty(info.getPositionName())) {
tvUserIdentity.setVisibility(View.GONE);
}else {
} else {
tvUserIdentity.setText(info.getPositionName());
tvUserIdentity.setVisibility(View.VISIBLE);
......
......@@ -108,7 +108,6 @@
</LinearLayout>
<TextView
android:id="@+id/tv_login"
android:layout_width="@dimen/size_150"
......@@ -513,12 +512,28 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_item_my_pat"
android:id="@+id/rl_item_share"
android:layout_width="0dp"
android:layout_height="@dimen/size_60"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/mycenter_icon_visitors" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/size_18"
android:text="@string/tv_share"
android:textColor="@color/colorMain"
android:textSize="@dimen/size_12" />
</RelativeLayout>
<RelativeLayout
......
......@@ -36,6 +36,7 @@
<string name="add_a_visitor_title">添加出游人</string>
<string name="tv_driver">驾驶人</string>
<string name="tv_traveler">出游人</string>
<string name="tv_share">分享</string>
<string name="tv_my_release">我的发布</string>
<string name="tv_open_membership">立即开通普通会员</string>
......
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':module_home')
api files('libs/ShareInstall_1.2.0.aar')
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rv.share">
<application>
<activity android:name=".ShareActivity" />
<meta-data
android:name="com.shareinstall.APP_KEY"
android:value="shareinstall为当前应用分配的appkey" />
<activity android:name=".BillActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package com.rv.share;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.base.utils.ui.image.round.RoundImageView;
import com.frame.base.url.Constance;
import com.ruiwenliu.wrapper.base.BaseActivity;
import com.ruiwenliu.wrapper.base.BaseBean;
import com.ruiwenliu.wrapper.base.BaseStatusActivity;
import com.ruiwenliu.wrapper.weight.TitleView;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.rv.share.presenter.BillPresenter;
import butterknife.BindView;
import butterknife.OnClick;
/********
*
* 海报界面
* created by john
*/
public class BillActivity extends BaseStatusActivity<BillPresenter> {
@BindView(R2.id.tv_back_title)
TextView tvBackTitle;
@BindView(R2.id.btn_share)
Button btnShare;
@BindView(R2.id.rimg_avatar)
RoundImageView imageView;
@BindView(R2.id.tv_name)
TextView tvName;
@BindView(R2.id.img_zxing)
ImageView imgZxing;
@BindView(R2.id.ll_long_click)
LinearLayout llLongClick;
@BindView(R2.id.ll_bill_content)
LinearLayout llBillContent;
@Override
protected int setLayout() {
return R.layout.activity_bill;
}
@Override
protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
titleView.setVisibility(View.GONE);
llLongClick.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
mPresenter.showShareDialog(llBillContent);
return false;
}
});
}
@Override
protected void loadData(Bundle savedInstanceState, Intent intent) {
}
@Override
public void onShowResult(int requestType, BaseBean result) {
}
@OnClick({R2.id.tv_back_title, R2.id.btn_share, R2.id.ll_long_click})
public void onViewClicked(View view) {
int id = view.getId();
if (id == R.id.tv_back_title) {
finish();
} else if (id == R.id.btn_share) {
mPresenter.showShareDialog(llBillContent);
}
}
}
package com.rv.share;
import android.content.Intent;
import android.os.Bundle;
import com.ruiwenliu.wrapper.base.BaseBean;
import com.ruiwenliu.wrapper.weight.TitleView;
import com.rv.home.rv.module.basic.BaseStatusActivity;
import com.rv.share.presenter.SharePresenter;
public class ShareActivity extends BaseStatusActivity<SharePresenter> {
@Override
protected int setLayout() {
return R.layout.activity_share;
}
@Override
protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
}
@Override
protected void loadData(Bundle savedInstanceState, Intent intent) {
super.loadData(savedInstanceState, intent);
mPresenter.showShareDialog();
}
@Override
public void onShowResult(int requestType, BaseBean result) {
}
}
package com.rv.share.presenter;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.rv.share.BillActivity;
import com.rv.share.utils.StorageUtils;
import com.rv.share.view.ShareChoiceDialog;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.ShareContent;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class BillPresenter extends CommonPresenter {
private ShareChoiceDialog dialog = null;
private ShareAction shareAction = null;
private LinearLayout view = null;
private Bitmap bitmap = null;
private UMImage image = null;
public void showShareDialog(LinearLayout llBillContent) {
this.view = llBillContent;
if (dialog == null) {
dialog = new ShareChoiceDialog.Builder(getPresenterContext())
.setShareListener(myListener)
.setWxVisiable(true)
.setWxCVisiable(true)
.setQQVisiable(true)
.create();
}
dialog.show();
}
/******
* 分享地址
* @param var1
* @param var2
*/
private void share(SHARE_MEDIA var1, String var2) {
if (shareAction == null) {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
shareAction.setPlatform(var1)//传入平台
.withText(var2);//分享内容
shareAction.share();
}
/******
* 分享文件
* @param var1
* @param var2
*/
private void share(SHARE_MEDIA var1, UMImage var2, String content) {
if (shareAction == null) {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
shareAction.setPlatform(var1)//传入平台
.withText(content)
.withMedia(var2);//分享内容
shareAction.share();
}
/**
* view转bitmap
*/
public 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_8888);
Canvas c = new Canvas(bmp);
c.drawColor(Color.WHITE);
v.layout(startX, startY, w + startX, h + startY);
v.draw(c);
return bmp;
}
public File saveBitmapFile(Bitmap bitmap) {
File file = new File(StorageUtils.getCachePath(getPresenterContext()) + System.currentTimeMillis() + ".jpg");//将要保存图片的路径
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
private UMShareListener shareListener = new UMShareListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
Log.e("xxxxxxxxxx", "shareOnstart");
}
@Override
public void onResult(SHARE_MEDIA share_media) {
Log.e("xxxxxxxxxx", "shareonResult");
}
@Override
public void onError(SHARE_MEDIA share_media, Throwable throwable) {
Log.e("xxxxxxxxxx", "shareonError:" + throwable.getMessage());
}
@Override
public void onCancel(SHARE_MEDIA share_media) {
Log.e("xxxxxxxxxx", "shareonCancel");
}
};
private ShareChoiceDialog.ShareListener myListener = new ShareChoiceDialog.ShareListener() {
private void shareDeal() {
if (view != null && bitmap == null) {
bitmap = viewConversionBitmap(view);
}
File file = null;
if (bitmap != null) {
file = saveBitmapFile(bitmap);
}
if (file != null) {
image = new UMImage(getPresenterContext(), file);//bitmap文件
image.compressStyle = UMImage.CompressStyle.SCALE;//大小压缩,默认为大小压缩,适合普通很大的图
image.compressStyle = UMImage.CompressStyle.QUALITY;//质量压缩,适合长图的分享
image.compressFormat = Bitmap.CompressFormat.PNG;
}
}
@Override
public void copyShare() {
}
@Override
public void wxShare() {
if (image == null) {
shareDeal();
}
if (image != null) {
share(SHARE_MEDIA.WEIXIN, image, "hello");
}
}
@Override
public void wxCShare() {
share(SHARE_MEDIA.WEIXIN_CIRCLE, "hello");
}
@Override
public void qqShare() {
}
@Override
public void billShare() {
}
@Override
public void close() {
}
};
@Override
public void detachView() {
super.detachView();
if (bitmap != null) {
bitmap.recycle();
}
}
}
package com.rv.share.presenter;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import com.rv.home.rv.module.basic.presenter.CommonPresenter;
import com.rv.share.BillActivity;
import com.rv.share.view.ShareChoiceDialog;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import java.io.File;
public class SharePresenter extends CommonPresenter {
private ShareChoiceDialog dialog = null;
private ShareAction shareAction = null;
public void showShareDialog() {
if (dialog == null) {
dialog = new ShareChoiceDialog.Builder(getPresenterContext())
.setShareListener(myListener)
.setCopyVisiable(true)
.setWxVisiable(true)
.setWxCVisiable(true)
.setQQVisiable(true)
.setBillVisiable(true)
.create();
}
dialog.show();
}
/******
* 分享地址
* @param var1
* @param var2
*/
private void share(SHARE_MEDIA var1, String var2) {
if (shareAction == null) {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
shareAction.setPlatform(var1)//传入平台
.withText(var2);//分享内容
shareAction.share();
}
/******
* 分享文件
* @param var1
* @param var2
*/
private void share(SHARE_MEDIA var1, File var2) {
if (shareAction == null) {
shareAction = new ShareAction((Activity) getPresenterContext()).setCallback(shareListener);
}
shareAction.setPlatform(var1)//传入平台
.withFile(var2);//分享内容
shareAction.share();
}
/*******
* 复制地址
* @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();
}
private UMShareListener shareListener = new UMShareListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
Log.e("xxxxxxxxxx", "shareOnstart");
}
@Override
public void onResult(SHARE_MEDIA share_media) {
Log.e("xxxxxxxxxx", "shareonResult");
}
@Override
public void onError(SHARE_MEDIA share_media, Throwable throwable) {
Log.e("xxxxxxxxxx", "shareonError:" + throwable.getMessage());
}
@Override
public void onCancel(SHARE_MEDIA share_media) {
Log.e("xxxxxxxxxx", "shareonCancel");
}
};
private ShareChoiceDialog.ShareListener myListener = new ShareChoiceDialog.ShareListener() {
@Override
public void copyShare() {
copy("http://www.baidu.com");
}
@Override
public void wxShare() {
share(SHARE_MEDIA.WEIXIN, "hello");
}
@Override
public void wxCShare() {
share(SHARE_MEDIA.WEIXIN_CIRCLE, "hello");
}
@Override
public void qqShare() {
}
@Override
public void billShare() {
getPresenterContext().startActivity(new Intent(getPresenterContext(), BillActivity.class));
}
@Override
public void close() {
}
};
}
package com.rv.share.utils;
import android.content.Context;
import android.os.Environment;
public class StorageUtils {
public static String getCachePath(Context context) {
String cachePath = null;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
cachePath = context.getExternalCacheDir().getPath();
} else {
cachePath = context.getCacheDir().getPath();
}
return cachePath;
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="5dp" />
<solid android:color="@color/white" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FE6E2F"
tools:context=".BillActivity">
<TextView
android:id="@+id/tv_back_title"
android:layout_width="wrap_content"
android:layout_height="@dimen/size_40"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/dp_10"
android:drawableLeft="@drawable/rv_common_icon_back_white"
android:drawablePadding="@dimen/size_5"
android:gravity="center_vertical"
android:text="生成海报"
android:textColor="@color/white"
android:textSize="@dimen/text_18" />
<LinearLayout
android:id="@+id/ll_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/dp_10"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="分享海报,可以让好友一起参加啦~"
android:textColor="@color/gray_f5f5f5"
android:textSize="@dimen/sp_12" />
<Button
android:id="@+id/btn_share"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginTop="@dimen/size_5"
android:layout_marginRight="@dimen/dp_10"
android:background="@drawable/shape_rv_bg_dark_yellow"
android:gravity="center"
android:text="立即分享"
android:textColor="@color/white"
android:textSize="@dimen/sp_16" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_bill_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ll_bottom"
android:layout_centerInParent="true"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:layout_marginBottom="@dimen/size_20"
android:background="@drawable/shape_rv_bg_bill"
android:orientation="vertical">
<ImageView
android:scaleType="fitXY"
android:src="@drawable/icon_bill_test"
android:layout_width="match_parent"
android:layout_height="280dp" />
<LinearLayout
android:gravity="left|center_vertical"
android:id="@+id/ll_long_click"
android:layout_width="match_parent"
android:layout_height="@dimen/size_120"
android:orientation="horizontal">
<com.base.utils.ui.image.round.RoundImageView
android:id="@+id/rimg_avatar"
android:layout_width="@dimen/size_60"
android:layout_height="@dimen/size_60"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/common_icon_avatar_default" />
<LinearLayout
android:layout_marginLeft="@dimen/size_5"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignRight="@id/rimg_avatar"
android:layout_centerVertical="true"
android:gravity="left"
android:orientation="vertical">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="房车旅行家Rose"
android:textSize="@dimen/sp_16" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="邀请你一起参加"
android:textColor="@color/gray_50000000"
android:textSize="@dimen/sp_12" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/dp_10"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/img_zxing"
android:layout_width="@dimen/size_80"
android:layout_height="@dimen/size_80"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="长按领50元现金"
android:textColor="@color/gray_50000000"
android:textSize="@dimen/dp_10" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ShareActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/size_200"
android:background="@drawable/shape_rv_bg_purple">
<ImageButton
android:id="@+id/imb_act"
android:layout_width="@dimen/size_80"
android:layout_height="@dimen/size_30"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="@dimen/size_20" />
<LinearLayout
android:layout_width="@dimen/size_200"
android:layout_height="@dimen/dp_40"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<!--<ImageView-->
<!--android:layout_width=""-->
<!--android:layout_height="" />-->
</LinearLayout>
</RelativeLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#66ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:weightSum="5"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_copy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:layout_marginBottom="13dp"
android:layout_weight="1"
android:gravity="center"
android:text="复制链接"
android:visibility="gone" />
<TextView
android:id="@+id/tv_weixin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:layout_marginBottom="13dp"
android:layout_weight="1"
android:gravity="center"
android:text="微信"
android:visibility="gone" />
<TextView
android:id="@+id/tv_weixin_circle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:layout_marginBottom="13dp"
android:layout_weight="1"
android:gravity="center"
android:text="朋友圈"
android:visibility="gone" />
<TextView
android:id="@+id/tv_qq"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:layout_marginBottom="13dp"
android:layout_weight="1"
android:gravity="center"
android:text="QQ"
android:visibility="gone" />
<TextView
android:id="@+id/tv_bill"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:layout_marginBottom="13dp"
android:layout_weight="1"
android:text="生成海报"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/size_10"
android:layout_marginRight="@dimen/dp_10">
<include layout="@layout/common_line" />
</LinearLayout>
<TextView
android:id="@+id/tv_cancel"
android:layout_width="match_parent"
android:layout_height="@dimen/size_48"
android:gravity="center"
android:text="取消" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#ffffff</color>
</resources>
<resources>
<string name="app_name">plugin_share</string>
</resources>
//include ':WXPay'
include ':RvFrame', ':plugin_calendar', ':plugin_time'
include ':RvFrame', ':plugin_calendar', ':plugin_time', ':plugin_share'
include ':RvTravel'
include ':RvClient'
include ':RvWrapper'
......
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