Download - Android N multi window
![Page 1: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/1.jpg)
Android N - Multi-WindowEric Chuang
![Page 2: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/2.jpg)
About Me
Eric Chuang
@ddsakura
@Yahoo
![Page 3: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/3.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/5.jpg)
Split-Screen Mode
![Page 6: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/7.jpg)
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 8: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/8.jpg)
https://youtu.be/K4eUZsgp06U?t=28s
![Page 9: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/9.jpg)
Freeform Mode
![Page 10: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/10.jpg)
![Page 11: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/11.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/12.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/13.jpg)
![Page 14: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/14.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/15.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/16.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/18.jpg)
Resizing background drawable
![Page 19: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/19.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/20.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/21.jpg)
Activity multi-windowing/PiP mode change notification & querying
![Page 22: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/22.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/23.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/24.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/25.jpg)
![Page 26: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/26.jpg)
![Page 27: Android N multi window](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/27.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/28.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/29.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042611/58ef7e051a28abf2248b45e1/html5/thumbnails/30.jpg)
Thank you