Back to project page palhike.
The source code is released under:
GNU General Public License
If you think the Android project palhike listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.palhike.android; import java.io.IOException; // ww w. j ava 2 s. c o m import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.util.Base64; import android.util.Log; public class TestAdapter { protected static final String TAG = "DataAdapter"; private final Context mContext; private SQLiteDatabase mDb; private DataBaseHelper mDbHelper; public TestAdapter(Context context) { this.mContext = context; mDbHelper = new DataBaseHelper(mContext); } public TestAdapter createDatabase() throws Exception { try { mDbHelper.createDataBase(); } catch (IOException mIOException) { Log.e(TAG, mIOException.toString() + " UnableToCreateDatabase"); throw mIOException; }catch (Exception e) { throw e; } return this; } public TestAdapter open() throws SQLException { try { if (mDbHelper.openDataBase()) { mDbHelper.close(); mDb = mDbHelper.getReadableDatabase(); } else { throw new SQLException("could not open database!!!"); } } catch (SQLException mSQLException) { Log.e(TAG, "open >>" + mSQLException.toString()); throw mSQLException; } return this; } public void close() { mDbHelper.close(); } public ObjectModel getObject(String id,String age, String language) { String queryStatement = ""; // if (age.equals("adult")) { // if (language.equals("en")) { // queryStatement = "SELECT _id,title_en AS title,description_en AS description,image1,image2,image3,image4,image5,num_images FROM objects WHERE _id ='" // + id + "'"; // } else { // queryStatement = "SELECT _id,title_ar AS title,description_ar AS description,image1,image2,image3,image4,image5,num_images FROM objects WHERE _id ='" // if (language.equals("en")) { // queryStatement = "SELECT _id,title_en AS titleEnglish,title_ar AS title,description_kids_en AS description,image1,image2,image3,image4,image5,num_images FROM objects WHERE _id ='" // + id + "'"; // } else { // queryStatement = "SELECT _id,title_en AS titleEnglish,title_ar AS title,description_kids_ar AS description,image1,image2,image3,image4,image5,num_images FROM objects WHERE _id ='" // + id + "'"; // } // if (language.equals("en")) { queryStatement = "SELECT _id,title_en AS titleEnglish,title_ar AS title,description_kids_en AS description,image1,image2,image3,image4,image5,num_images,scientific, didyouknow FROM objects WHERE _id ='" + id + "'"; } else { queryStatement = "SELECT _id,title_en AS titleEnglish,title_ar AS title,description_kids_ar AS description,image1,image2,image3,image4,image5,num_images,scientific, didyouknow FROM objects WHERE _id ='" + id + "'"; } Cursor cursor = mDb.rawQuery(queryStatement, null); if (cursor != null && cursor.moveToFirst()) { ObjectModel object = new ObjectModel( cursor.getString(cursor.getColumnIndex("_id")) , cursor.getString(cursor.getColumnIndex("title")) , cursor.getString(cursor.getColumnIndex("titleEnglish")) , cursor.getString(cursor.getColumnIndex("description")) , cursor.getString(cursor.getColumnIndex("num_images")) , (Base64.decode(cursor.getBlob(cursor.getColumnIndex("image1")),Base64.DEFAULT)) , (Base64.decode(cursor.getBlob(cursor.getColumnIndex("image2")),Base64.DEFAULT)) , (Base64.decode(cursor.getBlob(cursor.getColumnIndex("image3")),Base64.DEFAULT)) , (Base64.decode(cursor.getBlob(cursor.getColumnIndex("image4")),Base64.DEFAULT)) , (Base64.decode(cursor.getBlob(cursor.getColumnIndex("image5")),Base64.DEFAULT)) , cursor.getString(cursor.getColumnIndex("scientific")) , cursor.getString(cursor.getColumnIndex("didyouknow"))); cursor.close(); return object; } else { return null; } } public Cursor getLocations(){ String query ="SELECT * FROM locations"; Cursor cursor = mDb.rawQuery(query, null); return cursor; } public int getLocationFromQR(String id){ String query ="SELECT * FROM locations WHERE _id = '"+id+"'"; Cursor cursor = mDb.rawQuery(query, null); if(cursor.getCount()!=0){ cursor.moveToFirst(); int locationId = cursor.getInt(cursor.getColumnIndex("_id")); return locationId; } return 0; } }