import java.util.HashMap;
import org.apache.http.Header;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler.Callback;
import android.os.IBinder;
import android.os.Message;
import android.text.InputType;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;
import com.etoury.etoury.bean.User;
import com.etoury.etoury.http.Url;
import com.etoury.etoury.ui.view.ThirdLoginLoadingDialog;
import com.etoury.etoury.util.JsonUtil;
import com.etoury.etoury.util.SharedPreferencesUtil;
import com.etoury.project.R;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.mob.tools.utils.UIHandler; public class LoginActivity extends Activity implements OnClickListener,
Callback, PlatformActionListener { private EditText et_name, et_pass; private ImageButton homebtn;
private LinearLayout login_share_1;
private LinearLayout login_share_2;
private LinearLayout login_share_3;
private Button login;
private Button register;
private Button btnPasswordVisiable;
private Platform sina; private static final int MSG_LOGIN = 2;
private static final int MSG_AUTH_CANCEL = 3;
private static final int MSG_AUTH_ERROR = 4;
private static final int MSG_AUTH_COMPLETE = 5;
private boolean ifThridLogin = false;
private String thirdUserId;
private String thirdUserName;
private String thirdUserIcon;
private String thirdUserGender;
private boolean passwordVisiable = true;// 密码是否可见
private ThirdLoginLoadingDialog dialog; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (passwordVisiable) { }
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_login);
initView();
// Mob平台授权
ShareSDK.initSDK(this); } @Override
protected void onDestroy() {
ShareSDK.stopSDK();
super.onDestroy(); } private void initView() { et_name = (EditText) findViewById(R.id.login_account);
et_pass = (EditText) findViewById(R.id.login_password);
btnPasswordVisiable = (Button) findViewById(R.id.login_img_password_icon); homebtn = (ImageButton) findViewById(R.id.login_titlebar_back_tv);
login = (Button) findViewById(R.id.login_btn);
register = (Button) findViewById(R.id.login_bottom_btn); login_share_1 = (LinearLayout) findViewById(R.id.login_share_wechat);
login_share_2 = (LinearLayout) findViewById(R.id.login_share_qq);
login_share_3 = (LinearLayout) findViewById(R.id.login_share_sina);
dialog = new ThirdLoginLoadingDialog(this);
login.setOnClickListener(this);
register.setOnClickListener(this);
btnPasswordVisiable.setOnClickListener(this);
homebtn.setOnClickListener(this);
login_share_1.setOnClickListener(this);
login_share_2.setOnClickListener(this);
login_share_3.setOnClickListener(this); } @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login_titlebar_back_tv: finish();
break;
case R.id.login_btn: String userName = et_name.getText().toString();
String userPass = et_pass.getText().toString(); // 判断用户名和密码是否为空,trim是去掉空白
if (TextUtils.isEmpty(userName.trim())
|| TextUtils.isEmpty(userPass.trim())) {
Toast.makeText(this, "用户名或者密码不能为空", Toast.LENGTH_LONG).show();
} else {
// 发送请求给服务器
// 调用:loginByAsyncHttpClientPost(userName, userPass);
SharedPreferencesUtil.put(this, "userName", userName);
SharedPreferencesUtil.put(this, "userPass", userPass);
login(userName, userPass); } break; case R.id.login_img_password_icon: if (passwordVisiable) {
btnPasswordVisiable.setBackgroundDrawable(getResources()
.getDrawable(R.drawable.password_icon_visiable));
// 设置密码为可见。
et_pass.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
passwordVisiable = false;
} else {
btnPasswordVisiable.setBackgroundDrawable(getResources()
.getDrawable(R.drawable.password_icon_gone));
// 设置密码为不可见。
et_pass.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordVisiable = true;
} break;
case R.id.login_bottom_btn:
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
finish();
break;
case R.id.login_share_wechat:
dialog.setCanceledOnTouchOutside(false);
dialog.show();
authorize(new Wechat(this));
break;
case R.id.login_share_qq:
dialog.setCanceledOnTouchOutside(false);
dialog.show();
authorize(new QQ(this));
break;
case R.id.login_share_sina:
dialog.setCanceledOnTouchOutside(false);
dialog.show();
authorize(new SinaWeibo(this));
break;
default:
break;
} } // 授权
private void authorize(Platform plat) {
if (plat.isValid()) {
plat.removeAccount();
}
plat.setPlatformActionListener(this);
plat.SSOSetting(false);
plat.showUser(null);
} private void thirdRegister() {
System.out.println("0000000" + thirdUserId);
if (thirdUserId != null) {
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("thirdLoginId", thirdUserId);
params.put("password", "111111");
params.put("name", thirdUserName);
params.put("image", thirdUserIcon);
params.put("sex", thirdUserGender); client.post(Url.REGIST, params, new AsyncHttpResponseHandler() { @Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
System.out.println("111" + new String(arg2));
loginParse(new String(arg2));
} @Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2,
Throwable arg3) {
System.out.print("222");
}
});
} } private void login(String userName, String userPass) { AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("name", userName);
params.put("password", userPass);
System.out.println("1");
client.post(Url.LOGIN, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
loginParse(new String(arg2)); System.out.println(new String(arg2));
} @Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2,
Throwable arg3) {
Toast.makeText(getApplicationContext(), "连接失败请检查网络",
Toast.LENGTH_LONG).show(); }
}); } protected void loginParse(String response) { User user = JsonUtil.parseJsonToBean(response, User.class);
System.out.println("1");
if (user.result.equals("TRUE")) {
System.out.println("登录成功");
SharedPreferencesUtil.put(getApplicationContext(), "loginResult",
user.result); SharedPreferencesUtil.put(getApplicationContext(), "userImage",
user.content.image); SharedPreferencesUtil.put(getApplicationContext(), "userId",
user.content.userId); SharedPreferencesUtil.put(getApplicationContext(), "sessionId",
user.content.sessionId); SharedPreferencesUtil.put(getApplicationContext(),
"userGetHeadimgUri", user.content.image); finish(); } else { System.out.println("登录失败,原因为:" + user.reason);
Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT)
.show();
if (ifThridLogin) {
ifThridLogin = false;
dialog.dismiss();
} }
} @Override
public boolean handleMessage(Message msg) {
switch (msg.what) { case MSG_LOGIN: {
// 登录
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
System.out.println("-------登录成功--------"); }
break;
case MSG_AUTH_CANCEL: {
// 取消
Toast.makeText(this, "取消", Toast.LENGTH_SHORT).show();
System.out.println("-------取消--------");
dialog.dismiss();
}
break;
case MSG_AUTH_ERROR: {
// 取消授权
Toast.makeText(this, "授权错误", Toast.LENGTH_SHORT).show();
System.out.println("-------授权错误--------");
dialog.dismiss();
}
break;
case MSG_AUTH_COMPLETE: {
// 授权完成
// Toast.makeText(this, "授权完成", Toast.LENGTH_SHORT).show();
System.out.println("--------授权完成-------"); dialog.setCanceledOnTouchOutside(false);
dialog.show();
ifThridLogin = true;
thirdRegister(); }
break;
}
return false;
} }

