1 |
344f290c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
1c327853
|
Leszek Koltunski
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
344f290c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
55e6be1d
|
Leszek Koltunski
|
package org.distorted.helpers;
|
11 |
344f290c
|
Leszek Koltunski
|
|
12 |
|
|
import android.annotation.SuppressLint;
|
13 |
|
|
import android.content.Context;
|
14 |
|
|
import android.util.TypedValue;
|
15 |
|
|
import android.widget.LinearLayout;
|
16 |
|
|
|
17 |
dd874ae8
|
Leszek Koltunski
|
import com.google.android.material.button.MaterialButton;
|
18 |
344f290c
|
Leszek Koltunski
|
|
19 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20 |
|
|
|
21 |
|
|
@SuppressLint("ViewConstructor")
|
22 |
dd874ae8
|
Leszek Koltunski
|
public class TransparentImageButton extends MaterialButton
|
23 |
344f290c
|
Leszek Koltunski
|
{
|
24 |
dd874ae8
|
Leszek Koltunski
|
public static final int GRAVITY_START = 0;
|
25 |
|
|
public static final int GRAVITY_MIDDLE = 1;
|
26 |
|
|
public static final int GRAVITY_END = 2;
|
27 |
|
|
|
28 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29 |
|
|
|
30 |
b600ccd9
|
Leszek Koltunski
|
public TransparentImageButton(Context context, int icon, int gravity, LinearLayout.LayoutParams params)
|
31 |
8d1da3f1
|
Leszek Koltunski
|
{
|
32 |
|
|
super(context);
|
33 |
|
|
|
34 |
|
|
setLayoutParams(params);
|
35 |
|
|
setPadding(0,0,0,0);
|
36 |
|
|
setIconResource(icon);
|
37 |
|
|
setIconTint(null);
|
38 |
|
|
|
39 |
|
|
switch(gravity)
|
40 |
344f290c
|
Leszek Koltunski
|
{
|
41 |
8d1da3f1
|
Leszek Koltunski
|
case GRAVITY_START : setIconGravity(MaterialButton.ICON_GRAVITY_START ); break;
|
42 |
|
|
case GRAVITY_MIDDLE: setIconGravity(MaterialButton.ICON_GRAVITY_TEXT_START); break;
|
43 |
|
|
case GRAVITY_END : setIconGravity(MaterialButton.ICON_GRAVITY_END ); break;
|
44 |
344f290c
|
Leszek Koltunski
|
}
|
45 |
8d1da3f1
|
Leszek Koltunski
|
|
46 |
|
|
TypedValue outValue = new TypedValue();
|
47 |
|
|
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
|
48 |
|
|
setBackgroundResource(outValue.resourceId);
|
49 |
|
|
}
|
50 |
344f290c
|
Leszek Koltunski
|
}
|