| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.compatui; |
| 18 |
|
| 19 |
import android.annotation.IdRes; |
| 20 |
import android.app.TaskInfo; |
| 21 |
import android.app.TaskInfo.CameraCompatControlState; |
| 22 |
import android.content.Context; |
| 23 |
import android.util.AttributeSet; |
| 24 |
import android.view.View; |
| 25 |
import android.widget.ImageButton; |
| 26 |
import android.widget.LinearLayout; |
| 27 |
import android.widget.TextView; |
| 28 |
|
| 29 |
import com.android.wm.shell.R; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class CompatUILayout extends LinearLayout { |
| 35 |
|
| 36 |
private CompatUIWindowManager mWindowManager; |
| 37 |
|
| 38 |
public CompatUILayout(Context context) { |
| 39 |
this(context, null); |
| 40 |
} |
| 41 |
|
| 42 |
public CompatUILayout(Context context, AttributeSet attrs) { |
| 43 |
this(context, attrs, 0); |
| 44 |
} |
| 45 |
|
| 46 |
public CompatUILayout(Context context, AttributeSet attrs, int defStyleAttr) { |
| 47 |
this(context, attrs, defStyleAttr, 0); |
| 48 |
} |
| 49 |
|
| 50 |
public CompatUILayout(Context context, AttributeSet attrs, int defStyleAttr, |
| 51 |
int defStyleRes) { |
| 52 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 53 |
} |
| 54 |
|
| 55 |
void inject(CompatUIWindowManager windowManager) { |
| 56 |
mWindowManager = windowManager; |
| 57 |
} |
| 58 |
|
| 59 |
void updateCameraTreatmentButton(@CameraCompatControlState int newState) { |
| 60 |
int buttonBkgId = newState == TaskInfo.CAMERA_COMPAT_CONTROL_TREATMENT_SUGGESTED |
| 61 |
? R.drawable.camera_compat_treatment_suggested_ripple |
| 62 |
: R.drawable.camera_compat_treatment_applied_ripple; |
| 63 |
int hintStringId = newState == TaskInfo.CAMERA_COMPAT_CONTROL_TREATMENT_SUGGESTED |
| 64 |
? R.string.camera_compat_treatment_suggested_button_description |
| 65 |
: R.string.camera_compat_treatment_applied_button_description; |
| 66 |
final ImageButton button = findViewById(R.id.camera_compat_treatment_button); |
| 67 |
button.setImageResource(buttonBkgId); |
| 68 |
button.setContentDescription(getResources().getString(hintStringId)); |
| 69 |
final LinearLayout hint = findViewById(R.id.camera_compat_hint); |
| 70 |
((TextView) hint.findViewById(R.id.compat_mode_hint_text)).setText(hintStringId); |
| 71 |
} |
| 72 |
|
| 73 |
void setSizeCompatHintVisibility(boolean show) { |
| 74 |
setViewVisibility(R.id.size_compat_hint, show); |
| 75 |
} |
| 76 |
|
| 77 |
void setCameraCompatHintVisibility(boolean show) { |
| 78 |
setViewVisibility(R.id.camera_compat_hint, show); |
| 79 |
} |
| 80 |
|
| 81 |
void setRestartButtonVisibility(boolean show) { |
| 82 |
setViewVisibility(R.id.size_compat_restart_button, show); |
| 83 |
|
| 84 |
if (!show) { |
| 85 |
setSizeCompatHintVisibility( false); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
void setCameraControlVisibility(boolean show) { |
| 90 |
setViewVisibility(R.id.camera_compat_control, show); |
| 91 |
|
| 92 |
if (!show) { |
| 93 |
setCameraCompatHintVisibility( false); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
private void setViewVisibility(@IdRes int resId, boolean show) { |
| 98 |
final View view = findViewById(resId); |
| 99 |
int visibility = show ? View.VISIBLE : View.GONE; |
| 100 |
if (view.getVisibility() == visibility) { |
| 101 |
return; |
| 102 |
} |
| 103 |
view.setVisibility(visibility); |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 108 |
super.onLayout(changed, left, top, right, bottom); |
| 109 |
|
| 110 |
|
| 111 |
mWindowManager.relayout(); |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
protected void onFinishInflate() { |
| 116 |
super.onFinishInflate(); |
| 117 |
|
| 118 |
final ImageButton restartButton = findViewById(R.id.size_compat_restart_button); |
| 119 |
restartButton.setOnClickListener(view -> mWindowManager.onRestartButtonClicked()); |
| 120 |
restartButton.setOnLongClickListener(view -> { |
| 121 |
mWindowManager.onRestartButtonLongClicked(); |
| 122 |
return true; |
| 123 |
}); |
| 124 |
|
| 125 |
final LinearLayout sizeCompatHint = findViewById(R.id.size_compat_hint); |
| 126 |
((TextView) sizeCompatHint.findViewById(R.id.compat_mode_hint_text)) |
| 127 |
.setText(R.string.restart_button_description); |
| 128 |
sizeCompatHint.setOnClickListener(view -> setSizeCompatHintVisibility( false)); |
| 129 |
|
| 130 |
final ImageButton cameraTreatmentButton = |
| 131 |
findViewById(R.id.camera_compat_treatment_button); |
| 132 |
cameraTreatmentButton.setOnClickListener( |
| 133 |
view -> mWindowManager.onCameraTreatmentButtonClicked()); |
| 134 |
cameraTreatmentButton.setOnLongClickListener(view -> { |
| 135 |
mWindowManager.onCameraButtonLongClicked(); |
| 136 |
return true; |
| 137 |
}); |
| 138 |
|
| 139 |
final ImageButton cameraDismissButton = findViewById(R.id.camera_compat_dismiss_button); |
| 140 |
cameraDismissButton.setOnClickListener( |
| 141 |
view -> mWindowManager.onCameraDismissButtonClicked()); |
| 142 |
cameraDismissButton.setOnLongClickListener(view -> { |
| 143 |
mWindowManager.onCameraButtonLongClicked(); |
| 144 |
return true; |
| 145 |
}); |
| 146 |
|
| 147 |
final LinearLayout cameraCompatHint = findViewById(R.id.camera_compat_hint); |
| 148 |
cameraCompatHint.setOnClickListener( |
| 149 |
view -> setCameraCompatHintVisibility( false)); |
| 150 |
} |
| 151 |
} |