開發第二步之啟動動畫,登入新浪微博,發表微博等

來源:互聯網
上載者:User

首先看看,目前為大致的效果,細節有待最佳化。

1.開機動畫,小鳥旋轉,位移及放大等效果

2.正常顯示效果,包括app的表徵圖,版本號碼,應用程式名稱等。

3.當動畫效果結束後會彈出登入視窗。

4.登入進去後的顯示,目前為SDK提供的範例頁面,沒做修改。

5.發表微博

6.到新浪微博頁面查看剛剛發表的微博

目前邏輯結構不夠嚴謹,代碼不夠規範,有待修改。

部分源碼介紹:

1.Anim動畫效果,小鳥旋轉,位移及變大

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/accelerate_decelerate_interpolator"><rotate android:fromDegrees="0"        android:toDegrees="+1080"        android:pivotX="50%"        android:pivotY="50%"        android:duration="4000"/>            <translate android:fromYDelta="700%"          android:toXDelta="0"          android:duration="4000" />          <scale android:fromXScale="0"         android:fromYScale="0"         android:toXScale="1"         android:toYScale="1"         android:duration="4000"/></set>

2.介面裡引用這個anim特效:

// 圖片往上旋轉移動public void matrixToTop() {imgBTT.setBackgroundResource(R.drawable.bottom_to_top);Animation imgBttAni = AnimationUtils.loadAnimation(this,R.anim.img_bottom_to_top);imgBTT.startAnimation(imgBttAni);}

3.判斷網路連接是否開啟,開啟則開啟新浪微博認證,沒有開啟則跳轉到setting裡的網路設定或者直接退出

public void mainToChange() {System.out.println("mainToChange Enter");Log.e("kingfly", "psm.isPhoneConnecting=" + psm.isPhoneConnecting(this));if (psm.isPhoneConnecting(this)) {toOAuthSina();} else {System.out.println("mainToChange dialog");AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle(getString(R.string.net_alert_dialog_title));builder.setMessage(getString(R.string.net_alert_dialog_message));builder.setPositiveButton(getString(R.string.net_alert_dialog_potitive),new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubIntent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);ComponentName cName = new ComponentName("com.android.phone","com.android.phone.Settings");intent.setComponent(cName);startActivity(intent);}});builder.setNegativeButton(getString(R.string.net_alert_dialog_negative),new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stub// 程式退出事件Intent startMain = new Intent(Intent.ACTION_MAIN);startMain.addCategory(Intent.CATEGORY_HOME);startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(startMain);System.exit(0);}});builder.show();}}

// 判斷手機連網public boolean isPhoneConnecting(Context context) {try {ConnectivityManager manger = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo info = manger.getActiveNetworkInfo();return (info != null && info.isConnected());} catch (Exception e) {return false;}}

4.登入新浪微博需要提供的appkey及appsecret,這個只要使用者註冊了新浪微博開發人員就會有個內建的。源碼裡已刪除,還有郵箱登入密碼也刪除,使用者可修改為自己的郵箱來登入,其他的都是可以正常運行。

// 設定appkey及appsecret,如何擷取新浪微博appkey和appsecret請另外查詢相關資訊,此處不作介紹private static final String CONSUMER_KEY = "3796329";// 替換為開發人員的appkey,例如"1646212960";private static final String CONSUMER_SECRET = "fcb46476067fb4664b1c2b5c468f3";// 替換為開發人員的appkey,例如"94098772160b6f8ffc1315374d8861f9";

5.開始認證

public void toOAuthSina(){Weibo weibo = Weibo.getInstance();weibo.setupConsumerConfig(CONSUMER_KEY, CONSUMER_SECRET);// Oauth2.0// 隱式授權認證方式weibo.setRedirectUrl("http://www.sina.com");// 此處回調頁內容應該替換為與appkey對應的應用回調頁// 對應的應用回調頁可在開發人員登陸新浪微博開發平台之後,// 進入我的應用程式--應用詳情--應用資訊--進階資訊--授權設定--應用回調頁進行設定和查看,// 應用回調頁不可為空白weibo.authorize(RightFFriendActivity.this,new AuthDialogListener());}

6.完整源碼下載可參考:

http://download.csdn.net/detail/comkingfly/4189627

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.