| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 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 |
|
| 51 |
|
| 52 |
|
| 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 |
|
| 62 |
|
| 63 |
|
| 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 |
|
| 73 |
|
| 74 |
|
| 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 |
} |