Index

■ run configurations ■A detailed configuration screen, 49 Android prompt, edit, 48 benefits, 4 Run/Debug Configurations challenges, 5 screen, 48, 49 code names, 6 settings, 50 cumulative distribution, 8 running, 52, 53 developers, 7 SDK packages Dream/G1, 6 download/install, 51, 52 future, 9 Gradle build tool, 52 global market share, 4 SDK Manager option, 50, 51 issues, 7 versions, 51 versions/API levels, 7, 8 warnings/errors, 50 Android activity Android developer configuration change, 190 tools (ADT), 14 lifecycle, 184 Android developer website, 18 objectives, 189 Android development, 112 principles, 189 class, 114 states, 184 code structure, 113 Android application coding knowledge, 112 Android Studio screen, 41, 42 collections, 116 code written, 46–48 data, 114 Configure Your Project screen, 43, 44 exception handling, 115 Create New Project wizard, 42, 43 file handling, 115 Empty Activity option, 43 garbage collection, 115 logical building blocks generics, 116 activities, 63 interfaces, 115 content providers, 64 main activity, 114 intents, 63 OO, 114 services, 63 threading, 115 MyFirstApp project, 45, 46 Android Jetpack, 157, 158 language, 45 components, 158 libraries, 45 Android project structure name, 44 Android view, 56 package name, 44 gradle files save location, 45 build.gradle files, 61 SDK, 45 Java source files, 58

345 © Grant Allen 2021 G. Allen, Android for Absolute Beginners, https://doi.org/10.1007/978-1-4842-6646-5 346 Index

Android project structure (cont.) SDK Tools directory, 70, 71 manifest files system image, 71 AndroidManifest.xml, 56, 57 virtual devices, 71, 72, 75 features, 58 build tool, 81, 82 key attributes, 57 considerations, 16 MainActivity, 57, 58 cross-platform tools, 32 XML, 57 debugging Project Explorer view, 55, 56 breakpoints, 77, 78 gradle files, 60 debugger, 80 application versioning, 62 starting applications, 78–80 build.gradle files, 60 stepping, code, 80 dependencies, 62 website, 77 Jetpack, 62 desktop/laptop hardwares, 17 SDK version parameters, 61, 62 downloading, 15, 17, 18 resource files Eclipse, 14, 31 drawables, 58 event log, 82 layouts, 59 features, 86 mipmaps, 59 installation, 14 values, 59 IntelliJ IDEA, 14, 31, 32 Android services Logcat client to service communication, 295–297 console, 83 communication, 294 output, 83, 84 design, 300 operating systems example client, 302, 303 , 19, 20 Java logic, creating, 300, 302 macOS, 18, 19 manifest entries, providing, 294 Windows, 18 own service application Project Explorer creating, 292 context menus, 68 service class, implementation, 292 Project Source Files view, 66, 67 service lifecycle via callbacks, 293 Project view, 67 testing services, 304 run configurations UI interaction/user-facing activity, 291 debugger, 69 WorkManager, 292 general options, 68, 69 Android’s original notification model, 254 miscellaneous options, 69 Android Studio, 108 profiling, 70 4.0, 15 SDK manager, 84, 85 ADT, 14 SDKs, 16 agnostic development tools, 32 setup AVD Manager, 70 confirmation screens, 26 benefits, 72 data sharing prompt, 21, 22 category, 71 downloaded view, 28, 29 code running, real device, 75, 76 downloading components progress command, 71 screen, 27, 28 device menu, 72, 73 emulator setting, 26, 27 Multiple Devices option, 73, 74 gotchas, 26 MyFirstApp, 74, 75 home page, 22, 23 name/type, 71 import settings, 21 purpose, 72 Install Type, 23, 24 Index 347

splash screen, 20, 21 ■ startup screen, 29, 30 ■B user interface (UI) theme, 24, 25 , 100 verify setting screen, 25, 26 ButtonExample app, 140 tools, 81 URLs, 15 ■■C Android Virtual Device (AVD), 9 Callback methods, 185 Android Studio, 39 onCreate( ), 185 Android Virtual Device Manager screen, onDestroy( ), 188 34, 35 onPause( ), 187 approach, 33 onRestart( ), 188 configuration verification screen, 39, 40 onRestoreInstanceState( ), 186 cryptic device names, 37 onResume( ), 186, 187 current/historic options, 37 onRetainNonConfigurationInstance( ), 188 density, 37 onSaveInstanceState( ), 187 hardware option, 35, 36 onStart( ), 186 key software aspects, 38 onStop( ), 187 license agreement, 39 Calls manager home screen, 40, 41 ACTION_DIAL, 271, 272 pixel options, 36 CallExample application, laying out, physical devices, 36 267–270 resolution, 37 CallExample application, System Image selection screen, 37, 38 working logic, 270, 271 Welcome to Android Studio handling incoming calls, 273 screen, 33, 34 making telephony support optional, 266 Assets/raw files methods, 266 Android’s file system model, 310 specifying telephony support, 265 I/O, 310 cancelAll( ) method, 263 permissions, reading/writing CDATA values, 123 files, 311, 312 CheckBox widget, 147–149 population, resource files, 306–309 Classes, 110 Audacity, 100 Class methods, 114 Audio Console object, 110 assets/resources, choosing, 211, 212 ConstraintLayout, 129, 136, 159, 179 AudioPlayExample, 214–217 flow, 160, 162, 163 exploring playback options, 220, 221 Layer, 163 play back , 164 Android, 209 assets, 210 code, 212 ■■D file storage, 210 Data types, 110 media package, 211 DaVinci Resolve, 100 raw audio resource, 210 Debian/Debian-based systems, 245 streaming services, 210 Developer audio toolset playing back audio, 213, 214 Apple Mac owners, 231 recording audio, 221–227 audacity, 229, 230 streaming, 217, 218, 220 audio sampling/frequency, 228 AWS Device Farm, 96 audio theory, 229 348 Index

