1.新浪微博2.0 最差 无论是demo还是文档还是sdk的维护,各种问题 ,和1.0没法比,怀疑新浪到底还想不想开放了,好歹也是个大公司,居然写出那么恶心的代码
2.腾讯1.0也很差,但是腾讯2.0不错(不得不承认人家的技术实例),只是权限很少,功能也不多,很多东西可能要自己解析json 自己写网络逻辑.其实最恶心的还是权限,现在发个说说的权限都要申请.不要建议我用腾讯微博接入,有人用吗?
3.人人sdk 功能比较全面,架构也很好,可能好像人人是这个三个中最不是很普及的.正应了某个人人职员的话
"人人不是腾讯百度他们那么多的项目,每个人都会真正参与进去的"
这可能也暗示人人的专注一些吧.
看了人人的sdk感觉自己可以学习很多东西,现在整理如下
人人网SDK Demo项目学习 1 全局标题栏
人人的全局标题栏使用BaseActivity实现,其他用到标题栏的都继承他,
其他优点:
方便在BaseActivity中处理一些UI操作,比如显示toast等,
获取手机IMEI等的 需要使用context的方法 就不用各种传递context了.
BaseActivity的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/renren_demo_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/main_bg" android:orientation="vertical" > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/renren_demo_titlebar" android:layout_width="fill_parent" android:layout_height="50dip" android:background="@drawable/renren_demo_titlebar_background" android:paddingBottom="10dip" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="10dip" > <Button android:id="@+id/renren_demo_titlebar_left_button" android:layout_width="60dip" android:layout_height="40dip" android:layout_alignParentLeft="true" android:background="@drawable/renren_demo_titlebar_left_button" android:text="返回" android:textColor="#FFFFFF" android:textSize="14sp" /> <TextView android:id="@+id/renren_demo_titlebar_title_text" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="" android:textColor="#FFFFFF" android:textSize="20sp" /> <Button android:id="@+id/renren_demo_titlebar_right_button" android:layout_width="60dip" android:layout_height="40dip" android:layout_alignParentRight="true" android:background="@drawable/renren_demo_titlebar_right_button" android:text="查看Log" android:textColor="#FFFFFF" android:textSize="14sp" /> </RelativeLayout> </LinearLayout>
BaseActivity代码(增加了一个获取设备ID方法)
/** * $id$ */ package com.renren.api.connect.android.demo.activity; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.TelephonyManager; import android.view.View; import android.view.Window; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.renren.api.connect.android.Renren; import com.renren.api.connect.android.demo.R; /** * Base class for request Activity in the demo application * * @author Shaofeng Wang ([email protected]) */ public class BaseActivity extends Activity { /** * 根布局对象,用于在将来的子类中添加内容布局 */ protected LinearLayout root; /** * 标题栏左边按钮 */ protected Button titlebarLeftButton; /** * 标题栏中间文字 */ protected TextView titlebarText; /** * 标题栏右边按钮 */ protected Button titlebarRightButton; private ProgressDialog progressDialog; /** * 调用SDK接口的Renren对象 */ protected Renren renren; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 设置不显示标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置布局 setContentView(R.layout.base_layout); // 初始化控件 root = (LinearLayout) findViewById(R.id.renren_demo_root); titlebarLeftButton = (Button) findViewById(R.id.renren_demo_titlebar_left_button); titlebarRightButton = (Button) findViewById(R.id.renren_demo_titlebar_right_button); titlebarText = (TextView) findViewById(R.id.renren_demo_titlebar_title_text); // 注册“查看Log”按钮事件 titlebarRightButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(BaseActivity.this, LogActivity.class); BaseActivity.this.startActivity(intent); } }); // 注册“返回”按钮事件(子类若有不同的处理,则需覆盖此事件) titlebarLeftButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { finish(); } }); Intent intent = getIntent(); renren = intent.getParcelableExtra(Renren.RENREN_LABEL); if (renren != null) { renren.init(this); } } /** * 解析逗号分割的字符串 * * @return */ protected String[] parseCommaIds(String s) { if (s == null) { return null; } String[] ids = s.split(","); return ids; } /** * 显示等待框 */ protected void showProgress() { showProgress("Please wait", "progressing"); } /** * 显示等待框 * * @param title * @param message */ protected void showProgress(String title, String message) { progressDialog = ProgressDialog.show(this, title, message); } /** * 取消等待框 */ protected void dismissProgress() { if (progressDialog != null) { try { progressDialog.dismiss(); } catch (Exception e) { } } } /** * 显示Toast提示 * * @param message */ protected void showTip(String message) { Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } @Override protected void onDestroy() { super.onDestroy(); // 不销毁ProgressDialog会出现view not attached to window manager异常 dismissProgress(); } protected String getDeviceId() {//获取设备ID TelephonyManager tm = (TelephonyManager) this .getSystemService(Context.TELEPHONY_SERVICE); return tm.getDeviceId(); } }
测试一下
package com.renren.api.connect.android.demo; import com.renren.api.connect.android.demo.activity.BaseActivity; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; public class TestActivity extends BaseActivity { @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); LinearLayout mainLayout = (LinearLayout) getLayoutInflater().inflate( R.layout.main, null); root.addView(mainLayout);// 继承了BaseActivity // 想要再次添加布局就要使用这个方法了,如果在使用setContentView()就会把父类定义的标题栏覆盖了 titlebarRightButton.setOnClickListener(new View.OnClickListener() {// 重写BaseActivity的方法,改变他的事件 @Override public void onClick(View v) { showProgress(); } }); showTip("测试" + getDeviceId()); } }