Skip to content

Instantly share code, notes, and snippets.

@daichan4649
daichan4649 / button_selector.xml
Created August 30, 2012 09:33
Button(+selector) sample
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false"
android:drawable="@drawable/button_normal" />
<item
android:state_pressed="true"
android:drawable="@drawable/button_pressed" />
@daichan4649
daichan4649 / ReentrantLockTest.java
Created September 3, 2012 06:11
ReentrantLock test
private void test() {
final LockTest test = new LockTest();
new Thread(new Runnable() {
@Override
public void run() {
test.lockTest();
// test.readLockTest();
// test.writeLockTest();
}
@daichan4649
daichan4649 / border.xml
Created November 12, 2012 08:20
shape sample
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@android:color/holo_orange_light"/>
<stroke
android:width="8dip"
android:color="#64ff0000" />
</shape>
@daichan4649
daichan4649 / PdfUtil.java
Created November 12, 2012 09:22
show PDF (for Android)
public class PdfUtil {
public enum PdfType {
SAMPLE("sample.pdf");
private static final String TMP_DIR_ROOT = "/mnt/sdcard/";
private String fileName;
private PdfType(String fileName) {
@daichan4649
daichan4649 / AndroidManifest.xml
Created December 7, 2012 04:19
marquee text (for Android)
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@daichan4649
daichan4649 / MainActivity.java
Created December 12, 2012 02:08
タブ表示(for Android)
private void initTabLayout() {
// タブバー表示設定
View container = findViewById([resourceId]);
tabHost = (TabHost) container.findViewById(R.id.tabhost);
tabHost.setup();
for (TabType tabType : TabType.values()) {
tabHost.addTab(createTabSpec(tabHost, tabType));
}
// 初期表示タブ
@daichan4649
daichan4649 / activity_main(layout).xml
Created December 17, 2012 15:20
Multi-pane Layouts (for AndroidAdventCalendar2012)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
@daichan4649
daichan4649 / ContactListFragment.java
Created December 17, 2012 16:20
fragment replace (for AndroidAdventCalendar2012)
public class ContactListFragment extends ListFragment {
public static ContactListFragment newInstance() {
return new ContactListFragment();
}
private ArrayAdapter<ContactData> adapter;
private DataAccessor accessor;
@Override
@daichan4649
daichan4649 / ExpandableListViewTest.java
Last active December 12, 2015 05:19
ExpandableListView 長押し処理実装方法 (for Android)
// ExpandableListView 長押し時処理実装方法
// イベント発生順番
// (1) OnItemLongClickListener#onItemLongClick
// (2) OnCreateContextMenuListener#onCreateContextMenu
expandableListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// 選択要素位置
int groupPosition = ExpandableListView.getPackedPositionGroup(id);
@daichan4649
daichan4649 / CheckableLayout.java
Last active December 14, 2015 18:49
行選択可能(Checkable)な ListView に設定してるカスタムビュー内の 背景色/テキスト文字色 を selector だけで変更する
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 {