ようへい

2012年3月2日金曜日

Hello, Views (Tab Layout編)

Tab Layout | Android Developers
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html そのまんまですね。
それでは始めましょう。
プロジェクトHelloTabWidgetを作成します。
アクティビティ名はHelloTabWidgetActivityとします。
ふむふむ、タブ毎にクラスを作成するんですね。
1つ目のタブから作成しましょう。
新規にクラスファイルを作成します。
クラス名はArtistsActivityとします。
スーパークラスはActivityを指定します。
AlbumsActivity、SongsActivityも同様に作成します。
package com.blogspot.logroid.helloTabWidget;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ArtistsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView textview = new TextView(this);
        textview.setText("This is the Artists tab");
        setContentView(textview);
    }
}
package com.blogspot.logroid.helloTabWidget;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class AlbumsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView textview = new TextView(this);
        textview.setText("This is the Albums tab");
        setContentView(textview);
    }
}
package com.blogspot.logroid.helloTabWidget;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class SongsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView textview = new TextView(this);
        textview.setText("This is the Songs tab");
        setContentView(textview);
    }
}
AndroidManifest.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.blogspot.logroid.helloTabWidget"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HelloTabWidgetActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="AlbumsActivity"></activity>
        <activity android:name="ArtistsActivity"></activity>
        <activity android:name="SongsActivity"></activity>
    </application>

</manifest>
チュートリアルページにあるアイコンをローカルに保存。
タブに表示する画像を指定する状態リスト(Drawable)を作成します。
先ほど保存したしたアイコンをres/drawableに保存します。(res/drawableディレクトリが無い場合は作成します)
res/drawableにic_tab_artists.xmlという名前のxmlファイルを作成します。
ルート要素はselectorを選びます。
以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/ic_tab_artists_grey"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/ic_tab_artists_white" />
</selector>
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>
HelloTabWidgetActivityを以下のように変更します。
package com.blogspot.logroid.helloTabWidget;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class HelloTabWidgetActivity extends TabActivity {
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  Resources res = getResources(); // Resource object to get Drawables
  TabHost tabHost = getTabHost();  // The activity TabHost
  TabHost.TabSpec spec;  // Resusable TabSpec for each tab
  Intent intent;  // Reusable Intent for each tab

  // Create an Intent to launch an Activity for the tab (to be reused)
  intent = new Intent().setClass(this, ArtistsActivity.class);

  // Initialize a TabSpec for each tab and add it to the TabHost
  spec = tabHost.newTabSpec("artists").setIndicator("Artists",
    res.getDrawable(R.drawable.ic_tab_artists))
    .setContent(intent);
  tabHost.addTab(spec);

  // Do the same for the other tabs
  intent = new Intent().setClass(this, AlbumsActivity.class);
  spec = tabHost.newTabSpec("albums").setIndicator("Albums",
    res.getDrawable(R.drawable.ic_tab_albums))
    .setContent(intent);
  tabHost.addTab(spec);

  intent = new Intent().setClass(this, SongsActivity.class);
  spec = tabHost.newTabSpec("songs").setIndicator("Songs",
    res.getDrawable(R.drawable.ic_tab_songs))
    .setContent(intent);
  tabHost.addTab(spec);

  tabHost.setCurrentTab(2);
 }
}
AndroidManifest.xmlを開き、以下のように変更する
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.blogspot.logroid.helloTabWidget"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HelloTabWidgetActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="AlbumsActivity"></activity>
        <activity android:name="ArtistsActivity"></activity>
        <activity android:name="SongsActivity"></activity>
    </application>

</manifest>
実行します。
今回出てきたキーワードについて解説。
drawable
状態リスト
コード内から呼ばれて、紐付いたリソースが使用される。
TabHost
タブを格納するコンテナ。
中には、TabWidgetと、FrameLayoutが存在する必要がある。
TabWidget
タブ部分
FrameLayout
タブのコンテンツ部分
TabActivity
タブを制御するためのアクティビティ
getTabHost
TabHostを取得するメソッド
TabHost.TabSpec
タブのプロパティを定義するクラス
newTabSpec
引数に指定した文字に紐付くタブを認識させ、TabHost.TabSpecクラスのインスタンスを作成する
setIndicator
タブに対して、テキストやアイコン画像を設定する
setContent
タブの選択時に表示するビューをセットする
addTab
TabHostに対し、タブを追加する
関連記事

2012年3月1日木曜日

[Tasker] Tasker 設定 ①

