Skip to content

Instantly share code, notes, and snippets.

@daichan4649
daichan4649 / CheckableLayout.java
Created March 26, 2013 13:32
Checkable ListView (for Android)
package daichan4649.test;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;
public class CheckableLayout extends LinearLayout implements Checkable {
@daichan4649
daichan4649 / ProgressDialogFragment.java
Last active December 15, 2015 17:39
ProgressDialog (cancel pattern)
public class ProgressDialogFragment extends DialogFragmentBase {
public static ProgressDialogFragment newInstance() {
ProgressDialogFragment fragment = new ProgressDialogFragment();
// キャンセル無効(これやると、BACKキー自体無効になる)
// fragment.setCancelable(true);
return fragment;
}
@daichan4649
daichan4649 / ProgressDialogFragment.java
Last active February 24, 2019 11:20
Full screen ProgressDialog (for Android)
class ProgressDialogFragment extends DialogFragment {
public static ProgressDialogFragment newInstance() {
return new ProgressDialogFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent);
@daichan4649
daichan4649 / AndroidManifest.xml
Last active June 2, 2023 14:51
show Fragment on LockScreen (for Android)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="daichan4649.lockoverlay"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
@daichan4649
daichan4649 / UncaughtExceptionHandlerTest.java
Created April 11, 2013 09:35
set UncaughtExceptionHandler (for Android)
@Override
public void onCreate(Bundle savedInstanceState) {
Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
}
/** UncaughtExceptionHandler */
private UncaughtExceptionHandler uncaughtExceptionHandler = new UncaughtExceptionHandler() {
private UncaughtExceptionHandler originalUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
@Override
@daichan4649
daichan4649 / AndroidManifest.xml
Last active December 16, 2015 19:49
custom actionbar
<activity
android:name="CustomActionBarTestActivity"
android:label="@string/title_activity_custom_actionbar"
android:theme="@style/Theme.Custom" />
@daichan4649
daichan4649 / OptionMenuSample.java
Created April 30, 2013 09:40
show option menu (for Android)
// Fragment
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_search, menu);
@daichan4649
daichan4649 / IMETest.java
Created April 30, 2013 09:49
エンター押下時にIME閉じる (for Android)
// EditText に listener を設定
// [EditText].setOnEditorActionListener(mEditorActionListener);
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
hideIME(v);
}
return false;
@daichan4649
daichan4649 / RecordTest.java
Last active February 19, 2021 12:03
外部レコーダ(音声/動画)起動後に、保存データ(録音/録画)を取得 (Android)
private static final int REQ_CODE_MIC = 0;
private static final int REQ_CODE_MOVIE = 1;
private void startAudioRecorder() {
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
try {
startActivityForResult(intent, REQ_CODE_MIC);
} catch (Exception e) {
e.printStackTrace();
}
@daichan4649
daichan4649 / AndroidManifest.xml
Last active December 19, 2015 03:28
録音/録画/音声検索
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.recordtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />