2013年7月18日 星期四

[Android][Facebook][中文化] Facebook SDK for Android Tutorial - Personalize

2 - Personalize


這個教學列出使用 Facebook SDK for android 如何個人化你的app 經驗的大綱。個人化則藉由顯示使用者的 profile 裡的照片與名子來達成。
  • 使用 Request,   來建構一個使用Facebook API calls 的單一要求 。 需要被授權的使用者的一個request, 它必須在一個 open Session 被傳遞。Request 也可以是匿名的, 這是說它們並不一定需要一個使用者來授權。 在這個例子裡, 沒有  Session 需要被定義出來。當一個Request 被完成時, 假如有需要的話 , Facebook SDK 將在background 裡延展 access token 。 
  • Response 封裝了來自Facebook API call 的 response
  • ProfilePictureView 是一個顯示profile 照片的客製化 view 
  • GraphUse 是一個 提供一個強烈樣式表現的介面


你將會使用這些class 跟 interface 來獲取使用者的基本資訊以用來個人化你的 app。 你將使用一個 屬於 Request class 叫做 newMeRequest() 的靜態的方法呼叫程序。 這個方法會回傳使用者的資料。 當設定好 request , 你將定義一個 callback 來處理回復。這個回復是一個 GraphUser 種類的物件。你也將處理被傳回的使用者物件, 然後使用ProfilePictureView 顯示出使用者 profile 的照片,使用 TextView 顯示使用者的名子。

這個教學帶領你走過
  • 步驟 1 : 設定使用者介面
  • 步驟 2 : 展示使用者資訊
  • 下一步
  • 相關範例
注意: 在你開始這個個人化的 app 前, 確認你已經設定好授權了。

步驟 1 : 設定使用者介面


2013年7月16日 星期二

[Android][Facebook][中文化] Facebook SDK for Android Tutorial - Authenticate with Facebook Login 中文化

Authenticate with Facebook Login

前言: 

標題連結是 fackbook 官方的教學, 十分詳細。 我在邊練習範例的過程中將其中文化, 如有翻譯上的問題,還望指教。練習這個範例前, 別忘記 facebook 的 APP 註冊以及Project 相關的設定。 以下為Project 設定簡述:

1. 在 strings.xml,  加入app_id <string name="app_id">xxxxxxxxxxxxxxxxx</string>
2. 在 AndroidManifest.xml 加入 use permission , meta-data 與一個 facebook 的 activity
     *android.permission.INTERNET
     *加入  'Meta Data'  其 Name :  com.facebook.sdk.ApplicationId, 其 value : @string/app_id
     *加入 'Activity' 其 Name:  com.facebook.LoginActivity
可以參考我上篇文 :  Facebook SDK 安裝以及使用

[Android] Facebook SDK 安裝以及使用


主要參考 Facebook 的教學  Getting Started with the Facebook SDK for Android

因為我已經裝了 Eclipse 與 ADT, 就從下列步驟開始 -

1. 下載 facebook sdk 並請 import 到 project 裡

按 Getting Started with the Facebook SDK for Android Step 2 的 download Link 會自動開啟下載連結

2. 安裝 FBAndroid  APK 再裝置裡

我是到 Android 安裝目錄下的 plateform-tool 打 adb install  檔案路徑(FBAndroid-2.1.apk )


3. 獲取 sha1 key


2013年6月18日 星期二

[Android] Android ADT 22 升級後舊 project 無法執行

這一兩天突然的幾乎所有在 workspace 的 projects 都出現了問題, 出現問題的癥狀還不止一種, trace 個別問題讓人好頭大. 從新安裝了好幾次, 都沒有用。2 天的產值就報銷了 TAT ... 本來以為是自己為了讓 Google play 商店在 emulator 上 run 搞壞了系統。 2 天後才發現原來應該是 ADT 22 的問題。 (哭~ )

收集一下相關資訊等等解決 -
*1.  Official 公告
*2 .  簡易版本
*3. 中文版好用板
-------------------------------------------------------
雖然最後終於成功了!  我這個 Project 使用到 google play service  與 support v4, 因為這樣多了點波折。

