mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
5a3d929433
--HG-- rename : mobile/android/base/resources/layout-land-v14/browser_toolbar.xml => mobile/android/base/resources/layout-land-v14/browser_toolbar.xml.in rename : mobile/android/base/resources/layout-land-v14/browser_toolbar_menu.xml => mobile/android/base/resources/layout-land-v14/browser_toolbar_menu.xml.in rename : mobile/android/base/resources/layout-large-v11/browser_toolbar_menu.xml => mobile/android/base/resources/layout-large-v11/browser_toolbar_menu.xml.in rename : mobile/android/base/resources/layout-xlarge-v11/browser_toolbar_menu.xml => mobile/android/base/resources/layout-xlarge-v11/browser_toolbar_menu.xml.in rename : mobile/android/base/resources/layout/browser_toolbar.xml => mobile/android/base/resources/layout/browser_toolbar.xml.in rename : mobile/android/base/resources/layout/browser_toolbar_menu.xml => mobile/android/base/resources/layout/browser_toolbar_menu.xml.in extra : rebase_source : 9dc69355643a7b0f5f4ecadb7e2d5d4ce554ea7e
80 lines
2.5 KiB
Java
80 lines
2.5 KiB
Java
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Path;
|
|
import android.graphics.PorterDuff.Mode;
|
|
import android.util.AttributeSet;
|
|
import android.widget.ImageButton;
|
|
|
|
public class MenuButton extends ImageButton
|
|
implements CanvasDelegate.DrawManager {
|
|
Path mPath;
|
|
CurveTowards mSide;
|
|
CanvasDelegate mCanvasDelegate;
|
|
|
|
private enum CurveTowards { NONE, LEFT, RIGHT };
|
|
|
|
public MenuButton(Context context, AttributeSet attrs) {
|
|
super(context, attrs);
|
|
|
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbarCurve);
|
|
int curveTowards = a.getInt(R.styleable.BrowserToolbarCurve_curveTowards, 0x02);
|
|
a.recycle();
|
|
|
|
if (curveTowards == 0x00)
|
|
mSide = CurveTowards.NONE;
|
|
else if (curveTowards == 0x01)
|
|
mSide = CurveTowards.LEFT;
|
|
else
|
|
mSide = CurveTowards.RIGHT;
|
|
|
|
// Path is clipped.
|
|
mPath = new Path();
|
|
mCanvasDelegate = new CanvasDelegate(this, Mode.DST_OUT);
|
|
}
|
|
|
|
@Override
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
int width = getMeasuredWidth();
|
|
int height = getMeasuredHeight();
|
|
float curve = height * 1.125f;
|
|
|
|
mPath.reset();
|
|
|
|
// Clipping happens on opposite side for menu.
|
|
if (mSide == CurveTowards.RIGHT) {
|
|
mPath.moveTo(0, 0);
|
|
mPath.cubicTo(curve * 0.75f, 0,
|
|
curve * 0.25f, height,
|
|
curve, height);
|
|
mPath.lineTo(0, height);
|
|
mPath.lineTo(0, 0);
|
|
} else if (mSide == CurveTowards.LEFT) {
|
|
mPath.moveTo(width, 0);
|
|
mPath.cubicTo((width - (curve * 0.75f)), 0,
|
|
(width - (curve * 0.25f)), height,
|
|
(width - curve), height);
|
|
mPath.lineTo(width, height);
|
|
mPath.lineTo(width, 0);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void draw(Canvas canvas) {
|
|
mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
|
|
}
|
|
|
|
@Override
|
|
public void defaultDraw(Canvas canvas) {
|
|
super.draw(canvas);
|
|
}
|
|
}
|