2015年9月16日水曜日

Android Mリリース目前のAOSP mirrorの容量



久々にAOSP mirrorを作ってみました。
(備考:ローカルにAOSPのミラーを作成)


容量80GB超えたよ

上記の画像を見ていただければ、お分かり頂けると思いますが、容量が81.25GBと良い勢いで増えています。
いまSSD 128GB上に作成していますが、Android Mがリリースされると100GBまで行くんじゃないかと心配です。



とはいえ、頻繁にAOSPのソースを取得する現場ですと、mirrorがある方が効率的ですので導入を推奨いたします。

2015年9月15日火曜日

AOSP mirrorのrepo syncエラー: GPGが更新されない

久々にAOSP mirrorのrepo syncを実行したところ、エラーとなりました。
どうも、repoの更新ができていないよう。

info: A new version of repo is available


object 5ea32d135963da5542b78895f95332c6a17bbe11
type commit
tag v1.12.31
tagger Dan Willemsen  1441912006 -0700

repo v1.12.31

error: cannot run gpg: No such file or directory
error: could not run gpg.
error: could not verify the tag 'v1.12.31'


warning: Skipped upgrade to unverified version

ググってみたところ、次の方法で解決できるとのこと。
https://groups.google.com/forum/#!searchin/android-building/repo/android-building/ICajKIQlwC8/hxKulJLZ278J

mv ~/.repoconfig/gnupg ~/.repoconfig/gnupg_OLD

repoのconfig内のgnupgが更新されていないようなので、新規で取ってこいってことかな???
mv実行後、repo syncは無事に完遂しました。

2015年8月21日金曜日

iOS8.xでUITableViewAutomaticDimensionを使うと、セル位置が正常にならない

iOS8.xでTableViewのセル高さの自動調整が可能です。

    self.tableView.rowHeight = UITableViewAutomaticDimension



ただし、TableViewからセル選択により画面遷移後、戻ってきたときなど再表示をするとセル位置が調整されていないことがあります。 対策として、一度表示したセルの高さを保持しておいて、estimatedHeightForRowAtIndexPathで値を返します。

    var cellHeight:Dictionary = ["":0]
    
    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        
        cell.contentView.updateConstraints()
        self.cellHeight[String(indexPath.item )] = Float(cell.frame.size.height)
        
    }
    
    override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if(self.cellHeight[String(indexPath.item )] != nil){
            return CGFloat(self.cellHeight[String(indexPath.item )]!)
        }
        return self.tableView.estimatedRowHeight
        
    }

2015年6月13日土曜日

CoordinatorLayoutで困った時に確認するIssue Tracker

Android Design Support LibraryのCoordinatorLayoutを使った際に、困った既知(known issue)の問題をまとめます。

画面回転でBehaviorが正常に表示されない

AndroidManifest.xmlで、ActivityにconfigChanges属性で画面回転での再生成を追加すると、Behaviorが正常に表示されないことがあります。
ユースケースとしてはLandscapeからPortraitの画面回転で、現象が発生します。


この現象は、すでに本家Issue Trackerに登録されています。
CoordinatorLayout in design support library does not update child size on rotation
layout_behavior view height doesn't restore when keyboard goes down / ActionBar ActionView partially visible

AppBarLayoutがアニメーションしない

タッチを止めると、次のようにAppBarLayoutの部分が中途半端に残ってしまうことがあります。
Google Playアプリのようにアニメーションで全部消す/表示するには、タッチイベントとAppBarLayoutのオフセット位置、およびBehaviorのonNestedFlingを組み合わせて実装しないといけないのかな?
(ベストプラクティスを教えて欲しい)

Toolbar should settle when only partially scrolled

2015年6月6日土曜日

Android Support library v22.2で追加されたTextInputLayoutを使う

Material DesignのText fieldアニメーションが楽々に実装できるレイアウトです。
http://www.google.com/design/spec/components/text-fields.html#text-fields-single-line-text-field