有幾個關鍵點寫出來 :
1. ADT 22 根據 (1) 所說, 第三方 的 lib 都會被 Eclipse 放置在 Private Libraries  下,而 Referencing Library 則會放置在  Dependencies 裡。如果沒有使用到第三方 Library 的, ADT 22 造成的問題 , 網友們大部分只check private libraries 就行了。 之後當然要 clean & rebuild


注意: 之前有手動加的 lib 要手動去除 . 我之前手動加 google play service 與 support v4 的 lib , 所以把這兩個去掉了。 但是這兩個其實是存在的, 在 Private Libraries 下。

2. Google Play Service 事實上這次也升級了, 所以在 project 裡也要升級。就是使用 eclipse 將整個 project 從 workspace 刪掉,再重新 import 進來。

3. Clean 有時會出問題 , 如果有這樣的問題將 bin 整個殺掉, rebuild 。 bin 裡面去看有 gms 的 class

4. Properties => Android 裡還是如同以前一樣要加 google-play-service lib

5. google-ply-service lib 記得也要 check private libraries 跟 rebuild




--------------------------------------------------------------------------
Error Msg
Unable to start activity ComponentInfo
ClassNotFoundException
。。。。






-----------------------------------------------------------
等等, 怎麼出了個  Android Studio IDE 呀~
原來Eclipse 要被丟棄了呀。。。



2013年6月17日 星期一

[Android] Facebook apk crash at login in android emulator

Facebook 在 emulator 上異常終止
為了使用 Facebook 分享功能, 於是需再 android emulator 上安裝 facebook. 不過一到 login 就異常終止。  追蹤的原因的過程有點長, 就不詳述。  關鍵是我emulator 上有安裝 Google play service 。這個 apk (com.android.vending) 導致 facebook 一直 crash。 查了一下網路, 看到一篇 Church Tech 的文章, 說是,不從 google play 下載的 apk, googleplay 會讓他 crash 掉 >.<
Google Crashes Facebook Home’s Easy Updating Party, Now Requires All Play Apps To Be Updated Through The Play Store

我覺得這個蠻有可能的是原因的。

2013年5月15日 星期三

[Android Map] Change Location of Emulator

See the Article
http://developer.android.com/guide/topics/location/strategies.html#MockData

HighLight


Using the "geo" command in the emulator console



Step1: 執行 cmd 
    執行 cmd ,  cd 到 Android SDK 下的 tools   ie:  C:\Android\tools


Step2: 連上 emulator
     telent localhost 5554 
     5554 是 emulator 的 port , 通常會顯是在 emulator 後面。 
    可用 help 看一下 commands
   

2013年5月13日 星期一

[Android] MyTracks Notes (1)


AbstractMyTracksActivity

*public abstract class AbstractMyTracksActivity extends FragmentActivity 

*onCreate()
         1.  SpeechEngine 的 setup
               setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
         2. 一個個不同api 版本的不同設置 actionbar 與 home 鑑
             * ApiAdapterFactory.getApiAdapter().hideTitle(this)
             * ApiAdapterFactory.getApiAdapter().configureActionBarHomeAsUp(this);
         
         3. setContentView

2013年5月10日 星期五

[Java] 認真的讀一次 Java Class 做個 Note


Creating A Class 

Class : Class definition and Class body

public/abstract/final  class  (NameOfClass) extends (Super) implements (Interface01, Interface02, ...) {
                         Class Body
}

public : 可以被任何 class 使用。沒有 public 只能給同一個 package 的使用
abstract :  宣告無法被 instantiated 的 class
final : 宣告無法被繼承的 class

Variable :  可以宣告的項目

accessLevel  (static/final/transient/volatile ) type name
    accessLevel :  宣告可以可 access memeber varialbe 的種類(public/protected/package/private)
   static : class variable 而不是 instance variable
   final : variable 的值無法改變
   transient: variable 不應該被 serialized
   volatile : 防止 compiler 對一個 member 進行某種最佳化
   type nmae : variable type and name


2013年5月8日 星期三

[Android] Use Google Map API v2 (3) - Work on emulator


此篇為 [Android] Use Google Map API v2 - Create a map project 續篇


在 emulator 上 run google map 會出現下圖 -

