This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add wechat share function and fix some bugs
- Loading branch information
Showing
25 changed files
with
167 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":9,"versionName":"1.4.3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] | ||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":10,"versionName":"2.0.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/chejdj/wanandroid/util/wxshare/WxShareDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.chejdj.wanandroid.util.wxshare; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.PopupWindow; | ||
|
||
import com.chejdj.wanandroid.R; | ||
import com.chejdj.wanandroid.network.bean.article.Article; | ||
|
||
public class WxShareDialog { | ||
public static void showWxShareDialog(Context context, View parent, Article article) { | ||
PopupWindow popupWindow = new PopupWindow(LayoutInflater.from(context).inflate(R.layout.wechat_share, null), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); | ||
|
||
View.OnClickListener listener = (View v) -> { | ||
switch (v.getId()) { | ||
case R.id.share_friends: | ||
WxShareUtil.getInstance().shareToWeChat(context, article.getLink(), article.getTitle(), article.getDesc(), 0); | ||
break; | ||
case R.id.share_timeline: | ||
WxShareUtil.getInstance().shareToWeChat(context, article.getLink(), article.getTitle(), article.getDesc(), 1); | ||
break; | ||
default: | ||
Log.e("WxShareDialg", "no this view" + v.getId()); | ||
} | ||
popupWindow.dismiss(); | ||
}; | ||
|
||
|
||
popupWindow.setFocusable(true); | ||
popupWindow.setOutsideTouchable(true); | ||
popupWindow.setBackgroundDrawable(context.getDrawable(R.drawable.wx_share_bg)); | ||
|
||
popupWindow.getContentView().findViewById(R.id.share_friends).setOnClickListener(listener); | ||
popupWindow.getContentView().findViewById(R.id.share_timeline).setOnClickListener(listener); | ||
|
||
popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/chejdj/wanandroid/util/wxshare/WxShareUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.chejdj.wanandroid.util.wxshare; | ||
|
||
import android.content.Context; | ||
import android.graphics.BitmapFactory; | ||
import android.widget.Toast; | ||
|
||
import com.chejdj.wanandroid.R; | ||
import com.chejdj.wanandroid.WanAndroidApplication; | ||
import com.chejdj.wanandroid.util.StringUtil; | ||
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX; | ||
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; | ||
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject; | ||
import com.tencent.mm.opensdk.openapi.IWXAPI; | ||
import com.tencent.mm.opensdk.openapi.WXAPIFactory; | ||
|
||
public class WxShareUtil { | ||
private static final String APP_ID = "*****"; //填入自己的APPID | ||
private IWXAPI api; | ||
|
||
private WxShareUtil() { | ||
api = WXAPIFactory.createWXAPI(WanAndroidApplication.getMyApplication(), APP_ID, true); | ||
api.registerApp(APP_ID); | ||
} | ||
|
||
static class Wrapper { | ||
static WxShareUtil INSTANCE = new WxShareUtil(); | ||
} | ||
|
||
public static WxShareUtil getInstance() { | ||
return Wrapper.INSTANCE; | ||
} | ||
|
||
/** | ||
* @param link 网页链接 | ||
* @param title 网页title | ||
* @param description 网页描述 | ||
* @param type 分享类型,0代表会话,1代表朋友圈 | ||
*/ | ||
public void shareToWeChat(Context context, String link, String title, String description, int type) { | ||
|
||
WXWebpageObject webpageObject = new WXWebpageObject(); | ||
webpageObject.webpageUrl = link; | ||
WXMediaMessage msg = new WXMediaMessage(webpageObject); | ||
msg.title = title; | ||
msg.description = description; | ||
msg.setThumbImage(BitmapFactory.decodeResource(WanAndroidApplication.getMyApplication().getResources(), R.drawable.wanandroid)); | ||
|
||
SendMessageToWX.Req req = new SendMessageToWX.Req(); | ||
req.message = msg; | ||
req.scene = type == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline; | ||
boolean state = api.sendReq(req); | ||
if (!state) { | ||
Toast.makeText(context, StringUtil.getString(context, R.string.wx_share_error), Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" | ||
> | ||
<solid android:color="@color/white"/> | ||
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp"/> | ||
<stroke android:color="@color/gray" android:width="1dp"/> | ||
|
||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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:orientation="horizontal" | ||
> | ||
<TextView | ||
android:id="@+id/share_friends" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:text="@string/wx_friends" | ||
android:textSize="14sp" | ||
android:textColor="@color/black" | ||
android:gravity="center_horizontal" | ||
android:layout_weight="1" | ||
android:layout_marginTop="@dimen/margin_normal" | ||
android:drawableTop="@drawable/wc_friends" | ||
android:layout_marginBottom="@dimen/margin_normal" | ||
/> | ||
<TextView | ||
android:id="@+id/share_timeline" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:text="@string/wx_timeline" | ||
android:layout_marginBottom="@dimen/margin_normal" | ||
android:textSize="14sp" | ||
android:textColor="@color/black" | ||
android:layout_marginTop="@dimen/margin_normal" | ||
android:gravity="center_horizontal" | ||
android:layout_weight="1" | ||
android:drawableTop="@drawable/wc_timeline" | ||
/> | ||
|
||
</LinearLayout> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters