Skip to content

Instantly share code, notes, and snippets.

View takahirom's full-sized avatar

Takahiro Menju takahirom

View GitHub Profile
@takahirom
takahirom / AndroidManifest.xml
Last active July 6, 2019 09:33
Android Wearは通知にActivityを出せる!!!
<activity
android:name=".SampleActivity"
android:exported="true"
android:allowEmbedded="true"
android:label="@string/app_name"
android:taskAffinity="" />
@takahirom
takahirom / mobile-MainActivity.java
Last active August 29, 2015 14:03
Wear対応アプリをスマホでアプリ起動時に、WearでActivityを開始する
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_explain);
mGoogleApiClient = (new GoogleApiClient.Builder(this)).addApi(Wearable.API).build();
mGoogleApiClient.connect();
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(new ResultCallback() {
@takahirom
takahirom / FirstTime.java
Created July 19, 2014 15:00
初回起動時だけ○○する普通版
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
if(defaultSharedPreferences.getBoolean(PREF_KEY,true)){
defaultSharedPreferences.edit().putBoolean(PREF_KEY,false).apply();
//初めての時の処理
}else{
//二回目以降の処理
}
@takahirom
takahirom / HowToUse.java
Last active August 29, 2015 14:04
FirstTimePreferenceというクラスを使って初回だけ○○したいを実現する
new FirstTimePreference("PREF_KEY").action(CareActivity.this, new FirstTimePreference.FirstTimePreferenceListener() {
@Override
public boolean onFirstTime() {
//初めての時の処理
return true;//次回このメソッドを呼ぶかどうか
}
@Override
public void onNotFirstTime() {
@takahirom
takahirom / FirstTimePreference.java
Last active August 29, 2015 14:04
初回のみ○○したいを実現するクラス
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
/**
* 初めて使うときは〜というのを実現するためのクラス
* Created by tmen on 2014/07/17.
*/
public class FirstTimePreference {
private final String mKey;
@takahirom
takahirom / build.gradle
Last active August 29, 2015 14:06
Androidライブラリプロジェクト(aar)のファイルを直接読み込む
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.xxxx.xxxx"
minSdkVersion 18
targetSdkVersion 20
@takahirom
takahirom / JudgeAndroidWear.java
Last active August 29, 2015 14:06
Android Wearを判定する
import android.content.Context;
import java.lang.reflect.Method;
public class JudgeAndroidWear {
public static boolean isWear(Context context){
String defaultCharacteristics = "";
String characteristics = get(context, "ro.build.characteristics", defaultCharacteristics);
@takahirom
takahirom / mp4togif
Created March 29, 2015 10:30
mp4 to gif
mkdir work_for_gif
ffmpeg -i $1 -an -r 15 -s `ffmpeg -i $1 2>&1 | perl -lane 'print $1 if /(\d{2,}x\d+)/'` work_for_gif/%04d.png
convert work_for_gif/*.png output.gif
rm -rf work_for_gif
@takahirom
takahirom / unix
Last active August 31, 2015 14:39
jardiff command generator
ls -F | grep /|awk '
BEGIN{libraryPrefix="support-v4-"}
NR%2==1 {a=$0;sub("/","",a)}
NR%2==0 {b=$1;sub("/","",b)}
NR%2==0{print "jardiff.py " a "/" libraryPrefix a ".aar " b "/" libraryPrefix b ".aar > "a"-"b".patch"}
NR%2==1&&length(b)!=0{print "jardiff.py " b "/" libraryPrefix b".aar " a "/" libraryPrefix a ".aar > "b"-"a".patch"}'
@takahirom
takahirom / selectdevice.sh
Last active October 10, 2015 14:51
If device only one, print device. Else use peco
adb devices|grep -v "List of devices"|awk 'NF==2{print $1}'|awk 'BEGIN{all=""} {all =$0"\n"all} END{if(NR==1) {print($0)} else{system("echo \""all "\"|peco") } }'