/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { /* DEV StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); */ super.onCreate(savedInstanceState); setContentView(R.layout.playgame); mGameMode = getIntent().getStringExtra("mode"); final DatabaseHelper mOpenHelper = new DatabaseHelper(this, "wordlist"); m_db = mOpenHelper.getReadableDatabase(); m_playboard = (PlayBoard) findViewById(R.id.playboard); m_playboard.setBoardSize(5, 5); mBoardGameLogic.setBoard(m_playboard); m_word = (TextView) findViewById(R.id.word); mPlayTime = (TextView) findViewById(R.id.play_time); mScoreText = (TextView) findViewById(R.id.score); // Temporary components m_text_status = (TextView) findViewById(R.id.status); m_start_button = (Button) findViewById(R.id.restart_game); startGame(0); }
@Override protected HistoryAdapter doInBackground(AppCompatActivity... activity) { ArrayList<String> history = new ArrayList<>(); DatabaseHelper helper = new DatabaseHelper(MainActivity.mContext); SQLiteDatabase db = helper.getReadableDatabase(); Cursor c = db.query( DatabaseHelper.Columns.TABLE_NAME, new String[] { DatabaseHelper.Columns.COLUMN_INPUT, DatabaseHelper.Columns.COLUMN_RESULT }, null, null, null, null, DatabaseHelper.Columns._ID + " DESC"); if (c.moveToFirst()) { do history.add(c.getString(0) + " = " + c.getString(1)); while (c.moveToNext()); } c.close(); db.close(); helper.close(); if (activity.length > 0) return new HistoryAdapter(history, activity[0]); else return new HistoryAdapter(history, null); }
public static void updateCanUpgradePlugins(Context context, int value, String selection) { DatabaseHelper helper = PluginsDatabaseHelper.getDatabaseHelperInstance(context); SQLiteDatabase db = helper.getWritableDatabase(); Cursor cursor = db.rawQuery( "SELECT * FROM " + PluginsDatabaseHelper.PLUGIN_TABLE + " AS T1 INNER JOIN " + PluginsDatabaseHelper.PLUGIN_TABLE_EXTRA + " AS T2 ON T1.id = T2.id " + "WHERE T1.filename = ?", new String[] {selection}); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { if (cursor.getInt(cursor.getColumnIndex("update_flag")) == 1) { int id = cursor.getInt(cursor.getColumnIndex("id")); ContentValues values = new ContentValues(); values.put("update_flag", value); db.update( PluginsDatabaseHelper.PLUGIN_TABLE_EXTRA, values, "id = ?", new String[] {String.valueOf(id)}); } } cursor.close(); db.close(); helper.close(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); // 初回時のみデータベース作成 DatabaseHelper databaseHelper = new DatabaseHelper(this); SQLiteDatabase sqLiteDatabase = databaseHelper.getReadableDatabase(); sqLiteDatabase.close(); // いただきますボタン BootstrapButton startButton = (BootstrapButton) findViewById(R.id.start_button); startButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MyActivity.this, EatingActivity.class); startActivity(intent); } }); // Yummyの記録ボタン BootstrapButton historyButton = (BootstrapButton) findViewById(R.id.history_button); historyButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MyActivity.this, HistoryActivity.class); startActivity(intent); } }); }
private void setQuestion(Integer questionNo) { DatabaseHelper dbHelper = new DatabaseHelper(this); SQLiteDatabase db = dbHelper.getReadableDatabase(); String sql = "SELECT Pref, City0, City1, City2, City3, City4 FROM MyTable WHERE _id=" + questionNo.toString(); Cursor c = db.rawQuery(sql, null); c.moveToFirst(); String Kenmei = c.getString(c.getColumnIndex("Pref")); String Choice1 = c.getString(c.getColumnIndex("City1")); String Choice2 = c.getString(c.getColumnIndex("City2")); String Choice3 = c.getString(c.getColumnIndex("City3")); String Choice4 = c.getString(c.getColumnIndex("City4")); Seikai = c.getString(c.getColumnIndex("City0")); c.close(); db.close(); ((TextView) findViewById(R.id.textQuestion)).setText(Kenmei); ((Button) findViewById(R.id.button1)).setText(Choice1); ((Button) findViewById(R.id.button2)).setText(Choice2); ((Button) findViewById(R.id.button3)).setText(Choice3); ((Button) findViewById(R.id.button4)).setText(Choice4); }
@Test public void testInitializeUserId() { // the userId passed to initialize should override any existing values String sourceName = Constants.PACKAGE_NAME + "." + context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(sourceName, Context.MODE_PRIVATE); prefs.edit().putString(Constants.PREFKEY_USER_ID, "oldestUserId").commit(); DatabaseHelper dbHelper = DatabaseHelper.getDatabaseHelper(context); dbHelper.insertOrReplaceKeyValue(AmplitudeClient.USER_ID_KEY, "oldUserId"); String userId = "newUserId"; amplitude.initialize(context, apiKey, userId); Shadows.shadowOf(amplitude.logThread.getLooper()).runOneTask(); // Test that the user id is set. assertEquals(userId, amplitude.userId); assertEquals(userId, dbHelper.getValue(AmplitudeClient.USER_ID_KEY)); // Test that events are logged. RecordedRequest request = sendEvent(amplitude, "init_test_event", null); assertNotNull(request); // verified shared prefs not deleted assertEquals(prefs.getString(Constants.PREFKEY_USER_ID, null), "oldestUserId"); }
@Override protected void onPostExecute(final Boolean success) { mAuthTask = null; if (success) { String[] registerMsg = RegisterMsg.split(":"); DatabaseHelper dbHelper = new DatabaseHelper(RegisterActivity.this, "iPin"); SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("ID", registerMsg[1]); values.put("username", register_name_str); values.put("password", MD5_Password); values.put("sex", register_sex); values.put("telephone", register_telephone_str); values.put("HeadImageVersion", 0); values.put("autoLogin", true); db.update("LoginUser", values, "autoLogin=?", new String[] {"0"}); db.close(); dbHelper.close(); Intent intent = new Intent(RegisterActivity.this, InfoListActivity.class); startActivity(intent); RegisterActivity.this.finish(); } else { showProgress(false); register_password_confirm.setError("注册失败"); register_password_confirm.requestFocus(); } try { socket.close(); } catch (Exception e) { } }
public static void addMedicine(Context context, MedicineObject medicineObject) { DatabaseHelper databaseHelper = new DatabaseHelper(context); databaseHelper.addMedicine(medicineObject); DateHelper.generateDates(context, medicineObject); AlarmHelper.setAlarms( context, DateHelper.getDatesFromMedicineId(context, medicineObject.getId())); }
public void reset(Context context) { DatabaseHelper old = this.databaseHelper; this.databaseHelper = new DatabaseHelper(context.getApplicationContext(), DATABASE_NAME, null, DATABASE_VERSION); old.close(); fillCache(); }
private void callUpdate(MessageEntry messageEntry) throws StorageException { DatabaseHelper instance = DatabaseHelper.getInstance(this); final SQLiteDatabase db = instance.getWritableDatabase(); db.beginTransaction(); try { CommandBusHelper.sendMessage(this, GetMessageCommand.CANCEL_UPDATE); // Update the database instance.insertOrUpdateMessage(db, messageEntry); Long serverId = messageEntry.getServerId(); Long posted = messageEntry.getPosted(); String messString = messageEntry.getMessage(); Command command; if (serverId != null && posted != -1l) command = new EditMessageCommand(messString, serverId); else if (posted == -1l) command = new DeleteMessageCommand(serverId); else command = new PostMessageCommand(messString); CommandBusHelper.submitCommandSync(this, command); db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
public static List<Line> getLines(Context context) { DatabaseHelper dbHelper = new DatabaseHelper(context); SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = null; List<Line> lines = new ArrayList<Line>(); try { String[] columns = { LineDb.COL_ID, LineDb.COL_NAME, LineDb.COL_DESCRIPTION, LineDb.COL_REGION, LineDb.COL_POINTS, LineDb.COL_DIRECTION }; cursor = db.query(LineDb.TABLE, columns, null, null, null, null, null); while (cursor.moveToNext()) { Line line = new Line(); line.setId(cursor.getString(0)); line.setName(cursor.getString(1)); line.setDescription(cursor.getString(2)); line.setRegion(cursor.getString(3)); line.setPoints(Point.fromText(cursor.getString(4))); line.setDirection(cursor.getString(5)); lines.add(line); } return lines; } finally { if (null != cursor) cursor.close(); if (null != db) db.close(); } }
// 在使用该函数之前最好先判断数据库中movieList这个表是否为空 public List<UriInstance> queryFromUserID(int userID) { DatabaseHelper dbHelper = new DatabaseHelper(context, "CAMO_db1"); SQLiteDatabase db = dbHelper.getWritableDatabase(); Cursor cursor = db.query( "playList", new String[] {"userID", "uri", "classType", "name", "mediaType"}, "userID=?", new String[] {Integer.toString(userID)}, null, null, null); // UriInstance item = new UriInstance(); String uri = null; String classType = null; String name = null; String mediaType = null; List<UriInstance> list = new ArrayList<UriInstance>(); while (cursor.moveToNext()) { uri = cursor.getString(cursor.getColumnIndex("uri")); classType = cursor.getString(cursor.getColumnIndex("classType")); name = cursor.getString(cursor.getColumnIndex("name")); mediaType = cursor.getString(cursor.getColumnIndex("mediaType")); RdfFactory factory = RdfFactory.getInstance(); UriInstance item = factory.createInstance(uri, mediaType, classType, name); list.add(item); } dbHelper.close(); return list; }
public ArrayList<ActionEvent> getAllItems(Context context, boolean isHistory) { DatabaseHelper dh = new DatabaseHelper(context, TABLE_NAME); SQLiteDatabase db = dh.getReadableDatabase(); ArrayList<ActionEvent> aeList = new ArrayList<ActionEvent>(); Cursor c = db.query( TABLE_NAME, null, KEY_IS_HISTORY + "='" + getBooleanToLong(isHistory) + "'", null, null, null, "_id" + " DESC"); while (c.moveToNext()) { ActionEvent ae = new ActionEvent( c.getString(c.getColumnIndex(KEY_ACTION_NAME)), c.getLong(c.getColumnIndex(KEY_START_TIMESTAMP)), c.getString(c.getColumnIndex(KEY_ACTION_NOTE)), getLongToBoolean(c.getLong(c.getColumnIndex(KEY_IS_HISTORY))), c.getLong(c.getColumnIndex(KEY_START_DEALY)), c.getLong(c.getColumnIndex(KEY_START_DEALY))); ae.setBreakTimestamp(c.getLong(c.getColumnIndex(KEY_BREAK_TIMESTAMP))); ae.setState(c.getString(c.getColumnIndex(KEY_STATE))); aeList.add(ae); } c.close(); db.close(); return aeList; }
@Test public void testInitializeLastEventId() throws JSONException { DatabaseHelper dbHelper = DatabaseHelper.getDatabaseHelper(context); String sourceName = Constants.PACKAGE_NAME + "." + context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(sourceName, Context.MODE_PRIVATE); prefs.edit().putLong(Constants.PREFKEY_LAST_EVENT_ID, 3L).commit(); amplitude.initialize(context, apiKey); Shadows.shadowOf(amplitude.logThread.getLooper()).runOneTask(); assertEquals(amplitude.lastEventId, 3L); assertEquals((long) dbHelper.getLongValue(AmplitudeClient.LAST_EVENT_ID_KEY), 3L); amplitude.logEvent("testEvent"); Shadows.shadowOf(amplitude.logThread.getLooper()).runToEndOfTasks(); Shadows.shadowOf(amplitude.logThread.getLooper()).runToEndOfTasks(); RecordedRequest request = runRequest(amplitude); JSONArray events = getEventsFromRequest(request); assertEquals(events.getJSONObject(0).getLong("event_id"), 1L); assertEquals(amplitude.lastEventId, 1L); assertEquals((long) dbHelper.getLongValue(AmplitudeClient.LAST_EVENT_ID_KEY), 1L); // verify shared prefs deleted assertEquals(prefs.getLong(Constants.PREFKEY_LAST_EVENT_ID, -1), -1); }
@Test public void testInitializeOptOut() { ShadowLooper looper = Shadows.shadowOf(amplitude.logThread.getLooper()); String sourceName = Constants.PACKAGE_NAME + "." + context.getPackageName(); SharedPreferences prefs = context.getSharedPreferences(sourceName, Context.MODE_PRIVATE); prefs.edit().putBoolean(Constants.PREFKEY_OPT_OUT, true).commit(); DatabaseHelper dbHelper = DatabaseHelper.getDatabaseHelper(context); assertNull(dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY)); amplitude.initialize(context, apiKey); looper.runOneTask(); assertTrue(amplitude.isOptedOut()); assertEquals((long) dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY), 1L); amplitude.setOptOut(false); looper.runOneTask(); assertFalse(amplitude.isOptedOut()); assertEquals((long) dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY), 0L); // verify shared prefs deleted assertFalse(prefs.getBoolean(Constants.PREFKEY_OPT_OUT, false)); }
public static int getNewId(Context context) { int max = 0; DatabaseHelper databaseHelper = new DatabaseHelper(context); for (MedicineObject medicineObject : databaseHelper.getMedicines()) { if (medicineObject.getId() > max) max = medicineObject.getId(); } return max + 1; }
@Override public boolean onCreate() { final Context context = getContext(); final DatabaseHelper dbHelper = new DatabaseHelper(context); /** Create a write able database which will trigger its creation if it doesn't already exist. */ db = dbHelper.getWritableDatabase(); return (db == null) ? false : true; }
public void onClickUpdateData(View view) { helper.open(); if (helper.updateRecord(getId(), getName(), getPhone(), getEmail())) { Toast.makeText(this, "Update was successfull", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Update failed", Toast.LENGTH_SHORT).show(); } }
public static String getAllMedicinesToString(Context context) { DatabaseHelper databaseHelper = new DatabaseHelper(context); StringBuilder stringBuilder = new StringBuilder(); for (MedicineObject medicineObject : databaseHelper.getMedicines()) { stringBuilder.append(medicineObject.toString()); } return stringBuilder.toString(); }
@Override public boolean onCreate() { Context context = getContext(); DatabaseHelper dbHelper = new DatabaseHelper(context); Log.v("CP", "Create CP"); db = dbHelper.getWritableDatabase(); return (db != null); }
@Override public boolean onCreate() { Context context = getContext(); DatabaseHelper dbHelper = new DatabaseHelper(context); PruebaBD = dbHelper.getWritableDatabase(); PruebaBD = dbHelper.getReadableDatabase(); return (PruebaBD == null) ? false : true; // es un If }
public SendMsgDao(Context context) { this.context = context; try { helper = DatabaseHelper.getHelper(context); sendMsgDaoOpe = helper.getDao(SendMsg.class); } catch (SQLException e) { e.printStackTrace(); } }
private void Update(Entity entity) throws Exception { // get the statement... SqlStatement sql = this.GetUpdateStatement(entity); // run the statement... DatabaseHelper db = new DatabaseHelper(); db.EnsureTableExists(getEntityType()); db.ExecuteNonQuery(sql); }
void SaveShift(Shift shift) { int shiftId = db.createShift(shift); db.createJob_Shift(shiftId, job.getID()); CalculateWages(shift, job); ShowToast("Shift id = " + shiftId, getApplicationContext()); }
public NotebookDao(Context context) { this.context = context; try { helper = DatabaseHelper.getHelper(context); notebookDaoOpe = helper.getDao(Notebook.class); } catch (SQLException e) { e.printStackTrace(); } }
public FileHandler(Context context, DeviceScreen screen) { logger = UpmobileExceptionReporter.getInstance(context); databaseHelper = DatabaseHelper.getInstance(context); files = databaseHelper.getPictures(); width = screen.getSmallestWidth(); height = screen.getLargestWidth(); comparator = PictureData.TIME_COMPARATOR; Collections.sort(files, comparator); }
public void onClickDeleteRecord(View view) { helper.open(); if (helper.deleteRecord(getId())) { Toast.makeText(this, "Delete process succeded", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Record could not be deleted", Toast.LENGTH_SHORT).show(); } helper.close(); }
public static void clearLines(Context context) { DatabaseHelper dbHelper = new DatabaseHelper(context); SQLiteDatabase db = dbHelper.getWritableDatabase(); try { db.delete(LineDb.TABLE, null, null); } finally { db.close(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_details_list); list = (ListView) findViewById(R.id.list); DatabaseHelper database = new DatabaseHelper(getApplicationContext()); ArrayList<String> arrayList = database.getData(); adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_layout, arrayList); list.setAdapter(adapter); }
public DiggerAlbumDao(Context pContext) { mContext = pContext; mDbHelper = DatabaseHelper.getHelper(pContext); try { mDiggerAlbumDao = mDbHelper.getDao(DiggerAlbum.class); } catch (SQLException e) { e.printStackTrace(); Logger.e(TAG, "dao failure >>>" + e.getMessage()); } }