本帖最后由 909026364 于 2014-7-15 17:17 编辑
最近在开发app,想要实现分享功能,之前没有实现过这个功能。上网查了很多资料,折腾了很久,最后不得已还是用了现成的组件。 很快就实现了。。。。
先上个效果图:
下面是我的集成过程:
首先,下载SDK包
然后,提交应用申请key
第三步,在各大社交网站的开放平台申请账号并通过审核 将以上数据填写到,项目的asstes目录下youtui_sdk.xml文件中 先看看是怎么在类里调用的[mw_shl_code=java,true]package com.wgs.jiesuo;
import java.util.List; import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import cn.bidaround.youtui.YouTui;
import cn.bidaround.youtui.YouTuiViewType;
import cn.bidaround.youtui.login.AuthListener;
import cn.bidaround.youtui.login.AuthLogin;
import cn.bidaround.youtui.login.AuthUserInfo;
import cn.bidaround.youtui.social.ShareData;
import com.wgs.jiesuo.LockPatternView.Cell;
import com.wgs.jiesuo.LockPatternView.DisplayMode;
import com.wgs.jiesuo.LockPatternView.OnPatternListener;
public class MainActivity extends Activity implements OnClickListener {
// private OnPatternListener onPatternListener;
private LockPatternView lockPatternView;
private LockPatternUtils lockPatternUtils;
private Button btn_set_pwd;
private Button btn_reset_pwd;
private Button btn_check_pwd;
private boolean opFLag = false;
private Button popupBt, listBt;
private View main_sina_imageview, main_qq_imageview,
main_tencentwb_imageview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
YouTui.init(this);
initView();
}
void initView() {
ShareData shareData = ShareData.getInstance();
shareData.isAppShare = false;
shareData.setDescription("友推积分组件");
shareData.setTitle("友推分享");
shareData
.setText("通过友推积分组件,开发者几行代码就可以为应用添加分享送积分功能,并提供详尽的后台统计数据,除了本身具备的分享功能外,开发者也可将积分功能单独集成在已有分享组件的app上,快来试试吧?");
shareData.setTarget_url("http://youtui.mobi/");
shareData
.setImageUrl("http://cdnup.b0.upaiyun.com/media/image/default.png");
// shareData.setImagePath(Environment.getExternalStorageDirectory()+YoutuiConstants.FILE_SAVE_PATH+"demo.png");
popupBt = (Button) findViewById(R.id.popup_bt);
popupBt.setOnClickListener(this);
main_sina_imageview = findViewById(R.id.main_sina_imageview);
main_sina_imageview.setOnClickListener(this);
main_qq_imageview = findViewById(R.id.main_qq_imageview);
main_qq_imageview.setOnClickListener(this);
main_tencentwb_imageview = findViewById(R.id.main_tencentwb_imageview);
main_tencentwb_imageview.setOnClickListener(this);
lockPatternView = (LockPatternView) findViewById(R.id.lpv_lock);
btn_reset_pwd = (Button) findViewById(R.id.btn_reset_pwd);
btn_set_pwd = (Button) findViewById(R.id.btn_set_pwd);
btn_check_pwd = (Button) findViewById(R.id.btn_check_pwd);
btn_reset_pwd.setOnClickListener(this);
btn_set_pwd.setOnClickListener(this);
btn_check_pwd.setOnClickListener(this);
lockPatternUtils = new LockPatternUtils(this);
lockPatternView.setOnPatternListener(new OnPatternListener() {
public void onPatternStart() {
}
public void onPatternDetected(List<Cell> pattern) {
if (opFLag) {
int result = lockPatternUtils.checkPattern(pattern);
if (result != 1) {
if (result == 0) {
lockPatternView.setDisplayMode(DisplayMode.Wrong);
Toast.makeText(MainActivity.this, "密码错误",
Toast.LENGTH_LONG).show();
} else {
lockPatternView.clearPattern();
Toast.makeText(MainActivity.this, "请设置密码",
Toast.LENGTH_LONG).show();
lockPatternView.clearPattern();
}
} else {
Toast.makeText(MainActivity.this, "密码正确",
Toast.LENGTH_LONG).show();
lockPatternView.clearPattern();
}
} else {
lockPatternUtils.saveLockPattern(pattern);
Toast.makeText(MainActivity.this, "密码已经设置",
Toast.LENGTH_LONG).show();
lockPatternView.clearPattern();
}
}
public void onPatternCleared() {
}
public void onPatternCellAdded(List<Cell> pattern) {
}
});
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_reset_pwd:
lockPatternView.clearPattern();
lockPatternUtils.clearLock();
break;
case R.id.btn_check_pwd:
opFLag = true;
break;
case R.id.btn_set_pwd:
opFLag = false;
break;
case R.id.popup_bt:
YouTui.show(this, YouTuiViewType.BLACK_POPUP,false);
break;
case R.id.main_sina_imageview:
//新浪第三方登录
AuthLogin sinaAuth = new AuthLogin();
AuthListener sinaListener = new AuthListener() {
@Override
public void onAuthSucess(Activity arg0, AuthUserInfo userInfo) {
Log.i("sinaGender:", userInfo.getSinaGender());
Log.i("sinaName:", userInfo.getSinaName());
Log.i("sinaProfileImageUrl:", userInfo.getSinaProfileImageUrl());
Log.i("sinaScreenname:", userInfo.getSinaScreenname());
Log.i("sinaUid:", userInfo.getSinaUid());
}
@Override
public void onAuthFail(Activity arg0) {
}
@Override
public void onAuthCancel(Activity arg0) {
}
};
sinaAuth.sinaAuth(this, sinaListener);
break;
case R.id.main_qq_imageview:
/** qq第三方登录 */
AuthLogin qqLogin = new AuthLogin();
AuthListener qqListener = new AuthListener() {
@Override
public void onAuthSucess(Activity act, AuthUserInfo userInfo) {
Log.i("qqGender:", userInfo.getQqGender());
Log.i("qqImageUrl:", userInfo.getQqImageUrl());
Log.i("qqNickName:", userInfo.getQqNickName());
Log.i("qqOpenid:", userInfo.getQqOpenid());
}
@Override
public void onAuthFail(Activity act) {
}
@Override
public void onAuthCancel(Activity act) {
}
};
qqLogin.qqAuth(this, qqListener);
//qq第三方登录
break;
case R.id.main_tencentwb_imageview:
/** 腾讯微博第三方登录 */
AuthLogin tencentWbLogin = new AuthLogin();
AuthListener tencentWbListener = new AuthListener() {
@Override
public void onAuthSucess(Activity act, AuthUserInfo userInfo) {
Log.i("tencentWbName:", userInfo.getTencentWbName());
Log.i("tencentWbNick:", userInfo.getTencentWbNick());
Log.i("tencentWbOpenid:", userInfo.getTencentWbOpenid());
Log.i("tencentWbHead:", userInfo.getTencentWbHead());
}
@Override
public void onAuthFail(Activity act) {
}
@Override
public void onAuthCancel(Activity act) {
}
};
tencentWbLogin.tencentWbAuth(this, tencentWbListener);
//腾讯微博第三方登录
break;
}
}
protected void onDestroy() {
//调用
YouTui.release(this);
super.onDestroy();
}
}[/mw_shl_code]
记得把youtui-lib 这个文件导入到Eclipse开发工具中,在引用add进项目中,如图。
记得在清单配置好相应的信息,具体内容看源码。直接附上源码地址!
http://youtui.mobi/download/index.htm 欢迎大家交流分享方法哈~
|