OSDN Git Service

Add back button for freeform window
authorutzcoz <utzcoz@outlook.com>
Thu, 11 Jun 2020 12:16:55 +0000 (20:16 +0800)
committerutzcoz <utzcoz@outlook.com>
Thu, 11 Jun 2020 12:16:55 +0000 (20:16 +0800)
Signed-off-by: utzcoz <utzcoz@outlook.com>
config/hiddenapi-private-dex.txt
core/java/com/android/internal/policy/DecorView.java
core/java/com/android/internal/widget/DecorCaptionView.java
core/res/res/drawable/decor_back_button_dark.xml [new file with mode: 0644]
core/res/res/drawable/decor_back_button_light.xml [new file with mode: 0644]
core/res/res/layout/decor_caption.xml
core/res/res/values/arrays.xml
core/res/res/values/strings.xml
core/res/res/values/symbols.xml

index 2c48655..1615ff2 100644 (file)
@@ -113705,6 +113705,8 @@ Lcom/android/internal/R$drawable;->decor_close_button_dark:I
 Lcom/android/internal/R$drawable;->decor_close_button_light:I
 Lcom/android/internal/R$drawable;->decor_maximize_button_dark:I
 Lcom/android/internal/R$drawable;->decor_maximize_button_light:I
+Lcom/android/internal/R$drawable;->decor_back_button_dark:I
+Lcom/android/internal/R$drawable;->decor_back_button_light:I
 Lcom/android/internal/R$drawable;->default_lock_wallpaper:I
 Lcom/android/internal/R$drawable;->default_wallpaper:I
 Lcom/android/internal/R$drawable;->dialog_frame:I