随時追加していきます。
まずは、Variables使わないプロファイルから。

裏返しでスリープ(バックライト消灯)

Orientation Face Down
State -> Sensor -> Orientation -> Face Down
Load App
App -> Load App -> スクリーンロック可能なアプリ(Screen Off and Lock等)

通話終了時バイブ

Phone Idle
Event -> Phone -> Phone Idle -> Normal
Vibrate
Alert -> Vibrate -> 200
関連記事

3/1 Android ニュースひとまとめ

 KDDIが3月1日、月額390円のスマートフォンユーザー向けサービス「auスマートパス」のサービスを開始した。スタートに合わせて東京・原宿のKDDIデザイニングスタジオでは、KDDI 代表取締役執行役員専務 新規事業統括本部長の高橋誠氏と、auのテレビCMに出演している剛力彩芽さんによるセレモニーとトークセッションが開催された。剛力さんは、KDDIデザイニングスタジオの1日館長としてKスタの制服姿で登場した。
「auスマートパス」3月1日開始 各種サービスとの連携もスタート - ITmedia +D モバイル
http://plusd.itmedia.co.jp/mobile/articles/1203/01/news126.html
果たしてどの程度ユーザを獲得できるんでしょうか。
私は月額という点で、論外のサービスですね。
しかもスマートパス解約したらアプリが使えなくなるとか。
う~ん。
 ソニーデジタルネットワークアプリケーションズ(SDNA)が2月29日、Android向けのカメラアプリ「pick pic camera」を発売した。価格は230円。Androidマーケットからダウンロードできる。
Photo 「pick pic camera」

 pick pic cameraは、シャッターを押した前後の写真を連続撮影してくれるアプリだ。撮影後、履歴のサムネイルをタップすると自動保存された前後の写真が表示され、ベストタイミングのものを選択して保存し直すことができる。
ベストタイミングを逃さないAndroid用カメラアプリ「pick pic camera」 - ITmedia +D モバイル
http://plusd.itmedia.co.jp/mobile/articles/1202/29/news141.html
え~。無料じゃないの?
せめてXperiaユーザには無料にして欲しかったな。
関連記事

[Android アプリレビュー] Screebl

情報
Screebl
Screebl
Screebl
Pro版とLite版で基本機能は変わりません
標準搭載でも良いんじゃないかと思うくらい便利なアプリ。
コミックビュワーで本を読んでいて・・・あれ、スリープ(バックライト消灯)になった。
ブラウズしてて、ページを読んでたら・・・(ry

このアプリに出会うまではこんなストレスと戦っていました。
このアプリを入れると、端末の傾きを検知して、水平でなかったら使用中と判断しバックライトの消灯を行いません。
設定画面でセンサーの感度を設定可能です。(基本的にデフォルトで良いです)
使い方
インストールすると、通知領域にアイコンが表示されます。
アイコンをタップすると、画面が開くので、Enable Screeblにチェックを入れます。
以上で設定完了です。
無効にする場合は、Enable Screeblのチェックを外してください。

有料のPro版がありますが、機能に大きな差はなく、Tasker用のプラグインが入っているというだけです。
私はTasker利用者なので購入してみましたが、Enableにしても暫くDisableのままだったりと使い勝手が悪かったので、結局利用していません。

ちょっとでも傾いていると使用中と判断されてしまうので、Taskerと組み合わせて使用すると最強です。
組み合わせるTaskerのプロフィールは後程公開します。
公開しました
Screebl
動作
アプリケーションの安定性
価格
コストパフォーマンスが良いかどうか
関連記事

[Android アプリレビュー] Beautiful widgets

情報
Beautiful widgets
Beautiful widgets
Beautiful widgets
かなりメジャーなホーム画面ウィジェットアプリ。
私は主に時計と、天気予報をサクッと見るために置いています。
BeWeatherやMinimalistic Text、Cliph Weather等試しましたが、結局これに落ち着きました。
決め手は、GPSで取得する天気予報のポイントが正確であることと、ウィジェットの見た目です。
GetJarから無料で入手可能ですので、ぜひお試しください。
天気予報についてしか触れていませんが、天気予報以外にもバッテリー等表示できます。
使い方
ホーム画面にウィジェットを配置するところから始めます。
ウィジェットを配置したら、そのウィジェットをタップして、端末のメニューボタンを押します。
すると、設定項目が表示されるので、好みに合わせて設定します。
Beautiful widgets
動作
アプリケーションの安定性
価格
コストパフォーマンスが良いかどうか
関連記事