「Kindle Fire HD 8」の対応ファイルとインテントフィルター

「電子書籍」とひとことにいっても, 実は, ファイル形式やリーダー端末やアプリなど利用方法をさまざま.

Fire HD を買ってみたのですがそんな調査と使い方を少し探ってみようと.

いうても, Android 5.1 だろよ, とな.

インテントフィルター

デフォルトでインストールされている 電子書籍リーダーとしての Kindle アプリ.

AndroidManifest を見てみると以下抜粋.


...
<activity
    android:theme="@2131624707"
    android:label="@2131230864"
    android:icon="@2130839461"
    android:name="com.amazon.kindle.TabletStartActivity"
    android:launchMode="singleInstance"
    android:configChanges="orientation|screenLayout|screenSize">
    <meta-data
        android:name="restriction_filter"
        android:resource="@2131296307"/>

    <intent-filter>
        <action
            android:name="android.intent.action.MAIN"/>
        <category
            android:name="android.intent.category.LAUNCHER"/>
        <category
            android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

    <intent-filter>
        <action
            android:name="android.intent.action.VIEW"/>
        <category
            android:name="android.intent.category.DEFAULT"/>
        <category
            android:name="android.intent.category.BROWSABLE"/>
        <data
            android:scheme="kindle"/>
    </intent-filter>

    <intent-filter>
        <action
            android:name="android.intent.action.VIEW"/>
        <category
            android:name="android.intent.category.DEFAULT"/>
        <category
            android:name="android.intent.category.BROWSABLE"/>
        <data
            android:mimeType="application/x-mobipocket-ebook"
            android:scheme="file"/>
    </intent-filter>

    <intent-filter>
        <action
            android:name="android.intent.action.VIEW"/>
        <category
            android:name="android.intent.category.DEFAULT"/>
        <category
            android:name="android.intent.category.BROWSABLE"/>
        <data
         android:mimeType="application/x-mobi8-ebook"
         android:scheme="file"/>
   </intent-filter>

   <intent-filter>
      <action
         android:name="android.intent.action.VIEW"/>
      <category
         android:name="android.intent.category.DEFAULT"/>
      <category
         android:name="android.intent.category.BROWSABLE"/>
      <data
         android:mimeType="application/pdf"
         android:scheme="file"/>
   </intent-filter>

   <intent-filter>
      <action
         android:name="android.intent.action.VIEW"/>
      <category
         android:name="android.intent.category.DEFAULT"/>
      <category
         android:name="android.intent.category.BROWSABLE"/>
      <data
         android:mimeType="application/pdf"
         android:scheme="content"/>
   </intent-filter>

   <intent-filter>
      <action
         android:name="android.intent.action.VIEW"/>
      <category
         android:name="android.intent.category.DEFAULT"/>
      <category
         android:name="android.intent.category.BROWSABLE"/>
      <data
         android:scheme="file"
         android:host="*"
         android:pathPattern=".*pdf"/>
   </intent-filter>

</activity>
...

レガシーなスタイルの file スキーマからしか mobi ファイルは読みません.
pdfファイルに関しては content スキーマから読むことができます.

よって, 外部ファイルに対して kindle アプリをリーダーとして使うためには以下のファイル形式と配置が必要になります.

- pdf ファイル
- デバイスローカルに配置した mobi ファイル

epub 形式は直接は開けません.

意外と使えないようですがさらに調べていきます.

(→ つづく)


Convert Java File to Kotlin の後に その1「メンバとコンストラクタ」

まずは「Convert Java File to Kotlin」で変換してなんとなくは動いていますが.

一通り公式リファレンスは流し読みしていましたが

コードをみているとKotolinの持つ恩恵を得ているような気がしません.

逆に分かりづらくなったようにも思えたりします.

先人たちのコードを見ながら自然なKotlinコードに書き換えていきましょう.

メンバとコンストラクタ

以下のようなJavaコード.


public class TasksPresenter implements TasksContract.Presenter {

    private final TasksRepository mTasksRepository;

    private final TasksContract.View mTasksView;

    private TasksFilterType mCurrentFiltering = TasksFilterType.ALL_TASKS;

    private boolean mFirstLoad = true;

