Skip to content

Instantly share code, notes, and snippets.

@daichan4649
daichan4649 / layout.xml
Created June 29, 2013 07:02
GridLayout Sample (EditText/Spinner)
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="3"
android:padding="8dip"
android:useDefaultMargins="true" >
@daichan4649
daichan4649 / SelectModeDialogFragment.java
Last active December 19, 2015 19:39
DialogFragment 定番処理
public interface SelectModeDialogListener {
void onModeTypeSelected(ModeType selectedMode, int id);
}
public static DialogFragment newInstance(int id) {
Bundle args = new Bundle();
args.putInt("id", id);
DialogFragment fragment = new SelectModeDialogFragment();
fragment.setArguments(args);
return fragment;
@daichan4649
daichan4649 / Test.java
Last active December 19, 2015 23:49
画像ファイル内の EXIF 情報有無判定 (for Android)
public static boolean isExistLocationInfo(String filePath) {
if (TextUtils.isEmpty(filePath)) {
return false;
}
try {
ExifInterface exifIf = new ExifInterface(filePath);
float[] output = new float[2];
exifIf.getLatLong(output);
// GPS(0, 0) は取得失敗とみなす
if (output[0] == 0 && output[1] == 0) {
@daichan4649
daichan4649 / AndroidManifest.xml
Last active December 19, 2015 23:59
custom actionbar (for Android) MenuFragment 動的切替
<activity
android:name=".XxxActivity"
android:theme="@style/Custom" />
@daichan4649
daichan4649 / AndroidManifest.xml
Last active January 26, 2016 08:12
get GPS information (Android)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="daichan4649.gps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
@daichan4649
daichan4649 / AndroidManifest.xml
Last active December 21, 2015 12:19
物理メニューキーがある端末でも、ActionBar の overflowメニュー を強制的に表示する (for Android)
<application
android:name="daichan4649.actionbartest.TestApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="daichan4649.actionbartest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@daichan4649
daichan4649 / MoonUtil.java
Last active July 29, 2016 02:32
月齢計算(calculate age of the moon)
package daichan4649.moon;
public class MoonUtil {
/**
* 月齢取得
* @param year 年(1, 2, ..)
* @param month 月(1, 2, ..)
* @param day 日(1, 2, ..)
* @return 月齢
@daichan4649
daichan4649 / ProgressDialogFragment.java
Last active August 1, 2018 20:29
AsyncTask + ProgressDialogFragment (Android)
public class ProgressDialogFragment extends DialogFragment {
public final static String TITLE = "title";
public final static String MESSAGE = "message";
public final static String MAX = "max";
public final static String CANCELABLE = "cancelable";
public static ProgressDialogFragment newInstance() {
return new ProgressDialogFragment();
}
@daichan4649
daichan4649 / TestFragment.java
Created September 5, 2013 09:59
EditText が含まれる場合でも、起動時にキーボードを自動で開かない (Android)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ime開かない
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
@daichan4649
daichan4649 / ConfirmDialogFragment.java
Last active December 22, 2015 10:48
確認ダイアログ のサンプル。呼出元を FragmentType、表示文字列 で識別し、そこへ callback する。
public class ConfirmDialogFragment extends DialogFragment {
/**
* Fragment種別
*/
public enum FragmentType {
NONE(-1, ""),
/** 画面1 */
SCREEN_1(0, "login"),
/** 画面2 */