Revision dd874ae8
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/helpers/TransparentImageButton.java | ||
---|---|---|
24 | 24 |
import android.util.TypedValue; |
25 | 25 |
import android.widget.LinearLayout; |
26 | 26 |
|
27 |
import org.distorted.main.RubikActivity;
|
|
27 |
import com.google.android.material.button.MaterialButton;
|
|
28 | 28 |
|
29 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 30 |
|
31 | 31 |
@SuppressLint("ViewConstructor") |
32 |
public class TransparentImageButton extends androidx.appcompat.widget.AppCompatImageButton
|
|
32 |
public class TransparentImageButton extends MaterialButton
|
|
33 | 33 |
{ |
34 |
public TransparentImageButton(Context context, int icon, float scrWidth, int butWidth) |
|
34 |
public static final int GRAVITY_START = 0; |
|
35 |
public static final int GRAVITY_MIDDLE = 1; |
|
36 |
public static final int GRAVITY_END = 2; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
public TransparentImageButton(Context context, int icon, int butWidth, int gravity) |
|
35 | 41 |
{ |
36 | 42 |
super(context); |
37 | 43 |
|
38 |
final int padding = (int)(scrWidth*RubikActivity.PADDING); |
|
39 |
final int margin = (int)(scrWidth*RubikActivity.MARGIN); |
|
40 |
|
|
41 | 44 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(butWidth,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
42 | 45 |
|
43 |
params.topMargin = margin; |
|
44 |
params.bottomMargin = margin; |
|
45 |
params.leftMargin = margin; |
|
46 |
params.rightMargin = margin; |
|
47 |
|
|
48 | 46 |
setLayoutParams(params); |
49 |
setPadding(padding,0,padding,0); |
|
50 |
setImageResource(icon); |
|
47 |
setPadding(0,0,0,0); |
|
48 |
setIconResource(icon); |
|
49 |
setIconTint(null); |
|
50 |
|
|
51 |
switch(gravity) |
|
52 |
{ |
|
53 |
case GRAVITY_START : setIconGravity(MaterialButton.ICON_GRAVITY_START ); break; |
|
54 |
case GRAVITY_MIDDLE: setIconGravity(MaterialButton.ICON_GRAVITY_TEXT_START); break; |
|
55 |
case GRAVITY_END : setIconGravity(MaterialButton.ICON_GRAVITY_END ); break; |
|
56 |
} |
|
51 | 57 |
|
52 | 58 |
TypedValue outValue = new TypedValue(); |
53 | 59 |
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
Also available in: Unified diff
Convert the theme to be a MaterialTheme and the TransparentImageButton to be a MaterialButton - the first forced by the second, and the second because a MaterialButton gives us control over the location of the icon in top of it. We need that because of the new 'solve/scramble' split-button in the lower right of the Play screen.