SlideShare a Scribd company logo
1 of 53
Advanced Android Techniques By: GiladGaron
This presentation is based onTheEdge 2010 Android Application: Download it from the Market Download the source code: http://code.google.com/p/theedge2010/for all the examples in this presentation Before we begin! TheEdge 2010 Android App
UI Design Patterns I/O Access Optimizations Agenda
UI Design Patterns
Activity Layouts Intent A little reminder about: UI Design Patterns
Dashboard Action Bar Search Bar Quick Actions Flingable List Item “Applications are ahead of the framework” UI Design Patterns
Dashboard You know what they say about First Impressions... UI Design Patterns Dashboard
Introduce your application Reveal its functionality Update the user Just a layout, nothing fancy Dashboard UI Design Patterns
Dashboard Components UI Design Patterns Action Bar Updates Panel Functionality Panel
Implementation UI Design Patterns <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background">  <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="45dip" android:background="@color/action_bar_background">     <!-- Action Bar Code -->     </LinearLayout>    <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1">     <!-- Functionality Panel -->     </LinearLayout>       <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/now_playing" android:layout_width="fill_parent" android:layout_height="90dip" android:orientation="horizontal">     <!-- Update Panel -->     </LinearLayout> </LinearLayout>
Action Bar UI Design Patterns Action Bar
Improved Title Bar Persistent across the application Includes common actions Navigation Control Action Bar UI Design Patterns
Implementation UI Design Patterns <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="45dip" android:background="@color/action_bar_background">         <ImageButtonstyle="@style/action_bar_button" android:src="@drawable/home_btn_default" android:onClick="onHomeClick"/>           <ImageViewstyle="@style/action_bar_separator"/>         <TextViewstyle="@style/action_bar_text" android:text="Sessions"/>           <ImageViewstyle="@style/action_bar_separator"/>         <ImageButtonandroid:id="@+id/search_button" style="@style/action_bar_button" android:src="@drawable/search_button" android:onClick="onSearchClick"/> </LinearLayout>
Search Bar UI Design Patterns Search Bar
Implement search in your app Persistent across the application Can be used with the Action Bar Multiple search modes A clearer way to filter results Search Bar UI Design Patterns
Declare your application as searchable Declare an activity that handles the search Handle the search itself Implementation UI Design Patterns
Declare in /res/xml/searchable.xml Searchable Configuration UI Design Patterns <?xmlversion="1.0"encoding="utf-8"?> <searchablexmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="Hint" > </searchable>
Searchable Activity Declare as Searchable in the AndroidManifest.xml: UI Design Patterns <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.alphacsp.theedge" android:versionCode="4" android:versionName="1.03" android:installLocation="preferExternal">       <applicationandroid:label="TheEdge 2010"android:icon="@drawable/ic_launcher">           <activityandroid:name=".ui.activities.SearchActivity"android:label="Search"android:theme="@style/Theme.TheEdge">             <intent-filter>                 <actionandroid:name="android.intent.action.SEARCH"/>             </intent-filter>             <meta-dataandroid:name="android.app.searchable"android:resource="@xml/searchable"/>         </activity>         <activityandroid:name=".ui.activities.AboutActivity"android:label="About“ android:theme="@style/Theme.TheEdge"/>           <meta-dataandroid:name="android.app.default_searchable"android:value=".ui.activities.SearchActivity"/>  </manifest>
Searchable Activity Handle the Query: UI Design Patterns publicclassSearchActivityextendsTabActivity { @Override publicvoidonCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_activity);   Intentintent = getIntent(); String query = intent.getStringExtra(SearchManager.QUERY);   finalTabHost host = getTabHost();   IntentspeakersIntent = new Intent(SearchActivity.this, SpeakersActivity.class); speakersIntent.putExtra(SearchManager.QUERY, query); host.addTab(host.newTabSpec("Speakers").setIndicator(buildIndicator("Speakers")).setContent(speakersIntent));   IntentsessionsIntent = new Intent(SearchActivity.this, SessionsActivity.class); sessionsIntent.putExtra(SearchManager.QUERY, query); host.addTab(host.newTabSpec("Sessions").setIndicator(buildIndicator("Sessions")).setContent(sessionsIntent));     }
Quick Actions Quick context menu UI Design Patterns
Contextual actions driven popup menu Natural flow to the screen context Simple and effective Wow effect Quick Actions UI Design Patterns
Not in the SDK Custom Views Implementation taken from: Lorenz’s Bloghttp://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/ Implementation UI Design Patterns
Flingable List Item Flingable context menu UI Design Patterns
Contextual actions driven flinged menu Natural flow to the screen context Wow effect Flingable List Item UI Design Patterns
Major players: ViewFlipper Layout GestureDetector ListAdaptor ListActivity Implementation UI Design Patterns
Vertical scrollable view that allows multiple rows views (List Item) Uses ListAdapter to populate each List Item Recycles Views (So don’t cache them!) Supports different view types A few words about ListView UI Design Patterns
ListView should not hold N Views. Use ConvertView in getView method: ListView Recycler UI Design Patterns @Override publicViewgetView(int position, ViewconvertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.speakers_list, parent, false);       }       //Get your components from the view finalTextViewspeakerName = (TextView) convertView.findViewById(R.id.speaker_name);         //Get your item Speakerspeaker = getItem(position); returnconvertView;     }
ListView Recycler in action UI Design Patterns
ViewFlipper UI Design Patterns Allows transition between layouts Supports animations <ViewFlipperxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent">     <includeandroid:id="@+id/first"layout="@layout/sessions_list"/>     <includeandroid:id="@+id/second"layout="@layout/sessions_list_flinged"/> </ViewFlipper>
GestureDetector UI Design Patterns Detects various gestures and events using the supplied MotionEvents GestureDetectorgestureDetector= newGestureDetector(newGestureDetector.SimpleOnGestureListener() { @Override publicbooleanonFling(MotionEvent e1, MotionEvent e2, floatvelocityX, floatvelocityY) {             }   @Override publicbooleanonDown(MotionEvent e) {             }   @Override publicbooleanonSingleTapUp(MotionEvent e) {             }         });
Implementation UI Design Patterns Read the Source Code…
I/O Access
File System Database Network Types of I/O: I/O Access
Reading is fast Writing is slow  Disk space affects performance Make sure you support External Storage (Both in installation and in caches/data) Flash I/O I/O Access
Virtual Table that allows Full Text Search Produces results significantly faster than LIKE Comprehensive syntax SQLite FTS I/O Access
Creating FTS table Similar to creating a regular table: I/O Access publicclassDatabaseHelperextendsSQLiteOpenHelper {  privatestaticfinalStringDATABASE_NAME = "TheEdge"; publicstaticfinalStringSPEAKERS_TABLE = "speakers";   @Language("SQLite") privatestaticfinalStringCREATE_SPEAKERS_TABLE = "CREATE VIRTUAL TABLE " + SPEAKERS_TABLE + " USING fts3 	(speaker_name  TEXT , bio TEXT, company TEXT, image_uri TEXT)";   publicDatabaseHelper(Contextcontext, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version);     }   @Override publicvoidonCreate(SQLiteDatabasesqLiteDatabase) { Log.i(this.getClass().getSimpleName(), "Creating DB"); sqLiteDatabase.execSQL(CREATE_SPEAKERS_TABLE);     }  
Using: Use the MATCH keyword: I/O Access publicList<Session> searchSessions(String query) { finalList<Session> sessionList = newArrayList<Session>(); finalSQLiteDatabasereadableDatabase = getReadableDatabase(); finalCursorcursor = readableDatabase.rawQuery("select * from " + SESSIONS_TABLE + " where " + SESSIONS_TABLE + " match '" + query + "'", null); if (cursor.moveToFirst()) { do { finalSessionsession = newSession(); session.setTopic(cursor.getString(cursor.getColumnIndex("topic"))); session.setPresenter(cursor.getString(cursor.getColumnIndex("presenter"))); session.setSessionAbstract(cursor.getString(cursor.getColumnIndex("abstract"))); sessionList.add(session);         } while (cursor.moveToNext());     } if (!cursor.isClosed()) { cursor.close();     } returnsessionList; }  
Use a Service Use Apache HTTPClient not URLConnection Don’t do it on the UI thread Parsing can be costly, design your data structure carefully Network I/O Access
When using network, remember the following: Availability:Always check connectivity with ConnectivityManager. Performance:Don’t run on the UI Thread, use AsyncTask or Service. Bandwidth:Use as little as you can. Battery drain:Only use the network when you have to. I/O Access
I/O Access Activity with separate thread for Network
Optimization
Allows you to execute a task without having to manage thread pools. Defined by three generic types: Parameters, Progress and Result. Has a lifecycle: onPreExecute – Called before running the task. doInBackground – Actual work onProgressUpdate – Callback to update the UI on task progress onPostExecute – Called after task has ended, receives the response object Very smart and easy. AsyncTask Optimization
In order to implment lazy loading, we’ll need to do the following: Load the ListView an you would normally do. Create a task to fetch the data, use AsyncTask or a Service. Change the data on the UI thread. Use notifyDataSetChanged() to let ListView to update itself. Lazy Loading your ListView Optimization
Example Optimization publicclassSpeakersActivityextendsListActivityimplementsServiceListener {   privatevoidfetchImages() { for (Speakerspeaker : speakers) { SpeakerImageFetcherspeakerImageFetcher = newSpeakerImageFetcher(); speakerImageFetcher.execute(speaker);         }     }       privateclassSpeakerImageFetcherextendsAsyncTask<Speaker, Void, Void> {   @Override protectedVoiddoInBackground(Speaker... speakers) { finalSpeakerspeaker = speakers[0]; finalBitmapbitmap = dataAccessor.fetchImage(speaker.getImageUrl()); speaker.setSpeakerImage(bitmap); returnnull;         }   @Override protectedvoidonPostExecute(VoidaVoid) { speakersAdapter.notifyDataSetChanged();         }     } }
Runs in the background Is not killed when the application ends Running a service is easy Getting callbacks is a bit awkward Declare it in your AndroidManifest.xml Services Optimization
Services oriented application: Optimization SQLite HttpClient Data Accessor Service Service Helper Activity
Service Example: Optimization publicclassNetworkServiceextendsIntentService {   @Override protectedvoidonHandleIntent(Intent intent) { finalDataAccessordataAccessor = DataAccessor.getSingleton(this);   finalResultReceiver receiver = intent.getParcelableExtra(STATUS_LISTENER); finalintrequestAction = intent.getIntExtra(REFRESH_ACTION, -1); boolean result = false;   if (requestAction == REFRESH_SPEAKERS) {             result = dataAccessor.syncAllSpeakers();         } elseif (requestAction == REFRESH_SESSIONS) {             result = dataAccessor.syncAllSessions();         } elseif (requestAction == REFRESH_SCHEDULE) {             result = dataAccessor.syncAllEvents();         } elseif (requestAction == REFRESH_ALL) { dataAccessor.syncAllSpeakers(); dataAccessor.syncAllSessions(); dataAccessor.syncAllEvents();         } if (result) { receiver.send(STATUS_REFRESHED, Bundle.EMPTY);         } receiver.send(STATUS_NOT_REFRESHED, Bundle.EMPTY);     } }  
ResultReceiver: Implements Parcelable, so can be passed in the Intent object Good for “Here and now” results per intent Getting a Callback from a Service: Optimization
ResultReceiver Example Accepts the Activity as the Listener using a custom interface Optimization publicclassNetworkServiceHelperextendsResultReceiver {      privatefinalServiceListenerlistener;      publicNetworkServiceHelper(ServiceListener listener) { super(new Handler());        this.listener = listener;      }     @Override protectedvoidonReceiveResult(intresultCode, BundleresultData) { if (listener != null) { listener.onReceiveResult(resultCode, resultData);         }     } }
Optimization Using the service: publicclassScheduleActivityextendsActivityimplementsServiceListener {      privateNetworkServiceHelpernetworkServiceHelper;      @Override publicvoidonCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.schedule_activity); dataAccessor = DataAccessor.getSingleton(this); initCalendar(); networkServiceHelper = newNetworkServiceHelper(this); finalIntentserviceIntent = new Intent(Intent.ACTION_SYNC, null, this, NetworkService.class); serviceIntent.putExtra(NetworkService.STATUS_LISTENER, networkServiceHelper); serviceIntent.putExtra(NetworkService.REFRESH_ACTION, NetworkService.REFRESH_SCHEDULE); startService(serviceIntent);      } @Override publicvoidonReceiveResult(intresultCode, BundleresultData) {  if (resultCode == NetworkService.STATUS_REFRESHED) {  calendarLayout.removeAllViews();  initCalendar();         }     } }
Reference
Reference http://developer.android.com/guide/index.html http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/ http://code.google.com/p/theedge2010/ http://android-developers.blogspot.com/?hl=en http://www.google.com/events/io/2010/sessions.html#Android http://www.sqlite.org/fts3.html http://www.sqlite.org/cvstrac/wiki/wiki?p=FtsUsage
Thank You! We appreciate your feedback

