• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

development


Commit MetaInfo

修订版69c72dfdf901e07a132f3ad4856c2058e5efa2e9 (tree)
时间2011-01-09 11:34:43
作者Dianne Hackborn <hackbod@goog...>
CommiterDianne Hackborn

Log Message

Clean up from comments, enable throttling.

Change-Id: I719b0491a7953ab57d76634699c6fdf3ad8558e0

更改概述

差异

--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -343,7 +343,8 @@
343343 </activity>
344344
345345 <!-- Loader Samples -->
346-
346+
347+<!-- BEGIN_INCLUDE(loader_throttle) -->
347348 <activity android:name=".app.LoaderThrottle"
348349 android:label="@string/loader_throttle">
349350 <intent-filter>
@@ -353,6 +354,7 @@
353354 </activity>
354355 <provider android:name=".app.LoaderThrottle$SimpleProvider"
355356 android:authorities="com.example.android.apis.app.LoaderThrottle" />
357+<!-- END_INCLUDE(loader_throttle) -->
356358
357359 <!-- Intent Samples -->
358360
--- a/samples/ApiDemos/src/com/example/android/apis/app/LoaderThrottle.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/LoaderThrottle.java
@@ -16,6 +16,7 @@
1616
1717 package com.example.android.apis.app;
1818
19+//BEGIN_INCLUDE(complete)
1920 import android.app.Activity;
2021 import android.app.FragmentManager;
2122 import android.app.ListFragment;
@@ -29,6 +30,7 @@ import android.content.CursorLoader;
2930 import android.content.Loader;
3031 import android.content.UriMatcher;
3132 import android.database.Cursor;
33+import android.database.DatabaseUtils;
3234 import android.database.SQLException;
3335 import android.database.sqlite.SQLiteDatabase;
3436 import android.database.sqlite.SQLiteOpenHelper;
@@ -56,12 +58,12 @@ import java.util.HashMap;
5658 public class LoaderThrottle extends Activity {
5759 // Debugging.
5860 static final String TAG = "LoaderThrottle";
59-
61+
6062 /**
6163 * The authority we use to get to our sample provider.
6264 */
6365 public static final String AUTHORITY = "com.example.android.apis.app.LoaderThrottle";
64-
66+
6567 /**
6668 * Definition of the contract for the main table of our provider.
6769 */
@@ -86,12 +88,7 @@ public class LoaderThrottle extends Activity {
8688 */
8789 public static final Uri CONTENT_ID_URI_BASE
8890 = Uri.parse("content://" + AUTHORITY + "/main/");
89-
90- /**
91- * 0-relative position of a main ID segment in the path part of a main ID URI
92- */
93- public static final int MAIN_ID_PATH_POSITION = 1;
94-
91+
9592 /**
9693 * The MIME type of {@link #CONTENT_URI}.
9794 */
@@ -107,14 +104,14 @@ public class LoaderThrottle extends Activity {
107104 * The default sort order for this table
108105 */
109106 public static final String DEFAULT_SORT_ORDER = "data COLLATE LOCALIZED ASC";
110-
107+
111108 /**
112109 * Column name for the single column holding our data.
113110 * <P>Type: TEXT</P>
114111 */
115112 public static final String COLUMN_NAME_DATA = "data";
116113 }
117-
114+
118115 /**
119116 * This class helps open, create, and upgrade the database file.
120117 */
@@ -189,7 +186,7 @@ public class LoaderThrottle extends Activity {
189186 mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
190187 mUriMatcher.addURI(AUTHORITY, MainTable.TABLE_NAME, MAIN);
191188 mUriMatcher.addURI(AUTHORITY, MainTable.TABLE_NAME + "/#", MAIN_ID);
192-
189+
193190 // Create and initialize projection map for all columns. This is
194191 // simply an identity mapping.
195192 mNotesProjectionMap = new HashMap<String, String>();
@@ -227,8 +224,9 @@ public class LoaderThrottle extends Activity {
227224 case MAIN_ID:
228225 // The incoming URI is for a single row.
229226 qb.setProjectionMap(mNotesProjectionMap);
230- qb.appendWhere(MainTable._ID + "=" + uri.getPathSegments().get(
231- MainTable.MAIN_ID_PATH_POSITION));
227+ qb.appendWhere(MainTable._ID + "=?");
228+ selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
229+ new String[] { uri.getLastPathSegment() });
232230 break;
233231
234232 default:
@@ -299,7 +297,7 @@ public class LoaderThrottle extends Activity {
299297
300298 throw new SQLException("Failed to insert row into " + uri);
301299 }
302-
300+
303301 /**
304302 * Handle deleting data.
305303 */
@@ -322,14 +320,8 @@ public class LoaderThrottle extends Activity {
322320 case MAIN_ID:
323321 // If URI is for a particular row ID, delete is based on incoming
324322 // data but modified to restrict to the given ID.
325- finalWhere = MainTable._ID + " = " + uri.getPathSegments().get(
326- MainTable.MAIN_ID_PATH_POSITION);
327-
328- if (where != null) {
329- // Combine with incoming where, if specified.
330- finalWhere = finalWhere + " AND " + where;
331- }
332-
323+ finalWhere = DatabaseUtils.concatenateWhere(
324+ MainTable._ID + " = " + ContentUris.parseId(uri), where);
333325 count = db.delete(MainTable.TABLE_NAME, finalWhere, whereArgs);
334326 break;
335327
@@ -360,17 +352,11 @@ public class LoaderThrottle extends Activity {
360352 case MAIN_ID:
361353 // If URI is for a particular row ID, update is based on incoming
362354 // data but modified to restrict to the given ID.
363- finalWhere = MainTable._ID + " = " + uri.getPathSegments().get(
364- MainTable.MAIN_ID_PATH_POSITION);
365-
366- if (where != null) {
367- // Combine with incoming where, if specified.
368- finalWhere = finalWhere + " AND " + where;
369- }
370-
355+ finalWhere = DatabaseUtils.concatenateWhere(
356+ MainTable._ID + " = " + ContentUris.parseId(uri), where);
371357 count = db.update(MainTable.TABLE_NAME, values, finalWhere, whereArgs);
372358 break;
373-
359+
374360 default:
375361 throw new IllegalArgumentException("Unknown URI " + uri);
376362 }
@@ -380,13 +366,13 @@ public class LoaderThrottle extends Activity {
380366 return count;
381367 }
382368 }
383-
369+
384370 @Override
385371 protected void onCreate(Bundle savedInstanceState) {
386372 super.onCreate(savedInstanceState);
387373
388374 FragmentManager fm = getFragmentManager();
389-
375+
390376 // Create the list fragment and add it as our sole content.
391377 if (fm.findFragmentById(android.R.id.content) == null) {
392378 ThrottledLoaderListFragment list = new ThrottledLoaderListFragment();
@@ -400,7 +386,7 @@ public class LoaderThrottle extends Activity {
400386 // Menu identifiers
401387 static final int POPULATE_ID = Menu.FIRST;
402388 static final int CLEAR_ID = Menu.FIRST+1;
403-
389+
404390 // This is the Adapter being used to display the list's data.
405391 SimpleCursorAdapter mAdapter;
406392
@@ -409,11 +395,11 @@ public class LoaderThrottle extends Activity {
409395
410396 // Task we have running to populate the database.
411397 AsyncTask<Void, Void, Void> mPopulatingTask;
412-
398+
413399 @Override public void onActivityCreated(Bundle savedInstanceState) {
414400 super.onActivityCreated(savedInstanceState);
415401
416- setEmptyText("No data");
402+ setEmptyText("No data. Select 'Populate' to fill with data from Z to A at a rate of 4 per second.");
417403 setHasOptionsMenu(true);
418404
419405 // Create an empty adapter we will use to display the loaded data.
@@ -422,7 +408,7 @@ public class LoaderThrottle extends Activity {
422408 new String[] { MainTable.COLUMN_NAME_DATA },
423409 new int[] { android.R.id.text1 }, 0);
424410 setListAdapter(mAdapter);
425-
411+
426412 // Prepare the loader. Either re-connect with an existing one,
427413 // or start a new one.
428414 getLoaderManager().initLoader(0, null, this);
@@ -437,7 +423,7 @@ public class LoaderThrottle extends Activity {
437423
438424 @Override public boolean onOptionsItemSelected(MenuItem item) {
439425 final ContentResolver cr = getActivity().getContentResolver();
440-
426+
441427 switch (item.getItemId()) {
442428 case POPULATE_ID:
443429 if (mPopulatingTask != null) {
@@ -465,7 +451,7 @@ public class LoaderThrottle extends Activity {
465451 };
466452 mPopulatingTask.execute((Void[])null);
467453 return true;
468-
454+
469455 case CLEAR_ID:
470456 if (mPopulatingTask != null) {
471457 mPopulatingTask.cancel(false);
@@ -479,7 +465,7 @@ public class LoaderThrottle extends Activity {
479465 };
480466 task.execute((Void[])null);
481467 return true;
482-
468+
483469 default:
484470 return super.onOptionsItemSelected(item);
485471 }
@@ -499,7 +485,7 @@ public class LoaderThrottle extends Activity {
499485 @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) {
500486 CursorLoader cl = new CursorLoader(getActivity(), MainTable.CONTENT_URI,
501487 PROJECTION, null, null, null);
502- //cl.setUpdateThrottle(2000); // update at most every 2 seconds.
488+ cl.setUpdateThrottle(2000); // update at most every 2 seconds.
503489 return cl;
504490 }
505491
@@ -512,3 +498,4 @@ public class LoaderThrottle extends Activity {
512498 }
513499 }
514500 }
501+//END_INCLUDE(complete)