change package name to uiuios

This commit is contained in:
2020-11-02 15:31:36 +08:00
parent 164c1fc8a0
commit c5bda0953d
645 changed files with 3881 additions and 3881 deletions

View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
package com.android.uiuios.keyboard;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import com.android.uiuios.ItemInfo;
import com.android.uiuios.Launcher;
import com.android.uiuios.accessibility.LauncherAccessibilityDelegate;
import com.android.uiuios.popup.PopupContainerWithArrow;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Handles showing a popup menu with available custom actions for a launcher icon.
* This allows exposing various custom actions using keyboard shortcuts.
*/
public class CustomActionsPopup implements OnMenuItemClickListener {
private final Launcher mLauncher;
private final LauncherAccessibilityDelegate mDelegate;
private final View mIcon;
public CustomActionsPopup(Launcher launcher, View icon) {
mLauncher = launcher;
mIcon = icon;
PopupContainerWithArrow container = PopupContainerWithArrow.getOpen(launcher);
if (container != null) {
mDelegate = container.getAccessibilityDelegate();
} else {
mDelegate = launcher.getAccessibilityDelegate();
}
}
private List<AccessibilityAction> getActionList() {
if (mIcon == null || !(mIcon.getTag() instanceof ItemInfo)) {
return Collections.EMPTY_LIST;
}
AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain();
mDelegate.addSupportedActions(mIcon, info, true);
List<AccessibilityAction> result = new ArrayList<>(info.getActionList());
info.recycle();
return result;
}
public boolean canShow() {
return !getActionList().isEmpty();
}
public boolean show() {
List<AccessibilityAction> actions = getActionList();
if (actions.isEmpty()) {
return false;
}
PopupMenu popup = new PopupMenu(mLauncher, mIcon);
popup.setOnMenuItemClickListener(this);
Menu menu = popup.getMenu();
for (AccessibilityAction action : actions) {
menu.add(Menu.NONE, action.getId(), Menu.NONE, action.getLabel());
}
popup.show();
return true;
}
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
return mDelegate.performAction(mIcon, (ItemInfo) mIcon.getTag(), menuItem.getItemId());
}
}

View File

