Skip to content

Instantly share code, notes, and snippets.

View ochim's full-sized avatar

munehiro ochi ochim

View GitHub Profile
@ochim
ochim / binary-gap.md
Last active July 11, 2019 10:40
BinaryGap
fun solution(N: Int): Int {
    // 2進数に変換
    val s = N.toString(2)
    // sが0を含まないなら0を返す
    if (!s.contains('0')) return 0

    var max = 0
    var count  = 0
@ochim
ochim / if-your-Android-app-is-currently-in-foreground.md
Last active June 25, 2019 07:47
Best way to know if your Android app is currently in foreground

First

deprecated

public static boolean isApplicationInForeground(final Context context) {
    final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        final ComponentName topActivity = tasks.get(0).topActivity;
@ochim
ochim / android-getColor.md
Last active June 25, 2019 07:27
Android 6.0 Marshmallow (android sdk 23)からは getColorではなくContextCompat.getColor を使いましょう
@ochim
ochim / check-if-specific-channel-enabled.md
Created June 19, 2019 10:26
Android 通知チャンネルを有効にしているかどうか判定する
@ochim
ochim / AndroidNotification.md
Last active July 11, 2019 10:50
AndroidのNotificationを作成

Android Oreoから通知を送るにはまずチャンネルを登録するようになった。
https://feel-log.net/android/developer/o-notification-no-sound-vibration/

int importance = NotificationManager.IMPORTANCE_;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
NotificationManager manager =
            (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
@ochim
ochim / androidIconSize.md
Last active June 19, 2019 09:21
Android Icon Size

Android Icon Size guide for Android 6 Marshmallow

Android Icon Size guide for App Interface Icons

- MDPI (160dpi) Baseline HDPI (240dpi) 1.5x XHDPI (320dpi) 2x XXHDPI (480dpi) 3x XXXHDPI (640dpi) 4x
Launcher Icon 48px 72px 96px 166px 192px
Small Contextual icons 16px 24px 32px 48px 64px
Notification icons 22px icon in 24px area 33px icon in 36px area 44px icon in 48px area 66px icon in 72px area 88px icon in 96px area
@ochim
ochim / toByteArray.md
Last active June 19, 2019 07:53
[java] String.getBytes => [kotlin] String.toByteArray

[java] String.getBytes => [kotlin] String.toByteArray

fun String.toByteArray(
charset: Charset = Charsets.UTF_8
): ByteArray

Encodes the contents of this string using the specified character set and returns the resulting byte array.

@ochim
ochim / hanoi_tower.md
Last active May 30, 2019 15:53
[アルゴリズム]ハノイの塔
import java.util.*;

// ハノイの塔の実装
class Main {
    /*
    piles:3本をlistに格納
    名前なし:杭はLinkedList。円盤格納
    名前なし:円盤きさを整数
@ochim
ochim / gist:8a8791bf7d4779db3be18949659bc3df
Last active April 17, 2019 10:12
[Android]端末のスクリーンサイズを取得して、レイアウトやViewに割り当て