Android Open Source - HomeMovies Log Handler






From Project

Back to project page HomeMovies.

License

The source code is released under:

MIT License

If you think the Android project HomeMovies listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package il.co.All4Students.homemovies.util.log.db;
/*ww  w . ja  v a 2s .  c o m*/
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.DATABASE_NAME;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.DATABASE_VERSION;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.KEY_DATE;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.KEY_LOG;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.KEY_TAG;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.KEY_TIME;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.LOG_TAG;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.SELECT_HELPER;
import static il.co.All4Students.homemovies.util.log.db.LogDbConstants.TABLE_LOG;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

/**
 * Start DbHandler
 * 
 * @author Arkadi Yoskovitz
 * @date 2013-02-08
 */
public class LogHandler {
  private LogDbHelper logDBHelper;

  public LogHandler(Context context) {
    logDBHelper = new LogDbHelper(context, DATABASE_NAME, null,
        DATABASE_VERSION);
  }

  /**
   * All CRUD(Create, Read, Update, Delete) Operations
   */

  /**
   * Adding a new item to the SQLiteDatabase
   * 
   * @param logString
   */
  @SuppressLint("SimpleDateFormat")
  public void addLogItem(String logTag, String logString) {
    SQLiteDatabase db = logDBHelper.getWritableDatabase();
    String logDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date())
        .toString();
    String logTime = new SimpleDateFormat("HH:mm:ss.SSSZ E").format(
        new Date()).toString();

    try {
      ContentValues values = new ContentValues();
      values.put(KEY_DATE, logDate);
      values.put(KEY_TIME, logTime);
      values.put(KEY_TAG, logTag);
      values.put(KEY_LOG, logString);

      // Inserting Row
      db.insert(TABLE_LOG, null, values);
    } catch (SQLException e) {
      Log.d(LOG_TAG, "Add Item: " + e.getMessage());
    } finally {
      db.close(); // Closing database connection
    }
  }

  /**
   * Getting All logs
   * 
   * @return holderString.toString();
   */
  public String getAllLogs() {
    StringBuilder holderString = new StringBuilder();
    // Select All Query
    String selectQuery = SELECT_HELPER;

    SQLiteDatabase db = logDBHelper.getReadableDatabase();
    try {
      Cursor cursor = db.rawQuery(selectQuery, null);

      // looping through all rows and adding to list
      if (cursor.moveToFirst()) {
        do {
          holderString.append(Integer.parseInt(cursor.getString(0)))
              .append("\t").append(cursor.getString(1))
              .append("\t").append(cursor.getString(2))
              .append("\t").append(cursor.getString(3))
              .append("\t").append(cursor.getString(4))
              .append("\t").append("\n\n");
        } while (cursor.moveToNext());
      }
      cursor.close();
    } catch (SQLException e) {
      Log.d(LOG_TAG, "Get All Items: " + e.getMessage());
    } finally {
      db.close();
    }

    return holderString.toString();
  }

  /**
   * Deleting all logs from the Database
   */
  public void deleteAllLogs() {
    SQLiteDatabase db = logDBHelper.getWritableDatabase();
    try {
      String sqlDelete = "DELETE FROM " + TABLE_LOG;
      db.execSQL(sqlDelete);
    } catch (Exception e) {
      Log.d(LOG_TAG, "Delete Item: " + e.getMessage());
    } finally {
      db.close();
    }
  }
}




Java Source Code List

il.co.All4Students.homemovies.OkCancelBar.java
il.co.All4Students.homemovies.ScreenEdit.java
il.co.All4Students.homemovies.ScreenGridDetail.java
il.co.All4Students.homemovies.ScreenGrid.java
il.co.All4Students.homemovies.ScreenMain.java
il.co.All4Students.homemovies.ScreenPreferences.java
il.co.All4Students.homemovies.ScreenWeb.java
il.co.All4Students.homemovies.app.AppConstants.java
il.co.All4Students.homemovies.app.ApplicationPreference.java
il.co.All4Students.homemovies.app.HomeProjectApplication.java
il.co.All4Students.homemovies.core.ItemCompareRTID.java
il.co.All4Students.homemovies.core.ItemCompareRank.java
il.co.All4Students.homemovies.core.ItemCompareSubject.java
il.co.All4Students.homemovies.core.Item.java
il.co.All4Students.homemovies.util.adapter.ItemListAdapter.java
il.co.All4Students.homemovies.util.adapter.ScreenGridAdapter.java
il.co.All4Students.homemovies.util.app.AppUtil.java
il.co.All4Students.homemovies.util.db.ItemsDbConstants.java
il.co.All4Students.homemovies.util.db.ItemsDbHelper.java
il.co.All4Students.homemovies.util.db.ItemsHandler.java
il.co.All4Students.homemovies.util.dialog.RankDialog.java
il.co.All4Students.homemovies.util.dialog.ShareDialog.java
il.co.All4Students.homemovies.util.email.EmailUtil.java
il.co.All4Students.homemovies.util.image.ExternalStorageLoader.java
il.co.All4Students.homemovies.util.imageWeb.FileCache.java
il.co.All4Students.homemovies.util.imageWeb.ImageLoader.java
il.co.All4Students.homemovies.util.imageWeb.MemoryCache.java
il.co.All4Students.homemovies.util.json.JSONHandler.java
il.co.All4Students.homemovies.util.json.JSONUtilWithTags.java
il.co.All4Students.homemovies.util.json.JSONUtil.java
il.co.All4Students.homemovies.util.log.db.LogDbConstants.java
il.co.All4Students.homemovies.util.log.db.LogDbHelper.java
il.co.All4Students.homemovies.util.log.db.LogHandler.java
il.co.All4Students.homemovies.util.log.util.AppLog.java