@@ -0,0 +1,254 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
package com.android.uiuios.keyboard;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.RectEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.Property;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import com.android.uiuios.R;
/**
* A helper class to draw background of a focused view.
*/
public abstract class FocusIndicatorHelper implements
OnFocusChangeListener, AnimatorUpdateListener {
private static final float MIN_VISIBLE_ALPHA = 0.2f;
private static final long ANIM_DURATION = 150;
public static final Property<FocusIndicatorHelper, Float> ALPHA =
new Property<FocusIndicatorHelper, Float>(Float.TYPE, "alpha") {
@Override
public void set(FocusIndicatorHelper object, Float value) {
object.setAlpha(value);
}
@Override
public Float get(FocusIndicatorHelper object) {
return object.mAlpha;
}
};
public static final Property<FocusIndicatorHelper, Float> SHIFT =
new Property<FocusIndicatorHelper, Float>(
Float.TYPE, "shift") {
@Override
public void set(FocusIndicatorHelper object, Float value) {
object.mShift = value;
}
@Override
public Float get(FocusIndicatorHelper object) {
return object.mShift;
}
};
private static final RectEvaluator RECT_EVALUATOR = new RectEvaluator(new Rect());
private static final Rect sTempRect1 = new Rect();
private static final Rect sTempRect2 = new Rect();
private final View mContainer;
private final Paint mPaint;
private final int mMaxAlpha;
private final Rect mDirtyRect = new Rect();
private boolean mIsDirty = false;
private View mLastFocusedView;
private View mCurrentView;
private View mTargetView;
/**
* The fraction indicating the position of the focusRect between {@link #mCurrentView}
* & {@link #mTargetView}
*/
private float mShift;
private ObjectAnimator mCurrentAnimation;
private float mAlpha;
public FocusIndicatorHelper(View container) {
mContainer = container;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
int color = container.getResources().getColor(R.color.focused_background);
mMaxAlpha = Color.alpha(color);
mPaint.setColor(0xFF000000 | color);
setAlpha(0);
mShift = 0;
}
protected void setAlpha(float alpha) {
mAlpha = alpha;
mPaint.setAlpha((int) (mAlpha * mMaxAlpha));
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
invalidateDirty();
}
protected void invalidateDirty() {
if (mIsDirty) {
mContainer.invalidate(mDirtyRect);
mIsDirty = false;
}
Rect newRect = getDrawRect();
if (newRect != null) {
mContainer.invalidate(newRect);
}
}
public void draw(Canvas c) {
if (mAlpha > 0) {
Rect newRect = getDrawRect();
if (newRect != null) {
mDirtyRect.set(newRect);
c.drawRect(mDirtyRect, mPaint);
mIsDirty = true;
}
}
}
private Rect getDrawRect() {
if (mCurrentView != null && mCurrentView.isAttachedToWindow()) {
viewToRect(mCurrentView, sTempRect1);
if (mShift > 0 && mTargetView != null) {
viewToRect(mTargetView, sTempRect2);
return RECT_EVALUATOR.evaluate(mShift, sTempRect1, sTempRect2);
} else {
return sTempRect1;
}
}
return null;
}
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
endCurrentAnimation();
if (mAlpha > MIN_VISIBLE_ALPHA) {
mTargetView = v;
mCurrentAnimation = ObjectAnimator.ofPropertyValuesHolder(this,
PropertyValuesHolder.ofFloat(ALPHA, 1),
PropertyValuesHolder.ofFloat(SHIFT, 1));
mCurrentAnimation.addListener(new ViewSetListener(v, true));
} else {
setCurrentView(v);
mCurrentAnimation = ObjectAnimator.ofPropertyValuesHolder(this,
PropertyValuesHolder.ofFloat(ALPHA, 1));
}
mLastFocusedView = v;
} else {
if (mLastFocusedView == v) {
mLastFocusedView = null;
endCurrentAnimation();
mCurrentAnimation = ObjectAnimator.ofPropertyValuesHolder(this,
PropertyValuesHolder.ofFloat(ALPHA, 0));
mCurrentAnimation.addListener(new ViewSetListener(null, false));
}
}
// invalidate once
invalidateDirty();
mLastFocusedView = hasFocus ? v : null;
if (mCurrentAnimation != null) {
mCurrentAnimation.addUpdateListener(this);
mCurrentAnimation.setDuration(ANIM_DURATION).start();
}
}
protected void endCurrentAnimation() {
if (mCurrentAnimation != null) {
mCurrentAnimation.cancel();
mCurrentAnimation = null;
}
}
protected void setCurrentView(View v) {
mCurrentView = v;
mShift = 0;
mTargetView = null;
}
/**
* Gets the position of {@param v} relative to {@link #mContainer}.
*/
public abstract void viewToRect(View v, Rect outRect);
private class ViewSetListener extends AnimatorListenerAdapter {
private final View mViewToSet;
private final boolean mCallOnCancel;
private boolean mCalled = false;
public ViewSetListener(View v, boolean callOnCancel) {
mViewToSet = v;
mCallOnCancel = callOnCancel;
}
@Override
public void onAnimationCancel(Animator animation) {
if (!mCallOnCancel) {
mCalled = true;
}
}
@Override
public void onAnimationEnd(Animator animation) {
if (!mCalled) {
setCurrentView(mViewToSet);
mCalled = true;
}
}
}
/**
* Simple subclass which assumes that the target view is a child of the container.
*/
public static class SimpleFocusIndicatorHelper extends FocusIndicatorHelper {
public SimpleFocusIndicatorHelper(View container) {
super(container);
}
@Override
public void viewToRect(View v, Rect outRect) {
outRect.set(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
}
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
package com.android.uiuios.keyboard;
import android.graphics.Canvas;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import com.android.uiuios.keyboard.FocusIndicatorHelper.SimpleFocusIndicatorHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
import androidx.recyclerview.widget.RecyclerView.State;
/**
* {@link ItemDecoration} for drawing and animating focused view background.
*/
public class FocusedItemDecorator extends ItemDecoration {
private FocusIndicatorHelper mHelper;
public FocusedItemDecorator(View container) {
mHelper = new SimpleFocusIndicatorHelper(container);
}
public OnFocusChangeListener getFocusListener() {
return mHelper;
}
@Override
public void onDraw(Canvas c, RecyclerView parent, State state) {
mHelper.draw(c);
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
package com.android.uiuios.keyboard;
import android.graphics.Rect;
import android.view.View;
import com.android.uiuios.PagedView;
/**
* {@link FocusIndicatorHelper} for a generic view group.
*/
public class ViewGroupFocusHelper extends FocusIndicatorHelper {
private final View mContainer;
public ViewGroupFocusHelper(View container) {
super(container);
mContainer = container;
}
@Override
public void viewToRect(View v, Rect outRect) {
outRect.left = 0;
outRect.top = 0;
computeLocationRelativeToContainer(v, outRect);
// If a view is scaled, its position will also shift accordingly. For optimization, only
// consider this for the last node.
outRect.left += (1 - v.getScaleX()) * v.getWidth() / 2;
outRect.top += (1 - v.getScaleY()) * v.getHeight() / 2;
outRect.right = outRect.left + (int) (v.getScaleX() * v.getWidth());
outRect.bottom = outRect.top + (int) (v.getScaleY() * v.getHeight());
}
private void computeLocationRelativeToContainer(View child, Rect outRect) {
View parent = (View) child.getParent();
outRect.left += child.getX();
outRect.top += child.getY();
if (parent != mContainer) {
if (parent instanceof PagedView) {
PagedView page = (PagedView) parent;
outRect.left -= page.getScrollForPage(page.indexOfChild(child));
}
computeLocationRelativeToContainer(parent, outRect);
}
}
}