14. プラットフォーム・バージョン
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
16. Codename による割合
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
17. 前のページのデータは
Google Play へのアクセス( 14 日間)を集計したもの
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
18. Codename による割合
2012 年 11 月 1 日時点( 14 日間)
Gingerbread 54%
Ice Cream Sandwitch 26%
Froyo 12%
Eclair 3.1%
Jerry Bean 2.7%
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
19. Codename による割合 (API)
Gingerbread 54% API-9, 10
Ice Cream Sandwitch 26% API-15
Froyo 12% API-8
Eclair 3.1% API-7
Jerry Bean 2.7% API-16
2012 年 11 月 1 日時点( 14 日間)
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
25. deprecated
ある API パーツがアップグレードされると、
古い API は deprecated (非推奨)
になります。
既存のアプリが使用できるように、
削除はされません。
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
26. ただし、
ごく一部
セキュリティや安定性のために
API が 修正されたり削除される
場合があります。
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
27. 引き継がれます
その他、
すべての 旧バージョンの API パーツは
修正なしに引き継がれます。
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
28. たとえば互換性がないもの
● 新しく追加されたクラス( Fragment )
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
29. たとえば互換性がないもの
● 新しく追加されたクラス( ActionBar )
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
30. 互換性を保つには
● 以前の API を使って、同様の動きを実装
● Support Package
● サードパーティのライブラリ
● その他 ...
31. Support Package
http://developer.android.com/tools/extras/support-library.html
● Fragment
● FragmentManager
● FragmentTransaction
● ListFragment
● DialogFragment
● LoaderManager
● Loader
● AsyncTaskLoader
● CursorLoader
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
32. Support Package – ただし ...
The ActionBar is
not supported
by the library.
その代わりに、
MenuCompat.setShowAsAction()
が使えます。
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
33. Support Package – さらに ...
PreferenceFragment も非対応 ...
orz
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
40. Developer サイトの記事
Creating Backward-Compatible UIs
http://developer.android.com/training/backward-compatible-ui/index.html
Lessons として以下が紹介されています。
● Abstracting the New APIs
● Proxying to the New APIs
● Creating an Implementation with Older APIs
● Using the Version-Aware Component 今回は
ここに
注目。
41. Creating an Implementation with Older APIs
Decide on a Substitute Solution
● Action Bar は、イメージボタン、カスタムタイトル
バーやビューを水平に配置
● Action bar tabs は、ボタンを配置するか Tab Widget
を使う
● Number Picker や Switch は、 Spinner や Toggle
Button で
● ListPopupWindow や PopupMenu は PopupWindow で
http://developer.android.com/training/backward-compatible-ui/older-implementation.html
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
42. (Sample) NewsReader
Training: Designing multi screens
2012.11.22 at diamond cross のセミナーでも利用
47. values リソースで切替
res/values-sw600dp/layouts.xml
<resources>
<item name="main_layout"
type="layout">@layout/onepane</item>
onepane
<bool name="has_two_panes">false</bool>
false
</resources>
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
51. res/layout/onepane.xml
<linearLayout ...
<!-- 省略 -->
<fragment
android:id="@+id/headlines"
android:layout_height="fill_parent"
android:name=
"com.example.android.newsreader.HeadlinesFragment"
android:layout_width="match_parent" />
<!-- 省略 -->
</LinearLayout>
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
52. res/layout/twopanes.xml
<linearLayout ...
<!-- 省略 -->
<fragment
android:id="@+id/headlines"
android:layout_height="fill_parent"
android:name="com.example.android.newsreader.HeadlinesFragment"
android:layout_width="400dp"
android:layout_marginRight="10dp"/>
<fragment
android:id="@+id/article"
android:layout_height="fill_parent"
android:name="com.example.android.newsreader.ArticleFragment"
android:layout_width="fill_parent" />
<!-- 省略 -->
</LinearLayout>
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
53. タイトルを選んで記事を表示
@Override
public void onHeadlineSelected(int index) {
mArtIndex = index;
if (mIsDualPane) {
// display it on the article fragment
mArticleFragment.displayArticle(mCurrentCat.getArticle(index));
}
else {
// use separate activity
Intent i = new Intent(this, ArticleActivity.class);
i.putExtra("catIndex", mCatIndex);
i.putExtra("artIndex", index);
startActivity(i);
}
}
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
54. タイトルを選んで記事を表示
twopanes の場合はそのまま Fragment 表示
@Override
public void onHeadlineSelected(int index) {
mArtIndex = index;
if (mIsDualPane) {
// display it on the article fragment
mArticleFragment.displayArticle(mCurrentCat.getArticle(index));
}
else {
// use separate activity
Intent i = new Intent(this, ArticleActivity.class);
i.putExtra("catIndex", mCatIndex);
i.putExtra("artIndex", index);
startActivity(i);
}
onepane の場合は ArticleActivity 起動
}
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
55. ArticleActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCatIndex = getIntent().getExtras().getInt("catIndex", 0);
mArtIndex = getIntent().getExtras().getInt("artIndex", 0);
// If we are in two-pane layout mode, this activity is no longer necessary
if (getResources().getBoolean(R.bool.has_two_panes)) {
finish();
return;
}
// Place an ArticleFragment as our content pane
ArticleFragment f = new ArticleFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, f).commit();
// Display the correct news article on the fragment
NewsArticle article =
NewsSource.getInstance().getCategory(mCatIndex).getArticle(mArtIndex);
f.displayArticle(article);
}
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
56. レイアウト: onepane_with_bar
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:id="@+id/linearLayout1"
android:gravity="center"
android:layout_height="50dp">
<ImageView android:id="@+id/imageView1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/logo"
android:paddingRight="30dp"
android:layout_gravity="left"
android:layout_weight="0"
android:contentDescription="TODO"/>
<View android:layout_height="wrap_content"
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_weight="1" />
<Button android:id="@+id/categorybutton"
android:background="@drawable/button_bg"
android:layout_height="match_parent"
android:layout_weight="0"
android:layout_width="120dp"
style="@style/CategoryButtonStyle"/>
</LinearLayout>
<fragment android:id="@+id/headlines"
表示領域 (pane) が 1 個
android:layout_height="fill_parent"
android:name="com.example.android.newsreader.HeadlinesFragment"
アクションバーを実装
android:layout_width="match_parent" />
</LinearLayout>
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
57. values-sw600dp-land
<resources>
<item name="main_layout" type="layout">@layout/twopanes</item>
<bool name="has_two_panes">true</bool>
</resources>
values-sw600dp-land/layouts.xml
・ layout リソースの指定
・ 2 つの表示領域あり
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
58. レイアウト: twopanes
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment
android:id="@+id/headlines"
android:name="com.example.android.newsreader.HeadlinesFragment"
android:layout_width="121dp"
android:layout_height="fill_parent"
android:layout_marginRight="10dp" />
<fragment android:id="@+id/article"
android:layout_height="fill_parent"
android:name="com.example.android.newsreader.ArticleFragment"
android:layout_width="fill_parent" />
表示領域 (pane) が 2 個
</LinearLayout>
アクションバーは自動
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
60. ActionBar のセットアップ
● NewsReaderActivity の onCreate() にて
setUpActionBar(mIsDualPane, catIndex);
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
61. setUpActionBar
if (Build.VERSION.SDK_INT < 11) {
return;
}
android.app.ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
// 以下、ActionBarのセットアップ(略)
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
63. 先ほどの、レイアウト: onepane_with_bar
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:id="@+id/linearLayout1"
android:gravity="center"
android:layout_height="50dp">
<ImageView android:id="@+id/imageView1"
categorybutton"
android:layout_height="wrap_content"
<Button android:id="@+id/
android:layout_width="wrap_content"
android:src="@drawable/logo"
android:paddingRight="30dp"
android:background="@drawable/button_bg" android:layout_gravity="left"
android:layout_weight="0"
android:contentDescription="TODO"/>
android:layout_height="match_parent" <View android:layout_height="wrap_content"
android:id="@+id/view1"
android:layout_weight="0" android:layout_width="wrap_content"
android:layout_weight="1" />
<Button android:id="@+id/categorybutton"
android:layout_width="120dp" android:background="@drawable/button_bg"
android:layout_height="match_parent"
style="@style/CategoryButtonStyle"/> android:layout_weight="0"
android:layout_width="120dp"
style="@style/CategoryButtonStyle"/>
</LinearLayout>
<fragment android:id="@+id/headlines"
表示領域 (pane) が 1 個
android:layout_height="fill_parent"
android:name="com.example.android.newsreader.HeadlinesFragment"
アクションバーを実装
android:layout_width="match_parent" />
</LinearLayout>
Portions of this page are modifications based on work created and shared by the Android Open Source Project
and used according to terms described in the Creative Commons 2.5 Attribution License.
68. Android1.6(API 4) でテスト
Could not find method
com.example.android.newsreader.NewsReaderAc
tivity.getActionBar, referenced from method
com.example.android.newsreader.NewsReaderAc
tivity.setupActionBar
69. 1.6 は回避できず
@TargetApi(11)
public void setUpActionBar(boolean showTabs, int selTab) {
if (Build.VERSION.SDK_INT < 11) {
return;
}
android.app.ActionBar actionBar = getActionBar() ;
// 省略...
}
71. ActionBar のラッパー
public class ActionBarWrapper {
private ActionBar actionBar;
// Check if android.app.ActionBar exists and throw an error if
not
static {
try {
Class.forName("android.app.ActionBar");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// 省略
}