Skip to content

Commit

Permalink
plugins: Move VolumeToolTipView into common lib
Browse files Browse the repository at this point in the history
Change-Id: I83a36610bbce1d0892953b45a16970edb788d85c
  • Loading branch information
AgentFabulous committed Jul 8, 2020
1 parent 4d00e44 commit 2cabc2d
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 2 deletions.
4 changes: 2 additions & 2 deletions VolumePluginCommon/res/layout/volume_tool_tip_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -61,4 +61,4 @@
android:layout_marginLeft="-2dp"
android:layout_gravity="center_vertical"/>

</com.android.systemui.volume.VolumeToolTipView>
</co.potatoproject.plugin.volume.common.VolumeToolTipView>
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);

}
}

0 comments on commit 2cabc2d

Please sign in to comment.