aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VolumePluginCommon/res/layout/volume_tool_tip_view.xml4
-rw-r--r--VolumePluginCommon/src/co/potatoproject/plugin/volume/common/TriangleShape.java73
-rw-r--r--VolumePluginCommon/src/co/potatoproject/plugin/volume/common/VolumeToolTipView.java85
3 files changed, 160 insertions, 2 deletions
diff --git a/VolumePluginCommon/res/layout/volume_tool_tip_view.xml b/VolumePluginCommon/res/layout/volume_tool_tip_view.xml
index e4cad8e..4c46c76 100644
--- a/VolumePluginCommon/res/layout/volume_tool_tip_view.xml
+++ b/VolumePluginCommon/res/layout/volume_tool_tip_view.xml
@@ -16,7 +16,7 @@
~ limitations under the License
-->
-<com.android.systemui.volume.VolumeToolTipView
+<co.potatoproject.plugin.volume.common.VolumeToolTipView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tooltip_view"
android:layout_height="wrap_content"
@@ -61,4 +61,4 @@
android:layout_marginLeft="-2dp"
android:layout_gravity="center_vertical"/>
-</com.android.systemui.volume.VolumeToolTipView>
+</co.potatoproject.plugin.volume.common.VolumeToolTipView>
diff --git a/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/TriangleShape.java b/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/TriangleShape.java
new file mode 100644
index 0000000..9ea54e3
--- /dev/null
+++ b/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/TriangleShape.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2018 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 co.potatoproject.plugin.volume.common;
+
+import android.graphics.Outline;
+import android.graphics.Path;
+import android.graphics.drawable.shapes.PathShape;
+
+/**
+ * Wrapper around {@link android.graphics.drawable.shapes.PathShape}
+ * that creates a shape with a triangular path (pointing up or down).
+ */
+public class TriangleShape extends PathShape {
+ private Path mTriangularPath;
+
+ public TriangleShape(Path path, float stdWidth, float stdHeight) {
+ super(path, stdWidth, stdHeight);
+ mTriangularPath = path;
+ }
+
+ public static TriangleShape create(float width, float height, boolean isPointingUp) {
+ Path triangularPath = new Path();
+ if (isPointingUp) {
+ triangularPath.moveTo(0, height);
+ triangularPath.lineTo(width, height);
+ triangularPath.lineTo(width / 2, 0);
+ triangularPath.close();
+ } else {
+ triangularPath.moveTo(0, 0);
+ triangularPath.lineTo(width / 2, height);
+ triangularPath.lineTo(width, 0);
+ triangularPath.close();
+ }
+ return new TriangleShape(triangularPath, width, height);
+ }
+
+ /** Create an arrow TriangleShape that points to the left or the right */
+ public static TriangleShape createHorizontal(
+ float width, float height, boolean isPointingLeft) {
+ Path triangularPath = new Path();
+ if (isPointingLeft) {
+ triangularPath.moveTo(0, height / 2);
+ triangularPath.lineTo(width, height);
+ triangularPath.lineTo(width, 0);
+ triangularPath.close();
+ } else {
+ triangularPath.moveTo(0, height);
+ triangularPath.lineTo(width, height / 2);
+ triangularPath.lineTo(0, 0);
+ triangularPath.close();
+ }
+ return new TriangleShape(triangularPath, width, height);
+ }
+
+ @Override
+ public void getOutline(Outline outline) {
+ outline.setConvexPath(mTriangularPath);
+ }
+}
diff --git a/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/VolumeToolTipView.java b/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/VolumeToolTipView.java
new file mode 100644
index 0000000..e0d056e
--- /dev/null
+++ b/VolumePluginCommon/src/co/potatoproject/plugin/volume/common/VolumeToolTipView.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 The Potato Open Sauce 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 co.potatoproject.plugin.volume.common;
+
+import android.content.Context;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Resources;
+import android.graphics.CornerPathEffect;
+import android.graphics.Paint;
+import android.graphics.drawable.ShapeDrawable;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import androidx.core.content.ContextCompat;
+
+/**
+ * Tool tip view that draws an arrow that points to the volume dialog.
+ */
+public class VolumeToolTipView extends LinearLayout {
+ private SysUIR mSysUIR;
+
+ public VolumeToolTipView(Context context) {
+ this(context, null);
+ }
+
+ public VolumeToolTipView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public VolumeToolTipView(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public VolumeToolTipView(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ mSysUIR = new SysUIR(context);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ drawArrow();
+ }
+
+ private void drawArrow() {
+ Resources res;
+ try {
+ res = getContext().getPackageManager().getResourcesForApplication("com.android.systemui");
+ } catch (NameNotFoundException e) {
+ res = getContext().getResources();
+ }
+ View arrowView = findViewById(R.id.arrow);
+ ViewGroup.LayoutParams arrowLp = arrowView.getLayoutParams();
+ ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.createHorizontal(
+ arrowLp.width, arrowLp.height, false));
+ Paint arrowPaint = arrowDrawable.getPaint();
+ TypedValue typedValue = new TypedValue();
+ getContext().getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true);
+ arrowPaint.setColor(ContextCompat.getColor(getContext(), typedValue.resourceId));
+ // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
+ arrowPaint.setPathEffect(new CornerPathEffect(
+ res.getDimension(mSysUIR.dimen("volume_tool_tip_arrow_corner_radius"))));
+ arrowView.setBackground(arrowDrawable);
+
+ }
+}