SlideShare a Scribd company logo
1 of 52
Download to read offline
- -
private
package-private
protected
public
private String createDurationText(int duration) {

int hour = duration / 3600;

duration -= hour * 3600;

int min = duration / 60;

duration -= min * 60;

int sec = duration;

if (hour > 0) {

return String.format(Locale.ENGLISH, "%d:%02d:%02d", hour,
min, sec);

} else if (min > 0) {

return String.format(Locale.ENGLISH, "%02d:%02d", min,
sec);

} else {

return String.format(Locale.ENGLISH, "0:%02d", sec);

}

}

x
static String createDurationText(int duration) {

int hour = duration / 3600;

duration -= hour * 3600;

int min = duration / 60;

duration -= min * 60;

int sec = duration;

if (hour > 0) {

return String.format(Locale.ENGLISH, "%d:%02d:%02d", hour,
min, sec);

} else if (min > 0) {

return String.format(Locale.ENGLISH, "%02d:%02d", min,
sec);

} else {

return String.format(Locale.ENGLISH, "0:%02d", sec);

}

}
o
@Test

public void durationTextTest() {

assertEquals("1:24:32", MyCustomView.createDurationText(3600 +
24 * 60 + 32));

assertEquals("01:32", MyCustomView.createDurationText(60 +
32));

assertEquals("0:32", MyCustomView.createDurationText(32));

}
o
private static String TAG = "MainActivity";
x
private static final String TAG = "MainActivity";
o
public class MyCustomView extends View {



private int minHeight;



public MyCustomView(Context context) {

super(context);

init();

}



public MyCustomView(Context context, AttributeSet attrs) {

super(context, attrs);

init();

}



public MyCustomView(Context context, AttributeSet attrs, int
defStyleAttr) {

super(context, attrs, defStyleAttr);

init();

}



private void init() {

minHeight = 10;

}
x
public class MyCustomView extends View {



private final int minHeight;



public MyCustomView(Context context) {

this(context, null);

}



public MyCustomView(Context context, AttributeSet attrs) {

this(context, attrs, 0);

}



public MyCustomView(Context context, AttributeSet attrs, int
defStyleAttr) {

super(context, attrs, defStyleAttr);

minHeight = 10;

}
o
/**

* Created by yanzm on 2016/08/07.

*/

public class MainActivity extends AppCompatActivity {

x
/**

* ホーム画面

*

* ランチャーから起動される。

* 最初にトークンがローカルに保存されているか確認し、
* 保存されていない場合はログイン画面に遷移する。

*/
public class MainActivity extends AppCompatActivity {

o
x
/**

* 1分未満のときは 0:ss、1分以上1時間未満のときは mm:ss、

* 1時間以上のときは h:mm:ss 形式の文字列を返す

*

* @param duration 秒

* @return 再生時間文字列

*/

static String createDurationText(int duration) {
o
static String createDurationText(int duration) {

x
public interface MyInterface {



/**

* 再生時間を返す

*

* @param id 動画のID

* @return 秒

*/

int getDuration(String id);

}
o
public interface MyInterface {



int getDuration(String id);

}
http://y-anz-m.blogspot.jp/2015/06/androidsupportannotation.html
x public interface MyInterface {



/**

* …

*/

int getDuration(String id);

}
o public interface MyInterface {



/**

* …

*/

int getDuration(@NonNull String id);

}

public class IconUtils {



/**

* 対応する画像リソースを返す

*

* @param type アイコンのタイプ

* @return 画像リソース

*/

@DrawableRes

public static int getIconResId(@NonNull IconType type) {

…

}

}
o
x public interface ProfileService {



Profile getProfile(String userId);

}
o public interface ProfileService {



@WorkerThread

Profile getProfile(@NonNull String userId);

}
o public interface ProfileService {



/**

* プロフィールを取得する

* <p>

* userId が null のときは自分のプロフィールが返る

*

* @param userId ユーザーのID

* @return プロフィール

*/

@WorkerThread

Profile getProfile(@Nullable Integer userId);

}
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1);
x
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1);
o
x
o
x
o
x
o
x
o
x
o
x <FrameLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center">



<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

tools:text="Hello" />



</FrameLayout>
<FrameLayout

android:layout_width="match_parent"

android:layout_height="match_parent">



<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

tools:text="Hello" />



</FrameLayout>
o
<include>
<merge>
tools:text
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

tools:text="Hello" />
tools:layout_width
tools:layout_height
<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:layout_height="48dp"

tools:text="Hello" />
tools:visibility
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:visibility="gone"

tools:text="Hello"

tools:visibility="visible" />
tools:context
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/an
xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.sample.MainActivity">
tools:layout
<fragment

android:id="@+id/fragment_my"

android:name="com.sample.MyFragment"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:layout=“@layout/fragment_my" />
tools:showIn
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/a
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:showIn="@layout/activity_main">



…



</FrameLayout>
x abortOnError false
https://developer.android.com/studio/build/shrink-code.html
android {
...
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
x
o dependencies {

compile 'com.google.code.gson:gson:2.7'

}
libs/gson-2.2.2.jar
final DisplayMetrics metrics = getResources()
.getDisplayMetrics();

final int widthPixels = metrics.widthPixels;

final int heightPixels = metrics.heightPixels;

final float density = metrics.density;
https://developer.android.com/reference/android/text/TextUtils.html
@Override

protected void onCreate(@Nullable Bundle sav
super.onCreate(savedInstanceState);



final String userId = …

if (TextUtils.isEmpty(userId)) {

finish();

return;

}



…

}
public class ProfileActivity extends AppCompatActivity {



private static final String EXTRA_USER_ID = "user_id";



@NonNull

public static Intent createIntent(@NonNull Context context,
@NonNull String userId) {

Intent intent = new Intent(context, ProfileActivity.class);

intent.putExtra(EXTRA_USER_ID, userId);

return intent;

}



@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);



final String userId =
getIntent().getStringExtra(EXTRA_USER_ID);

}

}
public class ProfileFragment extends Fragment {



private static final String ARGS_USER_ID = "user_id";



@NonNull

public static ProfileFragment newInstance(@NonNull String userId)
ProfileFragment f = new ProfileFragment();

final Bundle args = new Bundle();

args.putString(ARGS_USER_ID, userId);

f.setArguments(args);

return f;

}



@Override

public void onActivityCreated(@Nullable Bundle savedInstanceState
super.onActivityCreated(savedInstanceState);



final String userId = getArguments() == null ? null

: getArguments().getString(ARGS_USER_ID);

}

}
Alt + Command + lo
https://techbooster.github.io/c90/

More Related Content

Viewers also liked

Whats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in FukuokaWhats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in FukuokaYuki Anzai
 
Master of RecyclerView
Master of RecyclerViewMaster of RecyclerView
Master of RecyclerViewYuki Anzai
 
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_techはじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_techTomohiro Kumagai
 
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -Yuki Anzai
 
Minimal Cake Pattern in Swift
Minimal Cake Pattern in SwiftMinimal Cake Pattern in Swift
Minimal Cake Pattern in SwiftHikaru Yoshimura
 
What's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in FukuokaWhat's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in FukuokaYuki Anzai
 
これからの設計の話をしよう
これからの設計の話をしようこれからの設計の話をしよう
これからの設計の話をしようshinnosuke kugimiya
 
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Yuki Anzai
 
Android cleanarchitecture
Android cleanarchitectureAndroid cleanarchitecture
Android cleanarchitectureTomoaki Imai
 
Android lint-srp-practice
Android lint-srp-practiceAndroid lint-srp-practice
Android lint-srp-practicecch-robo
 
全てSになる -RxJavaとLWSを持ち込む楽しさ-
全てSになる -RxJavaとLWSを持ち込む楽しさ-全てSになる -RxJavaとLWSを持ち込む楽しさ-
全てSになる -RxJavaとLWSを持ち込む楽しさ-Ryutaro Miyashita
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々ScalaプログラミングTomoharu ASAMI
 
開発チームにKotlinを導入した話
開発チームにKotlinを導入した話開発チームにKotlinを導入した話
開発チームにKotlinを導入した話Hiroshi Kikuchi
 
How to read "marble diagram"
How to read "marble diagram"How to read "marble diagram"
How to read "marble diagram"Yuki Anzai
 
3分で作る Kotlin Friendly な API
3分で作る Kotlin Friendly な API3分で作る Kotlin Friendly な API
3分で作る Kotlin Friendly な APIHiroshi Kikuchi
 
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」Yuki Anzai
 
Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -Yuki Anzai
 
Gradleでビルドするandroid NDKアプリ
Gradleでビルドするandroid NDKアプリGradleでビルドするandroid NDKアプリ
Gradleでビルドするandroid NDKアプリHideyuki Kikuma
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewYuki Anzai
 

Viewers also liked (20)

Whats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in FukuokaWhats's new in Android Studio at Google I/O extended in Fukuoka
Whats's new in Android Studio at Google I/O extended in Fukuoka
 
Master of RecyclerView
Master of RecyclerViewMaster of RecyclerView
Master of RecyclerView
 
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_techはじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
はじめて Phantom と遭遇して、闇雲に闘いを挑んでみた話 #kbkz_tech
 
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
Activity, Fragment, CustomView の使い分け - マッチョなActivityにさよならする方法 -
 
Minimal Cake Pattern in Swift
Minimal Cake Pattern in SwiftMinimal Cake Pattern in Swift
Minimal Cake Pattern in Swift
 
What's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in FukuokaWhat's new in Android N at Google I/O extended in Fukuoka
What's new in Android N at Google I/O extended in Fukuoka
 
これからの設計の話をしよう
これからの設計の話をしようこれからの設計の話をしよう
これからの設計の話をしよう
 
Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016Customizing Theme and Style for Material Design : Droid Kaigi 2016
Customizing Theme and Style for Material Design : Droid Kaigi 2016
 
Android cleanarchitecture
Android cleanarchitectureAndroid cleanarchitecture
Android cleanarchitecture
 
Android lint-srp-practice
Android lint-srp-practiceAndroid lint-srp-practice
Android lint-srp-practice
 
全てSになる -RxJavaとLWSを持ち込む楽しさ-
全てSになる -RxJavaとLWSを持ち込む楽しさ-全てSになる -RxJavaとLWSを持ち込む楽しさ-
全てSになる -RxJavaとLWSを持ち込む楽しさ-
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々Scalaプログラミング
 
開発チームにKotlinを導入した話
開発チームにKotlinを導入した話開発チームにKotlinを導入した話
開発チームにKotlinを導入した話
 
How to read "marble diagram"
How to read "marble diagram"How to read "marble diagram"
How to read "marble diagram"
 
3分で作る Kotlin Friendly な API
3分で作る Kotlin Friendly な API3分で作る Kotlin Friendly な API
3分で作る Kotlin Friendly な API
 
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
「Android アプリのガチ開 発者が Mobile Backend Starter を使ってみた」
 
Kotlinにお触り
Kotlinにお触りKotlinにお触り
Kotlinにお触り
 
Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -Life with Android - Docomo SmartPhone Lounge Event -
Life with Android - Docomo SmartPhone Lounge Event -
 
Gradleでビルドするandroid NDKアプリ
Gradleでビルドするandroid NDKアプリGradleでビルドするandroid NDKアプリ
Gradleでビルドするandroid NDKアプリ
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListView
 

More from Yuki Anzai

Watch face アプリを公開してみた
Watch face アプリを公開してみたWatch face アプリを公開してみた
Watch face アプリを公開してみたYuki Anzai
 
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?Yuki Anzai
 
Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷Yuki Anzai
 
Sublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEWSublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEWYuki Anzai
 
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談Yuki Anzai
 
マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向Yuki Anzai
 
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼ アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼ Yuki Anzai
 
Fragment を使ってみよう
Fragment を使ってみようFragment を使ってみよう
Fragment を使ってみようYuki Anzai
 
Android Layout Cookbook Seminor
Android Layout Cookbook SeminorAndroid Layout Cookbook Seminor
Android Layout Cookbook SeminorYuki Anzai
 
ボクの開発スタイル
ボクの開発スタイルボクの開発スタイル
ボクの開発スタイルYuki Anzai
 
Android Layout 3分クッキング
Android Layout 3分クッキングAndroid Layout 3分クッキング
Android Layout 3分クッキングYuki Anzai
 
application Next Generation presented by android女子部
application Next Generation presented by android女子部application Next Generation presented by android女子部
application Next Generation presented by android女子部Yuki Anzai
 
Head First XML Layout on Android
Head First XML Layout on AndroidHead First XML Layout on Android
Head First XML Layout on AndroidYuki Anzai
 

More from Yuki Anzai (13)

Watch face アプリを公開してみた
Watch face アプリを公開してみたWatch face アプリを公開してみた
Watch face アプリを公開してみた
 
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
"あんざいゆき" x "秋葉ちひろ" はカンファレンスアプリをどう作るのか?
 
Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷Android Pattern Cookbook で見るトレンドの変遷
Android Pattern Cookbook で見るトレンドの変遷
 
Sublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEWSublime Text 2 で始める ReVIEW
Sublime Text 2 で始める ReVIEW
 
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
ABC2013 Autumn あんざいゆき x 小太刀御禄 対談
 
マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向マルチスクリーン対応と最近のアプリの傾向
マルチスクリーン対応と最近のアプリの傾向
 
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼ アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
アプリのUIを改善するための7ステップ ∼Bump Recorder の UI を設計してみたよ編∼
 
Fragment を使ってみよう
Fragment を使ってみようFragment を使ってみよう
Fragment を使ってみよう
 
Android Layout Cookbook Seminor
Android Layout Cookbook SeminorAndroid Layout Cookbook Seminor
Android Layout Cookbook Seminor
 
ボクの開発スタイル
ボクの開発スタイルボクの開発スタイル
ボクの開発スタイル
 
Android Layout 3分クッキング
Android Layout 3分クッキングAndroid Layout 3分クッキング
Android Layout 3分クッキング
 
application Next Generation presented by android女子部
application Next Generation presented by android女子部application Next Generation presented by android女子部
application Next Generation presented by android女子部
 
Head First XML Layout on Android
Head First XML Layout on AndroidHead First XML Layout on Android
Head First XML Layout on Android
 

Androidオールスターズ2016 yanzm