diff --git a/core/java/com/android/internal/widget/DecorCaptionButton.java b/core/java/com/android/internal/widget/DecorCaptionButton.java new file mode 100644 index 0000000000000000000000000000000000000000..dcf1bb7498429e51da47bfda7ae3183c5b521942 --- /dev/null +++ b/core/java/com/android/internal/widget/DecorCaptionButton.java @@ -0,0 +1,79 @@ +package com.android.internal.widget; + +import android.graphics.Rect; +import android.view.View; + +public class DecorCaptionButton { + private View mMaximize; + private View mMinimize; + private View mClose; + private View mBack; + + private Rect mCloseRect = new Rect(); // click area of close button + private Rect mMinimizeRect = new Rect(); // click area of min button + private Rect mMaximizeRect = new Rect(); // click area of max button + private Rect mBackRect = new Rect(); // click area of back button + + public View getMaximize() { + return mMaximize; + } + + public View getMinimize() { + return mMinimize; + } + + public View getClose() { + return mClose; + } + + public View getBack() { + return mBack; + } + + public Rect getMaximizeRect() { + return mMaximizeRect; + } + public Rect getMinimizeRect() { + return mMinimizeRect; + } + + public Rect getCloseRect() { + return mCloseRect; + } + + public Rect getBackRect() { + return mBackRect; + } + + public void setMaximize(View view) { + mMaximize = view; + } + + public void setMinimize(View view) { + mMinimize = view; + } + + public void setClose(View view) { + mClose = view; + } + + public void setBack(View view) { + mBack = view; + } + + public void setMaximizeRect(Rect rect) { + mMaximizeRect = rect; + } + + public void setMinimizeRect(Rect rect) { + mMinimizeRect = rect; + } + + public void setCloseRect(Rect rect) { + mCloseRect = rect; + } + + public void setBackRect(Rect rect) { + mBackRect = rect; + } +} diff --git a/core/java/com/android/internal/widget/DecorCaptionView.java b/core/java/com/android/internal/widget/DecorCaptionView.java index d93075e35cc11c548c2a394f15a1662a03f0a0b2..6aebc7c08f7569de774d403600bdbbfd7294f00b 100644 --- a/core/java/com/android/internal/widget/DecorCaptionView.java +++ b/core/java/com/android/internal/widget/DecorCaptionView.java @@ -17,23 +17,25 @@ package com.android.internal.widget; import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.graphics.Color; import android.graphics.Rect; -import android.os.RemoteException; import android.util.AttributeSet; -import android.util.Log; +import android.util.Slog; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.ViewOutlineProvider; -import android.view.Window; import com.android.internal.R; import com.android.internal.policy.PhoneWindow; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; /** * This class represents the special screen elements to control a window on freeform @@ -75,7 +77,7 @@ import java.util.ArrayList; */ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, GestureDetector.OnGestureListener { - private final static String TAG = "DecorCaptionView"; + private static final String TAG = "DecorCaptionView"; private PhoneWindow mOwner = null; private boolean mShow = false; @@ -89,11 +91,8 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, private View mCaption; private View mContent; - private View mMaximize; - private View mMinimize; - private View mClose; - private View mBack; - private int mDefaultHeight = 42; // unChangeable caption height + private DecorCaptionButton mCaptionButton; + private static final int DEFAULT_HEIGHT = 42; // unChangeable caption height // Fields for detecting drag events. private int mTouchDownX; @@ -106,12 +105,25 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, // We use the gesture detector to detect clicks on close/maximize buttons and to be consistent // with existing click detection. private GestureDetector mGestureDetector; - private final Rect mCloseRect = new Rect(); // click area of close button - private final Rect mMinimizeRect = new Rect(); // click area of min button - private final Rect mMaximizeRect = new Rect(); // click area of max button - private final Rect mBackRect = new Rect(); // click area of back button private View mClickTarget; + public static class WindowProperty { + private WindowProperty() { } + + public static final int HIDE_BACK = 0x01; + public static final int HIDE_MINIMIZE = 0x02; + public static final int HIDE_MAXIMIZE = 0x04; + public static final int HIDE_CLOSE = 0x08; + public static final int SHOW_ALL = 0x00; + } + + private static final Map propertyMap; + + static { + propertyMap = new HashMap<>(); + propertyMap.put("QQ音乐", WindowProperty.HIDE_BACK); + } + public DecorCaptionView(Context context) { super(context); init(context); @@ -151,10 +163,10 @@ 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); - mMaximize = findViewById(R.id.maximize_window); - mMinimize = findViewById(R.id.minimize_window); - mBack = findViewById(R.id.back_window); - mClose = findViewById(R.id.close_window); + mCaptionButton.setMaximize(findViewById(R.id.maximize_window)); + mCaptionButton.setMinimize(findViewById(R.id.minimize_window)); + mCaptionButton.setBack(findViewById(R.id.back_window)); + mCaptionButton.setClose(findViewById(R.id.close_window)); } @Override @@ -164,11 +176,8 @@ 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(); - if (mMaximizeRect.contains(x, y)) { - mClickTarget = mMaximize; - } - if (mCloseRect.contains(x, y)) { - mClickTarget = mClose; + if (mCaptionButton.getCloseRect().contains(x, y)) { + mClickTarget = mCaptionButton.getClose(); } } return mClickTarget != null; @@ -202,8 +211,8 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, } // Checking for a drag action is started if we aren't dragging already and the // starting event is either a left mouse button or any other input device. - if (((e.getToolType(e.getActionIndex()) != MotionEvent.TOOL_TYPE_MOUSE || - (e.getButtonState() & MotionEvent.BUTTON_PRIMARY) != 0))) { + if ((e.getToolType(e.getActionIndex()) != MotionEvent.TOOL_TYPE_MOUSE || + (e.getButtonState() & MotionEvent.BUTTON_PRIMARY) != 0)) { mCheckForDragging = true; mTouchDownX = x; mTouchDownY = y; @@ -216,14 +225,15 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, mDragging = true; mLeftMouseButtonReleased = false; startMovingTask(e.getRawX(), e.getRawY()); - } else if (mDragging && !mLeftMouseButtonReleased) { - if (e.getToolType(e.getActionIndex()) == MotionEvent.TOOL_TYPE_MOUSE && + } else if (mDragging && !mLeftMouseButtonReleased && + e.getToolType(e.getActionIndex()) == MotionEvent.TOOL_TYPE_MOUSE && (e.getButtonState() & MotionEvent.BUTTON_PRIMARY) == 0) { - // There is no separate mouse button up call and if the user mixes mouse - // button drag actions, we stop dragging once he releases the button. - mLeftMouseButtonReleased = true; - break; - } + // There is no separate mouse button up call and if the user mixes mouse + // button drag actions, we stop dragging once he releases the button. + mLeftMouseButtonReleased = true; + break; + } else { + Slog.w(TAG, "ACTION_MOVE: nothing to do!!"); } break; @@ -290,7 +300,7 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, final int captionHeight; if (mCaption.getVisibility() != View.GONE) { measureChildWithMargins(mCaption, widthMeasureSpec, 0, heightMeasureSpec, 0); - captionHeight = mDefaultHeight; + captionHeight = DEFAULT_HEIGHT; } else { captionHeight = 0; } @@ -307,31 +317,73 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, MeasureSpec.getSize(heightMeasureSpec)); } + private int getAppProperty() { + Context context = mContext; + try { + PackageManager packageManager = context.getPackageManager(); + PackageInfo packageInfo = packageManager.getPackageInfo( + context.getPackageName(), 0); + int labelRes = packageInfo.applicationInfo.labelRes; + String appName = context.getResources().getString(labelRes); + Integer property = propertyMap.get(appName); + if (property != null) { + return property; + } else { + return WindowProperty.SHOW_ALL; + } + } catch (Exception e) { + Slog.w(TAG, "getAppProperty exc ocured!!return SHOW_ALL instead.", e); + } + return WindowProperty.SHOW_ALL; + } + + private int appProperty = getAppProperty(); + private boolean firstSetProperty = true; + + protected boolean showButton(int property, View button, Rect buttonRect, Rect showRect) { + if ((appProperty & property) == property) { + button.setVisibility(View.GONE); + buttonRect.setEmpty(); + return false; + } + + button.layout(showRect.left, showRect.top, showRect.right, showRect.bottom); + button.getHitRect(buttonRect); + return true; + } + + protected void showButtonFromRight(int property, View button, Rect buttonRect, Rect showRect) { + if (showButton(property, button, buttonRect, showRect)) { + showRect.offset(-showRect.width(), 0); + } + } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final int captionHeight; if (mCaption.getVisibility() != View.GONE) { - mCaption.layout(0, 0, mCaption.getMeasuredWidth(), mDefaultHeight); + mCaption.layout(0, 0, mCaption.getMeasuredWidth(), DEFAULT_HEIGHT); captionHeight = mCaption.getBottom() - mCaption.getTop(); - if (mBack.getHeight() != captionHeight) { + if (mCaptionButton.getClose().getHeight() != captionHeight || firstSetProperty) { + firstSetProperty = false; final int captionWidth = mCaption.getRight() - mCaption.getLeft(); - mBack.layout(0, 0, captionHeight, captionHeight); - mMinimize.layout(captionWidth - captionHeight * 3, 0, captionWidth - captionHeight * 2, captionHeight); - mMaximize.layout(captionWidth - captionHeight * 2, 0, captionWidth - captionHeight, captionHeight); - mClose.layout(captionWidth - captionHeight, 0, captionWidth, captionHeight); + showButton(WindowProperty.HIDE_BACK, mCaptionButton.getBack(), mCaptionButton.getBackRect(), + new Rect(0, 0, captionHeight, captionWidth)); + + Rect showRect = new Rect(captionWidth - captionHeight, 0, captionWidth, captionHeight); + showButtonFromRight(WindowProperty.HIDE_CLOSE, mCaptionButton.getClose(), + mCaptionButton.getCloseRect(), showRect); + showButtonFromRight(WindowProperty.HIDE_MAXIMIZE, mCaptionButton.getMaximize(), + mCaptionButton.getMaximizeRect(), showRect); + showButtonFromRight(WindowProperty.HIDE_MINIMIZE, mCaptionButton.getMinimize(), + mCaptionButton.getMinimizeRect(), showRect); } - - mMaximize.getHitRect(mMaximizeRect); - mMinimize.getHitRect(mMinimizeRect); - mBack.getHitRect(mBackRect); - mClose.getHitRect(mCloseRect); } else { captionHeight = 0; - mMaximizeRect.setEmpty(); - mMinimizeRect.setEmpty(); - mBackRect.setEmpty(); - mCloseRect.setEmpty(); + mCaptionButton.getMaximizeRect().setEmpty(); + mCaptionButton.getMinimizeRect().setEmpty(); + mCaptionButton.getBackRect().setEmpty(); + mCaptionButton.getCloseRect().setEmpty(); } if (mContent != null) { @@ -344,8 +396,10 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, } // This assumes that the caption bar is at the top. - mOwner.notifyRestrictedCaptionAreaCallback(mMinimize.getLeft(), mMinimize.getTop(), - mClose.getRight(), mClose.getBottom()); + View minimize = mCaptionButton.getMinimize(); + View close = mCaptionButton.getClose(); + mOwner.notifyRestrictedCaptionAreaCallback(minimize.getLeft(), minimize.getTop(), + close.getRight(), close.getBottom()); } /** * Determine if the workspace is entirely covered by the window. @@ -367,22 +421,6 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, mCaption.setOnTouchListener(this); } - /** - * Maximize the window by moving it to the maximized workspace stack. - **/ - private void maximizeWindow() { - /* - Window.WindowControllerCallback callback = mOwner.getWindowControllerCallback(); - if (callback != null) { - try { - callback.exitFreeformMode(); - } catch (RemoteException ex) { - Log.e(TAG, "Cannot change task workspace."); - } - } - */ - } - public boolean isCaptionShowing() { return mShow; } @@ -402,6 +440,11 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, return mCaption; } + @Override + protected LayoutParams generateLayoutParams(LayoutParams p) { + return new MarginLayoutParams(p); + } + @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { return new MarginLayoutParams(getContext(), attrs); @@ -413,11 +456,6 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, MarginLayoutParams.MATCH_PARENT); } - @Override - protected LayoutParams generateLayoutParams(LayoutParams p) { - return new MarginLayoutParams(p); - } - @Override protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { return p instanceof MarginLayoutParams; @@ -435,9 +473,7 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener, @Override public boolean onSingleTapUp(MotionEvent e) { - if (mClickTarget == mMaximize) { - maximizeWindow(); - } else if (mClickTarget == mClose) { + if (mClickTarget == mCaptionButton.getClose()) { mOwner.dispatchOnWindowDismissed(true /*finishTask*/); } return true;