Share SDK 第三方登录的更多相关文章

  1. iOS - Share 分享/第三方登录

    1.系统方式创建分享 按照下图在 Info.plist 文件中将 Localization native development region 的值改为 China.如果不设置此项弹出的分享页面中显示 ...

  2. iOS:友盟SDK第三方登录 分享及友盟统计的使用

    本文转载至 http://www.it165.net/pro/html/201503/37101.html Tag标签:第三方   01.#import "UMSocial.h" ...

  3. Android-友盟第三方登录与分享

    ### 前言 最近项目中又一次需要集成友盟的三方登录与分享,之前没有记录过,所以这次来写一下... ### 准备工作 1.注册友盟账号创建应用,获取key:申请地址http://www.umeng.c ...

  4. Unity利用Share SDK实现QQ、微信及微博第三方登录及定制内容分享(附代码)

    最近因为公司的项目需要添加一些实用性的功能,需要添加第三方登录及分享,采用的是Mob的SDK,可以先到其官网下载对应的SDK 点击这里,为了方便后期进行数据统计和分析,所以可以先添加一个应用,添加成功 ...

  5. 第三方登录SDK

    紧接着上次的第三方登录文档,这一波又来了. 一.使用qq登录https://connect.qq.com/ 首次登录的话会跳转到应用开发者注册,自己测试的话选择个人.下面的各项自己按真实情况填写. 注 ...

  6. Android应用之——最新版本号SDK V2.4实现QQ第三方登录

    为什么要写这篇博客呢?由于.我在做这个第三方登录的时候,找了非常多资料,发现要么就是过时了.要么就是说的非常不清楚.非常罗嗦.并且非常多都是一些小demo,不是什么实例.甚至连腾讯官方的文档都有这个问 ...

  7. CI框架 QQ接口(第三方登录接口PHP版)

    本帖内容较多,大部分都是源码,要修改的地方只有一个,其他只要复制过去,就可以完美运行.本帖主要针对CI框架,不用下载SDK,按我下面的步骤,建文件,复制代码就可以了.10分钟不要,接口就可完成.第一步 ...

  8. Android UmengShareSDK第三方登录

    Android UmengShareSDK 第三方登录- 今天就不废话了,集成平台第三方登录.市面上集成平台有shareSDK 和 Ument两种,shareSDK的ipa和服务好些,如果自己研究会很 ...

  9. QQ登录接口(第三方登录接口)

    CI框架 QQ接口(第三方登录接口PHP版) 本帖内容较多,大部分都是源码,要修改的地方只有一个,其他只要复制过去,就可以完美运行.本帖主要针对CI框架,不用下载SDK,按我下面的步骤,建文件,复制代 ...

