Android Open Source - TheCompressYourFiles D B Helper






From Project

Back to project page TheCompressYourFiles.

License

The source code is released under:

Apache License

If you think the Android project TheCompressYourFiles 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 th.watsize.musicplayer;
/* ww w .  j  a  v a 2s . c o  m*/
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

  private static final String TAB_NAME_MUSIC = "nevermusic";
  private static final String TAB_NAME_PLAYLIST = "playlist";
  private static final String CREATE_TAB_PLAYLIST = "create table "
      + "playlist(_id integer primary key,listname text)";
  private static final String CREATE_TAB_MUSIC = "create table "
      + "nevermusic(_id integer primary key autoincrement,music_id integer,clicks integer,"
      + "latest text,list1 integer,list2 integer,list3 integer,list4 integer,list5 integer)";

  private SQLiteDatabase db = null;
  private Cursor c = null;

  public DBHelper(Context context, String name, CursorFactory factory,
      int version) {
    super(context, name, factory, version);
    // TODO Auto-generated constructor stub
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    this.db = db;
    db.execSQL(CREATE_TAB_MUSIC);
    db.execSQL(CREATE_TAB_PLAYLIST);
  }

  @Override
  public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub

  }

  public void insertPlaylist(ContentValues values) {

    db = getWritableDatabase();

    db.insert(TAB_NAME_PLAYLIST, null, values);
    c = db.query(TAB_NAME_PLAYLIST, new String[] { "_id" }, null, null,
        null, null, null);
    int temp = c.getCount();
    c = db.query(TAB_NAME_PLAYLIST, null, null, null, null, null, null);
    temp = c.getCount();

    db.close();
  }

  public void clearTable(String tablename) {
    db = getWritableDatabase();
    c = db.query(tablename, new String[] { "_id" }, null, null, null, null,
        null);
    int temp = c.getCount();
    
    c.moveToFirst();
    for (int i = 0; i < c.getCount(); i++) {
      temp = c.getInt(c.getColumnIndex("_id"));
      db.delete(tablename, "_id=?", new String[] { String.valueOf(c
          .getInt(c.getColumnIndex("_id"))) });
      c.moveToNext();
    }
  }

  public void clearMusicDatabase() {
    clearTable(TAB_NAME_MUSIC);
    clearTable(TAB_NAME_PLAYLIST);
  }

  public void insertMusic(ContentValues values) {
    db = getWritableDatabase();
    db.insert(TAB_NAME_MUSIC, null, values);

    db.close();
  }

  public void deletePlayList(int id) {

    db = getWritableDatabase();

    db.delete(TAB_NAME_PLAYLIST, "_id=?",
        new String[] { String.valueOf(id) });
    db.close();
  }

  public void deleteMusic(int id) {

    db = getWritableDatabase();

    db.delete(TAB_NAME_MUSIC, "music_id=?",
        new String[] { String.valueOf(id) });
    db.close();
  }

  public void updateMusic(ContentValues values, int id) {

    db = getWritableDatabase();

    db.update(TAB_NAME_MUSIC, values, "music_id=" + id, null);
    db.close();
  }

  public void updatePlaylist(ContentValues values, int id) {

    db = getWritableDatabase();

    db.update(TAB_NAME_PLAYLIST, values, "_id=" + id, null);
    db.close();
  }

  public Cursor queryAllPlaylist() {

    db = getReadableDatabase();

    c = db.query(TAB_NAME_PLAYLIST, new String[] { "_id", "listname" },
        null, null, null, null, null);
    int temp = c.getCount();
    db.close();
    return c;
  }

  public Cursor queryPlaylistId() {

    db = getReadableDatabase();

    c = db.query(TAB_NAME_PLAYLIST, new String[] { "_id" }, null, null,
        null, null, null);
    int temp = c.getCount();
    c = db.query(TAB_NAME_PLAYLIST, null, null, null, null, null, null);
    temp = c.getCount();
    db.close();
    return c;
  }

  public Cursor queryMusic(int id) {

    db = getWritableDatabase();

    c = db.query(TAB_NAME_MUSIC, null, "music_id=?",
        new String[] { String.valueOf(id) }, null, null, null);
    db.close();
    return c;
  }

  public Cursor queryList(int pos) {

    db = getWritableDatabase();

    c = db.query(TAB_NAME_MUSIC, null, "list" + pos + "=?",
        new String[] { String.valueOf(1) }, null, null, null);
    return c;
  }

  public boolean queryIsInList(int pos, int id, String title) {

    db = getWritableDatabase();

    c = db.query(TAB_NAME_MUSIC, new String[] { "list" + pos },
        "music_id=?", new String[] { String.valueOf(id) }, null, null,
        null);

    if (c == null || c.getCount() == 0) {
      c.moveToFirst();
      ContentValues values = new ContentValues();
      Date currenttime = new Date();
      SimpleDateFormat format = new SimpleDateFormat(
          "yyyy-MM-dd HH:mm:ss");
      String dateStr = format.format(currenttime);
      values.put("music_id", id);
      values.put("clicks", 1);
      values.put("latest", dateStr);
      values.put("list1", 0);
      values.put("list2", 0);
      values.put("list3", 0);
      values.put("list4", 0);
      values.put("list5", 0);
      insertMusic(values);
      return false;
    } else {
      c.moveToFirst();
      if (c.getInt(c.getColumnIndex("list" + pos)) == 0) {
        return false;
      } else {
        return true;
      }
    }
  }

  public Cursor queryMusicByClicks() {

    db = getWritableDatabase();

    c = db.query(TAB_NAME_MUSIC, null, null, null, null, null,
        "clicks desc");
    int temp = c.getCount();
    c.moveToFirst();
    for (int i = 0; i < c.getCount(); i++) {
      temp = c.getInt(c.getColumnIndex("list1"));
      temp = c.getInt(1);
      c.moveToNext();
    }
    db.close();
    return c;
  }

  public Cursor queryMusicByRecently() {

    db = getWritableDatabase();

    c = db.query(TAB_NAME_MUSIC, null, null, null, null, null,
        "latest desc");
    int temp = c.getCount();
    String tempstr = "";
    c.moveToFirst();
    if (c != null || c.getCount() != 0) {
      for (int i = 0; i < c.getCount(); i++) {
        temp = c.getInt(1);
        tempstr = c.getString(2);
        c.moveToNext();
      }
    }

    db.close();
    return c;
  }

  public void close() {
    if (db != null) {
      db.close();
      db = null;
    }
    if (c != null) {
      c.close();
      c = null;
    }
  }
}