Developer audio toolset (cont.) parts, 123 encoding/decoding/data loss, 229 values, 121 resolution, 228 version/encoding, 118 WavePad, 230 Developer hardware ■■F AVDs, 90 Files cables, 93 examining external files charging cables/cradles/devices, 93 code, 313, 314 checklist, 87 layout, 312 CPUs, 88 saving/reading, 315–317 disk space, 89 streamlineIMEs, 316 keyboard, 93 external storage memory, 88, 89 Android file systems, history, 320 monitors/displays, 90 environment methods, 319, 320 mouse, 93 file I/O, 321 screen findViewById( ) method, 179, 180 actions, 92 FirstJavaDemo program, 110, 111 aim, 92 FirstJavaDemo.java file, 111 sizes, 90–92 Flow virtual layout, 162 storage, 90 Fragment-centric design, 194 USB ports, 93 Fragment lifecycle callback events, 196 Developer video toolset coding, 201, 202 editing suites, 244 color detail, 199 editing tools, 243 dual-pane, 200 open source tools, 244 single-pane, 199 Development environment, 13 color list, 198 doClick( ) and doStartAudio( ) methods, 220 fragment-based application doHideKeyboard( ) method, 316, 317 creation, 198 doPlayAudio( ) method, 216, 220 layout, 200, 201 doPlayVideo( ) method, 237 onAttach( ), 196 doSaveToFile( ) method, 315 onCreate( ), 196 .doStartRecording( ) method, 227 onCreateView( ), 196, 197 doStopVideo( ) method, 238 onDestroy( ), 198 onDestroyView( ), 198 ■■E onDetach( ), 198 Eclipse, 31 onInflate( ), 196 EditText widget, 144–147 onPause( ), 197 execSQL( ) method, 329, 337 onResume( ), 197 ExoPlayer, 221 onSaveInstanceState( ), 197 Extensible Markup Language (XML), 117 onStart( ), 197 Android, 124 onStop( ), 197 activity layouts, 128–130 onViewStateRestored( ), 197 resource definitions, 125 Fragments, 193 review, 124, 125 class, 193 attributes, 120 coding in action, 203, 204 creation, 118 features, 195 elements, 118–120 lifecycle, 195 namespaces, 122 XML, 194 Index 349

■ Intents ■G activity action, 282 Generics, 116 activity dependency, 282, 283 getCallState( ) method, 267 android’s verified links, 282 getExternalStorageDirectory( ) method, 312 behavior, 278, 279 getModels( ) method, 333 creating, 283 getResources( ) method, 305 definition, 277, 278 getSystemService( ) method, 251 invoked activity, 284, 285, 287, 288 Global community, 4 manifest, 281, 282 GNU Image Manipulation routing, 280 Program (GIMP), 100 Google, 6, 7, 14 Google Firebase Test Lab, 96 ■■J Gradle tool java binary, 109 command-line, 97, 98 Java 9, 107 gradle.org, 98 javac binary, 109 gradle.properties file, 96 Java Development Kit (JDK), 10, 105, 106 GridLayout, 177 Android Studio, 108 Java-managed layouts, 177 ■■H Java Runtime Environment (JRE), 105, 106 Java Virtual Machine (JVM), 106 HandBrake JetPlayer, 221 definition, 245 downloading/installing, 245 running, 245–248 ■■K VideoPlayExample, 249 Kotlin, 138 Handsets/tablets Android’s default behavior, 93 ■ AWS Device Farm, 96 ■L Google Firebase Test Lab, 96 Layouts, 157, 176 Samsung Remote Test Lab, 96 Android, 159 testing, 94, 95 containers, 159 virtual/augmenting, 94 grid, 177 hasSystemFeature( ) method, 266 table, 176 Honeycomb, 194 LinearLayout, 170 Hybrid model, 9 options, 171–173 qualifiers, 170, 171 ■ Linting tools, 165 ■I Linux, 15 If statement, 111 Lossy compression or encoding, 229 ImageButton widgets, 142–144 ImageView widgets, 142–144 Inkscape, 100 ■■M Input Method Editor (IME), 269 MacBook Air, 108 .insert( ) method, 337, 339 main( ) method, 110 insertModelRow( ) method, 337 MotionLayout-based Integrated Development applications, 164 Environment (IDE), 13, 14 MotionLayout designs, 164 IntelliJ IDEA, 14 mp.setAudioStreamType( ) method, 216 350 Index

