Presentation is loading. Please wait.

Presentation is loading. Please wait.

Favorite Twitter® Searches App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

Similar presentations


Presentation on theme: "Favorite Twitter® Searches App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved."— Presentation transcript:

1 Favorite Twitter® Searches App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

2

3

4

5

6

7

8

9 A ScrollView can contain other views (like a layout) and lets user scroll through content too large to display on the screen. Technologies Overview

10 SharedPreferences ▫ Used to manipulate a file of key/value pairs, which stores tags and Twitter search queries ▫ Going to read in the saved searches in refreshButtons method called from Activity’s OnCreate method  Acceptable because file is small Intents ▫ Typically used to launch activities ▫ Indicate an action to be performed and the data on which it is to be performed ▫ When button is touched, create a URL containing Twitter query, load into browser by creating new Intent, then pass Intent to startActivity method to launch browser. ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

11 Technologies Overview LayoutInflater ▫ Programmatically creates GUI components  In out app, each new search, adds another row. AlertDialog ▫ Used to display a message to the user  In case one of the EditText’s is empty or to confirm Clear ▫ While the dialog is displayed, user cannot interact with app (modal dialog) AndroidManifest.xml ▫ Created for you, when you create the app ▫ Add a new setting to the manifest to prevent the soft keyboard from displaying when the app first loads. ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

12 Building the App’s GUI and Resource Files Create project Create Resource Files ▫ colors.xml, dimen.xml, strings.xml Delete and Recreate main.xml Create GUI: Add TableLayout and Components Review Key features in main.xml Create another layout XML file ▫ Will define a TableRow that will be programmatically inflated to create each search Button and corresponding EditButton ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

13 Creating Resource Files Right click project name Select New > Other Select Android XML file from Android node in the New dialog Enter name of the xml file Under “What type of resource would you like to create?”, select Values Click Finish ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

14

15 User’s search queries are appended to this URL, before ahe twitter search is displayed.

16 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. From R.color class Can find list online Stretch horizontally to fill layout’s width Remember some of the attributes must be specified directly in the XML. Enables you to configure options for the current input method, here keyboard will have a a next button. Will change focus to next component that can accept input – tagEditText.

17 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Button for saving a search. Here keyboard will have a a done button - will hide the soft keyboard.

18 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

19 Search buttons will be displayed programatically in ScrollView

20 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

21 Create another layout XML file ▫ Right click layout folder and select New > Other ▫ In Android node, select Android XML file and click Next ▫ Enter new_tag_view.xml ▫ Under “What type of resource…?” select Layout radio button. ▫ Select the root element for the new layout – Choose TableRow. ▫ Click Finish. ▫ In Graphical Layout, select Android version and Device Configuration ▫ Add two buttons to the layout and configure them.  Text property will be configured programmatically. ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

22 new_tag_view.xml ©1992-2013 by Pearson Education, Inc. All Rights Reserved. So parent’s color shows through.

23 Building the App Package and import statements Write main (and only) Activity class for app Override OnCreate Write programmer defined refreshButton, makeTag, makeTagGUI, clearButtons methods Write 4 Inner Classes to implement OnClickListener for ▫ saveButton ▫ clearTagsButton ▫ newTagsButton ▫ editButton Edit AndroidManifest.xml file ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

24 The Java Code ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Sort tags. Access Android services. Used to manipulate key/value Pairs in files associated with app. Convert an Internet URL into proper format. Deals with soft keyboard. Dynamically inflate layout

25 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Declare instance variables.

26 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Read tag/query pairs from “searches” file. MODE_PRIVATE specifies accessibility to file: this file is ONLY accessible to this app.

27 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Get more references. Call programmer defined method.

28 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Call programmer defined method.

29 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Or modifies an existing query

30 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Android provides a service that enable you to inflate a layout. To obtain this service, you obtain a reference to it.

31 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

32

33

34 Argument to the Builder constructor is the context in which the dialog sill be displayed. Must be fully qualified, because we are calling it from within an anonymous inner class.

35 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. to confirm all stored searches to be removed Define positive button AND its event handler

36 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Dialog is cancellable; user can touch back button to dismiss dialog

37 ©1992-2013 by Pearson Education, Inc. All Rights Reserved. Event handler, registered for Each newTagButton as it is created Gets text of the button clicked Gets corresponding search query arg1 – constant to display data arg2 – uniform resource id to data on which we want to perform the action

38 ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

39 Android Manifest File When you create a project for an Android app in Eclipse, the ADT Plugin creates and configures AndroidManifest.xml file ▫ Describes information about the app ▫ The manifest element is the root element  package attribute  versionCode and versionName attributes  icon attribute  label attribute (name of the app)  uses-sdk specifies target SDK and min SDK version  WITHIN application element is the activity element ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

40

41 Activity element Activity elements are contained within application element If the app has more than one activity, each will have its own activity element Name attribute – specifies Activity’s class name, if preceded by a dot (.), class name is auto appended to a package name specified in manifest element windowSoftInputMode here is specified NOT to show the soft keyboard when activity is launched ▫ Can edit xml directly or open the manifest editor by double-clicking on the AndroidManifest.xml file ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

42

43 Activity element cont. Within activity element is the intent-filter element ▫ Specifies types of intents the Activity can respond to ▫ The intent-filter element must contain one or more action elements This contains just one action MAIN and its category is LAUNCHER ▫ This indicates that this activity should be listed in the application launcher with other apps on the device ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

44 Wrap-up Introduced ScrollView (ViewGroup) and Button Learned how to create resource files using New Android XML File dialog ▫ color.xml, dimen.xml and new_tag_view.xml Learned how to create GUI components dynamically by inflatin an XML layout Learned how to store key/value pairs in SharedPreferences and manipulate them Learned how to programmatically hide the soft keyboard ©1992-2013 by Pearson Education, Inc. All Rights Reserved.

45 Wrap-up Learned how to load a URI into a device’s web browser by creating a new Intent and passing it to Context’s startActivity method Learned how to use AlertDialog.Builder to configure and create AlertDialogs for displaying message to the user Learned how to use Arrays to sort and search Learned a bit about the AndroidManifest file and how to configure it ©1992-2013 by Pearson Education, Inc. All Rights Reserved.


Download ppt "Favorite Twitter® Searches App Android How to Program ©1992-2013 by Pearson Education, Inc. All Rights Reserved."

Similar presentations


Ads by Google