Skip to content

Instantly share code, notes, and snippets.

View benigumocom's full-sized avatar
🏠
🙆

chanzmao benigumocom

🏠
🙆
View GitHub Profile
@benigumocom
benigumocom / DemoActivity.java
Created August 24, 2012 17:09
登録・解除を確認するのでそれらのメニューを有効化する1
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
/*
* Typically, an application registers automatically, so options
* below are disabled. Uncomment them if you want to manually
* register or unregister the device (you will also need to
* uncomment the equivalent options on options_menu.xml).
*/
// 以下2つのcaseをコメントインする。
@benigumocom
benigumocom / options_menu.xml
Created August 24, 2012 17:12
登録・解除を確認するのでそれらのメニューを有効化する2
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Typically, an application registers automatically, so options below
are disabled. Uncomment them if you want to manually register or
unregister the device (you will also need to uncomment the equivalent
options on DemoActivity.onOptionsItemSelected())
-->
<!-- 以下2つのitemをコメントインする -->
<item
android:id="@+id/options_register"
@benigumocom
benigumocom / GCMIntentService.java
Created August 24, 2012 17:21
GCM 受信したメッセージを表示する
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
// intent から取得して表示する文字列に結合
Bundle extras = intent.getExtras();
String result = extras.getString("message");
String message = getString(R.string.gcm_message) + " = " + result;
@benigumocom
benigumocom / gist:3872748
Created October 11, 2012 14:27
インテントファイル渡し
File file = new File(ファイルパス); // 他アプリに渡すファイル
Intent intent = new Intent(Intent.ACTION_SEND); // データーを送信するインテント
intent.setType("image/png"); // データタイプの指定
intent.putExtra(Intent.EXTRA_SUBJECT, "件名");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(intent);
@benigumocom
benigumocom / gist:4421644
Last active December 10, 2015 10:29
アクティビティへのイベントコールバックの作成 (フラグメントからホストアクティビティへイベントを渡す)
public class MainActivity extends Activity
implements FragmentA.OnArtcleListener {
// コールバックを受け取るインターフェース
@Override
public void onArticleSelected(Uri articleUri) {
// 受け取ったUriで、別のView(フラグメント)を操作する
// ...
@benigumocom
benigumocom / gist:8128952
Created December 26, 2013 02:21
DevBytes: ActionBarCompat (Japanese) - YouTube https://www.youtube.com/watch?v=JApBHLZaNpo#t=335
<!--
ShareActionProvider
android.support.v7.widget.ShareActionProvider
-->
<menu xmlns:android="http://schemas/android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_share"
android:title="@string/menu_share"
yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider"
/*
ShareActionProvider
android.support.v7.widget.ShareActionProvider
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu
getMenuInflater().inflate(R.menu.main_memu, menu);
@benigumocom
benigumocom / gist:8450654
Created January 16, 2014 06:27
Threadによる非同期処理
final Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
switch(msg.what) {
case RESULT_WHAT:
handleResult((Result) msg.obj);
return true;
}
return false;
}
@benigumocom
benigumocom / gist:8450687
Created January 16, 2014 06:34
AsyancTaskによる非同期処理
private class DownloadFilesTask extends AsyncTask<Void, Integer, Result> {
@Override
protected void onPreExecute() {
// Something like showing a progress bar
}
@Override
protected Result doInBackground(Void... params) {
Result result = new Result();
@benigumocom
benigumocom / gist:8450717
Last active January 3, 2016 10:39
バージョンによるAsyncTaskのスケジューリング問題回避
/*
1.6 以前は、シングルスレッドで順番に実行される
1.6 から 2.3、スレッドプールで並列に実行される。
3.0 以降、デフォルトで以前の動作に戻る。スレッドプール利用はexecuteOnExecutor()で。
今どきの端末ではデフォルトでは並列実行されない。
*/
public class ConcurrentAsyncTask {
public static void execute(AsyncTask as) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
as.execute();