use of android.database.sqlite.SQLiteOpenHelper in project zxingfragmentlib by mitoyarzun.
the class HistoryManager method buildHistory.
/**
* <p>Builds a text representation of the scanning history. Each scan is encoded on one
* line, terminated by a line break (\r\n). The values in each line are comma-separated,
* and double-quoted. Double-quotes within values are escaped with a sequence of two
* double-quotes. The fields output are:</p>
*
* <ul>
* <li>Raw text</li>
* <li>Display text</li>
* <li>Format (e.g. QR_CODE)</li>
* <li>Timestamp</li>
* <li>Formatted version of timestamp</li>
* </ul>
*/
CharSequence buildHistory() {
SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getWritableDatabase();
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
StringBuilder historyText = new StringBuilder(1000);
while (cursor.moveToNext()) {
historyText.append('"').append(massageHistoryField(cursor.getString(0))).append("\",");
historyText.append('"').append(massageHistoryField(cursor.getString(1))).append("\",");
historyText.append('"').append(massageHistoryField(cursor.getString(2))).append("\",");
historyText.append('"').append(massageHistoryField(cursor.getString(3))).append("\",");
// Add timestamp again, formatted
long timestamp = cursor.getLong(3);
historyText.append('"').append(massageHistoryField(format.format(new Date(timestamp)))).append("\",");
// Above we're preserving the old ordering of columns which had formatted data in position 5
historyText.append('"').append(massageHistoryField(cursor.getString(4))).append("\"\r\n");
}
return historyText;
} finally {
close(cursor, db);
}
}
use of android.database.sqlite.SQLiteOpenHelper in project zxingfragmentlib by mitoyarzun.
the class HistoryManager method clearHistory.
void clearHistory() {
SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = null;
try {
db = helper.getWritableDatabase();
db.delete(DBHelper.TABLE_NAME, null, null);
} finally {
close(null, db);
}
}
use of android.database.sqlite.SQLiteOpenHelper in project zxingfragmentlib by mitoyarzun.
the class HistoryManager method addHistoryItemDetails.
public void addHistoryItemDetails(String itemID, String itemDetails) {
// As we're going to do an update only we don't need need to worry
// about the preferences; if the item wasn't saved it won't be udpated
SQLiteOpenHelper helper = new DBHelper(activity);
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = helper.getWritableDatabase();
cursor = db.query(DBHelper.TABLE_NAME, ID_DETAIL_COL_PROJECTION, DBHelper.TEXT_COL + "=?", new String[] { itemID }, null, null, DBHelper.TIMESTAMP_COL + " DESC", "1");
String oldID = null;
String oldDetails = null;
if (cursor.moveToNext()) {
oldID = cursor.getString(0);
oldDetails = cursor.getString(1);
}
if (oldID != null) {
String newDetails;
if (oldDetails == null) {
newDetails = itemDetails;
} else if (oldDetails.contains(itemDetails)) {
newDetails = null;
} else {
newDetails = oldDetails + " : " + itemDetails;
}
if (newDetails != null) {
ContentValues values = new ContentValues();
values.put(DBHelper.DETAILS_COL, newDetails);
db.update(DBHelper.TABLE_NAME, values, DBHelper.ID_COL + "=?", new String[] { oldID });
}
}
} finally {
close(cursor, db);
}
}
use of android.database.sqlite.SQLiteOpenHelper in project storio by pushtorefresh.
the class InterceptorTest method setUp.
@Before
public void setUp() throws Exception {
final SQLiteOpenHelper sqLiteOpenHelper = new TestSQLiteOpenHelper(RuntimeEnvironment.application);
callCount = new AtomicInteger(0);
interceptor1 = createInterceptor();
interceptor2 = createInterceptor();
storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).addTypeMapping(Tweet.class, SQLiteTypeMapping.<Tweet>builder().putResolver(TweetTableMeta.PUT_RESOLVER).getResolver(TweetTableMeta.GET_RESOLVER).deleteResolver(TweetTableMeta.DELETE_RESOLVER).build()).addInterceptor(interceptor1).addInterceptor(interceptor2).build();
}
use of android.database.sqlite.SQLiteOpenHelper in project android-zxing by PearceXu.
the class HistoryManager method addHistoryItem.
public void addHistoryItem(Result result, ResultHandler handler) {
// considered secure.
if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) || handler.areContentsSecure() || !enableHistory) {
return;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
deletePrevious(result.getText());
}
ContentValues values = new ContentValues();
values.put(DBHelper.TEXT_COL, result.getText());
values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());
SQLiteOpenHelper helper = new DBHelper(activity);
try (SQLiteDatabase db = helper.getWritableDatabase()) {
// Insert the new entry into the DB.
db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
}
}
Aggregations