Project

General

Profile

Download (4.32 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / states / RubikStateAbstract.java @ 6a76f80a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.states;
21

    
22
import android.annotation.SuppressLint;
23
import android.content.SharedPreferences;
24
import android.util.TypedValue;
25
import android.widget.LinearLayout;
26

    
27
import org.distorted.main.RubikActivity;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public abstract class RubikStateAbstract
32
  {
33
  @SuppressLint("ViewConstructor")
34
  static class TransparentImageButton extends androidx.appcompat.widget.AppCompatImageButton
35
    {
36
    public TransparentImageButton(RubikActivity act, int icon, float scrWidth, int butWidth)
37
      {
38
      super(act);
39

    
40
      final int padding = (int)(scrWidth*RubikActivity.PADDING);
41
      final int margin  = (int)(scrWidth*RubikActivity.MARGIN);
42

    
43
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(butWidth,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
44

    
45
      params.topMargin    = margin;
46
      params.bottomMargin = margin;
47
      params.leftMargin   = margin;
48
      params.rightMargin  = margin;
49

    
50
      setLayoutParams(params);
51
      setPadding(padding,0,padding,0);
52
      setImageResource(icon);
53

    
54
      TypedValue outValue = new TypedValue();
55
      act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
56
      setBackgroundResource(outValue.resourceId);
57
      }
58
    }
59

    
60
  @SuppressLint("ViewConstructor")
61
  static class TransparentButton extends androidx.appcompat.widget.AppCompatButton
62
    {
63
    public TransparentButton(RubikActivity act, int resId, float size, float scrWidth)
64
      {
65
      super(act);
66

    
67
      final int padding = (int)(scrWidth*RubikActivity.PADDING);
68
      final int margin  = (int)(scrWidth*RubikActivity.MARGIN);
69

    
70
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
71
      params.topMargin    = margin;
72
      params.bottomMargin = margin;
73
      params.leftMargin   = margin;
74
      params.rightMargin  = margin;
75

    
76
      setLayoutParams(params);
77
      setPadding(padding,0,padding,0);
78
      setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
79
      setText(resId);
80

    
81
      TypedValue outValue = new TypedValue();
82
      act.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true);
83
      setBackgroundResource(outValue.resourceId);
84
      }
85
    }
86

    
87
  abstract void enterState(RubikActivity act);
88
  abstract void leaveState(RubikActivity act);
89
  public abstract void savePreferences(SharedPreferences.Editor editor);
90
  public abstract void restorePreferences(SharedPreferences preferences);
91
  }
(1-1/9)