Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ 4844152a

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
import org.distorted.objectlib.main.TwistyObject;
33
import org.distorted.objectlib.scrambling.ObjectScrambler;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class BandagedPlayScreen
38
{
39
  private static final int NUM_SCRAMBLES = 24;
40

    
41
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
42
  private final LockController mLockController;
43
  protected MovesController mMovesController;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

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

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  private void setupSolveButton(final BandagedPlayActivity act)
76
    {
77
    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);
78
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
79
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
80

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

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  private void setupScrambleButton(final BandagedPlayActivity act)
95
    {
96
    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);
97
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
98
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
99

    
100
    mScrambleButton.setOnClickListener( new View.OnClickListener()
101
      {
102
      @Override
103
      public void onClick(View v)
104
        {
105
        ObjectControl control = act.getControl();
106
        TwistyObject object = control.getObject();
107
        ObjectScrambler.setSignature(object.getSignature());
108
        control.scrambleObject(NUM_SCRAMBLES);
109
        }
110
      });
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  void onAttachedToWindow(final BandagedPlayActivity act)
116
    {
117
    int width = act.getScreenWidthInPixels();
118

    
119
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
120
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
121
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
122

    
123
    LinearLayout layoutLeft = new LinearLayout(act);
124
    layoutLeft.setLayoutParams(paramsL);
125
    LinearLayout layoutMid  = new LinearLayout(act);
126
    layoutMid.setLayoutParams(paramsM);
127
    LinearLayout layoutRight= new LinearLayout(act);
128
    layoutRight.setLayoutParams(paramsR);
129

    
130
    setupBackButton(act);
131
    ObjectControl control = act.getControl();
132
    mMovesController.setupButton(act,control);
133
    layoutLeft.addView(mMovesController.getButton());
134
    mLockController.setupButton(act,control);
135
    layoutMid.addView(mLockController.getButton());
136

    
137
    layoutRight.addView(mBackButton);
138

    
139
    LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
140
    layoutLower.removeAllViews();
141
    layoutLower.addView(layoutLeft);
142
    layoutLower.addView(layoutMid);
143
    layoutLower.addView(layoutRight);
144

    
145
    setupScrambleButton(act);
146
    setupSolveButton(act);
147

    
148
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
149

    
150
    LinearLayout layoutLeftU = new LinearLayout(act);
151
    layoutLeftU.setLayoutParams(paramsL);
152
    LinearLayout layoutMidU  = new LinearLayout(act);
153
    layoutMidU.setLayoutParams(paramsM);
154
    LinearLayout layoutRightU= new LinearLayout(act);
155
    layoutRightU.setLayoutParams(paramsR);
156

    
157
    layoutLeftU.addView(mSolveButton);
158
    layoutRightU.addView(mScrambleButton);
159

    
160
    layoutUpper.removeAllViews();
161
    layoutUpper.addView(layoutLeftU);
162
    layoutUpper.addView(layoutMidU);
163
    layoutUpper.addView(layoutRightU);
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  public void setLockState(final BandagedPlayActivity act)
169
    {
170
    boolean locked = act.getControl().retLocked();
171
    mLockController.setState(act,locked);
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  public void reddenLock(final BandagedPlayActivity act)
177
    {
178
    ObjectControl control = act.getControl();
179
    mLockController.reddenLock(act,control);
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  public void addMove(Activity act, int axis, int row, int angle)
185
    {
186
    mMovesController.addMove(act,axis,row,angle);
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  public void saveMovePreferences(SharedPreferences.Editor editor)
192
    {
193
    mMovesController.savePreferences(editor);
194
    }
195

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

    
198
  public void restoreMovePreferences(Activity act, SharedPreferences preferences)
199
    {
200
    mMovesController.restorePreferences(act,preferences);
201
    }
202
}
(12-12/13)