126
120

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidのUtilsクラスまとめ

Posted at

はじめに

androidのUtilsをまとめた資料が見当たらなかったので作りました。
android.*パッケージに含まれるものだけまとめています。

TextUtils

文字列操作用Utils。
isEmpty()とかequals()とかよく使う。
文字列操作系も大体揃っていて便利。
isGraphic()とかellipsize()とか使ったことないけど気になるメソッドもある。
SupportLibraryに最新版との差分をまとめたTextUtilsCompatがある。
http://developer.android.com/reference/android/text/TextUtils.html
http://developer.android.com/reference/android/support/v4/text/TextUtilsCompat.html

NavUtils

Up動作を実装するのに使う。
これだけ使っても思ったように実装できないことが多い気がする。
Up動作の実装については以前まとめた
http://developer.android.com/reference/android/support/v4/app/NavUtils.html

DatabaseUtils

DBとCursorを扱うためのUtils。
Cursorの中身をContentValuesに入れるメソッドが大量にある。
concatenateWhere()という2つのwhere句をANDでつないでくれるメソッドが微妙に便利。
SupportLibraryに最新版との差分をまとめたDatabaseUtilsCompatがある。
http://developer.android.com/reference/android/database/DatabaseUtils.html
http://developer.android.com/reference/android/support/v4/database/DatabaseUtilsCompat.html

DateUtils

formatDateRange()formatDateTime()で色々な日付表現ができる。
でも大抵はSimpleDateFormatで事足りるイメージ。
非推奨のメソッドもあるので、使う際は注意。
http://developer.android.com/reference/android/text/format/DateUtils.html

URLUtil

URLを扱うためのUtils。
ただしURL型ではなくStringのみ受け付ける。
有効なURLかどうかを判定してくれるisValidUrl()やウェブURL判定のisNetworkUrl()isHttpsUrl()あたりは使えそう。
なぜかこいつだけ名前がUtil。
http://developer.android.com/reference/android/webkit/URLUtil.html

PhoneNumberUtils

電話番号を扱うためのUtils。
Intentから電話番号を取得するgetNumberFromIntent()tel:sip:も対応してて便利。
表示用に日本向け(!)に整形してくれるformatJapaneseNumber()というのもあるらしい。
isDialable()とか便利そうだけどちゃんと動くのか未確認…。
http://developer.android.com/reference/android/telephony/PhoneNumberUtils.html

AnimationUtils

リソースからアニメーションの生成をしてくれるUtils。
loadInterpolator()くらいしか使ったことがない…。
http://developer.android.com/reference/android/view/animation/AnimationUtils.html

ThumbnailUtils

サムネイルの生成Utils。
なんと画像だけでなく動画からもサムネイルの生成をしてくれる。
ただし、動画の場合はサイズが2種類しか選べない。
画像からは指定サイズで作れるから二重に生成すれば良いのだが…。
http://developer.android.com/reference/android/media/ThumbnailUtils.html

TouchUtils

タッチイベントをシミュレートするためのUtils。
ActivityInstrumentationTestCase2と合わせてUIテストに使う。
http://developer.android.com/reference/android/test/TouchUtils.html

GLUtils

OpenGL扱うときに使うっぽいUtils。
使ったことがない…。
http://developer.android.com/reference/android/opengl/GLUtils.html

GestureUtils

ジェスチャー関連の解析とかをやるときに使うらしい。
使ったことがない…。
http://developer.android.com/reference/android/gesture/GestureUtils.html

DebugUtils

DebugUtils.isObjectSelected()メソッドしかない。
ログ出すときにオブジェクトの状態がANDROID_OBJECT_FILTERという環境変数の設定とマッチするかチェックしてくれる。
ANDROID_OBJECT_FILTER環境変数ってどうやってセットするんだ?
http://developer.android.com/reference/android/util/DebugUtils.html

126
120
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
126
120

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?