public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case TOGGLE_SOUND: String soundEnabledText = "Sound On"; if (soundEnabled) { soundEnabled = false; myWhackAMoleView.soundOn = false; soundEnabledText = "Sound Off"; } else { soundEnabled = true; myWhackAMoleView.soundOn = true; } DatabaseAdapter db = new DatabaseAdapter(this); try { db.open(); } catch (SQLException sqle) { throw sqle; } db.insertOrUpdateRecord(Boolean.toString(soundEnabled)); db.close(); // SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0); // SharedPreferences.Editor editor = settings.edit(); // editor.putBoolean("soundSetting", soundEnabled); // editor.commit(); // writeXML(); Toast.makeText(this, soundEnabledText, Toast.LENGTH_SHORT).show(); break; } return false; }
@Override protected void onPreExecute() { databaseAdapter = new DatabaseAdapter(context); databaseAdapter.open(); tablicaSzerokosciAlbumow = databaseAdapter.pobranieTablicyWszystkichWspolrzedneAlbumu(pozycja, "szerokosc"); tablicaDlugosciAlbumow = databaseAdapter.pobranieTablicyWszystkichWspolrzedneAlbumu(pozycja, "dlugosc"); }
private void fillActivity() { ItemInfo item = mDbAdapter.getContentItem(mCategoryId, mIndex); Class res = R.drawable.class; int imageId = 0; try { imageId = res.getField(item.icon).getInt(null); } catch (Exception ex) { Log.w("ContentActivity", ex.getMessage()); } ImageView img = (ImageView) findViewById(R.id.list_view_item_icon); img.setImageResource(imageId); TextView text = (TextView) findViewById(R.id.list_view_item_text); text.setText(item.name); text = (TextView) findViewById(R.id.list_view_like_num); text.setText(Integer.toString(item.likeCount)); try { imageId = res.getField(item.picture).getInt(null); } catch (Exception ex) { Log.w("ContentActivity", ex.getMessage()); } img = (ImageView) findViewById(R.id.picture); img.setImageResource(imageId); text = (TextView) findViewById(R.id._text); text.setText(item.text); fillList(); }
public String getFirstPhotoInAlbum(String marker) { String sciezkaDoZdjecia = ""; String nazwaPodrozy = databaseAdapter.pobranieWartosciZTabeli( databaseAdapter.DB_TABLE_MAIN, DatabaseAdapter.KEY_TITLE, (int) pozycja); File file = new File( Environment.getExternalStorageDirectory() + File.separator + "Album podróżniczy" + File.separator + nazwaPodrozy); if (file.isDirectory()) { // listFile = file.listFiles(); final Pattern regex = Pattern.compile(marker + ".*"); File[] flists = file.listFiles( new FileFilter() { @Override public boolean accept(File file) { return regex.matcher(file.getName()).matches(); } }); if (flists.length > 0) { sciezkaDoZdjecia = flists[0].getAbsolutePath(); } } return sciezkaDoZdjecia; }
@Override protected void onPostExecute(MarkerOptions[] opcjeMarkerow) { for (int i = 0; i < opcjeMarkerow.length; i++) { googleMap.addMarker(opcjeMarkerow[i]); } databaseAdapter.close(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // open database DatabaseAdapter databaseConnector = new DatabaseAdapter(this); databaseConnector.open(); currentImage = "success"; OnSeekBarChangeListener customSeekBarListener = new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { ImageView img = (ImageView) findViewById(R.id.image); switch (progress) { case 0: img.setImageResource(R.drawable.success); currentImage = "success"; break; case 1: img.setImageResource(R.drawable.firstworld); currentImage = "firstworld"; break; case 2: img.setImageResource(R.drawable.onedoesnot); currentImage = "onedoesnot"; break; case 3: img.setImageResource(R.drawable.overattached); currentImage = "overattached"; break; } } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }; SeekBar customSeekBar = (SeekBar) findViewById(R.id.sbImageSelector); customSeekBar.setOnSeekBarChangeListener(customSeekBarListener); }
protected void saveCategoriesInTransaction(CategoryTree tree) { SQLiteDatabase database = db.db(); database.beginTransaction(); try { insertInTransaction(tree); database.setTransactionSuccessful(); } finally { database.endTransaction(); } }
private void insertInTransaction(List<Category> categories) { if (categories == null) return; for (Category category : categories) { if (category.id <= 0) continue; db.reInsertCategory(category); if (category.hasChildren()) { insertInTransaction(category.children); } } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.whackamole_layout); myWhackAMoleView = (WhackAMoleView) findViewById(R.id.mole); myWhackAMoleView.setKeepScreenOn(true); setVolumeControlStream(AudioManager.STREAM_MUSIC); DatabaseAdapter db = new DatabaseAdapter(this); try { db.open(); } catch (SQLException sqle) { throw sqle; } Cursor c = db.getRecord(1); startManagingCursor(c); if (c.moveToFirst()) { do { soundEnabled = Boolean.parseBoolean((c.getString(1))); } while (c.moveToNext()); } db.close(); // SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0); // soundEnabled = settings.getBoolean("soundSetting", true); /* try { readXML(); } catch (XmlPullParserException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } */ myWhackAMoleView.soundOn = soundEnabled; }
@Override public void onReceive(Context context, Intent intent) { Log.e(TAG, "Received intent: " + Preferences.PUSH_RECEIVED); Preferences.DEVICE_IS_HONEYCOMB = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB; dbAdapter = new DatabaseAdapter(context); dbAdapter.open(); ReciverQueryParseAsyncTask queryParse = new ReciverQueryParseAsyncTask(Preferences.DEVICE_IS_HONEYCOMB, context); queryParse.execute(); }
private void fillList() { ListView list = (ListView) findViewById(R.id.other_items_list); int itemsCount = mDbAdapter.getContentItemCountByCategory(mCategoryId); Random rand = new Random(); for (int i = 0; i < sListItemsCount; i++) { int index = rand.nextInt(itemsCount); while ((index == mIndex) || member(mItemsId, index, i)) { index = rand.nextInt(itemsCount); } mItemsId[i] = index; } SecondListAdapter adapter = new SecondListAdapter(this, mDbAdapter, mItemsId, mCategoryId); list.setAdapter(adapter); list.setOnItemClickListener(this); }
@Override public void onDestroy() { mDbAdapter.close(); super.onDestroy(); }
public CategoryTree loadCategories() { List<Category> categories = db.createQuery(Category.class).where(Expressions.gt("id", 0)).asc("left").list(); CategoryTree tree = CategoryTree.createFromList(categories); return tree; }
public void insertInTransaction(CategoryTree tree) { db.db().delete("category", null, null); db.reInsertCategory(Category.splitCategory(context)); db.reInsertCategory(Category.noCategory(context)); insertInTransaction(tree.getRoot().children); }