├── .google
└── packaging.yaml
├── Application
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ ├── android
│ │ └── multiwindowplayground
│ │ │ ├── MainActivity.java
│ │ │ └── activities
│ │ │ ├── AdjacentActivity.java
│ │ │ ├── BasicActivity.java
│ │ │ ├── CustomConfigurationChangeActivity.java
│ │ │ ├── LaunchBoundsActivity.java
│ │ │ ├── LoggingActivity.java
│ │ │ ├── MinimumSizeActivity.java
│ │ │ └── UnresizableActivity.java
│ │ └── example
│ │ └── android
│ │ └── common
│ │ └── logger
│ │ ├── Log.java
│ │ ├── LogFragment.java
│ │ ├── LogNode.java
│ │ ├── LogView.java
│ │ ├── LogWrapper.java
│ │ └── MessageOnlyLogFilter.java
│ └── res
│ ├── layout
│ ├── activity_logging.xml
│ ├── activity_main.xml
│ └── logging.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── CONTRIBUTING.md
├── LICENSE
├── NOTICE
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── kotlinApp
├── Application
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── android
│ │ │ └── multiwindowplayground
│ │ │ ├── MainActivity.kt
│ │ │ ├── activities
│ │ │ ├── AdjacentActivity.kt
│ │ │ ├── BasicActivity.kt
│ │ │ ├── CustomConfigurationChangeActivity.kt
│ │ │ ├── LaunchBoundsActivity.kt
│ │ │ ├── LoggingActivity.kt
│ │ │ ├── MinimumSizeActivity.kt
│ │ │ └── UnresizableActivity.kt
│ │ │ └── logger
│ │ │ ├── Log.kt
│ │ │ ├── LogFragment.kt
│ │ │ ├── LogNode.kt
│ │ │ ├── LogView.kt
│ │ │ ├── LogWrapper.kt
│ │ │ └── MessageOnlyLogFilter.kt
│ │ └── res
│ │ ├── layout
│ │ ├── activity_logging.xml
│ │ ├── activity_main.xml
│ │ └── logging.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
├── README.md
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
│ ├── icon-web.png
│ └── main.png
└── settings.gradle
├── screenshots
├── icon-web.png
└── main.png
└── settings.gradle
/.google/packaging.yaml:
--------------------------------------------------------------------------------
1 |
2 | # GOOGLE SAMPLE PACKAGING DATA
3 | #
4 | # This file is used by Google as part of our samples packaging process.
5 | # End users may safely ignore this file. It has no relevance to other systems.
6 | ---
7 | status: PUBLISHED
8 | technologies: [Android]
9 | categories: [UI]
10 | languages: [Java]
11 | solutions: [Mobile]
12 | github: android-MultiWindowPlayground
13 | level: INTERMEDIATE
14 | icon: screenshots/icon-web.png
15 | apiRefs:
16 | - android:android.content.Intent
17 | - android:android.app.ActivityOptions
18 | license: apache2
19 |
--------------------------------------------------------------------------------
/Application/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | buildscript {
18 | repositories {
19 | jcenter()
20 | }
21 |
22 | dependencies {
23 | classpath 'com.android.tools.build:gradle:3.0.0'
24 | }
25 | }
26 |
27 | allprojects {
28 | repositories {
29 | jcenter()
30 | }
31 | }
32 |
33 | apply plugin: 'com.android.application'
34 |
35 | android {
36 | compileSdkVersion 24
37 | buildToolsVersion '23.0.3'
38 |
39 | defaultConfig {
40 | applicationId "com.android.multiwindowplayground"
41 | minSdkVersion 24
42 | targetSdkVersion 24
43 | versionCode 1
44 | versionName "1.0"
45 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
46 |
47 | }
48 | buildTypes {
49 | release {
50 | minifyEnabled false
51 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
52 | }
53 | }
54 | compileOptions {
55 | sourceCompatibility JavaVersion.VERSION_1_7
56 | targetCompatibility JavaVersion.VERSION_1_7
57 | }
58 | }
59 |
60 | dependencies {
61 | compile fileTree(include: ['*.jar'], dir: 'libs')
62 | testCompile 'junit:junit:4.12'
63 | compile 'com.android.support:appcompat-v7:24.0.0-beta1'
64 | androidTestCompile 'com.android.support:support-annotations:24.0.0-beta1'
65 | androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
66 | }
67 |
--------------------------------------------------------------------------------
/Application/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
19 |
20 |
26 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
43 |
44 |
47 |
51 |
57 |
58 |
59 |
61 |
64 |
65 |
66 |
69 |
70 |
72 |
77 |
78 |
79 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground;
18 |
19 | import com.android.multiwindowplayground.activities.AdjacentActivity;
20 | import com.android.multiwindowplayground.activities.BasicActivity;
21 | import com.android.multiwindowplayground.activities.CustomConfigurationChangeActivity;
22 | import com.android.multiwindowplayground.activities.LaunchBoundsActivity;
23 | import com.android.multiwindowplayground.activities.LoggingActivity;
24 | import com.android.multiwindowplayground.activities.MinimumSizeActivity;
25 | import com.android.multiwindowplayground.activities.UnresizableActivity;
26 |
27 | import android.app.ActivityOptions;
28 | import android.content.Intent;
29 | import android.graphics.Rect;
30 | import android.os.Bundle;
31 | import android.util.Log;
32 | import android.view.View;
33 |
34 | public class MainActivity extends LoggingActivity {
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_main);
40 |
41 | View multiDisabledMessage = findViewById(R.id.warning_multiwindow_disabled);
42 | // Display an additional message if the app is not in multiwindow mode.
43 | if (!isInMultiWindowMode()) {
44 | multiDisabledMessage.setVisibility(View.VISIBLE);
45 | } else {
46 | multiDisabledMessage.setVisibility(View.GONE);
47 | }
48 | }
49 |
50 | public void onStartUnresizableClick(View view) {
51 | Log.d(mLogTag, "** starting UnresizableActivity");
52 |
53 | /*
54 | * This activity is marked as 'unresizable' in the AndroidManifest. We need to specify the
55 | * FLAG_ACTIVITY_NEW_TASK flag here to launch it into a new task stack, otherwise the
56 | * properties from the root activity would have been inherited (which was here marked as
57 | * resizable by default).
58 | */
59 | Intent intent = new Intent(this, UnresizableActivity.class);
60 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
61 | startActivity(intent);
62 | }
63 |
64 | public void onStartMinimumSizeActivity(View view) {
65 | Log.d(mLogTag, "** starting MinimumSizeActivity");
66 |
67 | startActivity(new Intent(this, MinimumSizeActivity.class));
68 | }
69 |
70 | public void onStartAdjacentActivity(View view) {
71 | Log.d(mLogTag, "** starting AdjacentActivity");
72 |
73 | /*
74 | * Start this activity adjacent to the focused activity (ie. this activity) if possible.
75 | * Note that this flag is just a hint to the system and may be ignored. For example,
76 | * if the activity is launched within the same task, it will be launched on top of the
77 | * previous activity that started the Intent. That's why the Intent.FLAG_ACTIVITY_NEW_TASK
78 | * flag is specified here in the intent - this will start the activity in a new task.
79 | */
80 | Intent intent = new Intent(this, AdjacentActivity.class);
81 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
82 | startActivity(intent);
83 | }
84 |
85 | public void onStartLaunchBoundsActivity(View view) {
86 | Log.d(mLogTag, "** starting LaunchBoundsActivity");
87 |
88 | // Define the bounds in which the Activity will be launched into.
89 | Rect bounds = new Rect(500, 300, 100, 0);
90 |
91 | // Set the bounds as an activity option.
92 | ActivityOptions options = ActivityOptions.makeBasic();
93 | options.setLaunchBounds(bounds);
94 |
95 | // Start the LaunchBoundsActivity with the specified options
96 | Intent intent = new Intent(this, LaunchBoundsActivity.class);
97 | startActivity(intent, options.toBundle());
98 |
99 | }
100 |
101 | public void onStartBasicActivity(View view) {
102 | Log.d(mLogTag, "** starting BasicActivity");
103 |
104 | // Start an Activity with the default options in the 'singleTask' launch mode as defined in
105 | // the AndroidManifest.xml.
106 | startActivity(new Intent(this, BasicActivity.class));
107 |
108 | }
109 |
110 | public void onStartCustomConfigurationActivity(View view) {
111 | Log.d(mLogTag, "** starting CustomConfigurationChangeActivity");
112 |
113 | // Start an Activity that handles all configuration changes itself.
114 | startActivity(new Intent(this, CustomConfigurationChangeActivity.class));
115 |
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/activities/AdjacentActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities;
18 |
19 | import com.android.multiwindowplayground.R;
20 |
21 | import android.os.Bundle;
22 | import android.view.View;
23 |
24 | /**
25 | * This Activity is to be launched adjacent to another Activity using the {@link
26 | * android.content.Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT}.
27 | *
28 | * @see com.android.multiwindowplayground.MainActivity#onStartAdjacentActivity(View)
29 | */
30 | public class AdjacentActivity extends LoggingActivity {
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_logging);
36 |
37 | setBackgroundColor(R.color.teal);
38 | setDescription(R.string.activity_adjacent_description);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/activities/BasicActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities;
18 |
19 | import com.android.multiwindowplayground.R;
20 |
21 | import android.os.Bundle;
22 | import android.view.View;
23 |
24 | /**
25 | * This activity is the most basic, simeple use case and is to be launched without any special
26 | * flags
27 | * or settings.
28 | *
29 | * @see com.android.multiwindowplayground.MainActivity#onStartBasicActivity(View)
30 | */
31 | public class BasicActivity extends LoggingActivity {
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_logging);
37 |
38 | // Set the color and description
39 | setDescription(R.string.activity_description_basic);
40 | setBackgroundColor(R.color.gray);
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/activities/CustomConfigurationChangeActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities;
18 |
19 | import com.android.multiwindowplayground.R;
20 |
21 | import android.content.res.Configuration;
22 | import android.os.Bundle;
23 | import android.view.View;
24 |
25 | /**
26 | * This activity handles configuration changes itself. The list of configuration changes that are
27 | * supported is defined in its AndroidManifest definition. Each configuration change triggers a
28 | * call to {@link #onConfigurationChanged(Configuration)}, which is logged in the {@link
29 | * LoggingActivity}.
30 | *
31 | * @see com.android.multiwindowplayground.MainActivity#onStartCustomConfigurationActivity(View)
32 | */
33 | public class CustomConfigurationChangeActivity extends LoggingActivity {
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setContentView(R.layout.activity_logging);
39 |
40 | setBackgroundColor(R.color.cyan);
41 | setDescription(R.string.activity_custom_description);
42 | }
43 |
44 | @Override
45 | public void onConfigurationChanged(Configuration newConfig) {
46 | super.onConfigurationChanged(newConfig);
47 |
48 | /*
49 | Note: The implementation in LoggingActivity logs the output o the new configuration.
50 | This callback is received whenever the configuration is updated, for example when the
51 | size of this Activity is changed.
52 | */
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/activities/LaunchBoundsActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities;
18 |
19 | import com.android.multiwindowplayground.R;
20 |
21 | import android.os.Bundle;
22 | import android.view.View;
23 |
24 | /**
25 | * In free-form mode, this activity is to be launched within a defined bounds on screen.
26 | * This property is set as part of the Intent that starts this activity.
27 | *
28 | * @see com.android.multiwindowplayground.MainActivity#onStartLaunchBoundsActivity(View)
29 | */
30 | public class LaunchBoundsActivity extends LoggingActivity {
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_logging);
36 |
37 | setBackgroundColor(R.color.lime);
38 | setDescription(R.string.activity_bounds_description);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/activities/LoggingActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities;
18 |
19 | import com.android.multiwindowplayground.R;
20 | import com.example.android.common.logger.Log;
21 | import com.example.android.common.logger.LogFragment;
22 | import com.example.android.common.logger.LogWrapper;
23 | import com.example.android.common.logger.MessageOnlyLogFilter;
24 |
25 | import android.content.res.Configuration;
26 | import android.os.Bundle;
27 | import android.os.PersistableBundle;
28 | import android.support.annotation.ColorRes;
29 | import android.support.annotation.StringRes;
30 | import android.support.v7.app.AppCompatActivity;
31 | import android.view.View;
32 | import android.widget.TextView;
33 |
34 | /**
35 | * Activity that logs all key lifecycle callbacks to {@link Log}.
36 | * Output is also logged to the UI into a {@link LogFragment} through {@link #initializeLogging()}
37 | * and {@link #stopLogging()}.
38 | */
39 | public abstract class LoggingActivity extends AppCompatActivity {
40 |
41 | protected String mLogTag = getClass().getSimpleName();
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | Log.d(mLogTag, "onCreate");
47 |
48 |
49 | }
50 |
51 | @Override
52 | public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
53 | super.onPostCreate(savedInstanceState, persistentState);
54 | Log.d(mLogTag, "onPostCreate");
55 | }
56 |
57 | @Override
58 | protected void onPause() {
59 | super.onPause();
60 | Log.d(mLogTag, "onPause");
61 | }
62 |
63 | @Override
64 | protected void onDestroy() {
65 | super.onDestroy();
66 | Log.d(mLogTag, "onDestroy");
67 | }
68 |
69 | @Override
70 | protected void onResume() {
71 | super.onResume();
72 | Log.d(mLogTag, "onResume");
73 | }
74 |
75 | @Override
76 | public void onConfigurationChanged(Configuration newConfig) {
77 | super.onConfigurationChanged(newConfig);
78 | Log.d(mLogTag, "onConfigurationChanged: " + newConfig.toString());
79 | }
80 |
81 | @Override
82 | protected void onPostCreate(Bundle savedInstanceState) {
83 | super.onPostCreate(savedInstanceState);
84 | Log.d(mLogTag, "onPostCreate");
85 | }
86 |
87 | @Override
88 | protected void onStart() {
89 | super.onStart();
90 | // Start logging to UI.
91 | initializeLogging();
92 |
93 | Log.d(mLogTag, "onStart");
94 | }
95 |
96 | @Override
97 | protected void onStop() {
98 | super.onStop();
99 | // Stop logging to UI when this activity is stopped.
100 | stopLogging();
101 |
102 | Log.d(mLogTag, "onStop");
103 | }
104 |
105 | @Override
106 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
107 | super.onMultiWindowModeChanged(isInMultiWindowMode);
108 |
109 | Log.d(mLogTag, "onMultiWindowModeChanged: " + isInMultiWindowMode);
110 | }
111 |
112 | // Logging and UI methods below.
113 |
114 | /** Set up targets to receive log data */
115 | public void initializeLogging() {
116 | // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
117 | // Wraps Android's native log framework
118 | LogWrapper logWrapper = new LogWrapper();
119 | Log.setLogNode(logWrapper);
120 |
121 | // Filter strips out everything except the message text.
122 | MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
123 | logWrapper.setNext(msgFilter);
124 |
125 | // On screen logging via a fragment with a TextView.
126 | LogFragment logFragment = (LogFragment) getSupportFragmentManager()
127 | .findFragmentById(R.id.log_fragment);
128 | msgFilter.setNext(logFragment.getLogView());
129 | }
130 |
131 | public void stopLogging() {
132 | Log.setLogNode(null);
133 | }
134 |
135 | /**
136 | * Set the description text if a TextView with the id description is available.
137 | */
138 | protected void setDescription(@StringRes int textId) {
139 | // Set the text and background color
140 | TextView description = (TextView) findViewById(R.id.description);
141 | if (description != null) {
142 | description.setText(textId);
143 | }
144 | }
145 |
146 | /**
147 | * Set the background color for the description text.
148 | */
149 | protected void setBackgroundColor(@ColorRes int colorId) {
150 | View scrollView = findViewById(R.id.scrollview);
151 | if (scrollView != null) {
152 | scrollView.setBackgroundResource(colorId);
153 | }
154 | }
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/activities/MinimumSizeActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities;
18 |
19 | import com.android.multiwindowplayground.R;
20 |
21 | import android.os.Bundle;
22 | import android.view.View;
23 |
24 | /**
25 | * This Activity has a minimum size defined in the AndroidManifeset.
26 | *
27 | * @see com.android.multiwindowplayground.MainActivity#onStartMinimumSizeActivity(View)
28 | */
29 | public class MinimumSizeActivity extends LoggingActivity {
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_logging);
35 |
36 | setBackgroundColor(R.color.pink);
37 | setDescription(R.string.activity_minimum_description);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/android/multiwindowplayground/activities/UnresizableActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities;
18 |
19 | import com.android.multiwindowplayground.R;
20 |
21 | import android.os.Bundle;
22 | import android.view.View;
23 |
24 | /**
25 | * This Activity is defined as unresizable in the AndroidManifest.
26 | * This means that this activity is always launched full screen and will not be resized by the
27 | * system.
28 | *
29 | * @see com.android.multiwindowplayground.MainActivity#onStartUnresizableClick(View)
30 | */
31 | public class UnresizableActivity extends LoggingActivity {
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_logging);
37 |
38 | setBackgroundColor(R.color.purple);
39 | setDescription(R.string.activity_description_unresizable);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/common/logger/Log.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.android.common.logger;
17 |
18 | /**
19 | * Helper class for a list (or tree) of LoggerNodes.
20 | *
21 | *
When this is set as the head of the list,
22 | * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
23 | * Most of the methods in this class server only to map a method call in Log to its equivalent
24 | * in LogNode.
25 | */
26 | public class Log {
27 |
28 | // Grabbing the native values from Android's native logging facilities,
29 | // to make for easy migration and interop.
30 | public static final int NONE = -1;
31 | public static final int VERBOSE = android.util.Log.VERBOSE;
32 | public static final int DEBUG = android.util.Log.DEBUG;
33 | public static final int INFO = android.util.Log.INFO;
34 | public static final int WARN = android.util.Log.WARN;
35 | public static final int ERROR = android.util.Log.ERROR;
36 | public static final int ASSERT = android.util.Log.ASSERT;
37 |
38 | // Stores the beginning of the LogNode topology.
39 | private static LogNode mLogNode;
40 |
41 | /**
42 | * Returns the next LogNode in the linked list.
43 | */
44 | public static LogNode getLogNode() {
45 | return mLogNode;
46 | }
47 |
48 | /**
49 | * Sets the LogNode data will be sent to.
50 | */
51 | public static void setLogNode(LogNode node) {
52 | mLogNode = node;
53 | }
54 |
55 | /**
56 | * Instructs the LogNode to print the log data provided. Other LogNodes can
57 | * be chained to the end of the LogNode as desired.
58 | *
59 | * @param priority Log level of the data being logged. Verbose, Error, etc.
60 | * @param tag Tag for for the log data. Can be used to organize log statements.
61 | * @param msg The actual message to be logged.
62 | * @param tr If an exception was thrown, this can be sent along for the logging
63 | * facilities
64 | * to extract and print useful information.
65 | */
66 | public static void println(int priority, String tag, String msg, Throwable tr) {
67 | if (mLogNode != null) {
68 | mLogNode.println(priority, tag, msg, tr);
69 | }
70 | }
71 |
72 | /**
73 | * Instructs the LogNode to print the log data provided. Other LogNodes can
74 | * be chained to the end of the LogNode as desired.
75 | *
76 | * @param priority Log level of the data being logged. Verbose, Error, etc.
77 | * @param tag Tag for for the log data. Can be used to organize log statements.
78 | * @param msg The actual message to be logged. The actual message to be logged.
79 | */
80 | public static void println(int priority, String tag, String msg) {
81 | println(priority, tag, msg, null);
82 | }
83 |
84 | /**
85 | * Prints a message at VERBOSE priority.
86 | *
87 | * @param tag Tag for for the log data. Can be used to organize log statements.
88 | * @param msg The actual message to be logged.
89 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
90 | * to extract and print useful information.
91 | */
92 | public static void v(String tag, String msg, Throwable tr) {
93 | println(VERBOSE, tag, msg, tr);
94 | }
95 |
96 | /**
97 | * Prints a message at VERBOSE priority.
98 | *
99 | * @param tag Tag for for the log data. Can be used to organize log statements.
100 | * @param msg The actual message to be logged.
101 | */
102 | public static void v(String tag, String msg) {
103 | v(tag, msg, null);
104 | }
105 |
106 |
107 | /**
108 | * Prints a message at DEBUG priority.
109 | *
110 | * @param tag Tag for for the log data. Can be used to organize log statements.
111 | * @param msg The actual message to be logged.
112 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
113 | * to extract and print useful information.
114 | */
115 | public static void d(String tag, String msg, Throwable tr) {
116 | println(DEBUG, tag, msg, tr);
117 | }
118 |
119 | /**
120 | * Prints a message at DEBUG priority.
121 | *
122 | * @param tag Tag for for the log data. Can be used to organize log statements.
123 | * @param msg The actual message to be logged.
124 | */
125 | public static void d(String tag, String msg) {
126 | d(tag, msg, null);
127 | }
128 |
129 | /**
130 | * Prints a message at INFO priority.
131 | *
132 | * @param tag Tag for for the log data. Can be used to organize log statements.
133 | * @param msg The actual message to be logged.
134 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
135 | * to extract and print useful information.
136 | */
137 | public static void i(String tag, String msg, Throwable tr) {
138 | println(INFO, tag, msg, tr);
139 | }
140 |
141 | /**
142 | * Prints a message at INFO priority.
143 | *
144 | * @param tag Tag for for the log data. Can be used to organize log statements.
145 | * @param msg The actual message to be logged.
146 | */
147 | public static void i(String tag, String msg) {
148 | i(tag, msg, null);
149 | }
150 |
151 | /**
152 | * Prints a message at WARN priority.
153 | *
154 | * @param tag Tag for for the log data. Can be used to organize log statements.
155 | * @param msg The actual message to be logged.
156 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
157 | * to extract and print useful information.
158 | */
159 | public static void w(String tag, String msg, Throwable tr) {
160 | println(WARN, tag, msg, tr);
161 | }
162 |
163 | /**
164 | * Prints a message at WARN priority.
165 | *
166 | * @param tag Tag for for the log data. Can be used to organize log statements.
167 | * @param msg The actual message to be logged.
168 | */
169 | public static void w(String tag, String msg) {
170 | w(tag, msg, null);
171 | }
172 |
173 | /**
174 | * Prints a message at WARN priority.
175 | *
176 | * @param tag Tag for for the log data. Can be used to organize log statements.
177 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
178 | * to extract and print useful information.
179 | */
180 | public static void w(String tag, Throwable tr) {
181 | w(tag, null, tr);
182 | }
183 |
184 | /**
185 | * Prints a message at ERROR priority.
186 | *
187 | * @param tag Tag for for the log data. Can be used to organize log statements.
188 | * @param msg The actual message to be logged.
189 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
190 | * to extract and print useful information.
191 | */
192 | public static void e(String tag, String msg, Throwable tr) {
193 | println(ERROR, tag, msg, tr);
194 | }
195 |
196 | /**
197 | * Prints a message at ERROR priority.
198 | *
199 | * @param tag Tag for for the log data. Can be used to organize log statements.
200 | * @param msg The actual message to be logged.
201 | */
202 | public static void e(String tag, String msg) {
203 | e(tag, msg, null);
204 | }
205 |
206 | /**
207 | * Prints a message at ASSERT priority.
208 | *
209 | * @param tag Tag for for the log data. Can be used to organize log statements.
210 | * @param msg The actual message to be logged.
211 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
212 | * to extract and print useful information.
213 | */
214 | public static void wtf(String tag, String msg, Throwable tr) {
215 | println(ASSERT, tag, msg, tr);
216 | }
217 |
218 | /**
219 | * Prints a message at ASSERT priority.
220 | *
221 | * @param tag Tag for for the log data. Can be used to organize log statements.
222 | * @param msg The actual message to be logged.
223 | */
224 | public static void wtf(String tag, String msg) {
225 | wtf(tag, msg, null);
226 | }
227 |
228 | /**
229 | * Prints a message at ASSERT priority.
230 | *
231 | * @param tag Tag for for the log data. Can be used to organize log statements.
232 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
233 | * to extract and print useful information.
234 | */
235 | public static void wtf(String tag, Throwable tr) {
236 | wtf(tag, null, tr);
237 | }
238 | }
239 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/common/logger/LogFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | package com.example.android.common.logger;
19 |
20 | import android.graphics.Typeface;
21 | import android.os.Bundle;
22 | import android.support.v4.app.Fragment;
23 | import android.text.Editable;
24 | import android.text.TextWatcher;
25 | import android.view.Gravity;
26 | import android.view.LayoutInflater;
27 | import android.view.View;
28 | import android.view.ViewGroup;
29 | import android.widget.ScrollView;
30 |
31 | /**
32 | * Simple fraggment which contains a LogView and uses is to output log data it receives
33 | * through the LogNode interface.
34 | */
35 | public class LogFragment extends Fragment {
36 |
37 | private LogView mLogView;
38 | private ScrollView mScrollView;
39 |
40 | public LogFragment() {
41 | }
42 |
43 | public View inflateViews() {
44 | mScrollView = new ScrollView(getActivity());
45 | ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
46 | ViewGroup.LayoutParams.MATCH_PARENT,
47 | ViewGroup.LayoutParams.MATCH_PARENT);
48 | mScrollView.setLayoutParams(scrollParams);
49 |
50 | mLogView = new LogView(getActivity());
51 | ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
52 | logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
53 | mLogView.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
54 | mLogView.setLayoutParams(logParams);
55 | mLogView.setClickable(true);
56 | mLogView.setFocusable(true);
57 | mLogView.setTypeface(Typeface.create("monospace", Typeface.NORMAL));
58 |
59 | // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
60 | int paddingDips = 16;
61 | double scale = getResources().getDisplayMetrics().density;
62 | int paddingPixels = (int) ((paddingDips * (scale)) + .5);
63 | mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
64 | mLogView.setCompoundDrawablePadding(paddingPixels);
65 |
66 | mLogView.setGravity(Gravity.BOTTOM);
67 |
68 | mScrollView.addView(mLogView);
69 | return mScrollView;
70 | }
71 |
72 | @Override
73 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
74 | Bundle savedInstanceState) {
75 |
76 | View result = inflateViews();
77 |
78 | mLogView.addTextChangedListener(new TextWatcher() {
79 | @Override
80 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
81 | }
82 |
83 | @Override
84 | public void onTextChanged(CharSequence s, int start, int before, int count) {
85 | }
86 |
87 | @Override
88 | public void afterTextChanged(Editable s) {
89 |
90 | mScrollView.post(new Runnable() {
91 | @Override
92 | public void run() {
93 | mScrollView
94 | .smoothScrollTo(0, mScrollView.getBottom() + mLogView.getHeight());
95 | }
96 | });
97 | }
98 | });
99 | return result;
100 | }
101 |
102 | public LogView getLogView() {
103 | return mLogView;
104 | }
105 | }
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/common/logger/LogNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.android.common.logger;
17 |
18 | /**
19 | * Basic interface for a logging system that can output to one or more targets.
20 | * Note that in addition to classes that will output these logs in some format,
21 | * one can also implement this interface over a filter and insert that in the chain,
22 | * such that no targets further down see certain data, or see manipulated forms of the data.
23 | * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
24 | * it received to HTML and sent it along to the next node in the chain, without printing it
25 | * anywhere.
26 | */
27 | public interface LogNode {
28 |
29 | /**
30 | * Instructs first LogNode in the list to print the log data provided.
31 | *
32 | * @param priority Log level of the data being logged. Verbose, Error, etc.
33 | * @param tag Tag for for the log data. Can be used to organize log statements.
34 | * @param msg The actual message to be logged. The actual message to be logged.
35 | * @param tr If an exception was thrown, this can be sent along for the logging
36 | * facilities
37 | * to extract and print useful information.
38 | */
39 | public void println(int priority, String tag, String msg, Throwable tr);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/common/logger/LogView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.android.common.logger;
17 |
18 | import android.app.Activity;
19 | import android.content.Context;
20 | import android.util.AttributeSet;
21 | import android.widget.TextView;
22 |
23 | /**
24 | * Simple TextView which is used to output log data received through the LogNode interface.
25 | */
26 | public class LogView extends TextView implements LogNode {
27 |
28 | public LogView(Context context) {
29 | super(context);
30 | }
31 |
32 | public LogView(Context context, AttributeSet attrs) {
33 | super(context, attrs);
34 | }
35 |
36 | public LogView(Context context, AttributeSet attrs, int defStyle) {
37 | super(context, attrs, defStyle);
38 | }
39 |
40 | /**
41 | * Formats the log data and prints it out to the LogView.
42 | *
43 | * @param priority Log level of the data being logged. Verbose, Error, etc.
44 | * @param tag Tag for for the log data. Can be used to organize log statements.
45 | * @param msg The actual message to be logged. The actual message to be logged.
46 | * @param tr If an exception was thrown, this can be sent along for the logging
47 | * facilities
48 | * to extract and print useful information.
49 | */
50 | @Override
51 | public void println(int priority, String tag, String msg, Throwable tr) {
52 |
53 | String priorityStr = null;
54 |
55 | // For the purposes of this View, we want to print the priority as readable text.
56 | switch (priority) {
57 | case android.util.Log.VERBOSE:
58 | priorityStr = "VERBOSE";
59 | break;
60 | case android.util.Log.DEBUG:
61 | priorityStr = "DEBUG";
62 | break;
63 | case android.util.Log.INFO:
64 | priorityStr = "INFO";
65 | break;
66 | case android.util.Log.WARN:
67 | priorityStr = "WARN";
68 | break;
69 | case android.util.Log.ERROR:
70 | priorityStr = "ERROR";
71 | break;
72 | case android.util.Log.ASSERT:
73 | priorityStr = "ASSERT";
74 | break;
75 | default:
76 | break;
77 | }
78 |
79 | // Handily, the Log class has a facility for converting a stack trace into a usable string.
80 | String exceptionStr = null;
81 | if (tr != null) {
82 | exceptionStr = android.util.Log.getStackTraceString(tr);
83 | }
84 |
85 | // Take the priority, tag, message, and exception, and concatenate as necessary
86 | // into one usable line of text.
87 | final StringBuilder outputBuilder = new StringBuilder();
88 |
89 | String delimiter = "\t";
90 | appendIfNotNull(outputBuilder, priorityStr, delimiter);
91 | appendIfNotNull(outputBuilder, tag, delimiter);
92 | appendIfNotNull(outputBuilder, msg, delimiter);
93 | appendIfNotNull(outputBuilder, exceptionStr, delimiter);
94 |
95 | // In case this was originally called from an AsyncTask or some other off-UI thread,
96 | // make sure the update occurs within the UI thread.
97 | ((Activity) getContext()).runOnUiThread((new Thread(new Runnable() {
98 | @Override
99 | public void run() {
100 | // Display the text we just generated within the LogView.
101 | appendToLog(outputBuilder.toString());
102 | }
103 | })));
104 |
105 | if (mNext != null) {
106 | mNext.println(priority, tag, msg, tr);
107 | }
108 | }
109 |
110 | public LogNode getNext() {
111 | return mNext;
112 | }
113 |
114 | public void setNext(LogNode node) {
115 | mNext = node;
116 | }
117 |
118 | /**
119 | * Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
120 | * the logger takes so many arguments that might be null, this method helps cut out some of the
121 | * agonizing tedium of writing the same 3 lines over and over.
122 | *
123 | * @param source StringBuilder containing the text to append to.
124 | * @param addStr The String to append
125 | * @param delimiter The String to separate the source and appended strings. A tab or comma,
126 | * for instance.
127 | * @return The fully concatenated String as a StringBuilder
128 | */
129 | private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
130 | if (addStr != null) {
131 | if (addStr.length() == 0) {
132 | delimiter = "";
133 | }
134 |
135 | return source.append(addStr).append(delimiter);
136 | }
137 | return source;
138 | }
139 |
140 | // The next LogNode in the chain.
141 | LogNode mNext;
142 |
143 | /** Outputs the string as a new line of log data in the LogView. */
144 | public void appendToLog(String s) {
145 | append("\n" + s);
146 | }
147 |
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/common/logger/LogWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.android.common.logger;
17 |
18 | import android.util.Log;
19 |
20 | /**
21 | * Helper class which wraps Android's native Log utility in the Logger interface. This way
22 | * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
23 | */
24 | public class LogWrapper implements LogNode {
25 |
26 | // For piping: The next node to receive Log data after this one has done its work.
27 | private LogNode mNext;
28 |
29 | /**
30 | * Returns the next LogNode in the linked list.
31 | */
32 | public LogNode getNext() {
33 | return mNext;
34 | }
35 |
36 | /**
37 | * Sets the LogNode data will be sent to..
38 | */
39 | public void setNext(LogNode node) {
40 | mNext = node;
41 | }
42 |
43 | /**
44 | * Prints data out to the console using Android's native log mechanism.
45 | *
46 | * @param priority Log level of the data being logged. Verbose, Error, etc.
47 | * @param tag Tag for for the log data. Can be used to organize log statements.
48 | * @param msg The actual message to be logged. The actual message to be logged.
49 | * @param tr If an exception was thrown, this can be sent along for the logging
50 | * facilities
51 | * to extract and print useful information.
52 | */
53 | @Override
54 | public void println(int priority, String tag, String msg, Throwable tr) {
55 | // There actually are log methods that don't take a msg parameter. For now,
56 | // if that's the case, just convert null to the empty string and move on.
57 | String useMsg = msg;
58 | if (useMsg == null) {
59 | useMsg = "";
60 | }
61 |
62 | // If an exeption was provided, convert that exception to a usable string and attach
63 | // it to the end of the msg method.
64 | if (tr != null) {
65 | msg += "\n" + Log.getStackTraceString(tr);
66 | }
67 |
68 | // This is functionally identical to Log.x(tag, useMsg);
69 | // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
70 | Log.println(priority, tag, useMsg);
71 |
72 | // If this isn't the last node in the chain, move things along.
73 | if (mNext != null) {
74 | mNext.println(priority, tag, msg, tr);
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/common/logger/MessageOnlyLogFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2016 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.android.common.logger;
17 |
18 | /**
19 | * Simple {@link LogNode} filter, removes everything except the message.
20 | * Useful for situations like on-screen log output where you don't want a lot of metadata
21 | * displayed,
22 | * just easy-to-read message updates as they're happening.
23 | */
24 | public class MessageOnlyLogFilter implements LogNode {
25 |
26 | LogNode mNext;
27 |
28 | /**
29 | * Takes the "next" LogNode as a parameter, to simplify chaining.
30 | *
31 | * @param next The next LogNode in the pipeline.
32 | */
33 | public MessageOnlyLogFilter(LogNode next) {
34 | mNext = next;
35 | }
36 |
37 | public MessageOnlyLogFilter() {
38 | }
39 |
40 | @Override
41 | public void println(int priority, String tag, String msg, Throwable tr) {
42 | if (mNext != null) {
43 | getNext().println(Log.NONE, null, msg, null);
44 | }
45 | }
46 |
47 | /**
48 | * Returns the next LogNode in the chain.
49 | */
50 | public LogNode getNext() {
51 | return mNext;
52 | }
53 |
54 | /**
55 | * Sets the LogNode data will be sent to..
56 | */
57 | public void setNext(LogNode node) {
58 | mNext = node;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/Application/src/main/res/layout/activity_logging.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
24 |
25 |
31 |
32 |
42 |
43 |
44 |
45 |
51 |
--------------------------------------------------------------------------------
/Application/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
18 |
19 |
24 |
25 |
33 |
34 |
42 |
43 |
48 |
49 |
59 |
60 |
65 |
66 |
72 |
73 |
79 |
80 |
86 |
87 |
93 |
94 |
99 |
100 |
106 |
107 |
113 |
114 |
115 |
116 |
117 |
123 |
124 |
--------------------------------------------------------------------------------
/Application/src/main/res/layout/logging.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
18 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/Application/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/Application/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/Application/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/Application/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | 64dp
19 |
20 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | #3F51B5
19 | #303F9F
20 | #FF4081
21 |
22 | #512DA8
23 | #C2185B
24 | #00695C
25 | #9E9D24
26 | #424242
27 | #F5F5F5
28 | #00838F
29 |
30 | #FFFFFF
31 |
32 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 | 16dp
20 | 16dp
21 | 16dp
22 |
23 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | MultiWindow Playground
19 | Multiwindow Playground
20 | This sample demonstrates the use of the multi-window API
21 | available in Android N.\nFirst, switch this app into
22 | split-screen mode
23 | (for example by long-pressing the recents button). Each button below starts a new activity
24 | with special flags.\nSee the files MainActivity.java and AndroidManifest.xml for
25 | implementation details.
26 |
27 | The buttons below demonstrate features only
28 | available in free-form multi-window mode.
29 | Start basic, default Activity
30 | Start unresizable Activity
31 | Start Activity adjacent
32 | Start Activity with minimum size
33 | Start Activity with launch bounds
34 | Start activity that handles configuration changes.
35 |
36 | This Activity was launched in a new task without any
37 | additional flags or options.
38 |
39 | This activity is set as unresizable in the
40 | AndroidManifest. This is done by setting the resizeableActivity property to
41 | false for this activity.
42 |
43 | This activity was launched with the flag
44 | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT.\n\nIf possible, it has been launched into the
45 | adjacent area from the activity that started it.\nThis is only a hint to the system. For
46 | example - if the application is not in split-screen mode, it will be launched full-screen.
47 | If it is launched in the same task as the initial Activity, it will retain its activity
48 | properties and its location.
49 |
50 | This activity handles configuration changes
51 | itself.\n\nIn the AndroidManifest, this activity has been configured to receive callbacks
52 | for screenSize|smallestScreenSize|screenLayout|orientation
53 | changes.\nTry resizing this activity to different sizes to see which configuration
54 | properties change.
55 |
56 | This activity has been launched with a launch bounds
57 | set in its intent. The bounds define the area into which the activity should be launched.
58 | \n\nNote that this flag only applies in free-form mode.
59 |
60 | This activity has a minimum size.\nIt was launched
61 | into the top/end corner with a a default size of 750dp by 500dp, with a minimum size of 750dp
62 | as defined in its layout attribute in the AndroidManifest definition.
63 | \n\nNote that this Activity was launched in a different task, otherwise the properties from
64 | the Activity that launched this one would have been applied.
65 |
66 |
67 |
--------------------------------------------------------------------------------
/Application/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
30 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to become a contributor and submit your own code
2 |
3 | ## Contributor License Agreements
4 |
5 | We'd love to accept your sample apps and patches! Before we can take them, we
6 | have to jump a couple of legal hurdles.
7 |
8 | Please fill out either the individual or corporate Contributor License Agreement (CLA).
9 |
10 | * If you are an individual writing original source code and you're sure you
11 | own the intellectual property, then you'll need to sign an [individual CLA]
12 | (https://cla.developers.google.com).
13 | * If you work for a company that wants to allow you to contribute your work,
14 | then you'll need to sign a [corporate CLA]
15 | (https://cla.developers.google.com).
16 |
17 | Follow either of the two links above to access the appropriate CLA and
18 | instructions for how to sign and return it. Once we receive it, we'll be able to
19 | accept your pull requests.
20 |
21 | ## Contributing A Patch
22 |
23 | 1. Submit an issue describing your proposed change to the repo in question.
24 | 1. The repo owner will respond to your issue promptly.
25 | 1. If your proposed change is accepted, and you haven't already done so, sign a
26 | Contributor License Agreement (see details above).
27 | 1. Fork the desired repo, develop and test your code changes.
28 | 1. Ensure that your code adheres to the existing style in the sample to which
29 | you are contributing. Refer to the
30 | [Android Code Style Guide]
31 | (https://source.android.com/source/code-style.html) for the
32 | recommended coding standards for this organization.
33 | 1. Ensure that your code has an appropriate set of unit tests which all pass.
34 | 1. Submit a pull request.
35 |
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | --------------
3 |
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
178 | END OF TERMS AND CONDITIONS
179 |
180 | APPENDIX: How to apply the Apache License to your work.
181 |
182 | To apply the Apache License to your work, attach the following
183 | boilerplate notice, with the fields enclosed by brackets "{}"
184 | replaced with your own identifying information. (Don't include
185 | the brackets!) The text should be enclosed in the appropriate
186 | comment syntax for the file format. We also recommend that a
187 | file or class name and description of purpose be included on the
188 | same "printed page" as the copyright notice for easier
189 | identification within third-party archives.
190 |
191 | Copyright {yyyy} {name of copyright owner}
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
204 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 |
2 | This sample uses the following software:
3 |
4 | Copyright 2018 The Android Open Source Project
5 |
6 | Licensed under the Apache License, Version 2.0 (the "License");
7 | you may not use this file except in compliance with the License.
8 | You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing, software
13 | distributed under the License is distributed on an "AS IS" BASIS,
14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | See the License for the specific language governing permissions and
16 | limitations under the License.
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | Android MultiWindowPlayground Sample
3 | ====================================
4 |
5 | This repo has been migrated to [github.com/android/views-widgets][1]. Please check that repo for future updates. Thank you!
6 |
7 | [1]: https://github.com/android/views-widgets
8 |
9 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/kotlinApp/Application/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 27
7 | defaultConfig {
8 | applicationId "com.android.multiwindowplayground"
9 | minSdkVersion 24
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation "com.android.support:appcompat-v7:27.0.2"
24 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
25 | }
26 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
19 |
20 |
26 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
43 |
44 |
47 |
51 |
57 |
58 |
59 |
61 |
64 |
65 |
66 |
69 |
70 |
72 |
77 |
78 |
79 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground
18 |
19 | import android.app.ActivityOptions
20 | import android.content.Intent
21 | import android.graphics.Rect
22 | import android.os.Bundle
23 | import android.util.Log
24 | import android.view.View
25 | import com.android.multiwindowplayground.activities.AdjacentActivity
26 | import com.android.multiwindowplayground.activities.BasicActivity
27 | import com.android.multiwindowplayground.activities.CustomConfigurationChangeActivity
28 | import com.android.multiwindowplayground.activities.LOG_TAG
29 | import com.android.multiwindowplayground.activities.LaunchBoundsActivity
30 | import com.android.multiwindowplayground.activities.LoggingActivity
31 | import com.android.multiwindowplayground.activities.MinimumSizeActivity
32 | import com.android.multiwindowplayground.activities.UnresizableActivity
33 |
34 | class MainActivity : LoggingActivity() {
35 |
36 | override fun onCreate(savedInstanceState: Bundle?) {
37 | super.onCreate(savedInstanceState)
38 | setContentView(R.layout.activity_main)
39 |
40 | // Display an additional message if the app is not in multiwindow mode.
41 | findViewById(R.id.warning_multiwindow_disabled).visibility =
42 | if (!isInMultiWindowMode) View.VISIBLE else View.GONE
43 | }
44 |
45 | @Suppress("UNUSED_PARAMETER")
46 | fun onStartUnresizableClick(view: View) {
47 | Log.d(LOG_TAG, "** starting UnresizableActivity")
48 |
49 | /*
50 | * This activity is marked as 'unresizable' in the AndroidManifest. We need to specify the
51 | * FLAG_ACTIVITY_NEW_TASK flag here to launch it into a new task stack, otherwise the
52 | * properties from the root activity would have been inherited (which was here marked as
53 | * resizable by default).
54 | */
55 | val intent = Intent(this, UnresizableActivity::class.java).apply {
56 | flags = Intent.FLAG_ACTIVITY_NEW_TASK
57 | }
58 | startActivity(intent)
59 | }
60 |
61 | @Suppress("UNUSED_PARAMETER")
62 | fun onStartMinimumSizeActivity(view: View) {
63 | Log.d(LOG_TAG, "** starting MinimumSizeActivity")
64 | startActivity(Intent(this, MinimumSizeActivity::class.java))
65 | }
66 |
67 | @Suppress("UNUSED_PARAMETER")
68 | fun onStartAdjacentActivity(view: View) {
69 | Log.d(LOG_TAG, "** starting AdjacentActivity")
70 |
71 | /*
72 | * Start this activity adjacent to the focused activity (ie. this activity) if possible.
73 | * Note that this flag is just a hint to the system and may be ignored. For example,
74 | * if the activity is launched within the same task, it will be launched on top of the
75 | * previous activity that started the Intent. That's why the Intent.FLAG_ACTIVITY_NEW_TASK
76 | * flag is specified here in the intent - this will start the activity in a new task.
77 | */
78 | val intent = Intent(this, AdjacentActivity::class.java).apply {
79 | addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT or Intent.FLAG_ACTIVITY_NEW_TASK)
80 | }
81 | startActivity(intent)
82 | }
83 |
84 | @Suppress("UNUSED_PARAMETER")
85 | fun onStartLaunchBoundsActivity(view: View) {
86 | Log.d(LOG_TAG, "** starting LaunchBoundsActivity")
87 |
88 | // Define the bounds in which the Activity will be launched into.
89 | val bounds = Rect(500, 300, 100, 0)
90 |
91 | // Set the bounds as an activity option.
92 | val options = ActivityOptions.makeBasic().apply {
93 | launchBounds = bounds
94 | }
95 |
96 | // Start the LaunchBoundsActivity with the specified options
97 | val intent = Intent(this, LaunchBoundsActivity::class.java)
98 | startActivity(intent, options.toBundle())
99 | }
100 |
101 | @Suppress("UNUSED_PARAMETER")
102 | fun onStartBasicActivity(view: View) {
103 | Log.d(LOG_TAG, "** starting BasicActivity")
104 |
105 | // Start an Activity with the default options in the 'singleTask' launch mode as defined in
106 | // the AndroidManifest.xml.
107 | startActivity(Intent(this, BasicActivity::class.java))
108 | }
109 |
110 | @Suppress("UNUSED_PARAMETER")
111 | fun onStartCustomConfigurationActivity(view: View) {
112 | Log.d(LOG_TAG, "** starting CustomConfigurationChangeActivity")
113 |
114 | // Start an Activity that handles all configuration changes itself.
115 | startActivity(Intent(this, CustomConfigurationChangeActivity::class.java))
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/activities/AdjacentActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities
18 |
19 | import android.os.Bundle
20 | import com.android.multiwindowplayground.R
21 |
22 | /**
23 | * This Activity is to be launched adjacent to another Activity using the
24 | * [android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT] flag.
25 | *
26 | * @see [com.android.multiwindowplayground.MainActivity.onStartAdjacentActivity]
27 | */
28 | class AdjacentActivity : LoggingActivity() {
29 |
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | setContentView(R.layout.activity_logging)
33 | setBackgroundColor(R.color.teal)
34 | setDescription(R.string.activity_adjacent_description)
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/activities/BasicActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities
18 |
19 | import android.os.Bundle
20 | import com.android.multiwindowplayground.R
21 |
22 | /**
23 | * This activity is the most basic, simple use case and is to be launched without any special
24 | * flags or settings.
25 | *
26 | * @see [com.android.multiwindowplayground.MainActivity.onStartBasicActivity]
27 | */
28 | class BasicActivity : LoggingActivity() {
29 |
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | setContentView(R.layout.activity_logging)
33 | setDescription(R.string.activity_description_basic)
34 | setBackgroundColor(R.color.gray)
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/activities/CustomConfigurationChangeActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities
18 |
19 | import android.os.Bundle
20 | import com.android.multiwindowplayground.R
21 |
22 | /**
23 | * This activity handles configuration changes itself. The list of configuration changes that are
24 | * supported is defined in its AndroidManifest definition. Each configuration change triggers a
25 | * call to [onConfigurationChanged], which is logged in the [LoggingActivity].
26 | *
27 | * @see [com.android.multiwindowplayground.MainActivity.onStartCustomConfigurationActivity]
28 | */
29 | class CustomConfigurationChangeActivity : LoggingActivity() {
30 |
31 | override fun onCreate(savedInstanceState: Bundle?) {
32 | super.onCreate(savedInstanceState)
33 | setContentView(R.layout.activity_logging)
34 | setBackgroundColor(R.color.cyan)
35 | setDescription(R.string.activity_custom_description)
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/activities/LaunchBoundsActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities
18 |
19 | import android.os.Bundle
20 | import com.android.multiwindowplayground.R
21 |
22 | /**
23 | * In free-form mode, this activity is to be launched within a defined bounds on screen.
24 | * This property is set as part of the Intent that starts this activity.
25 | *
26 | * @see [com.android.multiwindowplayground.MainActivity.onStartLaunchBoundsActivity]
27 | */
28 | class LaunchBoundsActivity : LoggingActivity() {
29 |
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | setContentView(R.layout.activity_logging)
33 | setBackgroundColor(R.color.lime)
34 | setDescription(R.string.activity_bounds_description)
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/activities/LoggingActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities
18 |
19 | import android.content.res.Configuration
20 | import android.os.Bundle
21 | import android.os.PersistableBundle
22 | import android.support.annotation.ColorRes
23 | import android.support.annotation.StringRes
24 | import android.support.v7.app.AppCompatActivity
25 | import android.view.View
26 | import android.widget.TextView
27 | import com.android.multiwindowplayground.R
28 | import com.android.multiwindowplayground.logger.Log
29 | import com.android.multiwindowplayground.logger.LogFragment
30 | import com.android.multiwindowplayground.logger.LogWrapper
31 | import com.android.multiwindowplayground.logger.MessageOnlyLogFilter
32 |
33 | const val LOG_TAG = "LoggingActivity"
34 |
35 | /**
36 | * Activity that logs all key lifecycle callbacks to [Log].
37 | * Output is also logged to the UI into a [LogFragment] through [initializeLogging] and
38 | * [stopLogging].
39 | */
40 | abstract class LoggingActivity : AppCompatActivity() {
41 |
42 | override fun onCreate(savedInstanceState: Bundle?) {
43 | super.onCreate(savedInstanceState)
44 | Log.d(LOG_TAG, "onCreate")
45 | }
46 |
47 | override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
48 | super.onCreate(savedInstanceState, persistentState)
49 | Log.d(LOG_TAG, "onCreatePersistable")
50 | }
51 |
52 | override fun onStart() {
53 | super.onStart()
54 | // Start logging to UI.
55 | initializeLogging()
56 |
57 | Log.d(LOG_TAG, "onStart")
58 | }
59 |
60 | override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
61 | super.onRestoreInstanceState(savedInstanceState)
62 | Log.d(LOG_TAG, "onRestoreInstanceState")
63 | }
64 |
65 | override fun onRestoreInstanceState(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
66 | super.onRestoreInstanceState(savedInstanceState, persistentState)
67 | Log.d(LOG_TAG, "onRestoreInstanceStatePersistable")
68 | }
69 |
70 | override fun onResume() {
71 | super.onResume()
72 | Log.d(LOG_TAG, "onResume")
73 | }
74 |
75 | override fun onPostCreate(savedInstanceState: Bundle?) {
76 | super.onPostCreate(savedInstanceState)
77 | Log.d(LOG_TAG, "onPostCreate")
78 | }
79 |
80 | override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
81 | super.onPostCreate(savedInstanceState, persistentState)
82 | Log.d(LOG_TAG, "onPostCreate")
83 | }
84 |
85 | override fun onConfigurationChanged(newConfig: Configuration) {
86 | super.onConfigurationChanged(newConfig)
87 | Log.d(LOG_TAG, "onConfigurationChanged: $newConfig")
88 | }
89 |
90 | override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, newConfig: Configuration?) {
91 | super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig)
92 | Log.d(LOG_TAG, "onMultiWindowModeChanged: $isInMultiWindowMode")
93 | }
94 |
95 | override fun onSaveInstanceState(outState: Bundle?) {
96 | super.onSaveInstanceState(outState)
97 | Log.d(LOG_TAG, "onSaveInstanceState")
98 | }
99 |
100 | override fun onSaveInstanceState(outState: Bundle?, outPersistentState: PersistableBundle?) {
101 | super.onSaveInstanceState(outState, outPersistentState)
102 | Log.d(LOG_TAG, "onSaveInstanceStatePersistable")
103 | }
104 |
105 | override fun onPause() {
106 | super.onPause()
107 | Log.d(LOG_TAG, "onPause")
108 | }
109 |
110 | override fun onStop() {
111 | super.onStop()
112 | // Stop logging to UI when this activity is stopped.
113 | stopLogging()
114 |
115 | Log.d(LOG_TAG, "onStop")
116 | }
117 |
118 | override fun onRestart() {
119 | super.onRestart()
120 | Log.d(LOG_TAG, "onRestart")
121 | }
122 |
123 | override fun onDestroy() {
124 | super.onDestroy()
125 | Log.d(LOG_TAG, "onDestroy")
126 | }
127 |
128 | /**
129 | * Set up targets to receive log data
130 | */
131 | private fun initializeLogging() {
132 | // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
133 | // Wraps Android's native log framework
134 | val logWrapper = LogWrapper()
135 | Log.logNode = logWrapper
136 |
137 | // Filter strips out everything except the message text.
138 | val msgFilter = MessageOnlyLogFilter()
139 | logWrapper.next = msgFilter
140 |
141 | // On screen logging via a fragment with a TextView.
142 | val logFragment = supportFragmentManager.findFragmentById(R.id.log_fragment) as LogFragment
143 | msgFilter.next = logFragment.logView
144 | }
145 |
146 | private fun stopLogging() {
147 | Log.logNode = null
148 | }
149 |
150 | protected fun setDescription(@StringRes textId: Int) {
151 | findViewById(R.id.description).setText(textId)
152 | }
153 |
154 | protected fun setBackgroundColor(@ColorRes colorId: Int) {
155 | findViewById(R.id.scrollview).setBackgroundResource(colorId)
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/activities/MinimumSizeActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities
18 |
19 | import android.os.Bundle
20 | import com.android.multiwindowplayground.R
21 |
22 | /**
23 | * This Activity has a minimum size defined in the AndroidManifest.
24 | *
25 | * @see [com.android.multiwindowplayground.MainActivity.onStartMinimumSizeActivity]
26 | */
27 | class MinimumSizeActivity : LoggingActivity() {
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | setContentView(R.layout.activity_logging)
32 | setBackgroundColor(R.color.pink)
33 | setDescription(R.string.activity_minimum_description)
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/activities/UnresizableActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.activities
18 |
19 | import android.os.Bundle
20 | import com.android.multiwindowplayground.R
21 |
22 | /**
23 | * This Activity is defined as unresizable in the AndroidManifest.
24 | * This means that this activity is always launched full screen and will not be resized by the
25 | * system.
26 | *
27 | * @see [com.android.multiwindowplayground.MainActivity.onStartUnresizableClick]
28 | */
29 | class UnresizableActivity : LoggingActivity() {
30 |
31 | override fun onCreate(savedInstanceState: Bundle?) {
32 | super.onCreate(savedInstanceState)
33 | setContentView(R.layout.activity_logging)
34 | setBackgroundColor(R.color.purple)
35 | setDescription(R.string.activity_description_unresizable)
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/logger/Log.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.logger
18 |
19 | /**
20 | * Helper class for a list (or tree) of LoggerNodes.
21 | *
22 | *
23 | * When this is set as the head of the list,
24 | * an instance of it can function as a drop-in replacement for [android.util.Log].
25 | * Most of the methods in this class serve only to map a method call in Log to its equivalent
26 | * in LogNode.
27 | */
28 | object Log {
29 |
30 | internal val NONE = -1
31 |
32 | // Use the native value from Android's native logging facilities for easy migration and interop.
33 | private val DEBUG = android.util.Log.DEBUG
34 |
35 | // Stores the beginning of the LogNode topology.
36 | internal var logNode: LogNode? = null
37 |
38 | /**
39 | * Instructs the LogNode to print the log data provided. Other LogNodes can
40 | * be chained to the end of the LogNode as desired.
41 | *
42 | * @param priority Log level of the data being logged. Verbose, Error, etc.
43 | * @param tag Tag for for the log data. Can be used to organize log statements.
44 | * @param msg The actual message to be logged. The actual message to be logged.
45 | */
46 | private fun println(priority: Int, tag: String, msg: String) {
47 | logNode?.println(priority, tag, msg, null)
48 | }
49 |
50 | /**
51 | * Prints a message at DEBUG priority.
52 | *
53 | * @param tag Tag for for the log data. Can be used to organize log statements.
54 | * @param msg The actual message to be logged.
55 | */
56 | fun d(tag: String, msg: String) {
57 | println(DEBUG, tag, msg)
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/logger/LogFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.logger
18 |
19 | import android.graphics.Typeface
20 | import android.os.Bundle
21 | import android.support.v4.app.Fragment
22 | import android.support.v4.app.FragmentActivity
23 | import android.text.Editable
24 | import android.text.TextWatcher
25 | import android.view.Gravity
26 | import android.view.LayoutInflater
27 | import android.view.View
28 | import android.view.ViewGroup
29 | import android.view.ViewGroup.LayoutParams.MATCH_PARENT
30 | import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
31 | import android.widget.ScrollView
32 |
33 | /**
34 | * Simple fragment which contains a [LogView] and is used to output log data it receives through the
35 | * [LogNode] interface.
36 | */
37 | class LogFragment : Fragment() {
38 |
39 | internal lateinit var logView: LogView
40 | private lateinit var scrollView: ScrollView
41 |
42 | private fun inflateViews(): View {
43 | val scrollParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
44 | val logParams = ViewGroup.LayoutParams(scrollParams).apply {
45 | height = WRAP_CONTENT
46 | }
47 |
48 | // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
49 | val paddingDips = 16
50 | val scale = resources.displayMetrics.density.toDouble()
51 | val paddingPixels = (paddingDips * scale + .5).toInt()
52 |
53 | logView = LogView(activity as FragmentActivity).apply {
54 | setTextAppearance(android.R.style.TextAppearance_Material_Medium)
55 | layoutParams = logParams
56 | isClickable = true
57 | isFocusable = true
58 | typeface = Typeface.create("monospace", Typeface.NORMAL)
59 | setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels)
60 | compoundDrawablePadding = paddingPixels
61 | gravity = Gravity.BOTTOM
62 | }
63 |
64 | scrollView = ScrollView(activity).apply {
65 | layoutParams = scrollParams
66 | addView(logView)
67 | }
68 | return scrollView
69 | }
70 |
71 | override fun onCreateView(
72 | inflater: LayoutInflater,
73 | container: ViewGroup?,
74 | savedInstanceState: Bundle?
75 | ): View? {
76 | val result = inflateViews()
77 |
78 | logView.addTextChangedListener(object : TextWatcher {
79 | override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
80 |
81 | override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
82 |
83 | override fun afterTextChanged(s: Editable) {
84 | scrollView.run { post { smoothScrollTo(0, scrollView.bottom + logView.height) }}
85 | }
86 | })
87 | return result
88 | }
89 |
90 | }
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/logger/LogNode.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.logger
18 |
19 | /**
20 | * Basic interface for a logging system that can output to one or more targets.
21 | * Note that in addition to classes that will output these logs in some format,
22 | * one can also implement this interface over a filter and insert that in the chain,
23 | * such that no targets further down see certain data, or see manipulated forms of the data.
24 | * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
25 | * it received to HTML and sent it along to the next node in the chain, without printing it
26 | * anywhere.
27 | */
28 | interface LogNode {
29 |
30 | /**
31 | * Instructs first LogNode in the list to print the log data provided.
32 | *
33 | * @param priority Log level of the data being logged. Verbose, Error, etc.
34 | * @param tag Tag for for the log data. Can be used to organize log statements.
35 | * @param msg The actual message to be logged. The actual message to be logged.
36 | * @param tr If an exception was thrown, this can be sent along for the logging
37 | * facilities to extract and print useful information.
38 | */
39 | fun println(priority: Int, tag: String?, msg: String, tr: Throwable?)
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/logger/LogView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.logger
18 |
19 | import android.app.Activity
20 | import android.content.Context
21 |
22 | /**
23 | * Simple TextView which is used to output log data received through the LogNode interface.
24 | */
25 | class LogView(context: Context) : android.support.v7.widget.AppCompatTextView(context), LogNode {
26 |
27 | // The next LogNode in the chain.
28 | private var next: LogNode? = null
29 |
30 | /**
31 | * Formats the log data and prints it out to the LogView.
32 | *
33 | * @param priority Log level of the data being logged. Verbose, Error, etc.
34 | * @param tag Tag for for the log data. Can be used to organize log statements.
35 | * @param msg The actual message to be logged. The actual message to be logged.
36 | * @param tr If an exception was thrown, this can be sent along for the logging
37 | * facilities to extract and print useful information.
38 | */
39 | override fun println(priority: Int, tag: String?, msg: String, tr: Throwable?) {
40 |
41 | // For the purposes of this View, we want to print the priority as readable text.
42 | val priorityStr = when (priority) {
43 | android.util.Log.VERBOSE -> "VERBOSE"
44 | android.util.Log.DEBUG -> "DEBUG"
45 | android.util.Log.INFO -> "INFO"
46 | android.util.Log.WARN -> "WARN"
47 | android.util.Log.ERROR -> "ERROR"
48 | android.util.Log.ASSERT -> "ASSERT"
49 | else -> "VERBOSE"
50 | }
51 |
52 | // Handily, the Log class has a facility for converting a stack trace into a usable string.
53 | var exceptionStr: String? = null
54 | if (tr != null) exceptionStr = android.util.Log.getStackTraceString(tr)
55 |
56 | // Take the priority, tag, message, and exception, and concatenate as necessary
57 | // into one usable line of text.
58 | val delimiter = "\t"
59 | val outputBuilder = StringBuilder().also {
60 | appendIfNotNullOrEmpty(it, priorityStr, delimiter)
61 | appendIfNotNullOrEmpty(it, tag, delimiter)
62 | appendIfNotNullOrEmpty(it, msg, delimiter)
63 | appendIfNotNullOrEmpty(it, exceptionStr, delimiter)
64 | }
65 |
66 | // In case this was originally called from an AsyncTask or some other off-UI thread,
67 | // make sure the update occurs within the UI thread.
68 | (context as Activity).runOnUiThread(Thread(Runnable {
69 | // Display the text we just generated within the LogView as a new line of log data.
70 | append("\n$outputBuilder")
71 | }))
72 |
73 | next?.println(priority, tag, msg, tr)
74 | }
75 |
76 | /**
77 | * Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
78 | * the logger takes so many arguments that might be null, this method helps cut out some of the
79 | * agonizing tedium of writing the same statement over and over.
80 | *
81 | * @param source StringBuilder containing the text to append to.
82 | * @param addStr The String to append
83 | * @param delimiter The String to separate the source and appended strings.
84 | */
85 | private fun appendIfNotNullOrEmpty(source: StringBuilder, addStr: String?, delimiter: String) {
86 | if (addStr.isNullOrEmpty()) return
87 | source.append(addStr).append(delimiter)
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/logger/LogWrapper.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.logger
18 |
19 | import android.util.Log
20 |
21 | /**
22 | * Helper class which wraps Android's native Log utility in the Logger interface. This way
23 | * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
24 | */
25 | class LogWrapper : LogNode {
26 |
27 | // For piping: The next node to receive Log data after this one has done its work.
28 | internal var next: LogNode? = null
29 |
30 | /**
31 | * Prints data out to the console using Android's native log mechanism.
32 | *
33 | * @param priority Log level of the data being logged. Verbose, Error, etc.
34 | * @param tag Tag for for the log data. Can be used to organize log statements.
35 | * @param msg The actual message to be logged. The actual message to be logged.
36 | * @param tr If an exception was thrown, this can be sent along for the logging
37 | * facilities to extract and print useful information.
38 | */
39 | override fun println(priority: Int, tag: String?, msg: String, tr: Throwable?) {
40 |
41 | // If an exception was provided, convert that exception to a usable string and attach
42 | // it to the end of the msg method.
43 | if (tr != null) msg.plus("\n${Log.getStackTraceString(tr)}")
44 |
45 | // This is functionally identical to Log.x(tag, useMsg);
46 | // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
47 | Log.println(priority, tag, msg)
48 |
49 | // If this isn't the last node in the chain, move things along.
50 | next?.println(priority, tag, msg, tr)
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/java/com/android/multiwindowplayground/logger/MessageOnlyLogFilter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.android.multiwindowplayground.logger
18 |
19 | /**
20 | * Simple [LogNode] filter, removes everything except the message.
21 | * Useful for situations like on-screen log output where you don't want a lot of metadata
22 | * displayed, just easy-to-read message updates as they're happening.
23 | */
24 | class MessageOnlyLogFilter : LogNode {
25 |
26 | var next: LogNode? = null
27 |
28 | override fun println(priority: Int, tag: String?, msg: String, tr: Throwable?) {
29 | next?.println(Log.NONE, null, msg, null)
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/layout/activity_logging.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
25 |
26 |
32 |
33 |
43 |
44 |
45 |
51 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
32 |
33 |
41 |
42 |
47 |
48 |
58 |
59 |
64 |
65 |
71 |
72 |
78 |
79 |
85 |
86 |
92 |
93 |
98 |
99 |
105 |
106 |
112 |
113 |
114 |
115 |
116 |
122 |
123 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/layout/logging.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/Application/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/Application/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/Application/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/Application/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/Application/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 64dp
20 |
21 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #3F51B5
20 | #303F9F
21 | #FF4081
22 |
23 | #512DA8
24 | #C2185B
25 | #00695C
26 | #9E9D24
27 | #424242
28 | #F5F5F5
29 | #00838F
30 |
31 | #FFFFFF
32 |
33 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 | 16dp
21 | 16dp
22 | 16dp
23 | 30sp
24 |
25 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | MultiWindow Playground
20 | Multiwindow Playground
21 | This sample demonstrates the use of the multi-window API
22 | available in Android N.\nFirst, switch this app into
23 | split-screen mode
24 | (for example by long-pressing the recents button). Each button below starts a new activity
25 | with special flags.\nSee the files MainActivity.kt and AndroidManifest.xml for
26 | implementation details.
27 |
28 | The buttons below demonstrate features only
29 | available in free-form multi-window mode.
30 | Start basic, default Activity
31 | Start unresizable Activity
32 | Start Activity adjacent
33 | Start Activity with minimum size
34 | Start Activity with launch bounds
35 | Start activity that handles configuration changes.
36 |
37 | This Activity was launched in a new task without any
38 | additional flags or options.
39 |
40 | This activity is set as unresizable in the
41 | AndroidManifest. This is done by setting the resizeableActivity property to
42 | false for this activity.
43 |
44 | This activity was launched with the flag
45 | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT.\n\nIf possible, it has been launched into the
46 | adjacent area from the activity that started it.\nThis is only a hint to the system. For
47 | example - if the application is not in split-screen mode, it will be launched full-screen.
48 | If it is launched in the same task as the initial Activity, it will retain its activity
49 | properties and its location.
50 |
51 | This activity handles configuration changes
52 | itself.\n\nIn the AndroidManifest, this activity has been configured to receive callbacks
53 | for screenSize|smallestScreenSize|screenLayout|orientation
54 | changes.\nTry resizing this activity to different sizes to see which configuration
55 | properties change.
56 |
57 | This activity has been launched with a launch bounds
58 | set in its intent. The bounds define the area into which the activity should be launched.
59 | \n\nNote that this flag only applies in free-form mode.
60 |
61 | This activity has a minimum size.\nIt was launched
62 | into the top/end corner with a a default size of 750dp by 500dp, with a minimum size of
63 | 750dp as defined in its layout attribute in the AndroidManifest definition.
64 | \n\nNote that this Activity was launched in a different task, otherwise the properties from
65 | the Activity that launched this one would have been applied.
66 |
67 | Enable multi-window mode to see this sample in
68 | action!
69 |
70 |
--------------------------------------------------------------------------------
/kotlinApp/Application/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
31 |
32 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/kotlinApp/README.md:
--------------------------------------------------------------------------------
1 | Android MultiWindowPlayground Sample (Kotlin)
2 | =============================================
3 |
4 | This sample demonstrates the use of the multi-window API available
5 | in Android N. It shows the use of new Intent flags and
6 | AndroidManifest properties to define the multi-window behavior.
7 | Switch the sample app into multi-window mode to see how it affects
8 | the lifecycle and behavior of the app.
9 |
10 | Introduction
11 | ------------
12 |
13 | Android N introduces new APIs to support multiple activities
14 | to be displayed at the same time.
15 |
16 | Activities that are started within the same task stack
17 | inherit their multiwindow properties from the activity that fired
18 | off the intent. The following features are available when an activity
19 | has been launched into a new task stack.
20 |
21 | An activity can be set as not resizable through the
22 | `android:resizableActivity` property in the AndroidManifest. All
23 | applications targeting Android N or above are resizable by default.
24 |
25 | In split-screen mode, an activity can be started adjacent to the
26 | launching activity by setting the
27 | `Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT` flag in its intent.
28 |
29 | Sometimes activities may choose to handle configuration changes
30 | themselves (for example for games or OpenGL-based applications). In this
31 | case, setting
32 | `android:configChanges=screenSize|smallestScreenSize|screenLayout|orientation`
33 | in the AndroidManifest definition of the activity enables callbacks for
34 | all configuration changes that may occur during multi-window use for the
35 | Activity. See [Handling Runtime Changes][1].
36 |
37 | In freeform mode (where applications can be freely resized), activities
38 | can be started within a certain area of the screen using the
39 | `ActivityOptions#setLaunchBounds` call.
40 |
41 | Alternatively, the preferred and minimum sizes can be set in a new
42 | `layout` property in the AndroidManifest.
43 |
44 |
45 | [1]: https://developer.android.com/guide/topics/resources/runtime-changes.html
46 |
47 | Pre-requisites
48 | --------------
49 |
50 | - Android SDK 27
51 | - Android Support Repository
52 |
53 | Screenshots
54 | -------------
55 |
56 |
57 |
58 | Getting Started
59 | ---------------
60 |
61 | This sample uses the Gradle build system. To build this project, use the
62 | "gradlew build" command or use "Import Project" in Android Studio.
63 |
64 | Support
65 | -------
66 |
67 | - Google+ Community: https://plus.google.com/communities/105153134372062985968
68 | - Stack Overflow: http://stackoverflow.com/questions/tagged/android
69 |
70 | If you've found an error in this sample, please file an issue:
71 | https://github.com/googlesamples/android-MultiWindowPlayground
72 |
73 | Patches are encouraged, and may be submitted by forking this project and
74 | submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
75 |
76 | License
77 | -------
78 |
79 | Copyright 2017 The Android Open Source Project, Inc.
80 |
81 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
82 | license agreements. See the NOTICE file distributed with this work for
83 | additional information regarding copyright ownership. The ASF licenses this
84 | file to you under the Apache License, Version 2.0 (the "License"); you may not
85 | use this file except in compliance with the License. You may obtain a copy of
86 | the License at
87 |
88 | http://www.apache.org/licenses/LICENSE-2.0
89 |
90 | Unless required by applicable law or agreed to in writing, software
91 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
92 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
93 | License for the specific language governing permissions and limitations under
94 | the License.
95 |
--------------------------------------------------------------------------------
/kotlinApp/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.2.0'
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:3.0.1'
9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | google()
16 | jcenter()
17 | }
18 | }
19 |
20 | task clean(type: Delete) {
21 | delete rootProject.buildDir
22 | }
23 |
--------------------------------------------------------------------------------
/kotlinApp/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/kotlinApp/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
--------------------------------------------------------------------------------
/kotlinApp/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/kotlinApp/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/kotlinApp/screenshots/icon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/screenshots/icon-web.png
--------------------------------------------------------------------------------
/kotlinApp/screenshots/main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/kotlinApp/screenshots/main.png
--------------------------------------------------------------------------------
/kotlinApp/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'Application'
2 |
--------------------------------------------------------------------------------
/screenshots/icon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/screenshots/icon-web.png
--------------------------------------------------------------------------------
/screenshots/main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-MultiWindowPlayground/7715ae5740140d7d39b750eb426e65075f795178/screenshots/main.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 |
2 | include 'Application'
3 |
--------------------------------------------------------------------------------