実装は非常に簡単で、EditTextをTextInputLayutで囲うだけです。
    <android.support.design.widget.TextInputLayout
            android:id="@+id/textInputLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:hintTextAppearance="@style/TextInputLayoutHintAppearance">
        <EditText
                android:id="@+id/editText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="HintText"
                android:ems="10"/>
    </android.support.design.widget.TextInputLayout>




各パーツはマテリアルカラーに準じています。

2015年5月29日金曜日

Android Support library v22.2で追加されたFloatingActionButtonを使う

早朝のGoogle I/O 2015のKeynoteと共に最新のAndroid Support libraryがリリースされました。
注目すべきはdesignパッケージです。本格的にマテリアルデザインのコンポーネントが追加されています。

http://developer.android.com/tools/support-library/index.html

Libのインポート

Android StudioでのDesign Support Libraryの追加方法は以下を参照、ですがTYPO(5/29時点)がありますので注意が必要です。
http://developer.android.com/tools/support-library/features.html#design

    compile 'com.android.support:design:22.2.0'

FloatingActionButton

次のように、レイアウトから使用可能です。

    <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_action_button"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/XXXX"
            android.support.design:backgroundTint="@color/fab_bg"
            android:contentDescription="@string/XXXX"/>
FABのカラーはデフォルト:colorAccentです。もしカラーを変更する場合はandroid.support.design:backgroundTint属性でカラーを指定します。


備考

Design Support Libraryはリリースされたばかりで、まだまだissueが沢山あります。
Lollipop端末でFABを確認したところ、Shadowが正しく表示されませんでした。
FAB doesn't have shadow on Lollipop https://code.google.com/p/android/issues/detail?id=175068 The FloatingActionButton has different margins on Lollipop and pre-Lollipop. https://code.google.com/p/android/issues/detail?id=175330
動作がおかしい場合は、issue trackerを確認することをお勧めします。

2015年4月26日日曜日

IntentsTestRuleを使って、Intentのテストを行う

IntentsTestRuleについて

IntentsTestRuleは、startActivity()でセットしたIntentのデータをテストすることができます。
このクラスはActivityTestRuleを継承したクラスで、各Testの実行前にEspresso-Intentsを初期化し、実行後にEspresso-Intentsをリリースします。
各テスト後にActivityはfinish()されます。

build.gradleにEspresso-Intentsライブラリを追加します。
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.1'

サンプルソース

次はユーザー操作によって、Intent.ACTION_CALLのIntentが発生したかどうかテストするサンプルプログラムです。
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityIntentTest {

    @Rule
    public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(
            MainActivity.class);

    @Before
    public void stubAllExternalIntents() {
        // By default Espresso Intents does not stub any Intents. Stubbing needs to be setup before
        // every test run. In this case all external Intents will be blocked.
        intending(not(isInternal()))
                .respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, null));
    }

    @Test
    public void callPhone() {
        // call action
        onView(withId(R.id.callButton)).perform(click());

        // test
        intended(allOf(
                hasAction(Intent.ACTION_CALL),
                hasData("tel:0123456789"),
                toPackage("com.android.server.telecom")));

    }
}
テストクラスは次のように作成します。
  • テストクラスにRunWithアノテーションをつける
  • IntentsTestRuleを生成する、Ruleアノテーションをつける

Intentが発生したかどうかは、次のように判定します。
  • intendedメソッドで意図したIntentが発生しているかチェックする
  • matchメソッドはこちらを参照


  • Activity起動時のIntentセット

    テストを行うActivityの起動用Intentが必要な場合、IntentsTestRule#getActivityIntentメソッドをオーバーライドしてIntentを返す。
        @Rule
        public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(MainActivity.class) {
    
            /**
            * Activity起動用Intent
            */
            @Override
            protected Intent getActivityIntent() {
                Intent intent = new Intent();
                // Activity起動用のパラメータをセット
                intent.putExtra(KEY_DATA,data);
                return intent;
            }
        };
    

    参考サイト:
    https://github.com/googlesamples/android-testing