發現此狀況時需要在 emulator 上安裝 2 個  apk . 
com.google.android.gms(-xxx).apk
com.android.vending(-xxx).apk
這個部份說一下, Google 說地圖無法再 emulator 上使用。 搜尋會看到很多這麼說。
不要放棄,應該是可以的。 但看起來每個人成功的方法不太一樣。我僅提供我的。

[Android] Use Google Map API v2 - Create a map project


此篇為續 [Android] Use Google Map API v2 - Get API Key


Step 3. Create a Map project

3.1 一如往常的 Create 一個 Android APP。
3.2 修改 Manifest.xml
*在 <application> Tag 裡加入
<meta-data    android:name="com.google.android.maps.v2.API_KEY"    android:value="AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0"/>裡面的 android:value 裡填 Step2 最後獲取40characters 的 APIKEY

2013年5月7日 星期二

[Android] Use Google Map API v2 - Get API Key


Google Developer :Google Maps Android API v2

說明 :

Step 1. Download Google Map API 
在 Eclipse 裡, 使用 Android SDK Manager, 找到 Extra , 看看 Google Play Service 是否有 installed 。

Step 2. Apply for Google Map Key 
使用Google Map 的 Service 需要有簽證\證書。 證書分為兩種 Debug 與 Release。 Debug 不可以用來 Release 。 首先我們先申請Debug。Realease 方法以後再加補。

獲取的方法如下
Debug:
1. 在 cmd 下打此指令

keytool -list -v -keystore "C:\Users\your_user_name\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

