Project

General

Profile

Download (2.17 KB) Statistics
| Branch: | Revision:

sokoban / distorted-sokoban / src / main / java / org / distorted / helpers / TransparentImageButton.java @ 3e26ff35

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.helpers;
11

    
12
import android.annotation.SuppressLint;
13
import android.content.Context;
14
import android.util.TypedValue;
15
import android.widget.LinearLayout;
16

    
17
import com.google.android.material.button.MaterialButton;
18

    
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
@SuppressLint("ViewConstructor")
22
public class TransparentImageButton extends MaterialButton
23
{
24
  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
  public TransparentImageButton(Context context, int icon, int gravity, LinearLayout.LayoutParams params)
31
    {
32
    super(context);
33

    
34
    setLayoutParams(params);
35
    setPadding(0,0,0,0);
36
    setIconResource(icon);
37
    setIconTint(null);
38

    
39
    switch(gravity)
40
      {
41
      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
      }
45

    
46
    TypedValue outValue = new TypedValue();
47
    context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
48
    setBackgroundResource(outValue.resourceId);
49
    }
50
}
(2-2/2)