Java Source Code List

com.android.gestures.CreateGestureActivity.java
com.android.gestures.GestureBuilderActivity.java
com.android.gestures.GestureMonitorActivity.java
com.markupartist.android.widget.ActionBar.java
com.markupartist.android.widget.ScrollingTextView.java
com.mirrorlabs.ui.widgets.ClickableSlidingDrawer.java
com.mirrorlabs.ui.widgets.DropDownMenu.java
com.mirrorlabs.ui.widgets.IcsListPopupWindow.java
com.mirrorlabs.ui.widgets.JavaYoutubeDownloader.java
com.mirrorlabs.ui.widgets.Panel.java
com.mirrorlabs.ui.widgets.ScrollPager.java
com.mirrorlabs.ui.widgets.SlidingFrameLayout.java
org.zeroxlab.widget.AnimationLayout.java
org.zeroxlab.widget.MyHorizontalScrollView.java
th.watsize.customcheckboxwidget.DontPressWithParentCheckBox.java
th.watsize.customtoast.Toaster.java
th.watsize.filebrowser.BackupManager.java
th.watsize.filebrowser.BaseActivity.java
th.watsize.filebrowser.BitmapManager.java
th.watsize.filebrowser.BookmarksProvider.java
th.watsize.filebrowser.CMDProcessor.java
th.watsize.filebrowser.CompressManager.java
th.watsize.filebrowser.DesEncrypter.java
th.watsize.filebrowser.DrawableManager.java
th.watsize.filebrowser.DrawableThreadLoader.java
th.watsize.filebrowser.DuplicatesManager.java
th.watsize.filebrowser.ExtractManager.java
th.watsize.filebrowser.FileUtils.java
th.watsize.filebrowser.FilebrowserULTRAActivity.java
th.watsize.filebrowser.ImageThreadLoader.java
th.watsize.filebrowser.LinuxShell.java
th.watsize.filebrowser.MimeTypes.java
th.watsize.filebrowser.MyApplication.java
th.watsize.filebrowser.PDFViewer.java
th.watsize.filebrowser.PreferenceActivity.java
th.watsize.filebrowser.ProcessManager.java
th.watsize.filebrowser.RootUtils.java
th.watsize.filebrowser.SearchFilesDialog.java
th.watsize.filebrowser.SearchFilesWidget.java
th.watsize.filebrowser.UltraBaseAdapter.java
th.watsize.imageviewer.EclairMotionEvent.java
th.watsize.imageviewer.ExpandImage.java
th.watsize.imageviewer.TouchImageView.java
th.watsize.imageviewer.WrapMotionEvent.java
th.watsize.menupopup.MenuItem.java
th.watsize.menupopup.PopupMenu.java
th.watsize.musicplayer.DBHelper.java
th.watsize.musicplayer.PlayerActivity.java
th.watsize.quickaction3D.ActionItem.java
th.watsize.quickaction3D.PopupWindows.java
th.watsize.quickaction3D.QuickAction.java
th.watsize.quickaction.ActionItem.java
th.watsize.quickaction.PopupWindows.java
th.watsize.quickaction.QuickAction.java
th.watsize.widgets.ExampleAppWidgetProvider1.java
th.watsize.widgets.ExampleAppWidgetProvider.java
th.watsize.widgets.UpdateWidgetService1.java
th.watsize.widgets.UpdateWidgetService.java