Created
June 11, 2014 14:41
-
-
Save esperia/d9ed7be2aaee27868989 to your computer and use it in GitHub Desktop.
enumの例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.co.kayo.android.ksapidemo.app.view; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.graphics.Color; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.support.v4.app.FragmentActivity; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.AdapterView; | |
import android.widget.BaseAdapter; | |
import android.widget.ListView; | |
import android.widget.TextView; | |
/** | |
* Created by esperia on 2014/06/11. | |
*/ | |
public class EnumListViewActivity extends FragmentActivity implements AdapterView.OnItemClickListener { | |
private ListView mListView; | |
private EnumAdapter mAdapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mListView = new ListView(this); | |
mListView.setOnItemClickListener(this); | |
mAdapter = new EnumAdapter(this); | |
mListView.setAdapter(mAdapter); | |
} | |
@Override | |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
Menus m = mAdapter.getItem(position); | |
if (m.name().startsWith("APP_")) { | |
Intent intent = new Intent(Intent.ACTION_VIEW); | |
intent.setData(m.getUri()); | |
startActivity(intent); | |
} | |
} | |
public enum Menus { | |
SECTION_APP("あぷり", null), | |
APP_CHROME("Chromeブラウザ", null, "https://play.google.com/store/apps/details?hl=ja&id=com.android.chrome"), | |
APP_MUOOOO("むおおおお", null, "https://play.google.com/store/apps/details?id=com.esperia09.android.cryptmuoooo"), | |
SECTION_MISC("その他", null), | |
MISC_SETTING("設定", "アプリの設定"), | |
MISC_OSS_LICENSE("オープンソースライセンス", "このアプリで使ってるやつ"),; | |
private final String title; | |
private final String subtitle; | |
private final String url; | |
Menus(String title, String subtitle) { | |
this.title = title; | |
this.subtitle = subtitle; | |
this.url = null; | |
} | |
Menus(String title, String subtitle, String url) { | |
this.title = title; | |
this.subtitle = subtitle; | |
this.url = url; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public String getSubtitle() { | |
return subtitle; | |
} | |
public Uri getUri() { | |
return Uri.parse(this.url); | |
} | |
} | |
public static class EnumAdapter extends BaseAdapter { | |
private static final String PREFIX_SECTION = "SECTION_"; | |
private final Context mContext; | |
public EnumAdapter(Context context) { | |
mContext = context; | |
} | |
@Override | |
public int getCount() { | |
return Menus.values().length; | |
} | |
@Override | |
public Menus getItem(int position) { | |
return Menus.values()[position]; | |
} | |
@Override | |
public long getItemId(int position) { | |
return position; | |
} | |
@Override | |
public boolean isEnabled(int position) { | |
return Menus.values()[position].name().startsWith(PREFIX_SECTION); | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
Menus m = Menus.values()[position]; | |
if (convertView == null) { | |
LayoutInflater inflater = LayoutInflater.from(mContext); | |
convertView = inflater.inflate(android.R.layout.simple_list_item_2, parent, false); | |
} | |
TextView titleView = (TextView) convertView.findViewById(android.R.id.text1); | |
TextView subtitleView = (TextView) convertView.findViewById(android.R.id.text2); | |
if (!isEnabled(position)) { | |
//セクション区切り | |
convertView.setBackgroundColor(Color.BLACK); | |
titleView.setTextColor(Color.WHITE); | |
subtitleView.setVisibility(View.GONE); | |
titleView.setText(m.getTitle()); | |
} else { | |
convertView.setBackgroundColor(Color.WHITE); | |
titleView.setTextColor(Color.BLACK); | |
subtitleView.setVisibility(View.VISIBLE); | |
titleView.setText(m.getTitle()); | |
subtitleView.setText(m.getSubtitle()); | |
} | |
return convertView; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Tables { | |
public static final int TRUE = 1; | |
public static final int FALSE = 0; | |
public enum Favorites implements BaseTables { | |
//@formatter:off | |
URL("url"), | |
TITLE("title"), | |
MODIFIED(BaseTables.MODIFIED), | |
CREATED(BaseTables.CREATED), | |
; | |
//@formatter:on | |
private static final String _TABLE = "favorites"; | |
private static final Uri _URI = Uri.parse(ContentResolver.SCHEME_CONTENT + "://" | |
+ ContentProviderKohno.AUTHORITY + "/" + _TABLE); | |
private final String fieldName; | |
private Favorites(String fieldName) { | |
this.fieldName = fieldName; | |
} | |
public static String getTable() { | |
return _TABLE; | |
} | |
public static Uri getContentUri() { | |
return _URI; | |
} | |
@Override | |
public String toString() { | |
return this.fieldName; | |
} | |
} | |
public interface BaseTables extends BaseColumns { | |
String _TABLE = null; | |
String _URI = null; | |
String MODIFIED = "modified"; | |
String CREATED = "created"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment