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. SQL Server性能常用语句

    查看各表的数据行数 SELECT o.name, i. ROWS FROM sysobjects o, sysindexes i WHERE o.id = i.id AND o.Xtype = ORD ...

  2. LINQ基础

    以下为<C#图解教程>读书笔记 LINQ是 直接嵌入C#的强类型查询语言 与LINQ相关的特性: 隐式类型的本地变量:使用var 对象/集合初始化语法:对象初始化语句/对象初始化器/对象初 ...

  3. 【BZOJ】【1565】【NOI2009】PVZ 植物大战僵尸

    网络流/最大权闭合子图+拓扑排序 感动死了>_<,一年多以前刚知道网络流的时候听说了这道名字很带感的题目,现在终于有实力切掉它了. 这题是最大权闭合子图模型的经典应用<_<,首 ...

  4. Application、Session、Cookie、ViewState的特性

    http://blog.csdn.net/zyw_anquan/article/details/7664132   Application的特性: 存储的物理位置:服务器端内存. 存储的类型限制:任意 ...

  5. HDU1002 -A + B Problem II(大数a+b)

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. Asp.Net缓存(1)

    知其根本,方能应用.MSDN上的缓存讲解.先看原来讲解. Asp.Net缓存概述 通常,应用程序可以将那些频繁访问的数据,以及那些需要大量处理时间来创建的数据存储在内存中,从而提高性能. 在这些情况下 ...

  7. linux 踢出用户方法

    linux系统root用户可强制踢制其它登录用户, 首先以root登录以便查看全部的在线用户信息,可用w命令查看登录用户信息 强制踢人命令格式:pkill -kill -t tty 解释: pkill ...

  8. 220 DIV2 A. Inna and Pink Pony

    Inna and Pink Pony 输入n,m,i,j,a,b 可以看成n行m列的矩阵,起点(i,j),每次移动(a,b),(-a,-b),(-a,b),(a,-b) 可移动到(1,m),(n,1) ...

  9. JVM基础学习

    public class TestJVM { // 运行时数据区[方法区.堆.程序计数器.虚拟机栈.本地方法栈] private static int _1M = 1024 * 1024; publi ...

  10. Unix环境编程之定时、信号与中断

    在linux下实现精度较高的定时功能,需要用到setitimer 和 getitimer函数. 函数原型: #include <sys/time.h> int getitimer(int ...