Skip to content

Instantly share code, notes, and snippets.

View sakurabird's full-sized avatar
💭
I may be slow to respond.

Yukari Sakurai sakurabird

💭
I may be slow to respond.
View GitHub Profile
@sakurabird
sakurabird / gist:6923255
Created October 10, 2013 18:35
(Android)Intentでカレンダーを呼び出し
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "!タイトル!"); // タイトル
intent.putExtra("description", "!内容!"); // 内容
intent.putExtra("eventLocation", "!場所!"); // 場所
Calendar cal = Calendar.getInstance();
// cal.set(2011, 4, 29, 20, 0);
intent.putExtra("beginTime", cal.getTimeInMillis()); // 開始日時
// cal.set(2011, 4, 29, 23, 0);
intent.putExtra("endTime", cal.getTimeInMillis()); // 終了日時
@sakurabird
sakurabird / gist:6923317
Created October 10, 2013 18:40
(Android)Intentでメールアプリを呼び出す。セキュリティ上好ましい方法
public void onClick1(View view) {
// logcatにメールアドレスが表示される呼び出し方。セキュリティ上好ましくない
Uri uri = Uri.parse("mailto:" + mail);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(intent);
}
public void onClick2(View view) {
// logcatにメールアドレスが表示されない呼び出し方。セキュリティ上好ましい
Uri uri = Uri.parse("mailto:");
@sakurabird
sakurabird / gist:6923647
Last active December 25, 2015 05:19
android 日付ダイアログ
private void showDateDialog() {
final Calendar calendar = Calendar.getInstance();
final int year = calendar.get(Calendar.YEAR);
final int month = calendar.get(Calendar.MONTH);
final int day = calendar.get(Calendar.DAY_OF_MONTH);
final DatePickerDialog datePickerDialog = new DatePickerDialog(
this,
new DatePickerDialog.OnDateSetListener() {
@sakurabird
sakurabird / gist:6923659
Created October 10, 2013 19:02
android 時刻ダイアログ
protected void showTimeDialog() {
final Calendar calendar = Calendar.getInstance();
final int hour = calendar.get(Calendar.HOUR_OF_DAY);
final int minute = calendar.get(Calendar.MINUTE);
final TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
@sakurabird
sakurabird / gist:6923843
Created October 10, 2013 19:12
Android WebViewでファイルのダウンロード
mWebView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype, long contentLength) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType(mimetype);
intent.setData(Uri.parse(url));
startActivity(intent);
}
@sakurabird
sakurabird / gist:7522877
Created November 18, 2013 05:15
webviewでAndroid4.0の場合、hostにポート番号が付加されてしまう件
// 認証リクエストがあった場合の挙動
@Override
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
// Android4.0の場合、hostにポート番号が付加されてしまうので、splitでポート番号を排除
String[] up = view.getHttpAuthUsernamePassword(
host.split(":")[0], realm);
if (up != null && up.length == 2) {
handler.proceed(up[0], up[1]);
}
@sakurabird
sakurabird / gist:7523039
Created November 18, 2013 05:36
screen size 表示
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch (screenSize) {
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Utils.showToast("Large screen");
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
Utils.showToast("Normal screen");
break;
@sakurabird
sakurabird / CircleImageView.java
Created July 9, 2015 13:51
CircleImageView for Material Design.
/**
* Copyright 2015-present Yukari Sakurai
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
/**
* 環境が日本語ならtrue
*/
public static boolean isJapan() {
String locale = MyApplication.getContext().getResources().getConfiguration().locale.getLanguage();
Utils.logDebug("locale:" + locale);
return locale.equals("ja");
}
@sakurabird
sakurabird / SoundSeekBarPreference.java
Last active November 29, 2016 15:36
Implementations of SeekBarPreference features specific to media volume.
/**
* Copyright 2015-present Yukari Sakurai
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software