随机推荐

  1. 传说中的Markov"不过如此”

    因为看一篇题为 Passive Measurement of Interference in WiFi Network with Application in Misbehavior Detectio ...

  2. 1486: [HNOI2009]最小圈 - BZOJ

      在机房的小伙伴提醒是二分之后,我想到了是判负环,所以我用spfa,而且我保持dis都是小于等于0,本以为这样就能过了,可是还是有一个点达到了3.8s左右(其他都是0.0几秒) 所以还是写了dfs版 ...

  3. 解决Ubuntu开机自动挂载硬盘回收站不可用等权限问题

    1.修改fstab sudo gedit /etc/fstab 2.添加如下代码 #Entry for /dev/sdb7 : UUID=78A675EB46D703C4 /media/anseey/ ...

  4. 【BZOJ】【3196】Tyvj 1730 二逼平衡树

    树套树 Orz zyf 学(co)习(py)了一下树套树的写法,嗯……就是线段树套平衡树. 具体实现思路就是:外部查询用的都是线段树,查询内部自己调用平衡树的操作. 抄抄代码有助理解= = 八中挂了… ...

  5. Centos——rpm和yum

    间歇性的学习了centos的一些使用,发现一段时间不操作,就会忘掉其中的概念或者操作方式方法,于是在此总结一下. 一.问题描述 首先,把一个我最常忘记的概念性的东西在这里记录一下: 什么是yum,什么 ...

  6. linux系统进程的内存布局

    内存管理模块是操作系统的心脏:它对应用程序和系统管理非常重要.今后的几篇文章中,我将着眼于实际的内存问题,但也不避讳其中的技术内幕.由于不少概念是通用的,所以文中大部分例子取自32位x86平台的Lin ...

  7. 用Ant实现Java项目的自动构建和部署(转)

    Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一.            ...

  8. Mysql忘记密码修改密码

    问题重现(以下讨论范围仅限Windows环境): C:\AppServ\MySQL> mysql -u root -p Enter password: ERROR 1045 (28000): A ...

  9. 让32位Eclipse和64位Eclipse同时在64的Windows7上运行

    转自让32位Eclipse和64位Eclipse同时在64的Windows7上运行 参考这篇文章:http://wenku.baidu.com/view/57994c270066f5335a81214 ...

  10. spring @resource @ Autowired

    Spring中什么时候用@Resource,什么时候用@service 当你需要定义某个类为一个bean,则在这个类的类名前一行使用@Service("XXX"),就相当于讲这个类 ...