Upload
yu-wei-chuang
View
1.484
Download
1
Embed Size (px)
Citation preview
Android N - Multi-WindowEric Chuang
About Me
Eric Chuang
@ddsakura
@Yahoo
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 (自由形式模式)
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.
Split-Screen Mode
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.
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.
https://youtu.be/K4eUZsgp06U?t=28s
Freeform Mode
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
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.
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().
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".../>
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.
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
Resizing background drawable
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);
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.
Activity multi-windowing/PiP mode change notification & querying
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
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()
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.
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.
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
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
Thank you