- -
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/

Androidオールスターズ2016 yanzm