Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
hkurokawa / UrlUtil.java
Last active March 29, 2016 01:00
A utility method to encode only the path segments of the given URL on Android
import android.net.Uri;
import android.util.Pair;
import java.util.List;
public final class UrlUtil {
static String encodePathSegments(String url) {
final Uri uri = Uri.parse(url);
final List<String> pathSegments = uri.getPathSegments();
final Uri.Builder builder = uri.buildUpon().path("");
@hkurokawa
hkurokawa / MainActivity.java
Created March 13, 2016 20:05
PowerMock + Robolectric
package com.hkurokawa.powermocktest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
@hkurokawa
hkurokawa / AndroidManifest.xml
Created December 22, 2015 11:15
Android Code to reproduce a behaviour getCurrentPosition() always returns the same value after setSurface(null) and setSurface(surface).
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hiroshikurokawa.videosample">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
@hkurokawa
hkurokawa / adb-screenshot.sh
Last active August 30, 2023 06:27
A shell script to take a screen shot of the android device, resize it and copy to clipboard
#! /bin/bash
## This script is for taking a screen shot of an Android device.
## If possible, it tries to resize the image file and then copy to the clipboard.
##
## Note the script generates screenshot_yyyyMMddHHmmss.png and screenshot_yyyyMMddHHmmss_s.png
## under /sdcard on the device (you can specify another location with '-t' option)
## and copies it to the current working directory.
##
## The script passes unrecognized arguments to adb command, which means you can specify "-e" or "-d"
@hkurokawa
hkurokawa / MainActivity.java
Created September 29, 2015 06:19
Really simple sample application
package com.hkurokawa.sampleapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
@hkurokawa
hkurokawa / MainActivity.java
Created August 25, 2015 04:06
SurfaceView を足そうとすると画面が点滅する ref: http://qiita.com/hkurokawa/items/e80f6525005b81bb5636
package com.hkurokawa.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MainActivity extends AppCompatActivity {
ViewGroup content;
@hkurokawa
hkurokawa / MainActivity.java
Created August 24, 2015 22:17
Screen is flashing when adding a SurfaceView
package com.hkurokawa.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MainActivity extends AppCompatActivity {
ViewGroup content;
@hkurokawa
hkurokawa / readDeviceIdleController.md
Last active August 29, 2015 14:23
DeviceIdleController を読んでみた

DeviceIdleController とは

SystemService で常に実行されている。M Preview の Doze モードを実装するためのもの。

挙動

以下のイベントを監視する。

  1. Screen on/off
  2. Charging status
  3. Significant motion detect
@hkurokawa
hkurokawa / CachedAsyncTaskLoader.java
Created March 27, 2015 08:40
AsyncTaskLoader Sample
/**
* <p>
* This loader caches the result so that it can be taken later - for example, after configuration
* was changed and activity is re-created.
* </p>
* Created by hiroshi on 2014/12/03.
*/
public abstract class CachedAsyncTaskLoader<T> extends AsyncTaskLoader<T> {
private T mCached;
private Throwable mError;
@hkurokawa
hkurokawa / MyApplication_app_build.gradle
Created January 14, 2015 02:57
Android Studio Sample Project importing Facebook SDK
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.hkurokawa.myapplication"
minSdkVersion 14
targetSdkVersion 21