30
Android N - Multi-Window Eric Chuang

Android N multi window

Embed Size (px)

Citation preview

Page 1: Android N multi window

Android N - Multi-WindowEric Chuang

Page 2: Android N multi window

About Me

Eric Chuang

@ddsakura

@Yahoo

Page 3: Android N multi window

What is Multi-Window

Android N adds support for displaying more than one app at the same time.

● Split-Screen Mode (分割畫面模式)● Picture-in-picture Mode (子母畫面模式)● Freeform mode (自由形式模式)

Page 4: Android N multi window

Switch into multi-window mode

● If the user opens the Overview screen and performs a long press on an activity title, they can drag that activity to a highlighted portion of the screen to put the activity in multi-window mode.

● If the user performs a long press on the Overview button, the device puts the current activity in multi-window mode, and opens the Overview screen to let the user choose another activity to share the screen.

Page 5: Android N multi window

Split-Screen Mode

Page 6: Android N multi window

Picture-in-picture(子母畫面) Mode

In Android N, Android TV users can now watch a video in a pinned window in a corner of the screen when navigating within apps.

Picture-in-picture (PIP) mode lets apps run a video activity in the pinned window while another activity continues in the background. The PIP window lets users multitask while using your app, which helps users be more productive.

Page 7: Android N multi window

Picture-in-picture Mode

The PIP window is 240 x 135 dp and is shown at the top-most layer in one of the four corners of the screen, chosen by the system.

The user can bring up a PIP menu that lets them toggle the PIP window to fullscreen, or close the PIP window, by holding down the Home button on the remote.

Page 9: Android N multi window

Freeform Mode

Page 10: Android N multi window
Page 11: Android N multi window

1. adb shell

2. su

3. setenforce 0

4. settings put global enable_freeform_support 1

5. cd /data/local/tmp

6. mkdir permissions

7. cd permissions

8. cp -a /system/etc/permissions/* ./

9. sed -e “s/live_wallpaper/freeform_window_management/” android.software.live_wallpaper.xml

>freeform.xml

10. mount --bind . /system/etc/permissions

11. stop

12. start

How to enable freeform on emulator

Ref : http://lifehacker.com/heres-what-freeform-windows-in-android-n-look-like-and-1766353465

Page 12: Android N multi window

Multi-Window Lifecycle

Multi-window mode does not change the activity lifecycle.

Only one resume activity in the system (the currently focused activity); all other visible activities are in the pause state, even they are visible.

Page 13: Android N multi window
Page 14: Android N multi window

Multi-Window Lifecycle handle

In multi-window mode, an app can be in the paused state and still be visible to the user.

An app might need to continue its activities even while paused.

For example, a video-playing app that is in paused mode but is visible should continue showing its video.

For this reason, we recommend that activities that play video not pause the video in their onPause() handlers. Instead, they should pause video in onStop(), and resume playback in onStart().

Page 15: Android N multi window

Configuration Changes

When the user puts an app into multi-window mode, the system notifies the activity of a configuration change, as specified in Handling Runtime Changes - screenSize, smallestScreenSize, screenLayout, orientation.

@Overridepublic void onConfigurationChanged(Configuration newConfig) { ...}

<activity android:name=".MyActivity" android:configChanges="screenSize|smallestScreenSize |screenLayout|orientation".../>

Page 16: Android N multi window

Configuring App for Multi-Window Modeandroid:resizeableActivity=["true" | "false"]

If this attribute is set to true, the activity can be launched in split-screen and freeform modes.

If the attribute is set to false, the activity does not support multi-window mode. If this value is false, and the user attempts to launch the activity in multi-window mode, the activity takes over the full screen.

If your app targets Android N, but you do not specify a value for this attribute, the attribute's value defaults to true.

Page 17: Android N multi window

Layout styleable

With Android N, the <layout> manifest element supports several attributes that affect how an activity behaves in multi-window mode:

● android:defaultWidth ○ Default width of the activity when launched in freeform mode.

● android:defaultHeight○ Default height of the activity when launched in freeform mode.

● Android:gravity● android:minimalHeight, android:minimalWidth

Page 18: Android N multi window

Resizing background drawable

Page 19: Android N multi window

Launch New Activities in Multi-Window Mode

Split-Screen Mode Only

android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT

Intent intent = new Intent(this, AdjacentActivity.class);intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);

Page 20: Android N multi window

Start activity at specific location & size

If a device is in freeform mode and you are launching a new activity, you can specify the new activity's dimensions and screen location by calling ActivityOptions.setLaunchBounds().

This method has no effect if the device is not in multi-window mode.

Page 21: Android N multi window

Activity multi-windowing/PiP mode change notification & querying

Page 22: Android N multi window

Drag and drop

Users can drag and drop data from one activity to another while the two activities are sharing the screen.

1. Detect the gesture2. Prepare the data3. Start the drag4. Monitor the progress5. Handle the drop

Page 23: Android N multi window

Drag and dropandroid.view.DropPermissions android.view.DragAndDropPermissions

Activity.requestDropPermissions() Activity.requestDragAndDropPermissions()

View.startDragAndDrop()

View.DRAG_FLAG_GLOBAL

View.DRAG_FLAG_GLOBAL_URI_READ

View.DRAG_FLAG_GLOBAL_URI_WRITE

View.cancelDragAndDrop()

View.updateDragShadow()

Page 24: Android N multi window

Tablet and phone layouts in split-screen

Apps may use the same or different layouts for mobile and tablet:

● Apps with similar layouts for mobile and tablet may switch between the tablet and mobile UIs when the app is resized, as the transition will not be jarring.

● Apps with completely different layouts for mobile and tablet should avoid using the mobile UI on tablet in split-screen mode. Instead, the existing tablet UI should be adapted to fit the smaller size to ensure that users have a consistent experience on both devices.

Page 25: Android N multi window
Page 26: Android N multi window
Page 27: Android N multi window

Design for condensed sizes first

● Design for the smallest size first● Start with a 220dp wide or tall layout, condensing and removing non-

essential elements.

Page 28: Android N multi window

5 tips for preparing for Multi-Window in Android N

1. Best to keep your UI stuff with the Activity Context.2. Handle configuration changes correctly3. Handle all orientations

a. For apps not targeting Android N, adding android:screenOrientation means you will not support multi-window at all 

4. Build a responsive UI for all screen sizes5. Activities started by other apps must always support multi-window

Ref: https://medium.com/google-developers/5-tips-for-preparing-for-multi-window-in-android-n-7bed803dda64

Page 29: Android N multi window

Reference

● Documentation:○ https://developer.android.com/preview/features/multi-window.html

● Design:○ https://www.google.com/design/spec/layout/split-screen.html

● Sample App:○ https://github.com/googlesamples/android-MultiWindowPlayground

Page 30: Android N multi window

Thank you