More Related Content

Recently uploaded

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

TheEdge 2010: Android Advanced Techniques

  • 2. This presentation is based onTheEdge 2010 Android Application: Download it from the Market Download the source code: http://code.google.com/p/theedge2010/for all the examples in this presentation Before we begin! TheEdge 2010 Android App
  • 3. UI Design Patterns I/O Access Optimizations Agenda
  • 5. Activity Layouts Intent A little reminder about: UI Design Patterns
  • 6. Dashboard Action Bar Search Bar Quick Actions Flingable List Item “Applications are ahead of the framework” UI Design Patterns
  • 7. Dashboard You know what they say about First Impressions... UI Design Patterns Dashboard
  • 8. Introduce your application Reveal its functionality Update the user Just a layout, nothing fancy Dashboard UI Design Patterns
  • 9. Dashboard Components UI Design Patterns Action Bar Updates Panel Functionality Panel
  • 10. Implementation UI Design Patterns <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background"> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="45dip" android:background="@color/action_bar_background"> <!-- Action Bar Code --> </LinearLayout>   <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"> <!-- Functionality Panel --> </LinearLayout>   <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/now_playing" android:layout_width="fill_parent" android:layout_height="90dip" android:orientation="horizontal"> <!-- Update Panel --> </LinearLayout> </LinearLayout>
  • 11. Action Bar UI Design Patterns Action Bar
  • 12. Improved Title Bar Persistent across the application Includes common actions Navigation Control Action Bar UI Design Patterns
  • 13. Implementation UI Design Patterns <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="45dip" android:background="@color/action_bar_background"> <ImageButtonstyle="@style/action_bar_button" android:src="@drawable/home_btn_default" android:onClick="onHomeClick"/>   <ImageViewstyle="@style/action_bar_separator"/> <TextViewstyle="@style/action_bar_text" android:text="Sessions"/>   <ImageViewstyle="@style/action_bar_separator"/> <ImageButtonandroid:id="@+id/search_button" style="@style/action_bar_button" android:src="@drawable/search_button" android:onClick="onSearchClick"/> </LinearLayout>
  • 14. Search Bar UI Design Patterns Search Bar
  • 15. Implement search in your app Persistent across the application Can be used with the Action Bar Multiple search modes A clearer way to filter results Search Bar UI Design Patterns
  • 16. Declare your application as searchable Declare an activity that handles the search Handle the search itself Implementation UI Design Patterns
  • 17. Declare in /res/xml/searchable.xml Searchable Configuration UI Design Patterns <?xmlversion="1.0"encoding="utf-8"?> <searchablexmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="Hint" > </searchable>
  • 18. Searchable Activity Declare as Searchable in the AndroidManifest.xml: UI Design Patterns <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.alphacsp.theedge" android:versionCode="4" android:versionName="1.03" android:installLocation="preferExternal">   <applicationandroid:label="TheEdge 2010"android:icon="@drawable/ic_launcher">   <activityandroid:name=".ui.activities.SearchActivity"android:label="Search"android:theme="@style/Theme.TheEdge"> <intent-filter> <actionandroid:name="android.intent.action.SEARCH"/> </intent-filter> <meta-dataandroid:name="android.app.searchable"android:resource="@xml/searchable"/> </activity> <activityandroid:name=".ui.activities.AboutActivity"android:label="About“ android:theme="@style/Theme.TheEdge"/>   <meta-dataandroid:name="android.app.default_searchable"android:value=".ui.activities.SearchActivity"/>  </manifest>
  • 19. Searchable Activity Handle the Query: UI Design Patterns publicclassSearchActivityextendsTabActivity { @Override publicvoidonCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_activity);   Intentintent = getIntent(); String query = intent.getStringExtra(SearchManager.QUERY);   finalTabHost host = getTabHost();   IntentspeakersIntent = new Intent(SearchActivity.this, SpeakersActivity.class); speakersIntent.putExtra(SearchManager.QUERY, query); host.addTab(host.newTabSpec("Speakers").setIndicator(buildIndicator("Speakers")).setContent(speakersIntent));   IntentsessionsIntent = new Intent(SearchActivity.this, SessionsActivity.class); sessionsIntent.putExtra(SearchManager.QUERY, query); host.addTab(host.newTabSpec("Sessions").setIndicator(buildIndicator("Sessions")).setContent(sessionsIntent)); }
  • 20. Quick Actions Quick context menu UI Design Patterns
  • 21. Contextual actions driven popup menu Natural flow to the screen context Simple and effective Wow effect Quick Actions UI Design Patterns
  • 22. Not in the SDK Custom Views Implementation taken from: Lorenz’s Bloghttp://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/ Implementation UI Design Patterns
  • 23. Flingable List Item Flingable context menu UI Design Patterns
  • 24. Contextual actions driven flinged menu Natural flow to the screen context Wow effect Flingable List Item UI Design Patterns
  • 25. Major players: ViewFlipper Layout GestureDetector ListAdaptor ListActivity Implementation UI Design Patterns
  • 26. Vertical scrollable view that allows multiple rows views (List Item) Uses ListAdapter to populate each List Item Recycles Views (So don’t cache them!) Supports different view types A few words about ListView UI Design Patterns
  • 27. ListView should not hold N Views. Use ConvertView in getView method: ListView Recycler UI Design Patterns @Override publicViewgetView(int position, ViewconvertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.speakers_list, parent, false); } //Get your components from the view finalTextViewspeakerName = (TextView) convertView.findViewById(R.id.speaker_name);   //Get your item Speakerspeaker = getItem(position); returnconvertView; }
  • 28. ListView Recycler in action UI Design Patterns
  • 29. ViewFlipper UI Design Patterns Allows transition between layouts Supports animations <ViewFlipperxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent"> <includeandroid:id="@+id/first"layout="@layout/sessions_list"/> <includeandroid:id="@+id/second"layout="@layout/sessions_list_flinged"/> </ViewFlipper>
  • 30. GestureDetector UI Design Patterns Detects various gestures and events using the supplied MotionEvents GestureDetectorgestureDetector= newGestureDetector(newGestureDetector.SimpleOnGestureListener() { @Override publicbooleanonFling(MotionEvent e1, MotionEvent e2, floatvelocityX, floatvelocityY) { }   @Override publicbooleanonDown(MotionEvent e) { }   @Override publicbooleanonSingleTapUp(MotionEvent e) { } });
  • 31. Implementation UI Design Patterns Read the Source Code…
  • 33. File System Database Network Types of I/O: I/O Access
  • 34. Reading is fast Writing is slow Disk space affects performance Make sure you support External Storage (Both in installation and in caches/data) Flash I/O I/O Access
  • 35. Virtual Table that allows Full Text Search Produces results significantly faster than LIKE Comprehensive syntax SQLite FTS I/O Access
  • 36. Creating FTS table Similar to creating a regular table: I/O Access publicclassDatabaseHelperextendsSQLiteOpenHelper {  privatestaticfinalStringDATABASE_NAME = "TheEdge"; publicstaticfinalStringSPEAKERS_TABLE = "speakers";   @Language("SQLite") privatestaticfinalStringCREATE_SPEAKERS_TABLE = "CREATE VIRTUAL TABLE " + SPEAKERS_TABLE + " USING fts3 (speaker_name TEXT , bio TEXT, company TEXT, image_uri TEXT)";   publicDatabaseHelper(Contextcontext, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version); }   @Override publicvoidonCreate(SQLiteDatabasesqLiteDatabase) { Log.i(this.getClass().getSimpleName(), "Creating DB"); sqLiteDatabase.execSQL(CREATE_SPEAKERS_TABLE); }  
  • 37. Using: Use the MATCH keyword: I/O Access publicList<Session> searchSessions(String query) { finalList<Session> sessionList = newArrayList<Session>(); finalSQLiteDatabasereadableDatabase = getReadableDatabase(); finalCursorcursor = readableDatabase.rawQuery("select * from " + SESSIONS_TABLE + " where " + SESSIONS_TABLE + " match '" + query + "'", null); if (cursor.moveToFirst()) { do { finalSessionsession = newSession(); session.setTopic(cursor.getString(cursor.getColumnIndex("topic"))); session.setPresenter(cursor.getString(cursor.getColumnIndex("presenter"))); session.setSessionAbstract(cursor.getString(cursor.getColumnIndex("abstract"))); sessionList.add(session); } while (cursor.moveToNext()); } if (!cursor.isClosed()) { cursor.close(); } returnsessionList; }  
  • 38. Use a Service Use Apache HTTPClient not URLConnection Don’t do it on the UI thread Parsing can be costly, design your data structure carefully Network I/O Access
  • 39. When using network, remember the following: Availability:Always check connectivity with ConnectivityManager. Performance:Don’t run on the UI Thread, use AsyncTask or Service. Bandwidth:Use as little as you can. Battery drain:Only use the network when you have to. I/O Access
  • 40. I/O Access Activity with separate thread for Network
  • 42. Allows you to execute a task without having to manage thread pools. Defined by three generic types: Parameters, Progress and Result. Has a lifecycle: onPreExecute – Called before running the task. doInBackground – Actual work onProgressUpdate – Callback to update the UI on task progress onPostExecute – Called after task has ended, receives the response object Very smart and easy. AsyncTask Optimization
  • 43. In order to implment lazy loading, we’ll need to do the following: Load the ListView an you would normally do. Create a task to fetch the data, use AsyncTask or a Service. Change the data on the UI thread. Use notifyDataSetChanged() to let ListView to update itself. Lazy Loading your ListView Optimization
  • 44. Example Optimization publicclassSpeakersActivityextendsListActivityimplementsServiceListener {   privatevoidfetchImages() { for (Speakerspeaker : speakers) { SpeakerImageFetcherspeakerImageFetcher = newSpeakerImageFetcher(); speakerImageFetcher.execute(speaker); } }   privateclassSpeakerImageFetcherextendsAsyncTask<Speaker, Void, Void> {   @Override protectedVoiddoInBackground(Speaker... speakers) { finalSpeakerspeaker = speakers[0]; finalBitmapbitmap = dataAccessor.fetchImage(speaker.getImageUrl()); speaker.setSpeakerImage(bitmap); returnnull; }   @Override protectedvoidonPostExecute(VoidaVoid) { speakersAdapter.notifyDataSetChanged(); } } }
  • 45. Runs in the background Is not killed when the application ends Running a service is easy Getting callbacks is a bit awkward Declare it in your AndroidManifest.xml Services Optimization
  • 46. Services oriented application: Optimization SQLite HttpClient Data Accessor Service Service Helper Activity
  • 47. Service Example: Optimization publicclassNetworkServiceextendsIntentService {   @Override protectedvoidonHandleIntent(Intent intent) { finalDataAccessordataAccessor = DataAccessor.getSingleton(this);   finalResultReceiver receiver = intent.getParcelableExtra(STATUS_LISTENER); finalintrequestAction = intent.getIntExtra(REFRESH_ACTION, -1); boolean result = false;   if (requestAction == REFRESH_SPEAKERS) { result = dataAccessor.syncAllSpeakers(); } elseif (requestAction == REFRESH_SESSIONS) { result = dataAccessor.syncAllSessions(); } elseif (requestAction == REFRESH_SCHEDULE) { result = dataAccessor.syncAllEvents(); } elseif (requestAction == REFRESH_ALL) { dataAccessor.syncAllSpeakers(); dataAccessor.syncAllSessions(); dataAccessor.syncAllEvents(); } if (result) { receiver.send(STATUS_REFRESHED, Bundle.EMPTY); } receiver.send(STATUS_NOT_REFRESHED, Bundle.EMPTY); } }  
  • 48. ResultReceiver: Implements Parcelable, so can be passed in the Intent object Good for “Here and now” results per intent Getting a Callback from a Service: Optimization
  • 49. ResultReceiver Example Accepts the Activity as the Listener using a custom interface Optimization publicclassNetworkServiceHelperextendsResultReceiver {   privatefinalServiceListenerlistener;   publicNetworkServiceHelper(ServiceListener listener) { super(new Handler()); this.listener = listener; }   @Override protectedvoidonReceiveResult(intresultCode, BundleresultData) { if (listener != null) { listener.onReceiveResult(resultCode, resultData); } } }
  • 50. Optimization Using the service: publicclassScheduleActivityextendsActivityimplementsServiceListener {   privateNetworkServiceHelpernetworkServiceHelper;   @Override publicvoidonCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.schedule_activity); dataAccessor = DataAccessor.getSingleton(this); initCalendar(); networkServiceHelper = newNetworkServiceHelper(this); finalIntentserviceIntent = new Intent(Intent.ACTION_SYNC, null, this, NetworkService.class); serviceIntent.putExtra(NetworkService.STATUS_LISTENER, networkServiceHelper); serviceIntent.putExtra(NetworkService.REFRESH_ACTION, NetworkService.REFRESH_SCHEDULE); startService(serviceIntent); } @Override publicvoidonReceiveResult(intresultCode, BundleresultData) { if (resultCode == NetworkService.STATUS_REFRESHED) { calendarLayout.removeAllViews(); initCalendar(); } } }
  • 52. Reference http://developer.android.com/guide/index.html http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/ http://code.google.com/p/theedge2010/ http://android-developers.blogspot.com/?hl=en http://www.google.com/events/io/2010/sessions.html#Android http://www.sqlite.org/fts3.html http://www.sqlite.org/cvstrac/wiki/wiki?p=FtsUsage
  • 53. Thank You! We appreciate your feedback

Editor's Notes

  1. Present as a story:Designing smart and cool UIThe work behind to UI – I/OAnd how to make it all work fast
  2. What is an activity: each screen is an activityA screen is defined by a layout, a layout could be an XML or Code. Explain why XML is better than code, and some Layout types.Intent is a way of describing of you want the android OS to do.
  3. When mentioninggoogle IO mention what is it
  4. Your application Home Screen
  5. The first screen the user sees
  6. Explain in short what’s a LinearLayout
  7. Voice search, suggestion, global search
  8. (Don’t believe the emulator!)
  9. Why rawQuery? Query method has too many parameters, they should use a builder…