hm-lok

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/hm-lok.git
Log | Files | Refs

commit 71200e251d69a7991c4ed36aa255c866edabdf1b
parent 95342a989706a16b8604118b81e7b34ae98401f8
Author: dankert <devnull@localhost>
Date:   Thu, 15 Sep 2011 00:00:23 +0200

Nächste Ausbaustufe mit Listview und Intents wie Navigation, Maps.

Diffstat:
AndroidManifest.xml | 9++++++---
res/drawable/hm_icon.jpg | 0
res/drawable/hm_logo.jpg | 0
res/drawable/hm_logo_tp.gif | 0
res/layout/main.xml | 11+++++------
res/layout/pvo.xml | 16++++++++++++++++
res/layout/pvo_detail.xml | 28++++++++++++++++++++++++++++
res/layout/pvo_entry.xml | 25+++++++++++++++++++++++++
res/menu/detail.xml | 6++++++
res/values/strings.xml | 5+++++
res/values/styles.xml | 11++++++++++-
src/de/jandankert/hansemerkur/HM.java | 6++----
src/de/jandankert/hansemerkur/PVODetail.java | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/jandankert/hansemerkur/PVOList.java | 253+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/jandankert/hansemerkur/adapter/PVOCursorAdapter.java | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/jandankert/hansemerkur/db/DataBaseHelper.java | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16 files changed, 688 insertions(+), 14 deletions(-)

