Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf ·...

10
4/6/11 1 Renderscript Coding Practices 2 Page © 2010 Motorola Mobility, Inc. Designing Apps for the Motorola XOOM Page Version 1.0 © 2010 Motorola Mobility, Inc. Renderscript New, high performance 3D graphics API Was used in Froyo for Live Wallpaper Is used in Honeycomb for Books and YouTube app Honeycomb introduces Renderscript as a public API For performance critical code where the traditional Open GL ES framework APIs are not fast enough!

Transcript of Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf ·...

Page 1: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

1

Renderscript

Coding Practices 2 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM Page

Version 1.0 © 2010 Motorola Mobility, Inc.

Renderscript

•  New, high performance 3D graphics API

•  Was used in Froyo for Live Wallpaper

•  Is used in Honeycomb for Books and YouTube app

•  Honeycomb introduces Renderscript as a public API

•  For performance critical code where the traditional Open GL ES framework APIs are not fast enough!

Page 2: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

2

Coding Practices 3 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM Page

Version 1.0 © 2010 Motorola Mobility, Inc.

YouTube and Renderscript

Coding Practices 4 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM Page

Version 1.0 © 2010 Motorola Mobility, Inc.

Books and Renderscript

Page 3: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

3

Coding Practices 5 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM Page

Version 1.0 © 2010 Motorola Mobility, Inc.

Renderscript API

•  A “computing” API for locating moving points in 3D

•  A “rendering” API for drawing textures over the points

•  A C-based scripting language to access this API

•  Only goal: squeeze last ounce of graphics performance!

•  Approach: API is a thin layer over features that are hardware-supported •  http://community.developer.motorola.com/t5/MOTODEV-Blog/

Introduction-to-Renderscript/ba-p/12136

Coding Practices 6 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM Page

Renderscript API

•  Android build tools compile your Renderscript .rs file to intermediate bytecode

•  and package it inside your application's .apk file

•  On the device, the bytecode is compiled (just-in-time) to machine code that is optimized for the exact device that it is running on

•  Machine code is cached for future use

•  This eliminates the need to target a specific architecture during the development process. Excellent!

Page 4: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

4

Coding Practices 7 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM Page

Version 1.0

Example .rs file (from Honeycomb samples) #pragma rs java_package_name(com.android.rs.helloworld)!

#include "rs_graphics.rsh” // header with graphics API’s!

// gTouchX and gTouchY are variables that will be reflected for use!// by the java API. We can use them to notify the script of touch events.!int gTouchX;!int gTouchY;!

// This is invoked automatically when the script is created!void init() {! gTouchX = 50.0f;! gTouchY = 50.0f;!}!

