From: gumartinm Date: Mon, 13 Feb 2012 07:19:21 +0000 (+0100) Subject: The first insert in my database. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=cb204967921584a166bf971ab3aa1bd9aa3770c5;p=JavaForFun The first insert in my database. --- diff --git a/Android/AndroidTetris/src/de/android/androidtetris/DrawView.java b/Android/AndroidTetris/src/de/android/androidtetris/DrawView.java index c4a1e76..1a2e892 100644 --- a/Android/AndroidTetris/src/de/android/androidtetris/DrawView.java +++ b/Android/AndroidTetris/src/de/android/androidtetris/DrawView.java @@ -49,8 +49,9 @@ public class DrawView extends SurfaceView { try { Thread.sleep(1000); } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + // This code implements the thread's interruption policy. It may swallow the + // interruption request. Java Concurrency in Practice §7.1.3 + // TODO: I should finish the process in this case. } synchronized (view.getHolder()) { diff --git a/Android/Testing/Test3/src/de/android/test3/Indexer.java b/Android/Testing/Test3/src/de/android/test3/Indexer.java index 05791f9..bbccaad 100644 --- a/Android/Testing/Test3/src/de/android/test3/Indexer.java +++ b/Android/Testing/Test3/src/de/android/test3/Indexer.java @@ -38,7 +38,7 @@ public final class Indexer { /** * The default sort order for this table */ - public static final String DEFAULT_SORT_ORDER = "by " + Index._ID; + public static final String DEFAULT_SORT_ORDER = Index._ID; /** * The MIME type of {@link #CONTENT_URI} providing a directory of notes. diff --git a/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java b/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java index 55a4e0d..d34a44f 100644 --- a/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java +++ b/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java @@ -21,13 +21,13 @@ public class IndexerOpenHelper extends SQLiteOpenHelper { /** * * Creates the underlying database with table name and column names taken from the - * NotePad class. + * Indexer class. */ @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + Indexer.Index.TABLE_NAME + " (" + Indexer.Index._ID + " INTEGER PRIMARY KEY, " - + Indexer.Index.COLUMN_NAME_ID_AD + " REAL" + " UNIQUE" + "NOT NULL" + + Indexer.Index.COLUMN_NAME_ID_AD + " INTEGER" + " UNIQUE" + " NOT NULL," + Indexer.Index.COLUMN_NAME_PATH + " TEXT(15)" + " UNIQUE" + " NOT NULL" + ");"); } diff --git a/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java b/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java index aa6cff2..f3abcc9 100644 --- a/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java +++ b/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java @@ -47,6 +47,24 @@ public class IndexerProvider extends ContentProvider { // Add a pattern that routes URIs terminated with "indexer" plus an integer // to a index ID operation sUriMatcher.addURI("de.android.test3.provider", Indexer.Index.TABLE_NAME + "/#", INDEXER_ID); + + + /* + * Creates and initializes a projection map that returns all columns + */ + + // Creates a new projection map instance. The map returns a column name + // given a string. The two are usually equal. + sIndexerProjectionMap = new HashMap(); + + // Maps the string "_ID" to the column name "_ID" + sIndexerProjectionMap.put(Indexer.Index._ID, Indexer.Index._ID); + + // Maps "idad" to "idad" + sIndexerProjectionMap.put(Indexer.Index.COLUMN_NAME_ID_AD, Indexer.Index.COLUMN_NAME_ID_AD); + + // Maps "path" to "path" + sIndexerProjectionMap.put(Indexer.Index.COLUMN_NAME_PATH, Indexer.Index.COLUMN_NAME_PATH); } @@ -198,11 +216,9 @@ public class IndexerProvider extends ContentProvider { // Performs the insert and returns the ID of the new note. long rowId = db.insert( - Indexer.Index.COLUMN_NAME_ID_AD, // The table to insert into. - Indexer.Index.COLUMN_NAME_PATH, // A hack, SQLite sets this column value to null - // if values is empty. - values // A map of column names, and the values to insert - // into the columns. + Indexer.Index.TABLE_NAME, // The table to insert into. + null, // A hack, SQLite sets this column value to null if values is empty. + values // A map of column names, and the values to insert into the columns. ); // If the insert succeeded, the row ID exists. @@ -292,6 +308,7 @@ public class IndexerProvider extends ContentProvider { orderBy // The sort order ); + // Tells the Cursor what URI to watch, so it knows when its source data changes c.setNotificationUri(getContext().getContentResolver(), uri); return c; diff --git a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java index fe94fe6..2f349ee 100644 --- a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java +++ b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java @@ -21,7 +21,10 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; -import android.content.ContentUris; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; import android.net.Uri; import android.net.http.AndroidHttpClient; import android.util.Log; @@ -34,11 +37,13 @@ public class MobieAdHttpClient implements Runnable private final Random random = new Random(); private final URL url; private final AndroidHttpClient httpClient; + private final Context context; - public MobieAdHttpClient(final String cookie, final URL url, final AndroidHttpClient httpClient) { + public MobieAdHttpClient(final String cookie, final URL url, final AndroidHttpClient httpClient, Context context) { this.cookie = cookie; this.url = url; this.httpClient = httpClient; + this.context = context; } @Override @@ -90,12 +95,12 @@ public class MobieAdHttpClient implements Runnable JSONArray finalResult = new JSONArray(tokener); for (int i = 0; i < finalResult.length(); i++) { JSONObject objects = finalResult.getJSONObject(i); - IndexerProvider databaseIndexer = new IndexerProvider(); - Uri.Builder prueba = new Uri.Builder(); - prueba.encodedAuthority("de.android.test3.provider"); - prueba.encodedPath("indexer"); - prueba.appendQueryParameter("id", (String) objects.get("id")); - databaseIndexer.query(prueba.build(), null, null, null, null); + ContentValues values = new ContentValues(); + values.put(Indexer.Index.COLUMN_NAME_PATH, "18188181"); + values.put(Indexer.Index.COLUMN_NAME_ID_AD, "22"); + Uri probando = Uri.parse("content://" + "de.android.test3.provider" + "/" + "indexer"); + this.context.getContentResolver().insert(probando, values); + Cursor cursor = this.context.getContentResolver().query(probando, null, null, null, null); downloadAds((Integer) objects.get("id"), (String)objects.get("domain"), (String)objects.get("link")); } } catch (URISyntaxException e) { diff --git a/Android/Testing/Test3/src/de/android/test3/NextActivity.java b/Android/Testing/Test3/src/de/android/test3/NextActivity.java index 9b84d2d..e148335 100644 --- a/Android/Testing/Test3/src/de/android/test3/NextActivity.java +++ b/Android/Testing/Test3/src/de/android/test3/NextActivity.java @@ -127,7 +127,7 @@ public class NextActivity extends Activity { Log.e(TAG, "Error while creating a URL", e); return; } - webServiceConnection = new MobieAdHttpClient(this.myCookie, url, httpClient); + webServiceConnection = new MobieAdHttpClient(this.myCookie, url, httpClient, this); this.exec.execute(webServiceConnection); } }