-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: Move VolumeToolTipView into common lib
Change-Id: I83a36610bbce1d0892953b45a16970edb788d85c
- Loading branch information
1 parent
4d00e44
commit 2cabc2d
Showing
3 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
VolumePluginCommon/src/co/potatoproject/plugin/volume/common/TriangleShape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
VolumePluginCommon/src/co/potatoproject/plugin/volume/common/VolumeToolTipView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |