Androidオールスターズ2016 yanzm

377 views
501 views

Published on

2016年のAndroidオールスターズイベントの資料です。

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
377
On SlideShare
0
From Embeds
0
Number of Embeds
234
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Androidオールスターズ2016 yanzm

  1. 1. - -
  2. 2. private package-private protected public
  3. 3. 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
  4. 4. 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
  5. 5. @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
  6. 6. private static String TAG = "MainActivity"; x private static final String TAG = "MainActivity"; o
  7. 7. 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
  8. 8. 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
  9. 9. /**
 * Created by yanzm on 2016/08/07.
 */
 public class MainActivity extends AppCompatActivity {
 x /**
 * ホーム画面
 *
 * ランチャーから起動される。
 * 最初にトークンがローカルに保存されているか確認し、 * 保存されていない場合はログイン画面に遷移する。
 */ public class MainActivity extends AppCompatActivity {
 o
  10. 10. 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) {

  11. 11. x public interface MyInterface {
 
 /**
 * 再生時間を返す
 *
 * @param id 動画のID
 * @return 秒
 */
 int getDuration(String id);
 } o public interface MyInterface {
 
 int getDuration(String id);
 }
  12. 12. http://y-anz-m.blogspot.jp/2015/06/androidsupportannotation.html
  13. 13. x public interface MyInterface {
 
 /**
 * …
 */
 int getDuration(String id);
 } o public interface MyInterface {
 
 /**
 * …
 */
 int getDuration(@NonNull String id);
 }

  14. 14. public class IconUtils {
 
 /**
 * 対応する画像リソースを返す
 *
 * @param type アイコンのタイプ
 * @return 画像リソース
 */
 @DrawableRes
 public static int getIconResId(@NonNull IconType type) {
 …
 }
 } o
  15. 15. x public interface ProfileService {
 
 Profile getProfile(String userId);
 } o public interface ProfileService {
 
 @WorkerThread
 Profile getProfile(@NonNull String userId);
 }
  16. 16. o public interface ProfileService {
 
 /**
 * プロフィールを取得する
 * <p>
 * userId が null のときは自分のプロフィールが返る
 *
 * @param userId ユーザーのID
 * @return プロフィール
 */
 @WorkerThread
 Profile getProfile(@Nullable Integer userId);
 }
  17. 17. 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
  18. 18. x o
  19. 19. x o
  20. 20. x o
  21. 21. x o
  22. 22. x o
  23. 23. 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>
  24. 24. <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
  25. 25. <include> <merge>
  26. 26. tools:text <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 tools:text="Hello" />
  27. 27. tools:layout_width tools:layout_height <TextView
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:layout_height="48dp"
 tools:text="Hello" />
  28. 28. tools:visibility <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:visibility="gone"
 tools:text="Hello"
 tools:visibility="visible" />
  29. 29. 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">
  30. 30. 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" />
  31. 31. 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>
  32. 32. x abortOnError false
  33. 33. https://developer.android.com/studio/build/shrink-code.html android { ... buildTypes { release { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
  34. 34. x o dependencies {
 compile 'com.google.code.gson:gson:2.7'
 } libs/gson-2.2.2.jar
  35. 35. final DisplayMetrics metrics = getResources() .getDisplayMetrics();
 final int widthPixels = metrics.widthPixels;
 final int heightPixels = metrics.heightPixels;
 final float density = metrics.density;
  36. 36. 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;
 }
 
 …
 }
  37. 37. 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);
 }
 }
  38. 38. 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);
 }
 }
  39. 39. Alt + Command + lo
  40. 40. https://techbooster.github.io/c90/

×