Project

General

Profile

« Previous | Next » 

Revision f3563327

Added by Leszek Koltunski over 2 years ago

Bandaged 3x3: solve and scramble buttons.

View differences:

src/main/java/org/distorted/bandaged/BandagedPlayActivity.java
22 22
import android.os.Build;
23 23
import android.os.Bundle;
24 24
import android.util.DisplayMetrics;
25
import android.view.DisplayCutout;
25 26
import android.view.View;
26 27
import android.view.ViewGroup;
27 28
import android.view.WindowManager;
......
46 47
{
47 48
    private static final int ACTIVITY_NUMBER = 4;
48 49
    private static final float RATIO_BAR  = 0.10f;
50
    private static final float RATIO_INSET= 0.09f;
49 51

  
50 52
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
51 53
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
52
    public static final float BUTTON_TEXT_SIZE    = 0.05f;
53 54

  
54 55
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
55 56
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
......
62 63
    private int mCurrentApiVersion;
63 64
    private BandagedPlayScreen mScreen;
64 65
    private String mObjectName;
65
    private int mHeightBar;
66
    private int mHeightLowerBar, mHeightUpperBar;
66 67

  
67 68
///////////////////////////////////////////////////////////////////////////////////////////////////
68 69

  
......
96 97

  
97 98
    private void computeBarHeights()
98 99
      {
99
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
100
      mHeightBar = barHeight;
101

  
102
      LinearLayout layout = findViewById(R.id.lowerBar);
103
      ViewGroup.LayoutParams params = layout.getLayoutParams();
104
      params.height = barHeight;
105
      layout.setLayoutParams(params);
100
      float height = mScreenHeight;
101
      int barHeight = (int)(height*RATIO_BAR);
102
      mHeightLowerBar = barHeight;
103
      mHeightUpperBar = barHeight;
104

  
105
      LinearLayout layoutTop = findViewById(R.id.upperBar);
106
      LinearLayout layoutBot = findViewById(R.id.lowerBar);
107

  
108
      ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams();
109
      paramsTop.height = mHeightUpperBar;
110
      layoutTop.setLayoutParams(paramsTop);
111
      ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams();
112
      paramsBot.height = mHeightLowerBar;
113
      layoutBot.setLayoutParams(paramsBot);
106 114
      }
107 115

  
108 116
///////////////////////////////////////////////////////////////////////////////////////////////////
......
131 139
        }
132 140
      }
133 141

  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

  
144
    @Override
145
    public void onAttachedToWindow()
146
      {
147
      super.onAttachedToWindow();
148

  
149
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
150
        {
151
        DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
152
        int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0;
153

  
154
        LinearLayout layoutHid = findViewById(R.id.hiddenBar);
155
        ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams();
156
        paramsHid.height = (int)(insetHeight*RATIO_INSET);
157
        layoutHid.setLayoutParams(paramsHid);
158
        mHeightUpperBar += paramsHid.height;
159
        }
160
      }
161

  
134 162
///////////////////////////////////////////////////////////////////////////////////////////////////
135 163
// do not avoid cutouts
136 164

  
......
177 205
      view.onResume();
178 206

  
179 207
      if( mScreen==null ) mScreen = new BandagedPlayScreen();
180
      mScreen.onAttachedToWindow(this,mObjectName);
208
      mScreen.onAttachedToWindow(this);
181 209

  
182 210
      if( mObjectName.length()>0 )
183 211
        {
......
240 268

  
241 269
    public int getHeightBar()
242 270
      {
243
      return mHeightBar;
271
      return mHeightLowerBar;
244 272
      }
245 273

  
246 274
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/bandaged/BandagedPlayScreen.java
34 34

  
35 35
public class BandagedPlayScreen
36 36
{
37
  private static final int NUM_SCRAMBLES = 24;
38

  
37 39
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
38 40
  private final LockController mLockController;
39 41
  protected MovesController mMovesController;
40
  private String mObjectName;
41
  private int mBarHeight;
42
  private float mButtonSize;
43 42

  
44 43
///////////////////////////////////////////////////////////////////////////////////////////////////
45 44

  
......
71 70

  
72 71
///////////////////////////////////////////////////////////////////////////////////////////////////
73 72

  
74
  void onAttachedToWindow(final BandagedPlayActivity act, final String objectName)
73
  private void setupSolveButton(final BandagedPlayActivity act)
75 74
    {
76
    int width = act.getScreenWidthInPixels();
77
    mBarHeight = act.getHeightBar();
78
    mButtonSize = width*BandagedPlayActivity.BUTTON_TEXT_SIZE;
75
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
76
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
77
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
78

  
79
    mSolveButton.setOnClickListener( new View.OnClickListener()
80
      {
81
      @Override
82
      public void onClick(View v)
83
        {
84
        act.getControl().solveObject();
85
        mMovesController.clearMoves(act);
86
        }
87
      });
88
    }
89

  
90
///////////////////////////////////////////////////////////////////////////////////////////////////
79 91

  
80
    mObjectName = objectName;
92
  private void setupScrambleButton(final BandagedPlayActivity act)
93
    {
94
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble);
95
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
96
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
97

  
98
    mScrambleButton.setOnClickListener( new View.OnClickListener()
99
      {
100
      @Override
101
      public void onClick(View v)
102
        {
103
        act.getControl().scrambleObject(NUM_SCRAMBLES);
104
        }
105
      });
106
    }
107

  
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
  void onAttachedToWindow(final BandagedPlayActivity act)
111
    {
112
    int width = act.getScreenWidthInPixels();
81 113

  
82 114
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
83 115
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
......
99 131

  
100 132
    layoutRight.addView(mBackButton);
101 133

  
102
    LinearLayout layout = act.findViewById(R.id.lowerBar);
103
    layout.removeAllViews();
104
    layout.addView(layoutLeft);
105
    layout.addView(layoutMid);
106
    layout.addView(layoutRight);
134
    LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
135
    layoutLower.removeAllViews();
136
    layoutLower.addView(layoutLeft);
137
    layoutLower.addView(layoutMid);
138
    layoutLower.addView(layoutRight);
139

  
140
    setupScrambleButton(act);
141
    setupSolveButton(act);
142

  
143
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
144

  
145
    LinearLayout layoutLeftU = new LinearLayout(act);
146
    layoutLeftU.setLayoutParams(paramsL);
147
    LinearLayout layoutMidU  = new LinearLayout(act);
148
    layoutMidU.setLayoutParams(paramsM);
149
    LinearLayout layoutRightU= new LinearLayout(act);
150
    layoutRightU.setLayoutParams(paramsR);
151

  
152
    layoutLeftU.addView(mSolveButton);
153
    layoutRightU.addView(mScrambleButton);
154

  
155
    layoutUpper.addView(layoutLeftU);
156
    layoutUpper.addView(layoutMidU);
157
    layoutUpper.addView(layoutRightU);
107 158
    }
108 159

  
109 160
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff