ラベル Google I/O の投稿を表示しています。 すべての投稿を表示
ラベル Google I/O の投稿を表示しています。 すべての投稿を表示

2011年5月10日火曜日

Eclipse で Google URL Shortener API を使う

Google IO の BootCamp の「Intro to Google Api」の簡単まとめ

# BootCamp の Schedule

# Google APIs Discovery Service

Google URL Shortener API

ログインした状態で http://goo.gl/ に行くと、自分が作った Short URL の一覧がみれる





Details をクリックすると、解析結果がみれる





---

Google API を使うには、API キーが必要 Google API Console で取得する

最初にプロジェクトを作成する

左側の Services をクリックして、使いたい Service を ON にする



左側の API Access をクリックして、API key を確認できる。



Eclipse に Google Plugin for Eclipse を入れる

新しい Web Application Project を作成し、



作成したプロジェクトを選択した状態で、[Add Google APIs...] をクリック



追加したい Google API を選択して [Finish] をクリック
今回は Google URL Shortener API を選択する



プログラムを書く

package yanzm.example.shortener.sample;

import java.io.IOException;
import javax.servlet.http.*;

import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.urlshortener.v1.Urlshortener;
import com.google.api.urlshortener.v1.model.Url;

@SuppressWarnings("serial")
public class GoogleUrlShortenerTestServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {

HttpTransport transport = new NetHttpTransport();
final JsonFactory jsonFactory = new JacksonFactory();

Urlshortener shortener = new Urlshortener("yanzm test", transport, jsonFactory);
shortener.accessKey = "YOUR API KEY";
Url returnUrl = shortener.url.get("http://goo.gl/ERwbw").execute();

resp.setContentType("text/plain");
resp.getWriter().println(returnUrl.longUrl);
}
}


実行すると、goo.gl/ERwbw を展開した URL が表示される

# Urlshortener の使い方がさっぱりわからなくて、
# 結局 UrlShortener とか UrlShortener.Url とかのコードをみて理解した。

 

2010年9月1日水曜日

Android 「The world of ListView」 - Gotchas and don’ts -

Google I/O の 「The world of ListView」というセッションを見たので
そのまとめ。

長いので、項目ごとに分けました。
今回は 「Gotchas and don'ts」

--------------------------------------

Google I/O の「The world of ListView」のページは こちら

セッションのスライドはこちら

 agenda

  • Virtualization and adapters

  • Item properties

  • Headers and footers

  • List selectors

  • Other features

  • Gotchas and don'ts


--------------------------------------

■ Gotchas and don'ts (落とし穴とやっちゃいけないこと)

# gotchas って単語しらなかった。「落とし穴」なんだね。

 * Gotcha(落とし穴)

  ・リストが真っ黒になった?!
    • 最適化に便利なので...
      – スクロール中の view が bitmap でキャッシュされてるとき
      – ブレンディングを避けるために不透明の bitmap を使っている
    • 解決方法
      – android:cacheColorHint="#00000000"
      – android:cacheColorHint
         ="@color/myBackgroundColor"

  ・スクロールバーのサイズが変わった?!
    • view がすごく異なる高さを持つときにおこる
    • Smooth scrollbar は各要素(item)の高さが必要
      – Too expensive(コストかかりすぎ!)
    • 解決方法
      – android:smoothScrollbar=”false”



 * Don't (やっちゃいけないこと)

  ・android:layout_height=”wrap_content”
    • ListView は仮想化されている
    • wrap_content = 子要素の最大
      – ListViewは均等サイズの子要素に対応
      – 数千個の子要素を測る?
    • Android framework cheats
      – 3個の子要素だけ測る
      – それでもコストかかりすぎ
    •間違った結果になる

  ・ScrollView の中に ListView を入れる
    • ScrollView がスクロールする
    • ListView がスクロールする
    • どれがスクロールする?

  ・adapter に view をキャッシュする
    • ListView の裏をかこうとしない
      – ListView は view の所有権とコントロールを前提としている
    • 複雑な再利用メカニズム
      – 多数の最適化
      – 我々も時にはそこにバグを残してしまう
    • 最悪の場合はアンデッド
      – 再利用者と画面の両方に view

  ・必要でないときに ListView を使う
    • ListView は...
      – 再帰的な、境界のないデータ用
      – (たくさんの)複雑さが加わる
    • LinearLayout や ScrollView では置き換えられない?


   

Android 「The world of ListView」 - Other features -

Google I/O の 「The world of ListView」というセッションを見たので
そのまとめ。

長いので、項目ごとに分けました。
今回は 「Other features」

--------------------------------------

Google I/O の「The world of ListView」のページは こちら

セッションのスライドはこちら

 agenda

  • Virtualization and adapters

  • Item properties

  • Headers and footers

  • List selectors

  • Other features

  • Gotchas and don'ts