index bac802e..2b2e5ca 100644 (file)
@@ -1994,7 +1994,12 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
     }
 
     private void setLightDecorCaptionShade(DecorCaptionView view) {
-               view.findViewById(R.id.pip_window).setBackgroundResource(
+        // region @boringdroid
+        view.findViewById(R.id.back_window).setBackgroundResource(
+                R.drawable.decor_back_button_light
+        );
+        // endregion
+        view.findViewById(R.id.pip_window).setBackgroundResource(
                 R.drawable.decor_pip_button_light);
         view.findViewById(R.id.minimize_window).setBackgroundResource(
                 R.drawable.decor_minimize_button_light);
@@ -2005,6 +2010,11 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
     }
 
     private void setDarkDecorCaptionShade(DecorCaptionView view) {
+        // region @boringdroid
+        view.findViewById(R.id.back_window).setBackgroundResource(
+                R.drawable.decor_back_button_dark
+        );
+        // endregion
                view.findViewById(R.id.pip_window).setBackgroundResource(
                 R.drawable.decor_pip_button_dark);
                view.findViewById(R.id.minimize_window).setBackgroundResource(
index ac05c9b..f4763f6 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.internal.widget;
 
+import android.app.Activity;
 import android.content.Context;
 import android.graphics.Color;
 import android.graphics.Rect;
@@ -107,6 +108,10 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
     private final Rect mMinimizeRect = new Rect();
     private final Rect mPipRect = new Rect();
     private View mClickTarget;
+    // region @boringdroid
+    private View mBack;
+    private final Rect mBackRect = new Rect();
+    // endregion
 
     public DecorCaptionView(Context context) {
         super(context);
@@ -147,6 +152,9 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
         // By changing the outline provider to BOUNDS, the window can remove its
         // background without removing the shadow.
         mOwner.getDecorView().setOutlineProvider(ViewOutlineProvider.BOUNDS);
+        // region @boringdroid
+        mBack = findViewById(R.id.back_window);
+        // endregion
         mPip = findViewById(R.id.pip_window);
         mMinimize = findViewById(R.id.minimize_window);
         mMaximize = findViewById(R.id.maximize_window);
@@ -160,6 +168,11 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
         if (ev.getAction() == MotionEvent.ACTION_DOWN) {
             final int x = (int) ev.getX();
             final int y = (int) ev.getY();
+            // region @boringdroid
+            if (mBackRect.contains(x, y)) {
+                mClickTarget = mBack;
+            }
+            // endregion
             // Only offset y for containment tests because the actual views are already translated.
             if (mPipRect.contains(x, y)) {
                 mClickTarget = mPip;
@@ -311,12 +324,18 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
         if (mCaption.getVisibility() != View.GONE) {
             mCaption.layout(0, 0, mCaption.getMeasuredWidth(), mCaption.getMeasuredHeight());
             captionHeight = mCaption.getBottom() - mCaption.getTop();
+            // region @boringdroid
+            mBack.getHitRect(mBackRect);
+            // endregion
             mPip.getHitRect(mPipRect);
             mMinimize.getHitRect(mMinimizeRect);
             mMaximize.getHitRect(mMaximizeRect);
             mClose.getHitRect(mCloseRect);
         } else {
             captionHeight = 0;
+            // region @boringdroid
+            mBackRect.setEmpty();
+            // endregion
             mPipRect.setEmpty();
             mMinimizeRect.setEmpty();
             mMaximizeRect.setEmpty();
@@ -333,8 +352,12 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
         }
 
         // This assumes that the caption bar is at the top.
-        mOwner.notifyRestrictedCaptionAreaCallback(mPip.getLeft(), mMaximize.getTop(),
+        // region @boringdroid
+        // mOwner.notifyRestrictedCaptionAreaCallback(mPip.getLeft(), mMaximize.getTop(),
+        //         mClose.getRight(), mClose.getBottom());
+        mOwner.notifyRestrictedCaptionAreaCallback(mBack.getLeft(), mBack.getTop(),
                 mClose.getRight(), mClose.getBottom());
+        // endregion
     }
     /**
      * Determine if the workspace is entirely covered by the window.
@@ -436,6 +459,16 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
 
     @Override
     public boolean onSingleTapUp(MotionEvent e) {
+        // region @boringdroid
+        if (mClickTarget == mBack) {
+            Window.WindowControllerCallback callback = mOwner.getWindowControllerCallback();
+            if (callback instanceof Activity) {
+                Activity activity = (Activity) callback;
+                activity.onBackPressed();
+            }
+            return true;
+        }
+        // endregion
         if (mClickTarget == mMinimize) {
             minimizeWindow();
         } else if (mClickTarget == mPip) {
diff --git a/core/res/res/drawable/decor_back_button_dark.xml b/core/res/res/drawable/decor_back_button_dark.xml
new file mode 100644 (file)
index 0000000..ec0f6a9
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+     Copyright (C) 2020 boringdroid
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="32.0dp"
+        android:height="32.0dp"
+        android:viewportWidth="32.0"
+        android:viewportHeight="32.0"
+        android:tint="@color/decor_button_dark_color">
+    <group android:scaleX="0.5"
+           android:scaleY="0.5"
+           android:translateX="8.0"
+           android:translateY="8.0">
+        <path
+            android:fillColor="@color/white"
+            android:pathData="M2.0,16.0l28.0,14.0l0.0,-28z" />
+    </group>
+</vector>
+
+
diff --git a/core/res/res/drawable/decor_back_button_light.xml b/core/res/res/drawable/decor_back_button_light.xml
new file mode 100644 (file)
index 0000000..7b9344a
--- /dev/null
@@ -0,0 +1,31 @@
+<!-- Copyright (C) 2015 The Android Open Source Project
+     Copyright (C) boringdroid
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="32.0dp"
+        android:height="32.0dp"
+        android:viewportWidth="32.0"
+        android:viewportHeight="32.0"
+        android:tint="@color/decor_button_light_color">
+    <group android:scaleX="0.5"
+           android:scaleY="0.5"
+           android:translateX="8.0"
+           android:translateY="8.0">
+        <path
+            android:fillColor="@color/white"
+            android:pathData="M2.0,16.0l28.0,14.0l0.0,-28z" />
+    </group>
+</vector>
index 55edbfc..534d27d 100644 (file)
             android:background="@drawable/decor_caption_title"
             android:focusable="false"
             android:descendantFocusability="blocksDescendants" >
+        <!-- region @boringdroid -->
+        <Button
+            android:id="@+id/back_window"
+            android:layout_width="32dp"
+            android:layout_height="32dp"
+            android:layout_margin="5dp"
+            android:padding="4dp"
+            android:layout_gravity="center_vertical|start"
+            android:contentDescription="@string/back_button_text"
+            android:background="@drawable/decor_back_button_dark" />
+        <Space
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:background="@color/transparent" />
+        <!-- endregion -->
         <Button
                 android:id="@+id/pip_window"
                 android:layout_width="32dp"
index 67a1334..20532be 100644 (file)
       <item>@drawable/decor_minimize_button_light</item>
       <item>@drawable/decor_pip_button_dark</item>
       <item>@drawable/decor_pip_button_light</item>
+      <!-- region @boringdroid -->
+      <item>@drawable/decor_back_button_dark</item>
+      <item>@drawable/decor_back_button_light</item>
+      <!-- endregion -->
    </array>
 
     <!-- Used in LocalePicker -->
index 2b9da1c..e422f93 100644 (file)
     <string name="floating_toolbar_close_overflow_description">Close overflow</string>
 
     <!-- Free style window strings -->
+    <!-- region @boringdroid -->
+    <string name="back_button_text">Back</string>
+    <!-- endregion -->
     <!-- Accessibility text for the minimize window button -->
     <string name="pip_button_text">Picture In Picture</string>
     <!-- Accessibility text for the minimize window button -->
index 57dfa63..be35095 100644 (file)
   <java-symbol type="drawable" name="decor_maximize_button_light" />
   <java-symbol type="drawable" name="decor_pip_button_dark" />
   <java-symbol type="drawable" name="decor_pip_button_light" />
+  <!-- region @boringdroid -->
+  <java-symbol type="id" name="back_window" />
+  <java-symbol type="drawable" name="decor_back_button_dark" />
+  <java-symbol type="drawable" name="decor_back_button_light" />
+  <!-- endregion -->
   <java-symbol type="color" name="decor_button_dark_color" />
   <java-symbol type="color" name="decor_button_light_color" />