    public TasksPresenter(@NonNull TasksRepository tasksRepository, @NonNull TasksContract.View tasksView) {
        mTasksRepository = checkNotNull(tasksRepository, "tasksRepository cannot be null");
        mTasksView = checkNotNull(tasksView, "tasksView cannot be null!");

        mTasksView.setPresenter(this);
    }

android-architecture/TasksPresenter.java at todo-mvp · googlesamples/android-architecture

Kotlin のプロパティを使って適切に初期化します. ほとんどのメンバ変数に割り当てられたコンストラクタパラメータは必要ありません.


class TasksPresenter(val tasksRepository: TasksRepository, val tasksView: TasksContract.View)
    : TasksContract.Presenter {

    override var filtering = TasksFilterType.ALL_TASKS

    private var mFirstLoad = true

    init {
        tasksView.setPresenter(this)
    }

主コンストラクタに注釈や可視性修飾子がない場合は、コンストラクタキーワードを省略できます。

Classes and Inheritance - Kotlin Programming Language

Convert Java File to Kotlin の後に その1「メンバとコンストラクタ」

Convert Java File to Kotlin の後に その2 「apply」

Convert Java File to Kotlin の後に その3 「Null Safety」

Convert Java File to Kotlin の後に その4 「lateinit」

Convert Java File to Kotlin の後に その5 「String Templates」


material.io「COLOR TOOL」で視覚的に配色をすばやく確認する

デザイナーでもプログラマーでなくても素早くブラウザで確認できます.

Color Tool - Material Design

自分が決めた配色のイメージを簡単に右上のアイコンリンクで他人に伝えることができます.

こんな感じで

あとは, 開発者向けに一括で出力できたらなあ.


新しくなった Android Asset Studio でマテリアルアイコンを自在に加工するべし

作者の Roman Nurik さんがつぶやいています.

使ってみましょう.

Android Asset Studio

Google から公開されているマテリアルデザインのアイコンを元に色やサイズやエフェクトをお好みにブラウザ上で設定してダウンロードできます.

編集後は, resディレクトリ以下解像度別のディレクトリの構造に合わせて作成されたzipアーカイブをダウンロードできます.


$ zipinfo -1 ic_launcher.zip
res/mipmap-xxxhdpi/ic_launcher.png
web_hi_res_512.png
res/mipmap-xxhdpi/ic_launcher.png
res/mipmap-xhdpi/ic_launcher.png
res/mipmap-hdpi/ic_launcher.png
res/mipmap-mdpi/ic_launcher.png


$ zipinfo -v ic_launcher.zip
Archive:  ic_launcher.zip
There is no zipfile comment.

End-of-central-directory record:
-------------------------------

  Zip archive file size:                    129862 (000000000001FB46h)
  Actual end-cent-dir record offset:        129840 (000000000001FB30h)
  Expected end-cent-dir record offset:      129840 (000000000001FB30h)
  (based on the length of the central directory and its expected offset)

  This zipfile constitutes the sole disk of a single-part archive; its
  central directory contains 6 entries.
  The central directory is 455 (00000000000001C7h) bytes long,
  and its (expected) offset in bytes from the beginning of the zipfile
  is 129385 (000000000001F969h).


Central directory entry #1:
---------------------------

  res/mipmap-xxxhdpi/ic_launcher.png

  offset of local header from start of archive:   0
                                                  (0000000000000000h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         5e505e31
  compressed size:                                20038 bytes
  uncompressed size:                              20028 bytes
  length of filename:                             34 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #2:
---------------------------

  There are an extra 16 bytes preceding this file.

  web_hi_res_512.png

  offset of local header from start of archive:   20118
                                                  (0000000000004E96h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         bb74dba5
  compressed size:                                74680 bytes
  uncompressed size:                              75392 bytes
  length of filename:                             18 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #3:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-xxhdpi/ic_launcher.png

  offset of local header from start of archive:   94862
                                                  (000000000001728Eh) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         ca100bd5
  compressed size:                                15772 bytes
  uncompressed size:                              15790 bytes
  length of filename:                             33 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #4:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-xhdpi/ic_launcher.png

  offset of local header from start of archive:   110713
                                                  (000000000001B079h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         6551b330
  compressed size:                                8409 bytes
  uncompressed size:                              8404 bytes
  length of filename:                             32 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #5:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-hdpi/ic_launcher.png

  offset of local header from start of archive:   119200
                                                  (000000000001D1A0h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         44371c4a
  compressed size:                                6539 bytes
  uncompressed size:                              6534 bytes
  length of filename:                             31 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

  There is no file comment.

Central directory entry #6:
---------------------------

  There are an extra 16 bytes preceding this file.

  res/mipmap-mdpi/ic_launcher.png

  offset of local header from start of archive:   125816
                                                  (000000000001EB78h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          yes
  file last modified on (DOS date/time):          2017 Jan 18 12:53:42
  32-bit CRC value (hex):                         4fce9139
  compressed size:                                3492 bytes
  uncompressed size:                              3487 bytes
  length of filename:                             31 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none

かんたんなアイコンであれば簡単に素早く作成できます.

Windows版デスクトップアプリ(.exe形式)もある模様.

romannurik/AndroidAssetStudio: A set of web-based tools for generating graphics and other assets that would eventually be in an Android application's res/ directory.


新しくなった Gradle Tips and Recipes : 各ソースセットの配置の確認

新しくなってます, Gradle Tips and Recipes .

Gradle Tips and Recipes | Android Studio

Gradle が利用するディレクトリ

それぞれ指定できるのはなんとなく知っていたが.


android {
  ...
  sourceSets {
    main {
      java.srcDirs = ['other/java']
    ....

これらの記述無し無指定のデフォルトの場合はどのディレクトリが利用対象になっているのか.

ドキュメントやツールスクリプトなど,

Git に登録して管理はしたいが, アプリ自体に影響ない位置はどこなのか??

と思っていましたが.

Configure Build Variants | Android Studio

右上 [Gradle] タブから以下ダブルクリックで実行.

MyApplication > Tasks > android > sourceSets

Gradle が認識している対象ディレクトリ群が Gradle Console に出力される.


------------------------------------------------------------
Project :app
------------------------------------------------------------

...

debug
----
Compile configuration: compile
build.gradle name: android.sourceSets.debug
Java sources: [app/src/debug/java]
Manifest file: app/src/debug/AndroidManifest.xml
Android resources: [app/src/debug/res]
Assets: [app/src/debug/assets]
AIDL sources: [app/src/debug/aidl]
RenderScript sources: [app/src/debug/rs]
JNI sources: [app/src/debug/jni]
JNI libraries: [app/src/debug/jniLibs]
Java-style resources: [app/src/debug/resources]

これで, AndroidStudio でファイルを操作しながらの Git 管理しても安心です.

他にもあれこれ小技がのっていますよ, このレシピ.