diff --git a/AndroidManifest.xml b/AndroidManifest.xml @@ -3,7 +3,7 @@ package="de.jandankert.hansemerkur" android:versionCode="1" android:versionName="1.0"> - <application android:theme="@style/HMDesign" android:icon="@drawable/mini" android:label="@string/app_name"> + <application android:theme="@style/HMDesign" android:icon="@drawable/hm_icon" android:label="@string/app_name"> <activity android:name=".HM" android:label="@string/app_name"> <intent-filter> @@ -12,11 +12,14 @@ </intent-filter> </activity> - </application> + <activity android:name=".PVOList" /> + <activity android:name=".PVODetail" /> + +</application> -<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> +<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <!-- Android 1.6 --> <uses-sdk android:minSdkVersion="4"></uses-sdk> diff --git a/res/drawable/hm_icon.jpg b/res/drawable/hm_icon.jpg Binary files differ. diff --git a/res/drawable/hm_logo.jpg b/res/drawable/hm_logo.jpg Binary files differ. diff --git a/res/drawable/hm_logo_tp.gif b/res/drawable/hm_logo_tp.gif Binary files differ. diff --git a/res/layout/main.xml b/res/layout/main.xml @@ -5,13 +5,12 @@ <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> - <ImageView android:src="@drawable/text_logo" - android:background="#B9DCCA" android:layout_width="fill_parent" - android:layout_height="wrap_content" /> + <ImageView android:src="@drawable/hm_logo_tp" + android:background="#B9DCCA" android:padding="20sp" android:layout_height="30sp" android:scaleType="fitXY" android:layout_width="60sp"/> <Button android:id="@+id/button_pvo" android:text="@string/pvo" - android:layout_width="fill_parent" android:layout_height="wrap_content" /> - <Button android:id="@+id/button_www" android:text="@string/website" - android:layout_width="fill_parent" android:layout_height="wrap_content" /> + android:layout_width="fill_parent" android:layout_height="wrap_content" style="@style/HMButton" android:layout_margin="20sp"/> + <Button android:id="@+id/button_www" android:text="@string/website" style="@style/HMButton" + android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="20sp"/> </LinearLayout> diff --git a/res/layout/pvo.xml b/res/layout/pvo.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + + <ListView + android:id="@id/android:list" + android:textSize="25sp" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:clickable="true" android:longClickable="true" + > + </ListView> + +</LinearLayout> diff --git a/res/layout/pvo_detail.xml b/res/layout/pvo_detail.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + <TextView android:text="@+id/TextView01" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_title" + android:textSize="30px"></TextView> + <TextView android:text="@+id/TextView02" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_name" + android:textSize="14px"></TextView> + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_str" + android:textSize="14px"></TextView> + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_plz" + android:textSize="14px"></TextView> + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_ort" + android:textSize="14px"></TextView> + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_entfernung" + android:textSize="14px"></TextView> + + <Button android:id="@+id/details" android:text="@string/phone" + android:layout_width="fill_parent" android:layout_height="wrap_content" /> + +</LinearLayout> diff --git a/res/layout/pvo_entry.xml b/res/layout/pvo_entry.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" android:layout_width="fill_parent" + android:layout_height="fill_parent" android:focusable="false" > + + <TextView android:text="@+id/TextView01" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_name" + android:textSize="30px"></TextView> + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_str" + android:textSize="14px"></TextView> + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_ort" + android:textSize="14px"></TextView> + <TextView android:text="@+id/TextView03" android:layout_width="wrap_content" + android:layout_height="wrap_content" android:id="@+id/pvo_entfernung" + android:focusable="false" android:clickable="true" android:longClickable="true" android:textSize="14px"></TextView> + + <!-- + <Button android:id="@+id/details" android:text="@string/phone" + android:layout_width="fill_parent" + android:layout_height="wrap_content" /> + --> + +</LinearLayout> diff --git a/res/menu/detail.xml b/res/menu/detail.xml @@ -0,0 +1,6 @@ +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@+id/item01" android:title="@string/end"></item> + <item android:id="@+id/itemNav" android:title="@string/navigate"></item> + <item android:id="@+id/itemMap" android:title="@string/map"></item> + <item android:id="@+id/itemCall" android:title="@string/phone"></item> +</menu> diff --git a/res/values/strings.xml b/res/values/strings.xml @@ -6,4 +6,9 @@ <string name="pvo">Partner vor Ort</string> <string name="website">Webseite</string> + <string name="phone">Anrufen</string> + <string name="map">Karte</string> + <string name="navigate">Navigiere zu</string> + <string name="no_location_available">Keine Position verfügbar</string> + </resources> diff --git a/res/values/styles.xml b/res/values/styles.xml @@ -9,7 +9,7 @@ <item name="windowFrame"> @drawable/scr_sm_hintergrund</item> --> -<!-- + <!-- <item name="panelForegroundColor"> #FF000000 </item> @@ -18,4 +18,13 @@ <item name="panelTextColor"> ?panelForegroundColor </item> --> </style> + + + <style name="HMButton" parent="HMDesign"> + <!-- + <item name="android:border">#006633</item> + --> + + + </style> </resources> \ No newline at end of file diff --git a/src/de/jandankert/hansemerkur/HM.java b/src/de/jandankert/hansemerkur/HM.java @@ -29,7 +29,7 @@ public class HM extends Activity @Override public void onClick(View v) { - final String url = "http://www.hansemerkur.de/partner-vor-ort"; + final String url = "http://www.hansemerkur.de"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); @@ -42,9 +42,7 @@ public class HM extends Activity @Override public void onClick(View v) { - final String url = "http://www.hansemerkur.de/service/kontakt/partner"; - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse(url)); + final Intent i = new Intent(HM.this,PVOList.class); startActivity(i); } }); diff --git a/src/de/jandankert/hansemerkur/PVODetail.java b/src/de/jandankert/hansemerkur/PVODetail.java @@ -0,0 +1,99 @@ +package de.jandankert.hansemerkur; + +import android.app.Activity; +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.widget.Toast; + +public class PVODetail extends Activity +{ + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.pvo_detail); + + } + + public boolean onCreateOptionsMenu(Menu menu) + { + super.onCreateOptionsMenu(menu); + MenuInflater mi = new MenuInflater(getApplication()); + mi.inflate(R.menu.detail, menu); + + return true; + } + + public boolean onOptionsItemSelected(MenuItem item) + { + switch (item.getItemId()) + { + case R.id.itemCall: + try + { + Intent callIntent = new Intent(Intent.ACTION_DIAL); + callIntent.setData(Uri.parse("tel:+494041190")); + startActivity(callIntent); + + } catch (ActivityNotFoundException e) + { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); + } + break; + + case R.id.itemNav: + try + { + Intent i = new Intent( + Intent.ACTION_VIEW, + Uri + .parse("google.navigation:q=Germany,Siegfried-Wedells-Platz+1,Hamburg")); + startActivity(i); + } catch (ActivityNotFoundException e) + { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); + } + break; + + case R.id.itemMap: + + try + { + String uri = "geo:0,0?q=Germany,Siegfried-Wedells-Platz+1,Hamburg"; + startActivity(new Intent(android.content.Intent.ACTION_VIEW, + Uri.parse(uri))); + } catch (ActivityNotFoundException e) + { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); + } + break; + + case R.id.item01: + super.finish(); + break; + default: + + } + return true; + + // Intent i = new Intent(Intent.ACTION_VIEW, Uri + // .parse("google.navigation:q=New+York")); + // startActivity(i); + + // Intent callIntent = new Intent(Intent.ACTION_CALL); + // callIntent.setData(Uri.parse("tel:123456789")); + // startActivity(callIntent); + + // String uri = "geo:"+ latitude + "," + longitude; + // startActivity(new Intent(android.content.Intent.ACTION_VIEW, + // Uri.parse(uri))); + + } + +}+ \ No newline at end of file diff --git a/src/de/jandankert/hansemerkur/PVOList.java b/src/de/jandankert/hansemerkur/PVOList.java @@ -0,0 +1,252 @@ +package de.jandankert.hansemerkur; + +import java.io.IOException; + +import android.app.AlertDialog; +import android.app.ListActivity; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.location.Location; +import android.location.LocationManager; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CursorAdapter; +import android.widget.ListView; +import android.widget.Toast; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.AdapterView.OnItemLongClickListener; +import de.jandankert.hansemerkur.adapter.PVOCursorAdapter; +import de.jandankert.hansemerkur.db.DataBaseHelper; + +public class PVOList extends ListActivity +{ + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.pvo); + + /* + * + * DataBaseHelper myDbHelper = new DataBaseHelper(); myDbHelper = new + * DataBaseHelper(this); + * + * try { + * + * myDbHelper.createDataBase(); + * + * } catch (IOException ioe) { + * + * throw new Error("Unable to create database"); + * + * } + * + * try { + * + * myDbHelper.openDataBase(); + * + * }catch(SQLException sqle){ + * + * throw sqle; + * + * } + */ + + Location loc = getLocation(); + + DataBaseHelper db = new DataBaseHelper(this); + try + { + db.createDataBase(); + } catch (IOException e) + { + throw new RuntimeException(e); + } + db.openDataBase(); + SQLiteDatabase database = db.getReadableDatabase(); + + double lat = 50.0; + double lon = 10.3; + if (loc != null) + { + + lat = loc.getLatitude(); + lon = loc.getLongitude(); + } else + { + new AlertDialog.Builder(this).setTitle( + getResources().getString(R.string.no_location_available)) + .show(); + // Toast.makeText(this, + // getResources().getString(R.string.no_location_available), + // Toast.LENGTH_LONG).show(); + } + Toast.makeText(this, "Suche wird gestartet", Toast.LENGTH_SHORT).show(); + + double laengeLaengengrad = 40000 / 360; + double laengeBreitengrad = laengeLaengengrad + * Math.cos(Math.cos(Math.toRadians(lat))); + laengeBreitengrad = 67; + + final String sql = "SELECT " + + "(? * (?-plz.lat)* ? * (?-plz.lat)) + (? * (? - plz.lon)*(? * (? - plz.lon))) AS entfernung," + + "vms.strasse,vms.plz,vms.ort,vms.vorname,vms.nachname," + + " vms.plz as _id" + " FROM vms" + + " left join plz on vms.plz=plz.plz" + + " where lon is not null and entfernung < (100*100)" + + " order by entfernung"; + + String[] param = new String[] { "" + laengeBreitengrad, "" + lat, + "" + laengeBreitengrad, "" + lat, "" + laengeLaengengrad, + "" + lon, "" + laengeLaengengrad, "" + lon }; + + Cursor cursor = database.rawQuery(sql, param); + + for (String c : cursor.getColumnNames()) + { + + System.out.println("***" + c); + } + + startManagingCursor(cursor); + + // Create an array of Strings, that will be put to our ListActivity + String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse", + "Ubuntu", "Solaris", "Android", "iPhone" }; + // Create an ArrayAdapter, that will actually make the Strings above + // appear in the ListView + // this.setListAdapter(new ArrayAdapter<String>(this, + // R.layout.pvo_entry,R.id.pvo_title, names)); + + String[] from = new String[] { "Ort", "entfernung", "Nachname", "Plz", + "Strasse", "Nachname" }; + int[] to = new int[] { R.id.pvo_ort, R.id.pvo_entfernung, + R.id.pvo_name, R.id.pvo_plz, R.id.pvo_str, R.id.pvo_title }; + + // Now create an array adapter and set it to display using our row + CursorAdapter pvoAdapter = new PVOCursorAdapter(this, cursor); + // CursorAdapter notes = new SimpleCursorAdapter(this, + // R.layout.pvo_entry,cursor,from,to); + + // if ( cursor.isAfterLast() ) { + // + // Toast.makeText(this, "Nichts gefunden", Toast.LENGTH_SHORT).show(); + // } + + ListView list = getListView(); + // list.settou + list.setOnItemLongClickListener(new OnItemLongClickListener() + { + + @Override + public boolean onItemLongClick(AdapterView<?> parent, View view, + int position, long id) + { + System.out.println("long clicked"); + Toast.makeText(PVOList.this, + "Item in position " + position + " long clicked", + Toast.LENGTH_LONG).show(); + // Return true to consume the click event. In this case the + // onListItemClick listener is not called anymore. + return true; + } + }); + list.setOnItemClickListener(new OnItemClickListener() + { + + @Override + public void onItemClick(AdapterView<?> parent, View view, + int position, long id) + { +// System.out.println("short clicked"); + Toast.makeText(PVOList.this, + "Item in position " + position + " short clicked", + Toast.LENGTH_LONG).show(); + + + final Intent i = new Intent(PVOList.this,PVODetail.class); + startActivity(i); + } + }); + + // list.setItemsCanFocus(false); + setListAdapter(pvoAdapter); + + } + + // @Override + // protected void onStop() + // { + // super.stop(); + // } + + private Location getLocation() + { + LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + Location loc = lm + .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + + return loc; + } + + @Override + public boolean onSearchRequested() + { + // TODO Auto-generated method stub + return super.onSearchRequested(); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) + { + super.onListItemClick(l, v, position, id); + // Get the item that was clicked + Object o = this.getListAdapter().getItem(position); + String keyword = o.toString(); + Toast.makeText(this, "You selected with short click: " + keyword, + Toast.LENGTH_LONG).show(); + + // Intent i = new Intent(Intent.ACTION_VIEW, Uri + // .parse("google.navigation:q=New+York")); + // startActivity(i); + + // Intent callIntent = new Intent(Intent.ACTION_CALL); + // callIntent.setData(Uri.parse("tel:123456789")); + // startActivity(callIntent); + + // String uri = "geo:"+ latitude + "," + longitude; + // startActivity(new Intent(android.content.Intent.ACTION_VIEW, + // Uri.parse(uri))); + } + + public boolean onCreateOptionsMenu(Menu menu) + { + super.onCreateOptionsMenu(menu); + MenuInflater mi = new MenuInflater(getApplication()); + mi.inflate(R.menu.menu, menu); + + return true; + } + + public boolean onOptionsItemSelected(MenuItem item) + { + switch (item.getItemId()) + { + case R.id.item01: + super.finish(); + break; + default: + + } + return true; + } + +}+ \ No newline at end of file diff --git a/src/de/jandankert/hansemerkur/adapter/PVOCursorAdapter.java b/src/de/jandankert/hansemerkur/adapter/PVOCursorAdapter.java @@ -0,0 +1,78 @@ +package de.jandankert.hansemerkur.adapter; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +import de.jandankert.hansemerkur.PVOList; +import de.jandankert.hansemerkur.R; +import de.jandankert.hansemerkur.R.id; +import de.jandankert.hansemerkur.R.layout; + +import android.content.Context; +import android.database.Cursor; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.View.OnClickListener; +import android.widget.CursorAdapter; +import android.widget.TextView; +import android.widget.Toast; + +public class PVOCursorAdapter extends CursorAdapter +{ + + public PVOCursorAdapter(Context context, Cursor c) + { + super(context, c); + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) + { + LayoutInflater layoutInflater = LayoutInflater.from(context); + + View view = layoutInflater.inflate(R.layout.pvo_entry, parent, false); + + view.setFocusable(false); + return view; + + //return layoutInflater.inflate(R.layout.pvo_entry, parent, false); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) + { +// view.setOnClickListener( new OnClickListener() +// { +// +// @Override +// public void onClick(View v) +// { +// System.out.println("short clicked"); +// Toast.makeText(v.getContext(), +// "Item in unknown position short clicked in Adapter", +// Toast.LENGTH_LONG).show(); +// } +// }); + //view.setClickable(false); + view.setFocusable(false); + + TextView entfernung = (TextView) view.findViewById(R.id.pvo_entfernung); + entfernung.setText("Ca. " + + new BigDecimal(Math.sqrt(cursor.getDouble(cursor + .getColumnIndexOrThrow("entfernung")))).setScale(1,RoundingMode.CEILING) + .toString() + " km"); + + TextView name = (TextView) view.findViewById(R.id.pvo_name); + name.setText(cursor.getString(cursor.getColumnIndexOrThrow("Vorname")) + + " " + + cursor.getString(cursor.getColumnIndexOrThrow("Nachname"))); + TextView str = (TextView) view.findViewById(R.id.pvo_str); + str.setText(cursor.getString(cursor.getColumnIndexOrThrow("Strasse"))); + + TextView ort = (TextView) view.findViewById(R.id.pvo_ort); + ort.setText(cursor.getString(cursor.getColumnIndexOrThrow("Plz"))+ " " + cursor.getString(cursor.getColumnIndexOrThrow("Ort"))); + } + + +} diff --git a/src/de/jandankert/hansemerkur/db/DataBaseHelper.java b/src/de/jandankert/hansemerkur/db/DataBaseHelper.java @@ -0,0 +1,153 @@ +package de.jandankert.hansemerkur.db; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import android.content.Context; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteException; +import android.database.sqlite.SQLiteOpenHelper; + +public class DataBaseHelper extends SQLiteOpenHelper{ + + //The Android's default system path of your application database. + private static String DB_PATH = "/data/data/de.jandankert.hansemerkur/databases/"; + + private static String DB_NAME = "hm.db"; + + private SQLiteDatabase myDataBase; + + private final Context myContext; + + /** + * Constructor + * Takes and keeps a reference of the passed context in order to access to the application assets and resources. + * @param context + */ + public DataBaseHelper(Context context) { + + super(context, DB_NAME, null, 1); + this.myContext = context; + } + + /** + * Creates a empty database on the system and rewrites it with your own database. + * */ + public void createDataBase() throws IOException{ + + boolean dbExist = checkDataBase(); + + if(dbExist){ + //do nothing - database already exist + }else{ + + //By calling this method and empty database will be created into the default system path + //of your application so we are gonna be able to overwrite that database with our database. + this.getReadableDatabase(); + + try { + + copyDataBase(); + + } catch (IOException e) { + + throw new Error("Error copying database"); + + } + } + + } + + /** + * Check if the database already exist to avoid re-copying the file each time you open the application. + * @return true if it exists, false if it doesn't + */ + private boolean checkDataBase(){ + + SQLiteDatabase checkDB = null; + + try{ + String myPath = DB_PATH + DB_NAME; + checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS); + + }catch(SQLiteException e){ + + //database does't exist yet. + + } + + if(checkDB != null){ + + checkDB.close(); + + } + + return checkDB != null ? true : false; + } + + /** + * Copies your database from your local assets-folder to the just created empty database in the + * system folder, from where it can be accessed and handled. + * This is done by transfering bytestream. + * */ + private void copyDataBase() throws IOException{ + + //Open your local db as the input stream + InputStream myInput = myContext.getAssets().open(DB_NAME); + + // Path to the just created empty db + String outFileName = DB_PATH + DB_NAME; + + //Open the empty db as the output stream + OutputStream myOutput = new FileOutputStream(outFileName); + + //transfer bytes from the inputfile to the outputfile + byte[] buffer = new byte[1024]; + int length; + while ((length = myInput.read(buffer))>0){ + myOutput.write(buffer, 0, length); + } + + //Close the streams + myOutput.flush(); + myOutput.close(); + myInput.close(); + + } + + public void openDataBase() throws SQLException{ + + //Open the database + String myPath = DB_PATH + DB_NAME; + myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY|SQLiteDatabase.NO_LOCALIZED_COLLATORS); + + } + + @Override + public synchronized void close() { + + if(myDataBase != null) + myDataBase.close(); + + super.close(); + + } + + @Override + public void onCreate(SQLiteDatabase db) { + + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } + + // Add your public helper methods to access and get content from the database. + // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy + // to you to create adapters for your views. + +}+ \ No newline at end of file