int root(int launchID) {! // Clear the background color! rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);! // Tell the runtime what the font color should be! rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);! // Introduce ourselves to the world by drawing a greeting! // at the position user touched on the screen! rsgDrawText("Hello World!", gTouchX, gTouchY);!

// Return value tells RS roughly how often to redraw! // in this case 20 ms! return 20;!}!

10 things……..

•  Honeycomb SDK

•  targetSdkVersion

•  Layouts

•  Exception handling

•  Compatibility mode

•  Drawables

•  Text

•  Permissions and features

•  Maintaining code base

•  Honeycomb SDK

Page 5: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

5

Coding Practices 9 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

10 things you can do right now

1.  Download the Honeycomb SDK (and updated tools) and test drive your app on the emulator.

Note if you have the preview SDK replace it with the updated public SDK. 2.  Change the targetSdkVersion to “11” and see what changes. 3.  Add /res/layout-xlarge and /res/layout-xlarge-port

folders to your project with layouts optimized for the larger screen. 4.  Update error handling to exit gracefully rather than defaulting to

ANRs or letting the user hang. 5.  Check to see if app is running in “compatibility mode”.

a.  minSdkVersion=“3” no targetSdkVersion; build against 1.5

b.  minSdkVersion=“3” and targetSdkVersion=“3”; built against any SDK > 1.5

c.  “Shadowbox effect”

Coding Practices 10 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

10 things you can do (con’t)

–  Set targetSdkVersion >= “4” and build against SDK >= 1.6

Page 6: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

6

Coding Practices 11 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

6.  Revisit your graphics in /res/drawable-<density>.

a.  Put background into ImageView and set scaleType=centerCrop!

b.  Patterned images can be tiled

c.  Read into createScaledBitmap() using the dimensions from DisplayMetrics!

d.  Use the 9-patch tool to create a “stretchable” region

10 things you can do right now (con’t)

Coding Practices 12 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

10 things you can do right now (con’t)

7.  Verify your text is legible and flows well on the larger screen.

–  With more real estate (1280 x 800) optimize text to take advantage of the space

Page 7: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

7

Coding Practices 13 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

10 things you can do right now (con’t)

–  Create 2 different <dimens> tags in /res/values and /res-values-xlarge with 2 different font sizes (both in units of sp)

–  Add @dimen/<variable> to <style> textSize property

<style name=’readText" parent="@android:style/TextAppearance"> !!<item name="android:textSize">@dimen/font_size</item>!!<item name="android:textColor">#000000</item> !

</style>!

Coding Practices 14 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

10 things you can do right now (con’t) 8.  Check your permissions and <uses-feature> tag that might filter your

app from the Market.

–  Permissions do not filter your app, <uses-feature> tag does.

–  The XOOM does not have telephony…well sort of. <uses-permission android:name=“CALL_PHONE” /> !<uses-permission android:name=“CALL_PRIVILEGED” />!<uses-permission android:name=“MODIFY_PHONE_STATE”!<uses-permission android:name=“PROCESS_OUTGOING_CALLS” />!<uses-permission android:name=“READ_SMS” />!<uses-permission android:name=“RECEIVE_SMS” />!<uses-permission android:name=“RECEIVE_MMS” />!<uses-permission android:name=“RECEIVE_WAP_PUSH” />!<uses-permission android:name=“SEND_SMS” />!<uses-permission android:name=“WRITE_APN_SETTINGS” />!<uses-permission android:name=“WRITE_SMS” />!

! ! <uses-feature ! ! ! !! ! !android:name=“android.hardware.telephony”!! ! !android:required=“true”/>

*implies*

Page 8: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

8

Coding Practices 15 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

10 things you can do right now (con’t)

–  You must explicitly set android:required="false” if you want to see the app on the XOOM

–  Run aapt tool on your apk to show explicit features

$ aapt dump badging <path_to_exported_.apk>!

$ ./aapt dump badging BTExample.apk package: name='com.example.android.btexample' versionCode='' versionName='' uses-permission:'android.permission.BLUETOOTH_ADMIN'uses-feature:'android.hardware.bluetooth' sdkVersion:'3' targetSdkVersion:'5’ <. . .>

–  Run MOTODEV App Validator to show implied features. •  http://developer.motorola.com/testing/app-validator/

Coding Practices 16 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

10 things you can do right now (con’t)

9.  Determine if you are going with one code base or two.

a.  Use reflection or lazy loading to keep one code base but take advantage of 3.0 features. Keep in mind fragments are available from 1.6 and above.

b.  Branch code and build against Android 3.0. Begin adding features such as actionbar and fragments.

10.  Download the Honeycomb SDK (and updated tools) and test drive your app on the emulator.

Page 9: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

9

Coding Practices 17 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

More information: developer.motorola.com

•  Tools

–  MOTODEV Studio: eclipse-based IDE with additional features (string localization, database manager)

–  App Validator: online tool for pre-testing Android apps for compatibility across devices

•  Technical Articles

–  Motorola XOOM Programming Tips

–  Understanding Texture Compression •  Product Specs

–  http://developer.motorola.com/products/xoom/ •  Discussion Boards

thank you

© 2010 Motorola Mobility, Inc.

18

Page 10: Designing Apps for XOOM pt2files.meetup.com/1285270/designing_apps_for_xoom_pt2.pdf · 2011-04-06 · – MOTODEV Studio: eclipse-based IDE with additional features (string localization,

4/6/11

10

Coding Practices 19 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

Q & A

Coding Practices 20 Page

© 2010 Motorola Mobility, Inc.

Designing Apps for the Motorola XOOM

LEGAL LICENSE NOTICES

Except where noted, sample source code written by Motorola Mobility Inc. and provided to you is licensed as described below. Copyright © 2010-2011, Motorola, Inc. All rights reserved except as otherwise explicitly indicated. •  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: •  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. •  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other

materials provided with the distribution.

Neither the name of the Motorola, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Other source code displayed in this presentation may be offered under other licenses.

Apache 2.0 Copyright © 2010, Android Open Source Project. All rights reserved unless otherwise explicitly indicated.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Creative Commons 3.0 Attribution License Portions of this presentation are reproduced from work created and shared by Google (http://code.google.com/policies.html) and used according to terms described in the Creative Commons 3.0 Attribution License (http://creativecommons.org/licenses/by/3.0/).