Skip to content

Instantly share code, notes, and snippets.

@wasnot
wasnot / file0.java
Created January 19, 2015 10:00
ContentProviderでSharedPreferencesを使う ref: http://qiita.com/wasnot/items/8329409a46f31f1724b3
public class TestProvider extends ContentProvider {
...
private SharedPreferences mPrefs;
@Override
public boolean onCreate() {
LogUtil.d(TAG, "onCreate " + Binder.getCallingPid() + ", "
@wasnot
wasnot / file0.java
Created January 21, 2015 07:43
AlertDialogをボタンタップ等で閉じない ref: http://qiita.com/wasnot/items/3dd9d4cf1754562fa4bd
AlertDialog.Builder b = new AlertDialog.Builder(activity);
b.setTitle("タイトル");
b.setPositiveButton(android.R.string.ok, null);
// ここでリスナーを実装しても渡されないので実装しなくても構いません。
b.setNegativeButton(android.R.string.cancel, null);
// AlertDialogを生成する前にgetButton等してもnullが返されます。
final AlertDialog dialog = b.show();
@wasnot
wasnot / dimens.xml
Last active August 29, 2015 14:14
ShapeDrawableの放射線状のグラデーションの半径指定について ref: http://qiita.com/wasnot/items/1e6794fbc047101756a6
<resources ...>
...
<item name="radius" format="float" type="dimen">200.34</item>
....
</resources>
@wasnot
wasnot / MyDialogActivity.java
Created May 20, 2015 08:20
ロック画面でのDialog表示する時の注意(Theme, windowIsFloatingをtrue) ref: http://qiita.com/wasnot/items/760bd2eb22c214485900
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ロック画面解除とロック画面上に表示するフラグを追加します。
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
@wasnot
wasnot / Test.java
Last active August 29, 2015 14:22
[Android][Lollipop]UsageStatsManagerを使ってみた ref: http://qiita.com/wasnot/items/6074dbcdd49141f8e7d8
// ActivityManagerServiceからはこんな風に呼ばれていました。
mUsageStatsService = IUsageStats.Stub.asInterface(ServiceManager.getService("usagestats"));
// リフレクションではこう呼んだり。。ServiceLocatorは上記ブログ参照。。
mUsageStatsService = ServiceLocator.getServiceStub("usagestats",
"com.android.internal.app.IUsageStats$Stub");
// 関数のコールもリフレクション。。
Class<?> clazz = Class.fromName("com.android.internal.app.IUsageStats$Stub");
Method method = clazz.getDeclaredMethod("getAllPkgUsageStats");
@wasnot
wasnot / MyFragment.java
Created June 22, 2015 12:26
[Android][Lollipop]Android5.0で可能になったSDカードへの書き込みを試す ref: http://qiita.com/wasnot/items/287d191c7da40f2e6080
// JavaのFileを扱うように自由に書き込みもできます。
// ただしSAFのAPIを介する必要があります。
// また、一度付与されたuriは保持しておく必要があります。
// Create a new file and write into it
DocumentFile newFile = pickedDir.createFile("text/plain", "My Novel");
try {
OutputStream out = getActivity().getContentResolver().openOutputStream(newFile.getUri());
out.write("A long time ago...".getBytes());
out.close();
} catch (FileNotFoundException e) {
@wasnot
wasnot / BackgroundHighlightedButton.swift
Last active August 29, 2015 14:23
[iOS][Swift]Storyboardでボタン背景色の設定がしたい ref: http://qiita.com/wasnot/items/3537d932e9550a5c4c27
class BackgroundHighlightedButton: UIButton {
@IBInspectable var highlightedBackgroundColor :UIColor?
@IBInspectable var nonHighlightedBackgroundColor :UIColor?
override var highlighted :Bool {
didSet {
if highlighted {
self.backgroundColor = highlightedBackgroundColor
}
else {
self.backgroundColor = nonHighlightedBackgroundColor
@wasnot
wasnot / MyReceiver.java
Created July 7, 2015 11:59
[Android][Lollipop]ロックスクリーンの通知タップからChromeが起動できない ref: http://qiita.com/wasnot/items/36e29bde2bb8be9f3570
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Context con = context.getApplicationContext();
if ("myaction".equals(action)) {
...
} else if (Intent.ACTION_VIEW.equals(action)) {
// 今回はとりあえず、ここでintentを作っていますが、中に入れたりしたほうがいいと思います。
Intent i = new Intent(Intent.ACTION_VIEW, intent.getData());
AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);
@wasnot
wasnot / file0.java
Created July 8, 2015 05:19
[Android][AppCompat]AppCompat22.2.0でv7.NotificationCompatが追加されてMediaStyleが使えるようになっていた ref: http://qiita.com/wasnot/items/1f687197f931c37cf496
new NotificationCompat.Builder(this).setStyle(new Notification.MediaStyle()
.setMediaSession(mySession))