Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedSurfaceTransactionHelper.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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.wm.shell.onehanded;
18
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.graphics.Rect;
22 import android.view.SurfaceControl;
23
24 import androidx.annotation.NonNull;
25
26 import com.android.wm.shell.R;
27
28 import java.io.PrintWriter;
29
30 /**
31 * Abstracts the common operations on {@link SurfaceControl.Transaction} for OneHanded transition.
32 */
33 public class OneHandedSurfaceTransactionHelper {
34 private static final String TAG = "OneHandedSurfaceTransactionHelper";
35
36 private final boolean mEnableCornerRadius;
37 private final float mCornerRadius;
38 private final float mCornerRadiusAdjustment;
39
40 public OneHandedSurfaceTransactionHelper(Context context) {
41 final Resources res = context.getResources();
42 mCornerRadiusAdjustment = res.getDimension(
43 com.android.internal.R.dimen.rounded_corner_radius_adjustment);
44 mCornerRadius = res.getDimension(com.android.internal.R.dimen.rounded_corner_radius)
45 - mCornerRadiusAdjustment;
46 mEnableCornerRadius = res.getBoolean(R.bool.config_one_handed_enable_round_corner);
47 }
48
49 /**
50 * Operates the translation (setPosition) on a given transaction and leash
51 *
52 * @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
53 */
54 OneHandedSurfaceTransactionHelper translate(SurfaceControl.Transaction tx, SurfaceControl leash,
55 float offset) {
56 tx.setPosition(leash, 0, offset);
57 return this;
58 }
59
60 /**
61 * Operates the crop (setMatrix) on a given transaction and leash
62 *
63 * @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
64 */
65 OneHandedSurfaceTransactionHelper crop(SurfaceControl.Transaction tx, SurfaceControl leash,
66 Rect destinationBounds) {
67 tx.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height());
68 return this;
69 }
70
71 /**
72 * Operates the round corner radius on a given transaction and leash
73 *
74 * @return same {@link OneHandedSurfaceTransactionHelper} instance for method chaining
75 */
76 OneHandedSurfaceTransactionHelper round(SurfaceControl.Transaction tx, SurfaceControl leash) {
77 if (mEnableCornerRadius) {
78 tx.setCornerRadius(leash, mCornerRadius);
79 }
80 return this;
81 }
82
83 interface SurfaceControlTransactionFactory {
84 SurfaceControl.Transaction getTransaction();
85 }
86
87 void dump(@NonNull PrintWriter pw) {
88 final String innerPrefix = " ";
89 pw.println(TAG + "states: ");
90 pw.print(innerPrefix + "mEnableCornerRadius=");
91 pw.println(mEnableCornerRadius);
92 pw.print(innerPrefix + "mCornerRadiusAdjustment=");
93 pw.println(mCornerRadiusAdjustment);
94 pw.print(innerPrefix + "mCornerRadius=");
95 pw.println(mCornerRadius);
96 }
97 }