-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
appId不匹配,调用会失败,需要在自己的app中按需使用。
- Loading branch information
liujinwei
committed
Jun 28, 2018
1 parent
e7c2284
commit 32d42fb
Showing
11 changed files
with
357 additions
and
3 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
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
185 changes: 185 additions & 0 deletions
185
app/src/main/java/net/arvin/socialhelper/sample/TestLoginShareActivity.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,185 @@ | ||
package net.arvin.socialhelper.sample; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.RadioGroup; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import net.arvin.socialhelper.SocialHelper; | ||
import net.arvin.socialhelper.callback.SocialLoginCallback; | ||
import net.arvin.socialhelper.callback.SocialShareCallback; | ||
import net.arvin.socialhelper.entities.QQShareEntity; | ||
import net.arvin.socialhelper.entities.ShareEntity; | ||
import net.arvin.socialhelper.entities.ThirdInfoEntity; | ||
import net.arvin.socialhelper.entities.WBShareEntity; | ||
import net.arvin.socialhelper.entities.WXShareEntity; | ||
import net.arvin.socialhelper.sample.utils.SocialUtil; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class TestLoginShareActivity extends AppCompatActivity implements View.OnClickListener, SocialLoginCallback, SocialShareCallback { | ||
private String imgUrl = "https://upload-images.jianshu.io/upload_images/3157525-afe6f0ba902eb523.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"; | ||
private String localImgUrl = "/storage/emulated/0/DCIM/Camera/IMG_20180422_113944.jpg"; | ||
private String title = "个人博客"; | ||
private String summary = "好好学习"; | ||
private String targetUrl = "https://arvinljw.github.io"; | ||
|
||
private SocialHelper socialHelper; | ||
|
||
private TextView tvLoginInfo; | ||
private RadioGroup rgShareInfo; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_test_login_share); | ||
setTitle("测试SocialHelper"); | ||
socialHelper = SocialUtil.getInstance().socialHelper(); | ||
initView(); | ||
initEvent(); | ||
} | ||
|
||
private void initView() { | ||
tvLoginInfo = findViewById(R.id.tv_login_info); | ||
rgShareInfo = findViewById(R.id.rg_share_info); | ||
} | ||
|
||
private void initEvent() { | ||
findViewById(R.id.img_qq).setOnClickListener(this); | ||
findViewById(R.id.img_wx).setOnClickListener(this); | ||
findViewById(R.id.img_wb).setOnClickListener(this); | ||
findViewById(R.id.img_qq_share).setOnClickListener(this); | ||
findViewById(R.id.img_wx_share).setOnClickListener(this); | ||
findViewById(R.id.img_wb_share).setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.img_qq: | ||
socialHelper.loginQQ(this, this); | ||
break; | ||
case R.id.img_wx: | ||
socialHelper.loginWX(this, this); | ||
break; | ||
case R.id.img_wb: | ||
socialHelper.loginWB(this, this); | ||
break; | ||
case R.id.img_qq_share: | ||
socialHelper.shareQQ(this, createQQShareEntity(), this); | ||
break; | ||
case R.id.img_wx_share: | ||
socialHelper.shareWX(this, createWXShareEntity(), this); | ||
break; | ||
case R.id.img_wb_share: | ||
socialHelper.shareWB(this, createWBShareEntity(), this); | ||
break; | ||
} | ||
} | ||
|
||
private ShareEntity createQQShareEntity() { | ||
ShareEntity shareEntity = null; | ||
int checkedRadioButtonId = rgShareInfo.getCheckedRadioButtonId(); | ||
switch (checkedRadioButtonId) { | ||
case R.id.rb_img: | ||
shareEntity = QQShareEntity.createImageInfo(localImgUrl, "ni6"); | ||
break; | ||
case R.id.rb_img_text: | ||
shareEntity = QQShareEntity.createImageTextInfo(title, targetUrl, | ||
imgUrl, summary, "ni6"); | ||
break; | ||
case R.id.rb_web: | ||
//分享到qq空间,因为qq图文就包含了targetUrl所以比较常用 | ||
ArrayList<String> imgUrls = new ArrayList<>(); | ||
imgUrls.add(imgUrl); | ||
shareEntity = QQShareEntity.createImageTextInfoToQZone(title, targetUrl, | ||
imgUrls, summary, "ni6"); | ||
break; | ||
} | ||
return shareEntity; | ||
} | ||
|
||
private ShareEntity createWXShareEntity() { | ||
ShareEntity shareEntity = null; | ||
int checkedRadioButtonId = rgShareInfo.getCheckedRadioButtonId(); | ||
switch (checkedRadioButtonId) { | ||
case R.id.rb_img: | ||
shareEntity = WXShareEntity.createImageInfo(false, localImgUrl); | ||
break; | ||
case R.id.rb_img_text: | ||
//微信图文是分开的,但是在分享到朋友圈的web中是可以有混合的 | ||
shareEntity = WXShareEntity.createImageInfo(false, R.mipmap.ic_launcher); | ||
break; | ||
case R.id.rb_web: | ||
shareEntity = WXShareEntity.createWebPageInfo(false, targetUrl, R.mipmap.ic_launcher, | ||
title, summary); | ||
break; | ||
} | ||
return shareEntity; | ||
} | ||
|
||
private ShareEntity createWBShareEntity() { | ||
ShareEntity shareEntity = null; | ||
int checkedRadioButtonId = rgShareInfo.getCheckedRadioButtonId(); | ||
switch (checkedRadioButtonId) { | ||
case R.id.rb_img: | ||
shareEntity = WBShareEntity.createImageTextInfo(localImgUrl, title); | ||
break; | ||
case R.id.rb_img_text: | ||
shareEntity = WBShareEntity.createImageTextInfo(R.mipmap.ic_launcher, title); | ||
break; | ||
case R.id.rb_web: | ||
shareEntity = WBShareEntity.createWebInfo(targetUrl, | ||
title, summary, R.mipmap.ic_launcher, "这是要说的内容"); | ||
break; | ||
} | ||
return shareEntity; | ||
} | ||
|
||
//用处:qq登录和分享回调,以及微博登录回调 | ||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (data != null && socialHelper != null) {//qq分享如果选择留在qq,通过home键退出,再进入app则不会有回调 | ||
socialHelper.onActivityResult(requestCode, resultCode, data); | ||
} | ||
} | ||
|
||
//用处:微博分享回调 | ||
@Override | ||
protected void onNewIntent(Intent intent) { | ||
super.onNewIntent(intent); | ||
if (socialHelper != null) { | ||
socialHelper.onNewIntent(intent); | ||
} | ||
} | ||
|
||
@Override | ||
public void loginSuccess(ThirdInfoEntity info) { | ||
tvLoginInfo.setText(toString(info)); | ||
} | ||
|
||
@Override | ||
public void socialError(String msg) { | ||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void shareSuccess() { | ||
Toast.makeText(this, "分享成功", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
private String toString(ThirdInfoEntity info) { | ||
return "登录信息 = {" + | ||
"unionId='" + info.getUnionId() + '\'' + | ||
", openId='" + info.getOpenId() + '\'' + | ||
", nickname='" + info.getNickname() + '\'' + | ||
", sex='" + info.getSex() + '\'' + | ||
", avatar='" + info.getAvatar() + '\'' + | ||
", platform='" + info.getPlatform() + '\'' + | ||
'}'; | ||
} | ||
} |
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,153 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout | ||
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:padding="12dp" | ||
tools:context=".TestLoginShareActivity"> | ||
|
||
<TextView | ||
android:id="@+id/tv_login_title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="第三方登录" | ||
android:textColor="@color/black" | ||
android:textSize="@dimen/sp_16" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/img_qq" | ||
style="@style/WW" | ||
android:layout_marginTop="10dp" | ||
android:padding="12dp" | ||
android:src="@mipmap/img_qq_p" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toLeftOf="@+id/img_wx" | ||
app:layout_constraintTop_toBottomOf="@+id/tv_login_title" | ||
/> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/img_wx" | ||
style="@style/WW" | ||
android:padding="12dp" | ||
android:src="@mipmap/img_wx_p" | ||
app:layout_constraintBottom_toBottomOf="@id/img_qq" | ||
app:layout_constraintLeft_toRightOf="@+id/img_qq" | ||
app:layout_constraintRight_toLeftOf="@+id/img_wb" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/img_wb" | ||
style="@style/WW" | ||
android:padding="12dp" | ||
android:src="@mipmap/img_wb_p" | ||
app:layout_constraintBottom_toBottomOf="@id/img_qq" | ||
app:layout_constraintLeft_toRightOf="@+id/img_wx" | ||
app:layout_constraintRight_toRightOf="parent" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/tv_login_info" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_marginTop="20dp" | ||
android:padding="8dp" | ||
android:text="" | ||
android:textColor="@color/black" | ||
app:layout_constraintBottom_toTopOf="@+id/divider" | ||
app:layout_constraintTop_toBottomOf="@+id/img_qq" | ||
/> | ||
|
||
<View | ||
android:id="@+id/divider" | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:background="#ccc" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.6" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/tv_share_title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="12dp" | ||
android:text="第三方分享" | ||
android:textColor="@color/black" | ||
android:textSize="@dimen/sp_16" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/divider" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/img_qq_share" | ||
style="@style/WW" | ||
android:layout_marginTop="10dp" | ||
android:padding="12dp" | ||
android:src="@mipmap/img_qq_p" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toLeftOf="@+id/img_wx_share" | ||
app:layout_constraintTop_toBottomOf="@+id/tv_share_title" | ||
/> | ||
|
||
|
||
<ImageView | ||
android:id="@+id/img_wx_share" | ||
style="@style/WW" | ||
android:padding="12dp" | ||
android:src="@mipmap/img_wx_p" | ||
app:layout_constraintBottom_toBottomOf="@id/img_qq_share" | ||
app:layout_constraintLeft_toRightOf="@+id/img_qq_share" | ||
app:layout_constraintRight_toLeftOf="@+id/img_wb_share" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/img_wb_share" | ||
style="@style/WW" | ||
android:padding="12dp" | ||
android:src="@mipmap/img_wb_p" | ||
app:layout_constraintBottom_toBottomOf="@id/img_qq_share" | ||
app:layout_constraintLeft_toRightOf="@+id/img_wx_share" | ||
app:layout_constraintRight_toRightOf="parent" | ||
/> | ||
|
||
<RadioGroup | ||
android:id="@+id/rg_share_info" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:checkedButton="@+id/rb_img_text" | ||
android:orientation="horizontal" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/img_qq_share"> | ||
|
||
<RadioButton | ||
android:id="@+id/rb_img" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="纯图片" | ||
/> | ||
|
||
<RadioButton | ||
android:id="@+id/rb_img_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="图文" | ||
/> | ||
|
||
<RadioButton | ||
android:id="@+id/rb_web" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="网页" | ||
/> | ||
|
||
</RadioGroup> | ||
|
||
</android.support.constraint.ConstraintLayout> |
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
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<dimen name="sp_16">16sp</dimen> | ||
</resources> |
Oops, something went wrong.