■ onViewStateRestored( ) method, 197 ■N openFileInput( ) and openFileOutput( ) Native Development Kit (NDK), 106 methods, 310 Non-Android Java application, 109 Open Handset Alliance, 7 Notifications openRawResources( ) method, 305 API level 26, 256 OpenShot, 100 capabilities, 251 Open source tools device, 264 Audacity, 100 icons, 255, 256 blender, 100 NotificationBuilderExample DaVinci Resolve, 100 application, 260–263 GIMP, 100 NotificationManager object, 252 Inkscape, 100 object, 252–254 LAME, 100 straightforward layout, 257 Olive, 100 supporting logic, 258, 260 OpenShot, 100 ■■O ■■P Object-oriented (OO) design, 110 PendingIntent, 255 Object-Relational Mapping (ORM), 340 Playing Back Video Olive, 100 Android, 233 onAttach( ) method, 196 controlling video, code, 236–238 onBind( ) method, 300 VideoView, 233–235 OnCheckedChangeListener, 174 println( ) method, 113 onClick( ) method, 237, 259, 313 onCreate( ) callback, 216 ■■Q onCreate( ) method, 141, 180, 185, query( ) method, 334 196, 260, 308 onCreateView( ) method, 196, 197 onDestroy( ) method, 187, 188, 198 ■■R onDestroyView( ) method, 198 RadioButton widget, 153, 154 onDetach method, 198 raiseNotification( ) method, 259 onDowngrade( ) method, 325 Raw-based approach, 306 onInflate( ) method, 196 readLine( ) method, 113 onPause( ) method, 187, 197 Receivers onPrepared( ) callback method, 217 limitations, 289 onReceive( ) method, 289 UI, 289 named onReceive( ), 289 user–facing application, 288 onRestart( ) method, 188 RelativeLayout, 164 onRestoreInstanceState( ) method, 186 action, 168 onResume( ) method, 186, 187, 197 positioning properties, 165, 166 onRetainNonConfigurationInstance( ) properties, 165 method, 188 widget position, 164, 165 onSaveInstanceState( ) widgets overlap, 169 methods, 187, 197 working, 166–168 onStartCommand( ) method, 300 Resource definition files, 125 onStart( ) method, 186, 187, 197 changing colors, 126, 127 onStop( ) method, 197 descriptive, 127, 128 Index 351

■■S ■■T Samsung Remote Test Lab, 96 TableLayout, 176 Service-to-client communication TextView widgets, 133, 135, 137 bindService( ), 298 callbacks/listeners, 299 ■ independent messaging, 299 ■U intents/broadcast receivers, 298 UI widgets, 132 notifications, 300 buttons, 138–141 use Messenger/Messenger object, 299 CheckBox, 147–149 use PendingIntent objects, 298 EditText, 144–147 setAnchorView( ) method, 237 ImageView/ImageButton, 142–144 .setAudioSource( ) method, 226 RadioButton, 153, 154 setContentView( ) method, 179 Switch, 150, 152 setLatestEventInfo( ) method, 255 TextView, 133–137 .setLights( ) method, 254 .update( ) method, 339 single-shot approach, 296 updateClickCounter( ) method, 141 SmartFileSaver.execute( ) method, 322 User Access Control (UAC), 18 Software Development Kits (SDKs), 15, 38 Source control, 98, 99 ■■V SQLite Video ACID data principles, 341 bitrate, 239 built-in tools, 342 codecs, 240 database applications, 325 containers/child codes, 241, 242 database-driven activity, 330–333 frame rate, 240 definition, 323, 324 HandBrake, 245 example applications, 326, 327, 329 VideoView, 233 features, 324 viewContact( ) method, 285 modifying data View-derived widget deleting data, 339 attributes, 132 inserting data, 337, 339 properties, 132 updating data, 339 View.OnClickListener, 140 packaging/managing, 340, 341 query approaches, 333, 334 room persistence library, 340 ■■W third-party database tools, 342 welcome_text value, 129 startService( ) method, 295, 300 call the stop( ) method, 217 ■ stopService( ) command, 296 ■X, Y, Z Switch widget, 150, 152 XML layouts, 177 System.console( ) method, 110 Java code, 178 System.out.println( ) method, 111 XML Path, 123 System.print( ) method, 111 XQuery, 123 System.readln( ) method, 111 XSLT, 123