The first insert in my database.
authorgumartinm <gu.martinm@gmail.com>
Mon, 13 Feb 2012 07:19:21 +0000 (08:19 +0100)
committergumartinm <gu.martinm@gmail.com>
Mon, 13 Feb 2012 07:19:21 +0000 (08:19 +0100)
Android/AndroidTetris/src/de/android/androidtetris/DrawView.java
Android/Testing/Test3/src/de/android/test3/Indexer.java
Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java
Android/Testing/Test3/src/de/android/test3/IndexerProvider.java
Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java
Android/Testing/Test3/src/de/android/test3/NextActivity.java

index c4a1e76..1a2e892 100644 (file)
@@ -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())
                        {
index 05791f9..bbccaad 100644 (file)
@@ -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.
index 55a4e0d..d34a44f 100644 (file)
@@ -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"
                                + ");");
        }
index aa6cff2..f3abcc9 100644 (file)
@@ -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<String, String>();
+
+        // 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;
index fe94fe6..2f349ee 100644 (file)
@@ -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) {
index 9b84d2d..e148335 100644 (file)
@@ -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);
     }
 }