Created
March 5, 2014 18:39
-
-
Save csdear/1b40541b3b33aba6520d to your computer and use it in GitHub Desktop.
baseAdapter - ITEM
<<>> denotes variable data.
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 <<packageName>>; | |
| import java.text.ParseException; | |
| import java.text.SimpleDateFormat; | |
| import java.util.Date; | |
| import java.util.Locale; | |
| import android.content.Intent; | |
| public class <<itemClassName>> { | |
| public static final String ITEM_SEP = System.getProperty("line.separator"); | |
| //Status / Priority fields for Item if needed | |
| public enum Priority { | |
| LOW, MED, HIGH | |
| }; | |
| public enum Status { | |
| NOTDONE, DONE | |
| }; | |
| //Base Item fields | |
| public final static String TITLE = "title"; | |
| public final static String PRIORITY = "priority"; | |
| public final static String STATUS = "status"; | |
| public final static String DATE = "date"; | |
| public final static String FILENAME = "filename"; | |
| //Base format if needing a date field. | |
| public final static SimpleDateFormat FORMAT = new SimpleDateFormat( | |
| "yyyy-MM-dd HH:mm:ss", Locale.US); | |
| //Item Field Methods | |
| private String mTitle = new String(); | |
| private Priority mPriority = Priority.LOW; | |
| private Status mStatus = Status.NOTDONE; | |
| private Date mDate = new Date(); | |
| <<itemClassName>>(String title, Priority priority, Status status, Date date) { | |
| this.mTitle = title; | |
| this.mPriority = priority; | |
| this.mStatus = status; | |
| this.mDate = date; | |
| } | |
| // Create a new Item from data packaged in an Intent | |
| <<itemClassName>>(Intent intent) { | |
| mTitle = intent.getStringExtra(<<itemClassName>>.TITLE); | |
| mPriority = Priority.valueOf(intent.getStringExtra(<<itemClassName>>.PRIORITY)); | |
| mStatus = Status.valueOf(intent.getStringExtra(<<itemClassName>>.STATUS)); | |
| try { | |
| mDate = <<itemClassName>>.FORMAT.parse(intent.getStringExtra(<<itemClassName>>.DATE)); | |
| } catch (ParseException e) { | |
| mDate = new Date(); | |
| } | |
| } | |
| public String getTitle() { | |
| return mTitle; | |
| } | |
| public void setTitle(String title) { | |
| mTitle = title; | |
| } | |
| public Priority getPriority() { | |
| return mPriority; | |
| } | |
| public void setPriority(Priority priority) { | |
| mPriority = priority; | |
| } | |
| public Status getStatus() { | |
| return mStatus; | |
| } | |
| public void setStatus(Status status) { | |
| mStatus = status; | |
| } | |
| public Date getDate() { | |
| return mDate; | |
| } | |
| public void setDate(Date date) { | |
| mDate = date; | |
| } | |
| // Take a set of String data values and | |
| // package them for transport in an Intent | |
| public static void packageIntent(Intent intent, String title, | |
| Priority priority, Status status, String date) { | |
| intent.putExtra(<<itemClassName>>.TITLE, title); | |
| intent.putExtra(<<itemClassName>>.PRIORITY, priority.toString()); | |
| intent.putExtra(<<itemClassName>>.STATUS, status.toString()); | |
| intent.putExtra(<<itemClassName>>, date); | |
| } | |
| public String toString() { | |
| return mTitle + ITEM_SEP + mPriority + ITEM_SEP + mStatus + ITEM_SEP | |
| + FORMAT.format(mDate); | |
| } | |
| public String toLog() { | |
| return "Title:" + mTitle + ITEM_SEP + "Priority:" + mPriority | |
| + ITEM_SEP + "Status:" + mStatus + ITEM_SEP + "Date:" | |
| + FORMAT.format(mDate); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment