Clean up from comments, enable throttling.
Change-Id: I719b0491a7953ab57d76634699c6fdf3ad8558e0
This commit is contained in:
@@ -344,6 +344,7 @@
|
||||
|
||||
<!-- Loader Samples -->
|
||||
|
||||
<!-- BEGIN_INCLUDE(loader_throttle) -->
|
||||
<activity android:name=".app.LoaderThrottle"
|
||||
android:label="@string/loader_throttle">
|
||||
<intent-filter>
|
||||
@@ -353,6 +354,7 @@
|
||||
</activity>
|
||||
<provider android:name=".app.LoaderThrottle$SimpleProvider"
|
||||
android:authorities="com.example.android.apis.app.LoaderThrottle" />
|
||||
<!-- END_INCLUDE(loader_throttle) -->
|
||||
|
||||
<!-- Intent Samples -->
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.example.android.apis.app;
|
||||
|
||||
//BEGIN_INCLUDE(complete)
|
||||
import android.app.Activity;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.ListFragment;
|
||||
@@ -29,6 +30,7 @@ import android.content.CursorLoader;
|
||||
import android.content.Loader;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
@@ -87,11 +89,6 @@ public class LoaderThrottle extends Activity {
|
||||
public static final Uri CONTENT_ID_URI_BASE
|
||||
= Uri.parse("content://" + AUTHORITY + "/main/");
|
||||
|
||||
/**
|
||||
* 0-relative position of a main ID segment in the path part of a main ID URI
|
||||
*/
|
||||
public static final int MAIN_ID_PATH_POSITION = 1;
|
||||
|
||||
/**
|
||||
* The MIME type of {@link #CONTENT_URI}.
|
||||
*/
|
||||
@@ -227,8 +224,9 @@ public class LoaderThrottle extends Activity {
|
||||
case MAIN_ID:
|
||||
// The incoming URI is for a single row.
|
||||
qb.setProjectionMap(mNotesProjectionMap);
|
||||
qb.appendWhere(MainTable._ID + "=" + uri.getPathSegments().get(
|
||||
MainTable.MAIN_ID_PATH_POSITION));
|
||||
qb.appendWhere(MainTable._ID + "=?");
|
||||
selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
|
||||
new String[] { uri.getLastPathSegment() });
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -322,14 +320,8 @@ public class LoaderThrottle extends Activity {
|
||||
case MAIN_ID:
|
||||
// If URI is for a particular row ID, delete is based on incoming
|
||||
// data but modified to restrict to the given ID.
|
||||
finalWhere = MainTable._ID + " = " + uri.getPathSegments().get(
|
||||
MainTable.MAIN_ID_PATH_POSITION);
|
||||
|
||||
if (where != null) {
|
||||
// Combine with incoming where, if specified.
|
||||
finalWhere = finalWhere + " AND " + where;
|
||||
}
|
||||
|
||||
finalWhere = DatabaseUtils.concatenateWhere(
|
||||
MainTable._ID + " = " + ContentUris.parseId(uri), where);
|
||||
count = db.delete(MainTable.TABLE_NAME, finalWhere, whereArgs);
|
||||
break;
|
||||
|
||||
@@ -360,14 +352,8 @@ public class LoaderThrottle extends Activity {
|
||||
case MAIN_ID:
|
||||
// If URI is for a particular row ID, update is based on incoming
|
||||
// data but modified to restrict to the given ID.
|
||||
finalWhere = MainTable._ID + " = " + uri.getPathSegments().get(
|
||||
MainTable.MAIN_ID_PATH_POSITION);
|
||||
|
||||
if (where != null) {
|
||||
// Combine with incoming where, if specified.
|
||||
finalWhere = finalWhere + " AND " + where;
|
||||
}
|
||||
|
||||
finalWhere = DatabaseUtils.concatenateWhere(
|
||||
MainTable._ID + " = " + ContentUris.parseId(uri), where);
|
||||
count = db.update(MainTable.TABLE_NAME, values, finalWhere, whereArgs);
|
||||
break;
|
||||
|
||||
@@ -413,7 +399,7 @@ public class LoaderThrottle extends Activity {
|
||||
@Override public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
setEmptyText("No data");
|
||||
setEmptyText("No data. Select 'Populate' to fill with data from Z to A at a rate of 4 per second.");
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// Create an empty adapter we will use to display the loaded data.
|
||||
@@ -499,7 +485,7 @@ public class LoaderThrottle extends Activity {
|
||||
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
CursorLoader cl = new CursorLoader(getActivity(), MainTable.CONTENT_URI,
|
||||
PROJECTION, null, null, null);
|
||||
//cl.setUpdateThrottle(2000); // update at most every 2 seconds.
|
||||
cl.setUpdateThrottle(2000); // update at most every 2 seconds.
|
||||
return cl;
|
||||
}
|
||||
|
||||
@@ -512,3 +498,4 @@ public class LoaderThrottle extends Activity {
|
||||
}
|
||||
}
|
||||
}
|
||||
//END_INCLUDE(complete)
|
||||
|
||||
Reference in New Issue
Block a user