<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3589895879669164419</id><updated>2011-08-01T22:06:59.609+02:00</updated><category term='altitude'/><category term='android'/><category term='puzzle'/><category term='sql'/><category term='opensource'/><category term='game'/><category term='score'/><category term='tutorial'/><title type='text'>Bartinger and Android</title><subtitle type='html'>My apps and tutorials!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bartinger.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3589895879669164419/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://bartinger.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Bartinger</name><uri>http://www.blogger.com/profile/09358068668862098946</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_7qFdJZZupM8/TUR3DonDXvI/AAAAAAAAAE0/6o6FMD9-ASM/s1600/61755_1603307919698_1146105671_1640646_1494961_n.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3589895879669164419.post-8643178444162056248</id><published>2011-01-31T13:06:00.006+01:00</published><updated>2011-02-17T09:28:41.717+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='android'/><category scheme='http://www.blogger.com/atom/ns#' term='game'/><category scheme='http://www.blogger.com/atom/ns#' term='score'/><title type='text'>Tutorial: Locale game scores with a SQL-Database</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Create a standard Android-Project, or include the following into your game.&lt;br /&gt;At first we need a class which creates a database if it doesn't exist and can access the database.&lt;br /&gt;&lt;br /&gt;Make a new class and call it &lt;i&gt;ScoreDatabase &lt;/i&gt;and extend it from&amp;nbsp;&lt;a href="http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html"&gt;SQLiteOpenHelper&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;import android.content.Context;&lt;br /&gt;import android.database.sqlite.SQLiteDatabase;&lt;br /&gt;import android.database.sqlite.SQLiteOpenHelper;&lt;br /&gt;import android.provider.BaseColumns;&lt;br /&gt;import android.util.Log;&lt;br /&gt;import at.bartinger.scoreexample.sql.model.ScoreModel;&lt;br /&gt;&lt;br /&gt;public class ScoreDatabase extends SQLiteOpenHelper{&lt;br /&gt;&lt;br /&gt; public ScoreDatabase(Context context) {&lt;br /&gt;  super(context, "score.db", null, 1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; @Override&lt;br /&gt; public void onCreate(SQLiteDatabase db) {&lt;br /&gt;  // TODO Create your tables here&lt;br /&gt;  Log.i("ScoreExample", "Create database: " + ScoreModel.TABLE_NAME);&lt;br /&gt;  &lt;br /&gt;  /*Creates the table in the database.&lt;br /&gt;   * id: to access a single entry; for example for deleting a row&lt;br /&gt;   * value: is the score which we want to save&lt;br /&gt;   * &lt;br /&gt;   */&lt;br /&gt;  &lt;br /&gt;  db.execSQL("create table " + ScoreModel.TABLE_NAME + " (" + &lt;br /&gt;          BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +&lt;br /&gt;          ScoreModel.KEY_VALUE + " INTEGER NOT NULL," +&lt;br /&gt;          ScoreModel.KEY_TIME + " TEXT);");&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @Override&lt;br /&gt; public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;This creates a database and a table with the rows: id, value(which is the score) and the date when the score gets inserted.&lt;br /&gt;&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;The super method contains:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;the application context to create and open the database&lt;/li&gt;&lt;li&gt;the name of the database file&lt;/li&gt;&lt;li&gt;used for creating cursor objects, or null for the default&lt;/li&gt;&lt;li&gt;number of the database (starting at 1); if the database is older,&amp;nbsp;&lt;a href="http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int)" style="color: #006699;"&gt;onUpgrade(SQLiteDatabase, int, int)&lt;/a&gt;&amp;nbsp;will be used to upgrade the database&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;the onCreate gets called when the database doesn't exist and should be created&lt;/li&gt;&lt;li&gt;there we create the table with the db.execSQL(...)&lt;/li&gt;&lt;li&gt;Note: you need some SQL&amp;nbsp;knowledge, Google-skills or post a question&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Next we make a new class named ScoreModel, which contains the table and row name and some method to access the score table.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;import java.util.Date;&lt;br /&gt;&lt;br /&gt;import android.content.ContentValues;&lt;br /&gt;import android.content.Context;&lt;br /&gt;import android.database.Cursor;&lt;br /&gt;import android.provider.BaseColumns;&lt;br /&gt;import android.util.Log;&lt;br /&gt;&lt;br /&gt;public class ScoreModel extends BaseModel {&lt;br /&gt;&lt;br /&gt; public final static String TABLE_NAME = "Score";&lt;br /&gt;&lt;br /&gt; public static final String KEY_VALUE = "value";&lt;br /&gt;&lt;br /&gt; public static final String KEY_TIME = "time";&lt;br /&gt;&lt;br /&gt; public ScoreModel(final Context context) {&lt;br /&gt;  super(context, TABLE_NAME);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Cursor getAllOrdered() {&lt;br /&gt;  return database.query(TABLE_NAME, null, null, null, null, null, KEY_VALUE + " DESC");&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getAllFormated(){&lt;br /&gt;  &lt;br /&gt;  String result = "";&lt;br /&gt;&lt;br /&gt;  Cursor cursor = getAllOrdered();&lt;br /&gt;&lt;br /&gt;  for (int i = 0; i &amp;lt; cursor.getCount(); i++) {&lt;br /&gt;   if(!cursor.moveToPosition(i)){&lt;br /&gt;    break;&lt;br /&gt;   }&lt;br /&gt;   int value = cursor.getInt(cursor.getColumnIndex(ScoreModel.KEY_VALUE));&lt;br /&gt;   String time = cursor.getString(cursor.getColumnIndex(ScoreModel.KEY_TIME));&lt;br /&gt;   &lt;br /&gt;   result+= (i+1) +".     " + value + "      " + time + "\n";&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  return result;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void add(final int value) {&lt;br /&gt;  final ContentValues values = new ContentValues();&lt;br /&gt;  values.put(KEY_VALUE, value);&lt;br /&gt;  Date tmpDate = new Date();&lt;br /&gt;  String date = tmpDate.getDate() + "." + tmpDate.getMonth()+1;&lt;br /&gt;  values.put(KEY_TIME, date);&lt;br /&gt;&lt;br /&gt;  database.insert(TABLE_NAME, null, values);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @Override&lt;br /&gt; public void remove(final int id) {&lt;br /&gt;  database.delete(TABLE_NAME, BaseColumns._ID + " = " + id, null);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;BaseModel is a class by &lt;a href="http://tomtasche.at/"&gt;TomTasche&lt;/a&gt;. You can just copy it and use it for every Model you'll ever need.&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;Download it &lt;a href="http://www.bartinger.co.de/files/tutorials/sql/BaseModel.java"&gt;here&lt;/a&gt;.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Note: In the BaseModel class you have to change this line if you named your database class different&lt;/li&gt;&lt;li&gt;database = new ScoreDatabase(context).getWritableDatabase();&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;At next we create some constants (table and row names).&lt;/li&gt;&lt;li&gt;getAllOrdered() &lt;/li&gt;&lt;ul&gt;&lt;li&gt;returns a Cursor which contains all scores ordered by score (&lt;i&gt;DESC&lt;/i&gt; means highest first, &lt;i&gt;ASC&lt;/i&gt; would be lowest first)&lt;/li&gt;&lt;ul&gt;&lt;li&gt;a cursor contains the results of a database query&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;getAllFormated()&lt;/li&gt;&lt;ul&gt;&lt;li&gt;calls the getAllOrdered() and saves the results in one String&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;add()&lt;/li&gt;&lt;ul&gt;&lt;li&gt;inserts a new score into the database with&amp;nbsp;ContentValues&lt;/li&gt;&lt;li&gt;put(&lt;i&gt;rowName&lt;/i&gt;, &lt;i&gt;value&lt;/i&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;remove()&lt;/li&gt;&lt;ul&gt;&lt;li&gt;is clear i think&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;Now here is how to use this whole random stuff we created :)&lt;br /&gt;&lt;pre class="java" name="code"&gt;ScoreModel model = new ScoreModel(this);&lt;br /&gt;&lt;br /&gt; //Generate a random score ...&lt;br /&gt; int score = (int)(Math.random()*100);&lt;br /&gt; //... and insert it into the database&lt;br /&gt; model.add(score);&lt;br /&gt;&lt;br /&gt; text.setText(model.getAllFormated());&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;a href="http://2.bp.blogspot.com/_7qFdJZZupM8/TUczodf1naI/AAAAAAAAAFY/TviOT5g1oig/s1600/device.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/_7qFdJZZupM8/TUczodf1naI/AAAAAAAAAFY/TviOT5g1oig/s320/device.png" width="212" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;i&gt;text &lt;/i&gt;is a TextView. Download the full source&amp;nbsp;&lt;a href="http://www.bartinger.co.de/files/tutorials/sql/ScoreExample.zip"&gt;here&lt;/a&gt;. Looks like this &amp;gt;&lt;/div&gt;&lt;br /&gt;DONE!!!&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;If you like it please share leave a comment :)&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Regards Bartinger!&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3589895879669164419-8643178444162056248?l=bartinger.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bartinger.blogspot.com/feeds/8643178444162056248/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bartinger.blogspot.com/2011/01/tutorial-locale-scores-with-sql.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3589895879669164419/posts/default/8643178444162056248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3589895879669164419/posts/default/8643178444162056248'/><link rel='alternate' type='text/html' href='http://bartinger.blogspot.com/2011/01/tutorial-locale-scores-with-sql.html' title='Tutorial: Locale game scores with a SQL-Database'/><author><name>Bartinger</name><uri>http://www.blogger.com/profile/09358068668862098946</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_7qFdJZZupM8/TUR3DonDXvI/AAAAAAAAAE0/6o6FMD9-ASM/s1600/61755_1603307919698_1146105671_1640646_1494961_n.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_7qFdJZZupM8/TUczodf1naI/AAAAAAAAAFY/TviOT5g1oig/s72-c/device.png' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3589895879669164419.post-2870007410272496789</id><published>2011-01-29T21:20:00.002+01:00</published><updated>2011-01-31T23:51:16.925+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='puzzle'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='altitude'/><category scheme='http://www.blogger.com/atom/ns#' term='opensource'/><category scheme='http://www.blogger.com/atom/ns#' term='android'/><title type='text'>Welcome back :)</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Hey guys!&lt;br /&gt;I was very lazy the last few months in terms of writing for my blog. But now all my test are over and have time again be more active here. Currently I'm working on a two main projects.&lt;br /&gt;&lt;br /&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;Altitude&lt;/li&gt;&lt;li&gt;A 3D puzzle game&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Altitude&lt;/b&gt; will be a condition based settings app. So you determine some conditions, like location or time and based on this the app will change the settings (wifi, mobile data, brightness, screen timeout) of your phone.&amp;nbsp;&amp;nbsp;You might know &lt;a href="http://www.twofortyfouram.com/"&gt;Locale&lt;/a&gt;. I'm working on an app, which&amp;nbsp;generally will hopefully be able to do the same. I decided to release&amp;nbsp;&amp;nbsp;it for FREE in the Android Market and also push the source code up to &lt;a href="https://github.com/Bartinger"&gt;GitHub&lt;/a&gt;.&amp;nbsp;&lt;a href="http://tomtasche.at/"&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 11px;"&gt;♥&lt;/span&gt;OpenSource&lt;span class="Apple-style-span" style="color: #333333; font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 11px;"&gt;♥&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://sphotos.ak.fbcdn.net/hphotos-ak-snc6/hs058.snc6/168800_1771396641811_1146105671_1983304_2191506_n.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="212" src="http://sphotos.ak.fbcdn.net/hphotos-ak-snc6/hs058.snc6/168800_1771396641811_1146105671_1983304_2191506_n.jpg" width="320" /&gt;&lt;/a&gt;The second project is just int the early stages of development and will be an puzzle game where you try to move a block into a whole.&lt;/div&gt;&lt;div&gt;This is a (very early) screenshot =&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I think at first I will finish &lt;b&gt;Altitude&lt;/b&gt; and the go on with my puzzle game.&lt;/div&gt;&lt;div&gt;I also decided to make some Android Code &lt;b&gt;tutorials&lt;/b&gt;, because I want to help you and also i want to improve my&amp;nbsp;English-skills and I thought that would be a good training. So stay tuned.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you have any questions, suggestions or ideas for Altitude, tutorials or something else please comment or feel free to &lt;a href="mailto:domiii.1992@gmail.com"&gt;contact me&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;If you like it please share and leave a comment:)&lt;/div&gt;&lt;div&gt;Regards Bartinger!&lt;br /&gt;&lt;br /&gt;PS: &lt;a href="http://twitter.com/#!/DevBartinger"&gt;Stay updated on Twitter!&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3589895879669164419-2870007410272496789?l=bartinger.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bartinger.blogspot.com/feeds/2870007410272496789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bartinger.blogspot.com/2011/01/welcome-back.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3589895879669164419/posts/default/2870007410272496789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3589895879669164419/posts/default/2870007410272496789'/><link rel='alternate' type='text/html' href='http://bartinger.blogspot.com/2011/01/welcome-back.html' title='Welcome back :)'/><author><name>Bartinger</name><uri>http://www.blogger.com/profile/09358068668862098946</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_7qFdJZZupM8/TUR3DonDXvI/AAAAAAAAAE0/6o6FMD9-ASM/s1600/61755_1603307919698_1146105671_1640646_1494961_n.jpg'/></author><thr:total>0</thr:total></entry></feed>
