Bài giảng Lập trình cho thiết bị di động - Bài 2: Xử lý giao diện người dùng

The View class represents the basic building block for user interface components.

a rectangular area on the screen

responsible for drawing and event handling.

is the base class for widgets

The ViewGroup subclass is the base class for layouts

invisible containers that hold other Views

and define inside views layout properties.

 

pptx219 trang | Chuyên mục: Android | Chia sẻ: dkS00TYs | Lượt xem: 1938 | Lượt tải: 4download
Tóm tắt nội dung Bài giảng Lập trình cho thiết bị di động - Bài 2: Xử lý giao diện người dùng, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
aunched Activity finishes. - To track feedback from the opened screen use the startActivityForResult (Will learn later) 171 8.1 Explicit Intent btnOpenChildActivity btnBacktoMainActivity 172 8.1 Explicit Intent 173 8.1 Explicit Intent 174 8.1 Explicit Intent Config Manifest 8.1 Explicit Intent An activity usually presents a single visual user interface from which a number of actions could be performed. Moving from one activity to another is accomplished by having the current activity start the next one through so called intents Bundle Activity 1 startActivity (Activity 2) Activity 2 Intent {action + data} Package from activity 1 175 8.1 Explicit Intent Bundle 176 The Android Bundle container is a simple mechanism used to pass data between activities. A Bundle is a type‐safe collection of pairs. There is a set of putXXX and getXXX methods to store and retrieve (single and array) values of primitive data types from/to the bundles. For example Put get 8.1 Explicit Intent Bundle 177 Bundling Complex Objects 8.1 Explicit Intent 178 Example using Intent with Bundle To learn more Bundle please visit the link below:  txta txtb btnketqua btnBack txtketqua MainActivity ResultActivity 8.1 Explicit Intent 179 8.1 Explicit Intent 180 Return the intent that started this activity. 181 8.2 Implicit Intent An implicit Intent is a mechanism that lets anonymous application components service action requests. That means you can ask the system to launch an Activity that can perform a given action without knowing which application, or Activity, will do so. Please visit the link below to see detail:  182 8.2 Implicit Intent 183 8.2 Implicit Intent 184 8.2 Implicit Intent ➤ ACTION_ANSWER Opens an Activity that handles incoming calls. Currently this is handled by the native in-call screen. ➤ ACTION_CALL Brings up a phone dialer and immediately initiates a call using the number supplied in the Intent URI. Generally it’s considered better form to use ACTION_DIAL ifpossible. ➤ ACTION_DELETE Starts an Activity that lets you delete the data specified at the Intent’s data URI. ➤ ACTION_DIAL Brings up a dialer application with the number to dial pre-populated from the Intent URI. By default this is handled by the native Android phone dialer. The dialer can normalize most number schemas: for example, tel:555-1234 and tel:(212) 555 1212 are both valid numbers. ➤ ACTION_EDIT Requests an Activity that can edit the data at the specified Intent URI. ➤ ACTION_INSERT Opens an Activity capable of inserting new items into the Cursor specified in the Intent URI. When called as a sub-Activity it should return a URI to the newly inserted item. Native Android Actions: 185 8.2 Implicit Intent Native Android Actions: ➤ ACTION_PICK Launches a sub-Activity that lets you pick an item from the Content Provider specified by the Intent URI. When closed it should return a URI to the item that was picked. The Activity launched depends on the data being picked: for example, passing content://contacts/people will invoke the native contacts list. ➤ ACTION_SEARCH Launches the Activity used for performing a search. Supply the search term as a string in the Intent’s extras using the SearchManager.QUERY key. ➤ ACTION_SENDTO Launches an Activity to send a message to the contact specified by the Intent URI. ➤ ACTION_SEND Launches an Activity that sends the data specified in the Intent. The recipient contact needs to be selected by the resolved Activity. Use setType to set the MIME type of the transmitted data. 186 8.2 Implicit Intent Native Android Actions: ➤ ACTION_VIEW The most common generic action. View asks that the data supplied in the Intent’s URI be viewed in the most reasonable manner. Different applications will handle view requests depending on the URI schema of the data supplied. Natively http: addresses will open in the browser, tel: addresses will open the dialer to call the number, geo: addresses will be displayed in the Google Maps application, and contact content will be displayed in the contact manager. ➤ ACTION_WEB_SEARCH Opens an Activity that performs a web search based on the text supplied in the Intent URI (typically the browser). 187 8.3 Getting results from Intents The startActivity(Intent) method is used to start a new activity, which will be placed at the top of the activity stack. The caller however continues to execute in its own thread. Sometimes you want to get a result back from the called sub‐activity when it ends. For example, you may start an activity that let the user pick a person from a list of contacts; when it ends, it returns the person that was selected. 188 8.3 Getting results from Intents 189 8.3 Getting results from Intents Before an invoked activity exits, it can call setResult (resultCode) to return a termination signal back to its parent. It is convenient to supply a result code, which can be the standard results Activity.RESULT_CANCELED, Activity.RESULT_OK, or any custom values. All of this information can be capture back on the parent's onActivityResult (int requestCodeID, int resultCode, Intent data) If a child activity fails for any reason (such as crashing), the parent activity will receive a result with the code RESULT_CANCELED. 190 8.3 Getting results from Intents 191 8.3 Getting results from Intents Example 1) Load list person on the ListView 2) Long Item Press on the ListView and choose this menu item 3) Click Lưu Button 192 8.3 Getting results from Intents 1) Load list person on the ListView 2) Long Item Press on the ListView and choose this menu item 3) Click Lưu Button 193 8.3 Getting results from Intents 1) Load list person on the ListView 2) Long Item Press on “ty Be’o” item on the ListView and choose this menu item 3) Click Co Button 194 8.3 Getting results from Intents We create a new Project with name LearnActivityForResult This project has 3 Activity, each Activity will have 1 Layout (see the picture) One Person Serializable class. This object will use to send from MainActivity to another sub activity and vice versa The contextmenu 195 8.3 Getting results from Intents The Person Serializable This Object use to send from Activity A to another Activity B And show on the ListView in the MainActivity 196 8.3 Getting results from Intents The mycontextmenu XML 197 8.3 Getting results from Intents The MainActivity XML Person object 198 8.3 Getting results from Intents The MainActivity coding For Requestcode For Resultcode Make contextmenu Track the Item clicked 199 8.3 Getting results from Intents The MainActivity coding 200 8.3 Getting results from Intents The MainActivity coding 201 8.3 Getting results from Intents The MainActivity coding This method use to get data from sub activity callback 202 8.3 Getting results from Intents The New Activity XML Please config as the same in the Manifest xml Use the TableLayout to design for this Activity, here are the ids for each item in this Activity: 203 8.3 Getting results from Intents The New Activity coding 204 8.3 Getting results from Intents The Edit Activity XML Please config as the same in the Manifest xml Use the TableLayout to design for this Activity, here are the ids for each item in this Activity: 205 8.3 Getting results from Intents The Edit Activity coding 206 9. Touch & Multi touch 9.1 Setup a touch listener 9.2 The MotionEvent object 9.3 Handling Multiple Touches 9.4 Demo Multi touch application 207 9.1 Setup a touch listener Touch events can be intercepted by a view object through the registration of an onTouchListener event listener and the implementation of the corresponding onTouch() callback method. 208 9.2 The MotionEvent object The MotionEvent object passed through to the onTouch() callback method is the key to obtaining information about the event. Information contained within the object includes the location of the touch within the view and the type of action performed. The MotionEvent object is also the key to handling multiple touches. An important aspect of touch event handling involves being able to identify the type of action performed by the user. The type of action associated with an event can be obtained by making a call to the getActionMasked() method of the MotionEvent object which was passed through to the onTouch() callback method. 209 9.2 The MotionEvent object When the first touch on a view occurs, the MotionEvent object will contain an action type of ACTION_DOWN together with the coordinates of the touch. When that touch is lifted from the screen an ACTION_UP event is generated. Any motion of the touch between the ACTION_DOWN and ACTION_UP events will be represented by ACTION_MOVE events. 210 9.3 Handling Multiple Touches When more than one touch is performed simultaneously on a view, the touches are referred to as pointers. In a multi-touch scenario, pointers begin and end with event actions of type ACTION_POINTER_UP and ACTION_POINTER_DOWN respectively. In order to identify the index of the pointer that triggered the event, the getActionIndex() callback method of the MotionEvent object must be called. 211 9.4 Demo Multi touch application 212 9.4 Demo Multi touch application 213 10. Multi language in Android 10.1 Why multi language? 10.2 Setup multi language 214 10.1 Why multi language? Everyone on over the world use the cell phone with different language (maybe?). So your application should support Multilanguage to best sell. Right? The focus is the English language or Chinese language or Vietnamese language or combodia…? I think that you should support Multilanguage, and you? Điện thoại cháu toàn tiếng Campuchia, bà hok config được 215 10.2 Setup multi language Some country code, please visit this link:  Choose the language in the configuration It will auto append the country code 216 10.2 Setup multi language 217 10.2 Setup multi language The code above will auto choose exactly the language to show on the Listview 218 10.2 Setup multi language Choose different language to see data on the Listview 219 Exercise END 220 

File đính kèm:

  • pptx2 - XỬ LÝ GIAO DIỆN NGƯỜI DÙNG.pptx
Tài liệu liên quan