*your_user_name => 你的使用者名稱。
我的 Android SDK 並不是裝在 Default Directory,但這個目錄仍是在 User\(One's User name) 底下。
* 如果 cmd 下輸入指令沒有 keytool 這個指令的話,可能是 Java 環境變數沒設。 
參考: 設定Java 環境變數

成功了會跑出下列輸出

SHA1 後面就是 fingerprint
(長這樣 SHA1: BB:0D:AC:74:D3:21:E1:43:07:71:9B:62:90:AF:A1:66:6E:44:5D:75) 


2013年5月5日 星期日

[Android] Screen Size Notes






  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp
Screen characteristic Qualifier Description
Size small Resources for small size screens.
normal Resources for normal size screens. (This is the baseline size.)
large Resources for large size screens.
xlarge Resources for extra large size screens.
Density ldpi Resources for low-density (ldpi) screens (~120dpi).
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
nodpi Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.
tvdpi Resources for screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33*mdpi. For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.
Orientation land Resources for screens in the landscape orientation (wide aspect ratio).
port Resources for screens in the portrait orientation (tall aspect ratio).
Aspect ratio long Resources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration.
notlong Resources for use screens that have an aspect ratio that is similar to the baseline screen configuration.





Screen Resolution Names


http://tekeye.biz/2012/screen-resolution-names

2013年4月29日 星期一

[Android]Google I/O Memory Leak 筆記 2 - Tools


此篇為 Google I/O Memory Leak 筆記 1 - 觀念 的續篇

HighLight
1. 初步的的 Memory Leak 偵測是看你的 LogCat
紅色圈起來的地方是 System Alive Object , 看起來隨著時間不斷的加大, 並且沒有減少的跡象, 因此判定有 Memory Leak

2. 所以就要把 Memory Heap dump 下來使用 Eclipse Memory Analyzer Tool (MAT) 進行下一步分析。
     到 DMMS 中 進行 Dump 。 (參考下圖 的icon)
 

2013年4月27日 星期六

[Android] Google I/O Memory Leak 筆記 1 - 觀念

從 C/C++ 到 Android/Java Destructor 不見了! 但是對 Memory Leak 的擔憂並沒有消失, 反而是為 Android 時不時的 GC 而擔憂。 找了下面這 Google I/O Memory Leak 的演講, 看完可以建立很不錯的觀念。


Google I/O 2011: Memory management for Android Apps





===================================================
From Below My Own Notes
===================================================

2013年4月26日 星期五

[Android] Android Installation

紀錄一下 Android 的安裝, 讓以後重灌時更方便

1. 主要程式的下載
    1.1  Java
            http://www.oracle.com/technetwork/java/javase/downloads/index.html
    1.2. Eclipse
           http://www.eclipse.org/downloads/
           很多的次版本 , Android developer site 是連結到  Eclipse for Mobile Developer
           安裝完畢會問你的 workspace。 看你的 projects 要放哪裡, 就給個 directory
    1.3 Eclipse Android ADT
           http://developer.android.com/sdk/installing/installing-adt.html#Download
           安裝方法, 到 Help -> Install New Software -> 將下列網址輸入, eclipse 自動會抓取
           http://adt-addons.googlecode.com/svn/trunk/installer/com.android.ide.eclipse.installer.update/


2013年4月13日 星期六

[Android] TableLayout 的使用法

目前最喜歡用 TableLayout, 不過, 直覺使用時有些並不符合我的期待, 因此研究一下這個Layout 使用法。 分為兩部份, 第一部份是 Android Reference 裡的內容, 第二部份是 Api Demo 裡的實作。

Android Reference :  TableLayout

HightLight Principles

1 .  Table 有 row & column 。  column 可以 Span (像 HTML  )
2.  Column 寬度的定義是 - 所有 row 裡有著最寬的cell的那個column 的寬度。
3. Table 總寬度就是他的 container 的寬度, Table 的 children 寬度必須是MATCH_PARENT, 但高度可以是其它, 像 TableRow default 就是 WRAP_CONTENT

4.  TableLayout 可以設定特定 Column 是 shrinkable 與stretchable (兩者可同時存在)
5.  Shrinkable 就是說 column width 可以減縮到讓 table 放在他的 parent object 裡 (感覺好偉大 www)
6. Stretchable  就是說  column 可以延展自己的寬度把空白填滿
7. 如果要隱藏column 用 Collapse
8. Column - number ,  Cell ( ie. view object)  可以設定 column-number 如果不自訂的化系統會幫忙定   以 increase +1 的方法. Column number 是從 0 開始的
9. 如果你的view object 不放在 Table row 裡, layout會把這個 view 當作一個 row 來看 (span all columns)


ApiDemo 解析 : 


Api TableLayout Demo 06. More spanning and stretchable (學習  Column Number / Stretch  )


[Android] Weibo Share via sso 微博分享 sso 方法


SSO 說明參考 官方文件
移动应用SSO授权

這是 微博分享的番外篇 呀!

簡單的來說, 如果使用者的手機有安裝 Weibo  客戶端, 那麼要分享的 App 就可以直接調用這個 weibo APP 來進行分享.

微博分享的番外篇  提到怎樣使用weibo sdk 進行 OAuth2.0 授權已及怎樣調用 api 分享文件。 現在要這基礎上, 加上透過 sso 的方式獲取授權

1. Import SSO packages 

SSO 的 package 有兩個 1. com.sina.sso 2 com.weibo.skd.android.sso  import 到 ShareWeibo(My own App)

2. 在 Program 中呼叫使用 SsoHandler 來進行 sso 授權

直接調用 ssoHandler 的 authorize 就好!  如果APP 有支援 3.0 以上的微博版本, 就會透過 sso 來授權, 要不然 SsoHandler 就會直接呼叫 Weibo.java 作OAuth2.0 授權。 User 並不用再寫一個判斷了

  mSsoHandler = new SsoHandler(ShareActivity.this, m_weibo);
  mSsoHandler.authorize(new WeiboAuthDialog(ShareActivity.this));

       (OAuth2.0 授權是  m_weibo.authorize(this, new WeiboAuthDialog(this));)


2013年4月7日 星期日

[Android] Menu icon 製作

Android Menu icon 製作規則整理 

整理  Icon Design Guidelines

Highlight : 

1. Greyscales and flat-front  and PNG format

2. 版本 variant 

2.1 Android 3.0 以後要參考 Action Bar Icons 因為3.0 以後Action Bar取代了Menu
   2.1.1 PNG transparent no background 
   2.1.2 Size
          xhdpi 48x48  hdpi 36x36           mdpi 24x24           ldpi  18x18
   2.1.3 For 2 android theme
   2.1.3.1  Holo Light
   Color Fill :  #333333, 60% opacity
   Inner Content : Inner content should subtract from the outer shape and consist purely of transparent pixels.