Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ f3563327

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.bandaged;
21

    
22
import android.app.Activity;
23
import android.content.SharedPreferences;
24
import android.view.View;
25
import android.widget.LinearLayout;
26

    
27
import org.distorted.helpers.LockController;
28
import org.distorted.helpers.MovesController;
29
import org.distorted.helpers.TransparentImageButton;
30
import org.distorted.main.R;
31
import org.distorted.objectlib.main.ObjectControl;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

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

    
39
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
40
  private final LockController mLockController;
41
  protected MovesController mMovesController;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  public BandagedPlayScreen()
46
    {
47
    mLockController = new LockController();
48
    mMovesController= new MovesController();
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  private void setupBackButton(final BandagedPlayActivity act)
54
    {
55
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
56
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
57
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
58

    
59
    mBackButton.setOnClickListener( new View.OnClickListener()
60
      {
61
      @Override
62
      public void onClick(View v)
63
        {
64
        ObjectControl control = act.getControl();
65
        if( control!=null ) control.unblockEverything();
66
        act.finish();
67
        }
68
      });
69
    }
70

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

    
73
  private void setupSolveButton(final BandagedPlayActivity act)
74
    {
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
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
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();
113

    
114
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
115
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
116
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
117

    
118
    LinearLayout layoutLeft = new LinearLayout(act);
119
    layoutLeft.setLayoutParams(paramsL);
120
    LinearLayout layoutMid  = new LinearLayout(act);
121
    layoutMid.setLayoutParams(paramsM);
122
    LinearLayout layoutRight= new LinearLayout(act);
123
    layoutRight.setLayoutParams(paramsR);
124

    
125
    setupBackButton(act);
126
    ObjectControl control = act.getControl();
127
    mMovesController.setupButton(act,control);
128
    layoutLeft.addView(mMovesController.getButton());
129
    mLockController.setupButton(act,control);
130
    layoutMid.addView(mLockController.getButton());
131

    
132
    layoutRight.addView(mBackButton);
133

    
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);
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  public void setLockState(final BandagedPlayActivity act)
163
    {
164
    boolean locked = act.getControl().retLocked();
165
    mLockController.setState(act,locked);
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  public void reddenLock(final BandagedPlayActivity act)
171
    {
172
    ObjectControl control = act.getControl();
173
    mLockController.reddenLock(act,control);
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

    
178
  public void addMove(Activity act, int axis, int row, int angle)
179
    {
180
    mMovesController.addMove(act,axis,row,angle);
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  public void saveMovePreferences(SharedPreferences.Editor editor)
186
    {
187
    mMovesController.savePreferences(editor);
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  public void restoreMovePreferences(Activity act, SharedPreferences preferences)
193
    {
194
    mMovesController.restorePreferences(act,preferences);
195
    }
196
}
(12-12/13)