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())
{
/**
* 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.
/**
*
* 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"
+ ");");
}
// 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);
}
// 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.
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;
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;
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
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) {
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);
}
}