The Busy Coder''''s Guide to Android Developmentby Mark L. Murphy.The Busy Coder''''s Guide to Android potx

400 1.2K 0
The Busy Coder''''s Guide to Android Developmentby Mark L. Murphy.The Busy Coder''''s Guide to Android potx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

The Busy Coder's Guide to Android Development by Mark L Murphy The Busy Coder's Guide to Android Development by Mark L Murphy Copyright © 2008 CommonsWare, LLC All Rights Reserved Printed in the United States of America CommonsWare books may be purchased in printed (bulk) or digital form for educational or business use For more information, contact direct@commonsware.com Printing History: Jul 2008: Version 1.0 ISBN: 978-0-9816780-0-9 The CommonsWare name and logo, “Busy Coder's Guide”, and related trade dress are trademarks of CommonsWare, LLC All other trademarks referenced in this book are trademarks of their respective firms The publisher and author(s) assume no responsibility for errors or omissions or for damages resulting from the use of the information contained herein Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Table of Contents Welcome to the Warescription! xiii Preface xv Welcome to the Book! xv Prerequisites xv Warescription .xvi Book Bug Bounty .xvii Source Code License xviii Creative Commons and the Four-to-Free (42F) Guarantee xviii The Big Picture What Androids Are Made Of .3 Activities Content Providers Intents Services Stuff At Your Disposal Storage Network Multimedia .5 GPS Phone Services .6 Project Structure Root Contents The Sweat Off Your Brow .8 iii Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition And Now, The Rest of the Story What You Get Out Of It .9 Inside the Manifest 11 In The Beginning, There Was the Root, And It Was Good .11 Permissions, Instrumentations, and Applications (Oh, My!) 12 Your Application Does Something, Right? 13 Creating a Skeleton Application 17 Begin at the Beginning 17 The Activity 18 Dissecting the Activity 19 Building and Running the Activity .21 Using XML-Based Layouts 23 What Is an XML-Based Layout? 23 Why Use XML-Based Layouts? 24 OK, So What Does It Look Like? 25 What's With the @ Signs? 26 And We Attach These to the Java How? 26 The Rest of the Story 27 Employing Basic Widgets 29 Assigning Labels 29 Button, Button, Who's Got the Button? 30 Fleeting Images 31 Fields of Green Or Other Colors 31 Just Another Box to Check 34 Turn the Radio Up .37 It's Quite a View 39 Useful Properties 39 Useful Methods 39 Working with Containers 41 Thinking Linearly 42 Concepts and Properties .42 Example 45 All Things Are Relative .50 iv Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Concepts and Properties .50 Example 53 Tabula Rasa 56 Concepts and Properties .56 Example 59 Scrollwork 60 Using Selection Widgets .65 Adapting to the Circumstances 65 Using ArrayAdapter 66 Other Key Adapters .67 Lists of Naughty and Nice 68 Spin Control 70 Grid Your Lions (Or Something Like That ) 74 Fields: Now With 35% Less Typing! 78 Galleries, Give Or Take The Art 82 Employing Fancy Widgets and Containers 83 Pick and Choose 83 Time Keeps Flowing Like a River .88 Making Progress 89 Putting It On My Tab 90 The Pieces .91 The Idiosyncrasies 91 Wiring It Together 93 Other Containers of Note 96 Applying Menus 97 Flavors of Menu 97 Menus of Options .98 Menus in Context 100 Taking a Peek .102 Embedding the WebKit Browser 107 A Browser, Writ Small .107 Loading It Up .109 Navigating the Waters 111 v Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Entertaining the Client .111 Settings, Preferences, and Options (Oh, My!) 114 Showing Pop-Up Messages 117 Raising Toasts 117 Alert! Alert! 118 Checking Them Out 119 Dealing with Threads 123 Getting Through the Handlers 123 Messages .124 Runnables 127 Running In Place 127 Utilities (And I Don't Mean Water Works) .128 And Now, The Caveats 128 Handling Activity Lifecycle Events 131 Schroedinger's Activity .131 Life, Death, and Your Activity 132 onCreate() and onCompleteThaw() 132 onStart(), onRestart(), and onResume() 133 onPause(), onFreeze(), onStop(), and onDestroy() 134 Using Preferences 137 Getting What You Want 137 Stating Your Preference .138 A Preference For Action 138 Accessing Files 143 You And The Horse You Rode In On .143 Readin' 'n Writin' .147 Working with Resources 151 The Resource Lineup 151 String Theory 152 Plain Strings 152 String Formats 153 Styled Text 153 Styled Formats 154 vi Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Got the Picture? 158 XML: The Resource Way 160 Miscellaneous Values 163 Dimensions 163 Colors 164 Arrays 165 Different Strokes for Different Folks 166 Managing and Accessing Local Databases 171 A Quick SQLite Primer 172 Start at the Beginning 173 Setting the Table 174 Makin' Data 174 What Goes Around, Comes Around 176 Raw Queries 176 Regular Queries 177 Building with Builders .177 Using Cursors .179 Change for the Sake of Change 179 Making Your Own Cursors 180 Data, Data, Everywhere .180 Leveraging Java Libraries 183 The Outer Limits 183 Ants and Jars 184 Communicating via the Internet 187 REST and Relaxation 187 HTTP Operations via Apache Commons 188 Parsing Responses 190 Stuff To Consider .192 Email over Java 193 Creating Intent Filters 199 What's Your Intent? 200 Pieces of Intents 200 Stock Options .201 vii Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Intent Routing 202 Stating Your Intent(ions) 203 Narrow Receivers .205 Launching Activities and Sub-Activities 207 Peers and Subs 208 Start 'Em Up 208 Make an Intent 209 Make the Call .209 Finding Available Actions via Introspection .215 Pick 'Em 216 Adaptable Adapters 220 Would You Like to See the Menu? 223 Asking Around 225 Using a Content Provider 229 Pieces of Me .229 Getting a Handle .230 Makin' Queries 231 Adapting to the Circumstances 233 Doing It By Hand .235 Position .235 Getting Properties .236 Setting Properties 237 Give and Take 238 Beware of the BLOB! 239 Building a Content Provider .241 First, Some Dissection .241 Next, Some Typing 242 Step #1: Create a Provider Class 243 ContentProvider 243 DatabaseContentProvider 252 Step #2: Supply a Uri 252 Step #3: Declare the Properties 252 Step #4: Update the Manifest 253 viii Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Notify-On-Change Support 254 Requesting and Requiring Permissions 257 Mother, May I? 258 Halt! Who Goes There? .259 Enforcing Permissions via the Manifest 260 Enforcing Permissions Elsewhere .261 May I See Your Documents? .262 Creating a Service 263 Getting Buzzed 264 Service with Class 264 When IPC Attacks! 266 Write the AIDL 267 Implement the Interface 268 Manifest Destiny .270 Where's the Remote? 271 Invoking a Service .273 Bound for Success .274 Request for Service 276 Prometheus Unbound .276 Manual Transmission 276 Alerting Users Via Notifications .279 Types of Pestering .279 Hardware Notifications 280 Icons 281 Letting Your Presence Be Felt 281 Accessing Location-Based Services 287 Location Providers: They Know Where You're Hiding 288 Finding Yourself 288 On the Move 292 Are We There Yet? Are We There Yet? Are We There Yet? 292 Testing Testing 296 Mapping with MapView and MapActivity 299 The Bare Bones 299 ix Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Exercising Your Control .301 Zoom 301 Center 302 Reticle 303 Traffic and Terrain .303 Follow You, Follow Me 305 Layers Upon Layers 307 Overlay Classes 308 Drawing the Overlay 308 Handling Screen Taps 310 Playing Media 313 Get Your Media On 314 Making Noise 315 Moving Pictures 321 Handling Telephone Calls 325 No, No, No – Not That IPhone 326 What's Our Status? 326 You Make the Call! 326 Searching with SearchManager 333 Hunting Season 333 Search Yourself 335 Craft the Search Activity 336 Update the Manifest 340 Try It Out 342 The TourIt Sample Application 347 Installing TourIt 347 Demo Location Provider 347 SD Card Image with Sample Tour 348 Running TourIt 349 Main Activity 350 Configuration Activity .352 Cue Sheet Activity .354 Map Activity .355 x Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition The TourIt Sample Application To support manually flipping the TourViewActivity implements onKeyUp(): pages of the details panel, public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode==KeyEvent.KEYCODE_DPAD_LEFT || keyCode==KeyEvent.KEYCODE_DPAD_RIGHT) { stopAnimation(); if (keyCode==KeyEvent.KEYCODE_DPAD_LEFT) { detailsPanel.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in)); detailsPanel.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out)); if (detailsPanel.getDisplayedChild()==0) { detailsPanel.setDisplayedChild(detailsPanel.getChildCount()-1); } else { detailsPanel.setDisplayedChild(detailsPanel.getDisplayedChild()-1); } } } else { detailsPanel.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in)); detailsPanel.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out)); detailsPanel.showNext(); } return(super.onKeyUp(keyCode, event)); } Or, the checkbox can toggle automatic animation, courtesy of the flipping features built into ViewFlipper: private void startAnimation() { detailsPanel.startFlipping(); isFlipping=true; } private void stopAnimation() { detailsPanel.stopFlipping(); isFlipping=false; } 366 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition The TourIt Sample Application TourMapActivity The guts of TourMapActivity are covered extensively in the chapter on mapping services and are not repeated here for brevity TourEditActivity By and large, TourEditActivity is just a form for the user to fill in waypoint details Two things are interesting here First, for the distance traveled field, we use a custom FloatInputMethod class, that constrains input to be positive or negative floating-point numbers: class FloatInputMethod extends NumberInputMethod { private static final String CHARS="0123456789-."; } protected char[] getAcceptedChars() { return(CHARS.toCharArray()); } Also, when the "Fill In My Location!" button is clicked, we just that – find the current location and fill in the latitude, longitude, and elevation fields accordingly, as is described in the chapter on location services HelpActivity The HelpActivity is a thin shell around the WebKit browser It loads static HTML out of the project's assets/ directory, which is referenced in code as file:///android_assets, as shown below: @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.help); browser=(WebView)findViewById(R.id.browser); browser.setWebViewClient(new Callback()); browser.getSettings().setDefaultFontSize(browser.getSettings().getDefaultFontS ize()+4); 367 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition The TourIt Sample Application String page=getIntent().getStringExtra(PAGE); } if (page==null) { browser.loadUrl("file:///android_asset/index.html"); } else { browser.loadUrl("file:///android_asset/"+page+".html"); } By default, it will load the home page If, however, the activity was started by another activity that passed in a specific page to view, it loads that page instead hooks into the WebKit browser to detect clicks on links Since the only links in the help are to other help pages, it simply loads in the requested page: HelpActivity private class Callback extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); } return(true); } ConfigActivity The ConfigActivity class mostly loads data out of preferences, updates the layout's widgets to match, then reverses the process when the activity is paused (e.g., when the user clicks Close from the options menu) The most interesting thing here is the spinner of location providers – this is covered in detail in the chapter on location services 368 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index BoxLayout .41 Class Builder 118, 119 AbsoluteLayout .96 Bundle 133, 134, 201, 210, 264, 277 ActionEvent 20 Button 23, 25-28, 30, 31, 155, 159, 322 ActionListener .20 Calendar 86 Activity .8, 68, 101, 117, 118, 126, 128, 132, 137, 147, 173, 174, 206, 207 Canvas 308, 309 ActivityAdapter 68, 220, 223, 225 CharSequence .268 ActivityIconAdapter 68, 220 CheckBox 34, 37, 39 ActivityManager 123 Chrono 84 Adapter 220 Clocks 88 AdapterView 101 ComponentName 224, 225, 275 AlertDialog .118, 119 CompoundButton 37 AnalogClock 88 ConcurrentLinkedQueue 265 ArrayAdapter .66, 67, 69, 77, 146, 289, 364 ConfigActivity .282, 289, 291, 305, 362, 368 ArrayList .146 ContentManager 280 AudioDemo 316 ContentObserver 254, 255 AutoComplete .79 ContentProvider 173, 174, 177, 238, 239, 243 AutoCompleteTextView 33, 78-80 ContentResolver 237, 239, 254 BaseColumns .252 ContentValues 175, 237, 238, 247, 249, 253 Box 41 Context 66, 118, 137, 147, 173, 174, 234 369 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index ContextMenu 100, 101 Grid 75 ContextMenuInfo 101 GridView 74, 75, 82 Criteria 290, 292, 306 Handler 123-128, 133, 295, 296 Critieria 290, 297 HelpActivity 209, 362, 367, 368 Cursor 67, 179, 180, 231, 233-237, 239, 246, 247, 253 HttpClient .188-190 CursorAdapter .67 HttpMethod 188 CursorFactory 173, 180 IBinder 266, 275 DatabaseContentProvider 243, 244, 252 ImageButton 31, 158, 159 DatabaseHelper 244 Images 158 DateFormat 86 ImageView 31, 158, 240, 314 DatePicker .83 InputMethod 32 DatePickerDialog 83, 86 InputStream .143, 146, 147, 188, 191 DeadObjectException 276, 329 InputStreamReader 147 Dialer 327 Intent 90, 111, 112, 220, 223-225, 243, 273, 275, 277, 281, 292-295, 305, 314, 339 Dialog 128 IntentReceiver .205, 206 DigitalClock 88 IPhone 326, 328, 329 Direction .237, 361 Iterator 235 Document 146 JButton 20, 21 Double 209 JCheckBox .66 Drawable 82, 93, 158, 281 JComboBox 70 EditView 31, 32, 78, 79, 83, 231 JLabel .66 ExpandableListView .96 JList 66 Field .32 JTabbedPane 90 FloatInputMethod .367 JTable .66 FlowLayout 42 Label 30 Folder 195 Launch 210 Forecast 191 Linear .45 FrameLayout .91-93 LinearLayout 41-46, 58, 93 Gallery 65, 82 List 68, 102, 225, 268, 289 GetMethod 188, 190 ListActivity 68, 69, 92, 299 370 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index ListAdapter 96, 220, 339 NowRedux 27 ListCellRenderer 66 Object 101 ListDemo 104 OnCheckedChangeListener 34, 35, 48, 140 ListView .68, 70, 71, 82, 102, 188, 220, 233, 234, 299, 336, 339, 363 OnClickListener 20, 86, 121, 140, 211 OnCompletionListener .319 Location .189, 290 OnDateSetListener 84, 86 LocationIntentReceiver 306 OnItemSelectedListener .72 LocationManager 288-290, 292, 293, 305 OnPopulateContextMenuListener .101, 103 LocationProvider 288-290, 292, 296, 297 OnPreparedListener 319 Lorem 336 OnTimeSetListener 84, 86 LoremBase 337 OutputStream 147 LoremDemo 339, 341 OutputStreamWriter 147 LoremSearch 341 Overlay 308, 310 MailBuzz 185, 193, 263, 265, 273, 274 OverlayController .308 MailBuzzService 263, 264, 267 PackageManager 225 MailClient 194 Parcelable 268 Map 134, 137, 175, 237, 268 Pick .216, 258 MapActivity 299-301 PickDemo 258 MapController 301, 302, 305 PixelCalculator 308-310 MapView 299-304 PixelConverter .309 MediaController 322, 324 Point 302, 303, 309-311 MediaPlayer 315, 316, 319, 320 PostMethod 188 Menu .98, 100, 223 Prefs 139 Menu.Item .99-101, 225 ProgressBar 90, 125, 126, 129 Menus 102 Provider 233, 244, 247-252, 361 Message 119, 124, 126, 127 ProviderWrapper 289 MessageCountListener 194 ProximityIntentReceiver .294 MyActivity 224 RadioButton 37-41, 46 Notification 263, 280, 281 RadioGroup 37, 38, 40, 41, 46, 48, 49 NotificationManager 280, 281 ReadWrite .147 Now .19, 27, 28 371 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index RectF 311 TableRow 56-58 Relative 53 TabSpec 93, 94 RelativeLayout 41, 50, 51, 54, 55, 59 TabWidget 91-93 Resources .143, 161 TextView 26, 29-31, 34, 37, 67, 77, 86, 97, 234, 336 RouteAdapter 364 TextWatcher 79, 80 RouteOverlay 308, 309, 311 TimePicker 83, 84 Runnable 99, 100, 123, 124, 127, 128 TimePickerDialog .83, 84, 86 Scroll 60 TimerTask 266 ScrollView 41, 60, 62 Toast 117, 118, 121, 190, 311 SecretsProvider 242 Tour 232, 233, 236, 237, 361 SecurityException .258 TourEditActivity 238, 291, 360, 362, 367 Service 264, 269 TourIt 300 ServiceConnection .274-276 TourListActivity 232, 234, 360, 362 Session 195 TourMapActivity 300, 304, 305, 307, 308, 362, 367 SharedPreferences 138 TourViewActivity .232, 233, 282, 283, 293, 294, 360, 362, 363, 366 SimpleAdapter 67 UIThreadUtilities 123, 128 SimpleCursorAdapter 233-235, 363 Uri 31, 158, 178, 200, 201, 203-205, 207, 209, 211, 215-217, 220, 224, 229-232, 237-243, 246-252, 254, 255, 280, 314, 315 Spanned 153, 154 Spinner 70, 71, 78, 82, 220, 233 VideoDemo 323 SQLiteDatabase .173-175 VideoView .321-324 SQLiteQueryBuilder 176-178, 246, 247 View 23, 26, 27, 39, 58, 62, 101, 118, 123, 127, 128 Static 144, 161 ViewFlipper 362, 365, 366 Store 195 Waypoint .237, 361 String99, 118, 119, 137, 154, 156, 188, 210, 231, 246, 268 Weather 188 Strings 154 WeatherDemo .190 Tab 92 WebKit 188, 190 TabActivity .92, 94, 362 WebSettings 114 TabHost 91-94 WebView 107-109, 111-115 Table 59 WebViewClient .112, 113 TableLayout 41, 56-59 XmlPullParser 161, 162 372 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index END_TAG 161 Command FACTORY_TEST_ACTION 201 adb pull 181 FIRST .99 adb push 181, 323, 348 GADGET_CATEGORY 202 adb shell .180, 348 GET .188 ant 8, GET_CONTENT_ACTION 201 ant install .347 HOME_CATEGORY 202 dex 185, 186 HORIZONTAL 42 sqlite3 180 ID 174 Constant INBOX 195 ACCESS_ASSISTED_GPS 288 INSERT 172, 175, 176 ACCESS_CELL_ID .288 INSERT_ACTION 201 ACCESS_GPS .288 INTEGER 172 ACCESS_POSITION 288 LARGER 115 ALTERNATE_CATEGORY 223 LAUNCHER 201, 204 ALTERNATIVE .201, 224 LAUNCHER_CATEGORY 202 ALTERNATIVE_CATEGORY 202, 224 LENGTH_LONG 118 ANSWER_ACTION .201 LENGTH_SHORT 118 BIND_AUTO_CREATE .275 MAIN 204 BROWSABLE_CATEGORY 202 MAIN_ACTION 201, 202 CALL_ACTION 201 MATCH_DEFAULT_ONLY 225 CONTENT_URI 254 MEDIA_MOUNTED_ACTION 202 DEFAULT 201 NULL .175 DEFAULT_CATEGORY 202, 225 ORDER BY 231 DELETE 175, 176, 239 PERMISSION_DENIED .261 DELETE_ACTION .201 PERMISSION_GRANTED 261 DIAL_ACTION .201 PICK_ACTION .200-202, 210, 231, 243 DIALER_DEFAULT_KEYS 335 PICK_ACTIVITY_ACTION 201, 216, 217 EDIT_ACTION .200-202 POLL 266, 269 END_DOCUMENT 161 POST 188 373 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index PREFERENCE_CATEGORY 202 add() 98, 99 PROJECTION .232 addId() 230 R .27 addIntentOptions() 100, 223-225 READ_CONTACTS 258 addMenu() 100 RECEIVE_SMS .262 addProximityAlert() 293 RESULT_CANCELLED 210 addSeparator() .100 RESULT_FIRST_USER 210 addSubMenu() .100 RESULT_OK 210, 216, 217 addTab() 94 RUN_ACTION .201 appendWhere() 178 SEARCH_ACTION .201, 339 applyFormat() 156 SELECT 172, 176, 178, 179 applyMenuChoice() .104 SELECTED_ALTERNATIVE_CATEGORY 202 beforeTextChanged() 80 SEND_ACTION 201 bindService() 275, 276 SENDTO_ACTION 201 broadcastIntent() 210, 261, 262 SMALLEST 115 broadcastIntentSerialized() 210 START_TAG 161, 162 buildForecasts() 190 SUNDAY 84 buildQuery() 178 SYNC_ACTION 202 bulkInsert() 238 TAB_CATEGORY 202 call() 326-328 TAG_ACTION 223 cancel() 280, 281 TEST_CATEGORY .202 canGoBack() 111 TEXT .161 canGoBackOrForward() 111 TITLE 234 canGoForward() 111 UPDATE 175, 176, 237, 238 centerMapTo() .302 VERTICAL .42 check() .37, 38 VIEW_ACTION .200, 202, 209, 217, 314 checkAccount() 269, 270 WEB_SEARCH_ACTION 202 checkAccountImpl() 270 WHERE 175-178, 231, 238, 239, 246, 249-251 checkCallingPermission() 261 clear() 138 Method clearCache() 111 374 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index clearCheck() 37 getAttributeCount() 162 clearHistory() 111 getAttributeName() .162 close() 147, 174, 179, 180 getBearing() 290 commit() .138 getBestProvider() 290 commitUpdates() 180, 237 getBoolean() 138 count() 179 getCheckedRadioButtonId() 37 create() 119 getCollectionType() .251 createDatabase() 173, 181 getColumnIndex() .179 delete() 175, 176, 239, 250, 252 getColumnNames() .179 deleteDatabase() 174 getContentProvider() 238 deleteInternal() 252 getContentResolver() 237, 254 deleteRow() 180 getCurrentLocation() 290 dial() .326-328 getFloat() .236 draw() 308, 309 getIMAPMessageIds() 195 drawCircle() 309 getInputStream() 239 drawText() 309 getInt() 179, 236 edit() .138 getIntent() 336 enable() 268, 277 getLastKnownPosition() .290 enablePoll() 270 getLatitude() 189 endCall() 326 getLocation() .189 equery() 179 getLongitude() .189 execSQL() 174, 175 getMapCenter() 303 findViewById() 27, 28, 40, 94, 143, 301 getMapController() 301 finish() 140, 149 getMessageIds() 195 first() .179, 235 getName() 289 generatePage() 191 getOutputStream() .239 get() .175 getPackageManager() 225 getAltitude() 290 getParent() .39 getAsInteger() .175 getParentOfType() 40 getAsString() 175 getPointXY() 309 375 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index getPollState() .270 isChecked() 34, 37 getPOP3MessageIds() 195 isCollectionUri() 248, 250 getPreferences() 137, 138 isEnabled() .39, 276 getProgress() 90 isFirst() 236 getProviders() 289 isFocused() 39 getRequiredColumns() .249 isLast() 236 getResources() 143 isNull() 236 getRootView() .40 isOffhook() 326 getSettings() 114 isSatellite() 304 getSharedPreferences() 137, 138 isStreetView() 304 getSingleType() 251 isTraffic() .304 getSpeed() 290 isUIThread() 128 getString() .153, 156, 179, 236 last() .235 getStringArray() 165 loadData() .109, 110 getTitle() 237 loadTime() 113 getType() .251, 252 loadUrl() 108-110 getView() 67, 77, 235 makeMeAnAdpater() 339 getXml() 161 makeText() 118 goBack() 111 managedQuery() 231-234 goBackOrForward() 111 move() 236 goForward() 111 moveTo() 236 handleMessage() 124, 126 newCursor() 180 hasAltitude() .290 newTabSpec() 93, 94 hasBearing() 290 next() 161, 179, 236 hasSpeed() 290 notify() 280, 281 incrementProgressBy() 90 notifyChange() .254, 255 insert() 175, 238, 245, 248, 249, 252, 253 obtainMessage() 124 insertInternal() 252 onActivityResult() 210, 216 isAfterLast() 179, 236 onBind() 266, 269 isBeforeFirst() 236 onCheckedChanged() 35, 48, 142 376 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index onClick() 20, 21 openFileInput() 147, 149 onCompleteThaw() .133, 134 openFileOutput() 147, 149 onContextItemSelected() .101, 104 openRawResource() .143 onCreate() 20, 21, 26, 27, 38, 48, 98, 103, 108, 132-134, 140, 146, 156, 190, 234, 244, 252, 264-266, 303, 310, 329, 335, 336, 339 pause() 315, 324 onCreateOptionsMenu() 98, 100, 101, 104 populateDefaultValues() 249 onCreatePanelMenu() 100 populateMenu() 103, 104 onDestroy() 134, 140, 264, 266 position() .236 onFreeze() 133, 134 post() .127, 128 onItemSelected() 365 postDelayed() .127 onKeyUp() 366 prepare() .315 onListItemClick() 69 prepareAsync() 315, 319, 320 onNewIntent() .336, 339 prev() 236 onOptionsItemSelected() .99-101, 104 putInt() 237 onPageStarted() 112 putString() 237 onPause() 133, 134, 140, 149, 206, 264 query() .176-178, 180, 246, 247, 252, 253 onPopulateContextMenu() 101 queryIntentActivityOptions() 225 onReceivedHttpAuthRequest() 112 queryInternal() 252 onReceiveIntent() .205, 206 rawQuery() 176, 180 onRestart() 134 registerContentObserver() 254 onResume() 133, 134, 140, 149, 189, 206, 264, 291, 305 registerIntent() 206 onSearchRequested() 335 releaseConnection() 188 onServiceConnected() 275, 276 reload() 111 onServiceDisconnected() 275, 276 remove() .138 onStart() 126, 127, 133, 264, 277 removeProximityAlert() 293 onStop() 133, 134, 140 removeUpdates() 292 onTap() 310, 311 requery() .180, 237 onTextChanged() 80 requestFocus() .39 onTooManyRedirects() 112 requestUpdates() 292, 305 openDatabase() 173 runOnUIThread() 128 play() 324 377 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index sendMessage() 124 setIndicator() 93, 94 sendMessageAtFrontOfQueue() 124 setItemCheckable() 99 sendMessageAtTime() 124 setJavaScriptCanOpenWindowsAutomatically() 115 sendMessageDelayed() 124 setJavaScriptEnabled() 115 setAccuracy() 290 setLayoutView() 26 setAdapter() 68, 70, 75, 78 setListAdapter() 69 setAlphabeticShortcut() .99 setMessage() 119 setAltitudeRequired() 290 setNegativeButton() .119 setCellRenderer() 66 setNeutralButton() .119 setChecked() .34, 38, 142, 276 setNumericShortcut() 99 setColumnCollapsed() 59 setOnClickListener() .20, 149 setColumnShrinkable() 59 setOnCompletionListener() 319 setColumnStretchable() .59 setOnItemSelectedListener() 68, 70, 75 setContent() 93, 94 setOnPopulateContextMenuListener() 101 setContentView() 20, 40 setOnPreparedListener() .319 setCostAllowed() 290 setOrientation() 42 setCurrentTab() 94 setPadding() 44 setDataSource() 315 setPositiveButton() .119 setDefaultFontSize() .115 setProgress() 90 setDefaultKeyMode() 335 setProjectionMap() 178 setDropDownViewResource() 70 setQwertyMode() 99 setDuration() 118 setResult() 210 setEnabled() 39 setText() 21 setFantasyFontFamily() 114 setTextSize() 115 setFollowMyLocation() .305 setTitle() .119 setGravity() 44 setTypeface() 24 setGroupCheckable() .98, 99 setup() 94, 320 setHeader() 100 setupTimer() 265, 266, 270 setIcon() 119 setUseDesktopUserAgent() 115 setImageURI() 31 setView() .118 378 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index setWebViewClient() .112 updateTime() 20 shouldOverrideUrlLoading() 112, 113 updateView() .307 show() .118, 119, 121, 324 upgradeDatabases() 252 showList() 363 zoomTo() 301 showNotification() 282 sRadioOn() 326 Property android:authorities 253, 254 start() 315 android:autoText 31 startActivity() .209, 210, 220 android:background .39 startService() .277 android:capitalize 31 startSubActivity() 210, 216 android:collapseColumns .59 stop() .315, 320 android:columnWidth 74 stopPlayback() .324 android:completionThreshold .78 stopService() 277 android:digits 31 supportUpdates() 179 android:drawSelectorOnTop 71, 82 switch() 100 android:horizontalSpacing 74 toggle() .34, 37 android:id 25, 26, 37, 51, 91-93 toggleEdgeZooming() 302 android:indeterminate 90 toggleRadioOnOff() 326 android:indeterminateBehavior 90 toggleSatellite() 304 android:inputMethod 32 toggleStreetView() 304 android:label 13 toggleTraffic() 304 android:layout_above 52 toString() .66, 289 android:layout_alignBaseline .52 unbindService() 276 android:layout_alignBottom 52 unregisterContentObserver() .255 android:layout_alignLeft 52 unregisterIntent() .206 android:layout_alignParentBottom 51 update() 175, 176, 237, 238, 249-253 android:layout_alignParentLeft 51 updateInt() 180 android:layout_alignParentRight 51 updateInternal() 252 android:layout_alignParentTop .51, 55 updateLabel() 86 android:layout_alignRight 52 updateString() .180 379 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition Keyword Index android:layout_alignTop 52, 53 android:padding 44, 45 android:layout_below 52 android:paddingBottom .45 android:layout_centerHorizontal 51 android:paddingLeft .45 android:layout_centerInParent .51 android:paddingRight 45 android:layout_centerVertical 51 android:paddingTop .45, 92 android:layout_column 57 android:password 31 android:layout_gravity 44 android:permission 260, 271 android:layout_height 25, 43, 53, 92 android:phoneNumber 32 android:layout_span .57 android:progress 90 android:layout_toLeft 52 android:shrinkColumns 58 android:layout_toRight 52 android:singleLine 31, 32 android:layout_weight 43 android:spacing .82 android:layout_width 25, 43, 47, 53 android:spinnerSelector .82 android:manifest 12 android:src .31 android:max 90, 125 android:stretchColumns .58 android:name 13, 253, 258, 270, 341 android:stretchMode 74 android:nextFocusDown 39 android:text .25, 29 android:nextFocusLeft 39 android:textColor 30, 34 android:nextFocusRight .39 android:textStyle 29, 31 android:nextFocusUp 39 android:typeface 29 android:numColumns 74 android:value .341 android:numeric 31 android:verticalSpacing 74 android:orientation 42 android:visibility 39 380 Subscribe to updates at http://commonsware.com Special Creative Commons BY-NC-SA 3.0 License Edition ... passed to the ActionListener configured for the button In Android, a button click causes onClick() to be invoked in the OnClickListener instance configured for the button The listener is provided the. .. the JButton equivalent Building and Running the Activity To build the activity, either use your IDE''s built-in Android packaging tool, or run ant in the base directory of your project Then, to. .. like the Button instance we created in the previous chapter The Rest of the Story In the original Now demo, the button''s face would show the current time, which would reflect when the button was

Ngày đăng: 05/03/2014, 21:20

Từ khóa liên quan

Mục lục

  • Welcome to the Book!

  • Prerequisites

  • Warescription

  • Book Bug Bounty

  • Source Code License

  • Creative Commons and the Four-to-Free (42F) Guarantee

  • The Big Picture

    • What Androids Are Made Of

      • Activities

      • Content Providers

      • Intents

      • Services

      • Stuff At Your Disposal

        • Storage

        • Network

        • Multimedia

        • GPS

        • Phone Services

        • Project Structure

          • Root Contents

          • The Sweat Off Your Brow

          • And Now, The Rest of the Story

          • What You Get Out Of It

          • Inside the Manifest

            • In The Beginning, There Was the Root, And It Was Good

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan