android 3

38
Android 3.0 Honeycomb Robert Cooper Reach Health

Upload: robert-cooper

Post on 19-May-2015

851 views

Category:

Technology


1 download

DESCRIPTION

What's new in Android 3.0 Honeycomb

TRANSCRIPT

Page 1: Android 3

Android 3.0 Honeycomb

Robert CooperReach Health

Page 2: Android 3

What is Honeycomb?

Tablet-specific version of Android New UI Metaphors New LaF (Holographic) New/Improved APIs. Old APIs made optional (telephony, etc) New Technologies

Basis for future releases 3.1 seems to be on-deck Merged with phone branch?

Page 3: Android 3

What are we going to talk about?

Hopefully everything, at least briefly. Detailed discussion of the things I just you

are most likely to care about as a developer :P

Page 4: Android 3

New UI Metaphor

ActionBar Used for “App Global” Tabs Special MenuItems or SubMenus App Icon with a “Logical Home” operation

No Hard Buttons NotificationBar now includes “Back”, “Home”

and “Tasks” Long-Touch context menus deprecated as

a model

Page 5: Android 3

New UI Metaphor

Page 6: Android 3

New Look and Feel

Holographic look and feel added Make it more TRON-ish… … but not too TRON-ish Lots of glows, varied depth line markers,

3D transitions Improved text ops mechanics

Page 7: Android 3

New Look and Feel

Page 8: Android 3

New Look and Feel

Page 9: Android 3

New Look and Feel

Page 10: Android 3

New APIs

Fragments Sub-Activities

Loaders Async-Friendly Content Fetchers

ActionBar New Menuing and Nav System.

Enhanced Interaction for Widgets and Notifications

Drag and Drop

Page 11: Android 3

New APIs: Fragments

Fragments Fragments are Sub-Activities that can be

recomposed based on UI factors (screen size, orientation, etc)

Part of 3.0, but available as a build-in backport as far back as 1.6 with the “Android Compatibility Package” (Available in the SDK/AVD Manager)

Page 12: Android 3

New APIs: Fragments

Fragments mimic Activity lifecycle: onCreate() onStart() onCreateView()* onPause() onStop()

Page 13: Android 3

New APIs: Fragments

Fragments laid out as part of Layouts<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"    android:layout_width="match_parent"    android:layout_height="match_parent">    <fragment android:name="com.example.news.ArticleListFragment"            android:id="@+id/list"            android:layout_weight="1"            android:layout_width="0dp"            android:layout_height="match_parent" />    <fragment android:name="com.example.news.ArticleReaderFragment"            android:id="@+id/viewer"            android:layout_weight="2"            android:layout_width="0dp"            android:layout_height="match_parent" /></LinearLayout>

Page 14: Android 3

New APIs: Fragments

Each Fragment becomes unique in the application

Can move between Activities with different combinations of Fragments by passing Fragment model/URI information using the FragmentManager API.

FragmentTransaction can be used to manipulate fragment state and “back” behavior

Page 15: Android 3

New APIs: Fragments

FragmentTransaction

Fragment newFragment = new ExampleFragment();FragmentTransaction transaction = getFragmentManager().beginTransaction();

transaction.replace(R.id.fragment_container, newFragment);transaction.addToBackStack(null);

transaction.commit();

Page 16: Android 3

New APIs: Loaders

Loaders provide a standard way to load data for Fragments

AsyncTaskLoader provides API for loading data asynchronously

CursorLoader loads a paged dataset asynchronously – this is likely what you want to read, for example, an Atom Pub Proto data source remotely.

Page 17: Android 3

New APIs: ActionBar

Moving MenuItems to the ActionBar

<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android">    <item android:id="@+id/menu_add"          android:icon="@drawable/ic_menu_save"          android:title="@string/menu_save"          android:showAsAction="ifRoom|withText" /></menu>

Page 18: Android 3

New APIs: ActionBar

Custom Views in ActionBar<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">    <item android:id="@+id/menu_search"        android:title="Search"        android:icon="@drawable/ic_menu_search"        android:showAsAction="ifRoom"    android:actionLayout="@layout/searchview"

android:actionViewClass="android.widget.SearchView"

/></menu>

Page 19: Android 3

New APIs: ActionBar

Custom Views in ActionBar (cont)

SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();

Page 20: Android 3

New APIs: ActionBar

Navigation Big win over iOS!

Implicit “Home” widget (vs iOS Nav Bar) App Global Tabs (vs iOS Tool Bar) App List Navigation

Page 21: Android 3

New APIs: ActionBar

Getting the “Home” icon viewView home = a.findViewById(android.R.id.home);home.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { a.finish(); }}); Adding “Up” marker

ActionBar actionBar = this.getActionBar();actionBar.setDisplayHomeAsUpEnabled(true);

Page 22: Android 3

New APIs: ActionBar

ActionBar Tabs final ActionBar actionBar = getActionBar();

actionBar.setNavigationMode( ActionBar.NAVIGATION_MODE_TABS);

// remove the activity title to make space for tabsactionBar.setDisplayShowTitleEnabled(false);

Fragment artistsFragment = new ArtistsFragment();actionBar.addTab(actionBar.newTab()

.setText(R.string.tab_artists)    .setTabListener(new TabListener(artistsFragment)));

Fragment albumsFragment = new AlbumsFragment();actionBar.addTab(actionBar.newTab()

.setText(R.string.tab_albums)     .setTabListener(new TabListener(albumsFragment)));

Page 23: Android 3

New APIs: ActionBar

ActionBar List (Spinner) Navigation ActionBar actionBar = getActionBar();

actionBar.setNavigationMode( ActionBar.NAVIGATION_MODE_LIST); actionBar.setListNavigationCallbacks( new SpinnerAdapter(){ public View getDropDownView(int position,  View convertView, View Group parent){ // … }

}, new OnNavigationListener(){ public boolean onNavigationItemSelected( int itemPosition, long itemId){ //… } });

Page 24: Android 3

New APIs: Notifications

Notifications can now use RemoteViews to allow interaction with the popup notification, rather than just launch an intent.

RemoteViews layout = new RemoteViews( getPackageName(), R.layout.notification);

notification.contentView = layout;

layout.setOnClickPendingIntent( R.id.my_button, getDialogPendingIntent( "You pressed it!"));

Page 25: Android 3

New APIs: Notifications

PendingIntent getDialogPendingIntent( String dialogText) {

        return PendingIntent.getActivity(                this, // send back to the creating Act.                dialogText.hashCode(),                 new Intent(ACTION_DIALOG)                        .putExtra(Intent.EXTRA_TEXT,

dialogText)                        .addFlags(

Intent.FLAG_ACTIVITY_NEW_TASK),                0);    }

Page 26: Android 3

New APIs: Notifications

Handling the PendingIntent:

if (ACTION_DIALOG.equals(intent.getAction())) {            showDialog(

intent.getStringExtra( Intent.EXTRA_TEXT))}

PendingIntent then becomes an invisible call back into your Activity.

Page 27: Android 3

New APIs: Drag and Drop

Any View can now be dragged about the screen.

To begin a drag action call:myView.startDrag( dragData, dragShadowBuilder, localData,

0 /*unused int flags */); Can be called from you

OnClick/OnLongClick listeners… localData is just any Object that will be

sent with each DragEvent.

Page 28: Android 3

New APIs: Drag and Drop

dragData: is a ClipData object. This contains the data representation of what is being dragged:

ClipData.Item item = new ClipData.Item(v.getTag()); ClipData dragData = new ClipData(v.getTag(), ClipData.MIMETYPE_TEXT_PLAIN,item);

Be sure to use the “tag” property for your model data!

Page 29: Android 3

New APIs: Drag and Drop

Create the DrawShadowBuilder. This returns the view that is dragged about under the pointer.

This class takes a View as an argument and looks a lot like the stock View paint lifecycle.@Overridepublic void onProvideShadowMetrics (Point size, Point touch)@Overridepublic void onDrawShadow(Canvas canvas)

The first method sets the bounds, the second paints to the canvas.

You can use the View’s existing draw() method then mutate it

Page 30: Android 3

New APIs: Drag and Drop

DragEvents onDragEvent(DragEvent) or

View.OnDragListener on any view (These are really for Drop Targets)

DragEvent.getAction() returns one of the possible event action types.

Page 31: Android 3

New APIs: Drag and Drop

ACTION_DRAG_STARTED Sent to all active Views – check here for drop target

validity! ACTION_DRAG_ENTERED

Sent when the touch enters the box of the View ACTION_DRAG_LOCATION

Sent on each move while in the box of the View ACTION_DRAG_EXITED

Sent when the touch leaves the box. ACTION_DROP

Sent on drop event *ONLY* when the View/Listener returned “true” from the ACTION_DRAG_STARTED event.

Page 32: Android 3

New Technologies

Support for Hardware Accelerated Graphics Applies to stock animations and drawing APIs Comes damned near for free but… … if you haven’t tested it, it doesn’t work. Romain Guy eats his words! :P

Property animation RenderScript

A C99-ish script for doing OpenGL ops Should be like falling off a log for people with

OpenCL experience (read: not me)

Page 33: Android 3

New Technologies: GFX Aceleration

Activation/Deactivation Step 1: Add…

android:hardwareAccelerated="true|false“

…to your <application> or <activity> Step 2: Profit!

Page 34: Android 3

New Technologies: Propery Anim

Looks a whole lot like every other reflective animator (Swing-X, Gwittir, Moo Tools, etc)

Lots of possible options, but easily summarized:ObjectAnimator anim = ObjectAnimator.ofFloat(

someObject, “someProperty", startValue, endValue); anim.setInterpolater( someInterpolater );

anim.setDuration(1000);anim.start();

Page 35: Android 3

New Technologies: Property Anim

Lots of stock interpolators (mutation strategies) AccelerateDecelerateInterpolator : Sinoidal AccelerateInterpolator : Geometric AnticipateInterpolator : Start backwards, then

fling forward BounceInterpolator : Bounces around the end

value Linear Interpolator : Even steps “And many, many more!”

Page 36: Android 3

New Technologies: RenderScript

Not even going to get into this. Example from Google:

#pragma version(1)#pragma rs java_package_name(com.android.example.hellocompute)

rs_allocation gIn;rs_allocation gOut;rs_script gScript;

const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};

void root(const uchar4 *v_in, uchar4 *v_out, const void *usrData, uint32_t x, uint32_t y) {    float4 f4 = rsUnpackColor8888(*v_in);

    float3 mono = dot(f4.rgb, gMonoMult);    *v_out = rsPackColorTo8888(mono);}

void filter() {    rsForEach(gScript, gIn, gOut, 0);}

Page 37: Android 3

… but wait, there’s more!

DownloadManager API is VASTLY improved over the Gingerbread version! It is actually usable now!

HTTP Live Streaming support Improved SIP API over Gingerbread. Accessibility improvements

Page 38: Android 3

YMMV

Still questions about what API 12 will mean ActionBar/New Notifications on Phones? Is that

a good idea? Keeping phones with the current menu

strategy? How to detect “Tablet-y” systems?

Google TV? Lots and Lots of “Reflectively constructed

strategies” – I it is manageable, but getting harder to support older devices