Back to project page Books.
The source code is released under:
Apache License
If you think the Android project Books listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.contender.books; // ww w . j av a 2 s . c o m import java.util.Date; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.database.Cursor; import android.os.Bundle; import android.text.format.DateFormat; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; /** * Implements a ListView that connects to the {@link BooksStorage#HISTORY_TABLE_NAME} * table and displays it. * <p> * A very basic View that just shows the books deleted from the main books table, but * provides no interaction with them. * * @author Paul Klinkenberg <pklinken@gmail.com> * @version {@value com.contender.books.MainView#BOOKS_VERSION} */ public class HistoryActivity extends Activity { private static final String TAG = "HistoryActivity"; private ListView listView; private Cursor mCursor; BaseAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_history); } /** * Text converter implemented by the ListView * <p> * if the processed field is {@link R.id.itemDuedateText} returns a string * to display time the formatted return(deletion) date. */ private String convText(TextView v, String text) { if(v.getId() == R.id.itemDuedateText) { Date returnDate = new Date(Long.parseLong(text)); CharSequence format = DateFormat.format("MMM d, yyyy", returnDate); return format.toString(); } return text; } /** * Initializes this view, loading the data from the DB and setting the sortorder. */ @Override public void onResume() { super.onResume(); SharedPreferences settings = this.getSharedPreferences(MainView.PREFS_NAME, 0); int sortOrder = settings.getInt(MainView.PREFS_SORT_ORDER, 0); String sortOrderString; switch (sortOrder) { case 0: sortOrderString = new String(BooksStorage.COLUMN_NAME_RETURNDATE); break; case 1: sortOrderString = new String(BooksStorage.COLUMN_NAME_BOOK); break; case 2: sortOrderString = new String(BooksStorage.COLUMN_NAME_CONTACT); break; default: sortOrderString = null; } mCursor = MainView.BooksProvider.query(BooksStorage.HISTORY_TABLE_NAME, new String[] { BooksStorage.COLUMN_NAME__ID, BooksStorage.COLUMN_NAME_BOOK, BooksStorage.COLUMN_NAME_CONTACT, BooksStorage.COLUMN_NAME_RETURNDATE }, null, null, sortOrderString); if(mCursor == null) { Log.e(TAG, "Received empty cursor"); finish(); } adapter = new SpecialCursorAdapter(this, R.layout.overview_item, mCursor, new String[] { BooksStorage.COLUMN_NAME_BOOK, BooksStorage.COLUMN_NAME_CONTACT, BooksStorage.COLUMN_NAME_RETURNDATE }, new int[] { R.id.itemBookText, R.id.itemContactText, R.id.itemDuedateText }, 0) { @Override public void setViewText(TextView v, String text) { super.setViewText(v, convText(v, text));; } }; listView = (ListView) findViewById(R.id.listView); listView.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.history, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. Intent intent; switch(item.getItemId()) { case R.id.action_settings: intent = new Intent(getApplicationContext(), SettingsActivity.class); startActivity(intent); return true; case R.id.action_about: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.about_title); Resources res = getResources(); String aboutMessage = res.getString(R.string.about_message, MainView.BOOKS_VERSION); builder.setMessage(aboutMessage); AlertDialog aboutDialog = builder.create(); aboutDialog.show(); TextView view = (TextView) aboutDialog.findViewById(android.R.id.message); view.setTextSize(12); return true; } return super.onOptionsItemSelected(item); } }