--------------------------------------

■ Other features

 * Transcript and stack from bottom

   • android:transcriptMode
     – コンテンツが変わったときのリストの振る舞い
     – "disabled", スクロールしない
     – "normal", 最後の要素が見えているなら、底部までスクロールする
     – "alwaysScroll", いつも底部までスクロールする

   • android:stackFromBottom
     – 要素を逆順にスタックする
     – adapter の最後の要素からスタートする

   • チャットなどにいい
     – Messaging, Talk, IRC, etc.




 * Text filter

   • android:textFilterEnabled="true"
   • adapter は Filterable を実装する必要がある
     – CursorAdapter 、 ArrayAdapterなど
     – getFilter() を実装する
   • Filter を実装する


// Filters the content of the adapter on a worker thread
protected FilterResults performFiltering(CharSequence prefix)

// Displays the results on the UI thread
protected void publishResults(CharSequence constraint, FilterResults results)


   CursorAdapter や ArrayAdapter のコードをみるのがいいらしい

2010年8月30日月曜日

Android 「The world of ListView」 - List selectors -

Google I/O の 「The world of ListView」というセッションを見たので
そのまとめ。

長いので、項目ごとに分けました。
今回は 「List selectors」

--------------------------------------

Google I/O の「The world of ListView」のページは こちら

セッションのスライドはこちら

 agenda

  • Virtualization and adapters

  • Item properties

  • Headers and footers

  • List selectors

  • Other features

  • Gotchas and don'ts


--------------------------------------

■ List selectors

 • 選択中のアイテムをハイライト
 • タッチモードでは表示されない
   – タッチモードには選択中がない!
 • リスト要素の背後に表示
   – android:drawSelectorOnTop="true" にすると前に表示される





<selector>
<item android:state_window_focused="false"
android:drawable="@color/transparent" />

<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/list_selector_background_disabled" />

<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/list_selector_background_disabled" />

<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />

<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />

<item android:state_focused="true"
android:drawable="@drawable/list_selector_background_focus" />
</selector>


 要素(項目)が不透明な場合は、selector drawable を使う
  – convertView.setBackground(R.drawable.selector)


<selector>
<item android:state_selected="true"
android:drawable="@color/transparent" />

<item android:state_selected="false"
android:drawable="#ff00ff00" />
<selector/>

2010年8月27日金曜日

Android 「The world of ListView」 - Headers and footers -

Google I/O の 「The world of ListView」というセッションを見たので
そのまとめ。

長いので、項目ごとに分けました。
今回は 「Headers and footers」

--------------------------------------

Google I/O の「The world of ListView」のページは こちら

セッションのスライドはこちら

 agenda

  • Virtualization and adapters

  • Item properties

  • Headers and footers

  • List selectors

  • Other features

  • Gotchas and don'ts


--------------------------------------

■ Headers and footers



 * Fixed

   fixed header/footer は簡単。次のように
   LinearLayout でOK


<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<!-- ... -->

</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" />

</LinearLayout>



 * Scrolling

  一緒にスクロールする header/footer はメソッドが用意されている
  twitter の reload / more load みたいなやつ。

  • ListView.addHeaderView()
  • ListView.addFooterView()
  • setAdapter() の前に呼ばなければならない
  • isSelectable == Adapter.isEnabled()
    – Sorry, our bad(混乱する名前にしちゃってごめんね。。。)

  addHeaderView() と addFooterView() は isSelectable という
  パラメータを保持している。
  これは、使われている final adapter が items が有効になっている
  リストに report back するかどうかに対応する。
  「ちょっと混乱する名前だね」って言ってた。

  (This corresponds to whether or not the final adapter
   being used will report back to the list that these
   items are enabled.)

 * Wrapped adapter

  ListView では、内部的に別の adapter の中に your adapter を
  wrapping することで、scrolling header / footer を実現している。
  そのため、最初の最後の要素(item)では、異なるタイプの view を返す。
  よって、setAdapter で渡した adapter と getAdapter
  で返ってくる adapter は異なる。ちょっと注意が必要。


ListView list = ...;
list.addHeaderView(myHeader);
list.addFooterView(myFooter);
list.setAdapter(myAdapter);

boolean same = list.getAdapter() == myAdapter;
// same == false!
// getAdapter() returns a
// android.widget.HeaderViewListAdapter

2010年8月26日木曜日

Android 「The world of ListView」 - Item properties -

Google I/O の 「The world of ListView」というセッションを見たので
そのまとめ。

長いので、項目ごとに分けました。
今回は 「Item properties」

--------------------------------------

Google I/O の「The world of ListView」のページは こちら

セッションのスライドはこちら

 agenda

  • Virtualization and adapters

  • Item properties

  • Headers and footers

  • List selectors

  • Other features

  • Gotchas and don'ts


--------------------------------------

■ Item properties

 * Enabled or disabled

   • Enabled
     – 選択、クリックができる要素
   • Disabled
     – コンテンツ内の区切り線・ヘッダ

   • 例)マーケットアプリ
     緑が Disabled Items



 * Choice mode
   • Single choice mode (radio buttons)
   • Multiple choice mode (checked items)
   • 選択されているのはどれ?
     – Single choice mode
       • getCheckedItemPosition()
     – Multiple choice mode
       • getCheckedItemPositions()
     – Stable IDs はポジションが変化するような場合に役立つ
       • getCheckedItemIds()
       • Stable ID は項目の挿入や削除によって変化しない
       (ポジションは変わる)
       • an integer

   • 例)左:Single choice mode, 右:Multiple choice mode





 * Focusable
   • setItemsCanFocus(boolean itemsCanFocus)
   • itemsCanFocus = false : リストの要素全体はフォーカスできる
   • itemsCanFocus = true : リストの要素内の view にフォーカスできる

   # 「UIで大きな制限の1つが、トラックボールとタッチスクリーン両方を
   # サポートしなければならないということ。
   # タッチしたら、フォーカスや選択はすぐ消えるように、早い段階に決めた。
   # なぜなら、choice mode があるから。
   # ユーザーがリスト内の項目をタップして、かつ画面上の選択を
   # 維持させることはできない。
   # ListViewは本当に難しいこと発生させないようにコントロールしている。

   # 例えば、1つの行に複数のボタンが含まれているけれども、
   # トラックボールを使った場合、行全体が選択される。
   # その理由は、行全体を選択している状態から、その中の小さい要素を
   # 選択するというトラックボールナビゲーションを持つことは、
   # とてもやっかいだから。」

   もし、行の中の小要素(ボタンとか、リンク)にフォーカスさせないなら
   itemCnaFocus = true にする。

   • 例)右:itemsCanFocus = false, 左 : itemsCanFocus = true



 # Item の view が複雑になると、この Focusable をどっちにするかは
 # 悩ましいところ。登壇者も、いいアイディアがあればコミュニティに
 # フィードバックしてほしいと言ってました。
 # 将来的に改善したいとも言ってたので、期待したいです。

2010年8月24日火曜日

Android 「The world of ListView」 - Virtualization and adapters -

Google I/O の 「The world of ListView」というセッションを見たので
そのまとめ。

長いので、項目ごとに分けました。
今回は 「Virtualization and adapters」

--------------------------------------

Google I/O の「The world of ListView」のページは こちら

セッションのスライドはこちら

 agenda

  • Virtualization and adapters

  • Item properties

  • Headers and footers

  • List selectors

  • Other features

  • Gotchas and don'ts

--------------------------------------

■ Virtualization and adapters

 ・ Virtualization
  * 問題点 : 巨大なデータセット
   ・メモリ
   ・パフォーマンス
  
  10,000 item くらいの(ってセッションでは言ってた)データを
  比較的速く扱うには?
  普通は、10,000 個のview を view の階層に添付したくはないよね。
  そのために、、、

  * 解決方法
   ・必要に応じでデータを格納
   ・view をリサイクルして、オブジェクトのチャーン(object churn)を減らす
  

 ・ Adapters
  * 用語
   – index: 子要素
   – position: adapter 内のデータ
   – id: データの識別子

  * Stable IDs
   – hasStableIds() == true で調べる
   – 常に同じ値を参照するための ID
   – ListView に役立つ!!

  * getView(int position, View convertView, ViewGroup parent)
   – 全データの表示を制御
   – 最適化
   – はまりやすい!「Shoot yourself in the foot (and the face)」

  ローカルのデータや、データベースのデータや、ネットワークから
  とったデータ、から割り当てたデータソースから、データを取り出す。
  view は単純な TextView だったり、複雑なレイアウトだったりする。
  
 
  * getView の 最適化ポイント
   • ListView is smart
   • convertView
    – ListView で提供される
    – 要素(item)のタイプと一致
    – 再利用すべし!!

   extra view パラメータの呼び出しを convert view に
   渡してしまえばOK。ListView がスクリーン外の view を
   再利用する方法と同じ最適化方法。
   
   ListView はスクリーン外へ移動した全部の extra view を
   keep track して、既存のデータを入れてから返す。
   これが、convert view parameter。
   つまり、自動的に item のタイプを match up している。
   もし、adapter 内に異なるデータによる複数のタイプ
   (例えば、画像と文字)がある場合、ListViewに adapter
   のあるポジションがどのタイプか聞いたとき convert view は
   いつも正しいタイプになっている(必要がある)。
   でもこれはあんまり賢いやりかたじゃない。
   
   だから、
    もし convertView が null じゃないなら、再利用する!
   

   ● getView のダメな使い方 (The Slow Way)


public View getView(int position, View convertView, ViewGroup parent) {
View item = mInflater.inflate(R.layout.list_item_icon_text, null);
((TextView) item.findViewById(R.id.text)).setText(DATA[position]);
((ImageView) item.findViewById(R.id.icon)).setImageBitmap(
(position & 1) == 1 ? mIcon1 : mIcon2);
return item;
}

    getView 内で毎回 view を inflate してはダメ!
    xml を毎回 parse することは、メモリもCPUも使うので
    とっても無駄が多い。


   ● getView の普通の使い方 (The Right Way)


public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item, parent, false);
}
((TextView) convertView.findViewById(R.id.text)).setText(DATA[position]);
((ImageView) convertView.findViewById(R.id.icon)).setImageBitmap(
(position & 1) == 1 ? mIcon1 : mIcon2);
return convertView;
}

    最初だけ view を inflate して、それを再利用する


   ● getView の賢い使い方 (The Fast Way)

   ViewHolder を使うべし


static class ViewHolder {
TextView text;
ImageView icon;
}



public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item_icon_text, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);

convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}

holder.text.setText(DATA[position]);
holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);

return convertView;
}

    最初だけ view を inflate して、holder を介して再利用する


    このくらい違う




   * How to shoot yourself in the foot (どのようにはまりやすいか)
     • ロカールビューのキャッシュ
     • adapter からビューにアクセスする
     • convertView の構造を変える
     • getView の呼び出しについての仮定

   * データの変更を制御する
    • notifyDataSetChanged()
     – データの新規作成 or 更新
    • notifyDataSetInvalidated()
     – アクセスできるデータがないとき

   * 異なるビュータイプを制御する
    • 要素のタイプ (item types) を Built-in にする
    • getItemViewType
     – 与えられたポジションのビューのタイプを取得
     – 正しい convertView を提供するのに使う
    • getViewTypeCount
     – 予測されるタイプの数を取得

   * slow data sources を制御する
    • UIスレッドで adapter の変更 (modification)
    • Fetching data can happen anywhere
    • 別のスレッド上でデータをリクエストする
    • UIスレッドで、adapter の変更をコミットする
    • notifyDataSetChanged() を呼び出す

 書きかけだけど、一旦出します。
 もうちょっと追記するかも。

2010年5月24日月曜日

Google I/O のメモ

Google I/O のメモ(というかリンク集)です。
関係あるような、ないようなのも含まれてたり、なかったり。。。

---

公式ページ
・http://code.google.com/intl/ja/events/io/2010/

発表の目玉

・WebMプロジェクト: MozillaおよびOperaと共同で推進する新たなビデオフォーマット

・Google App Engine for Business: PaaSの企業向けバージョン。管理・サポート機能などを追加し、米VMwareとの提携でポータビリティを強化

・Google Storage for Developers: 100Gバイトのストレージと月間300Bバイトまでの帯域を無料で利用できる、開発者向けのオンラインストレージサービス

・Google Waveの一般公開: Google Labsのプロジェクトのままだが、招待が必要なくなった

・Chrome App Store: Webアプリのオンラインストア。サードパーティーはここでWebアプリを販売できる

・Google Font API: オープンソースのWeb向けフォント


Google Strage
http://code.google.com/intl/ja/apis/storage/


Google Font API
http://code.google.com/webfonts
http://code.google.com/intl/ja/apis/webfonts/
http://www.ideaxidea.com/archives/2010/05/font_previewer.html
http://code.google.com/intl/ja/apis/webfonts/docs/getting_started.html


Google Latitude API
http://googlecode.blogspot.com/2010/05/with-new-google-latitude-api-build.html


webM
http://www.webmproject.org/
http://nightly.mozilla.org/webm/
http://hacks.mozilla.org/2010/05/firefox-youtube-and-webm/
http://labs.opera.com/
http://tsushima.dat2ch.net/test/read.cgi/news/1274307850/l50
http://es.prit.jp/php-rss/gadget.php
http://d.hatena.ne.jp/ampll/20100519/1274295134
http://www.streamingmedia.com/Articles/Editorial/Featured-Articles/First-Look-H.264-and-VP8-Compared-67266.aspx
http://x264dev.multimedia.cx/?p=377


Chrome Web Store
https://chrome.google.com/webstore


HTML5
http://labs.adobe.com/technologies/html5pack/


device's pictures
http://www.flickr.com/photos/androidandme/sets/72157623971136149/detail/


Wave
https://wave.google.com/wave/#restored:wave:googlewave.com!w+v7BXJrZkBJT


Android
http://www.itmedia.co.jp/enterprise/articles/1005/21/news029.html
http://code.google.com/intl/ja/android/c2dm/
http://www.google.com/mobileads/


その他
http://replicaisland.net/
http://www.thespeechsource.com/cart.asp