Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ 80f574a1

1 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 da56b12f Leszek Koltunski
// Copyright 2022 Leszek Koltunski                                                               //
3 9530f6b0 Leszek Koltunski
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 44fec653 Leszek Koltunski
// 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 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.bandaged;
11
12 88b94310 Leszek Koltunski
import android.app.Activity;
13
import android.content.SharedPreferences;
14 9530f6b0 Leszek Koltunski
import android.view.View;
15
import android.widget.LinearLayout;
16
17
import org.distorted.helpers.LockController;
18
import org.distorted.helpers.MovesController;
19
import org.distorted.helpers.TransparentImageButton;
20
import org.distorted.main.R;
21
import org.distorted.objectlib.main.ObjectControl;
22
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24
25
public class BandagedPlayScreen
26
{
27 bb3bc6a9 Leszek Koltunski
  private static final int NUM_SCRAMBLES = 300;
28 b72b71a1 Leszek Koltunski
29 ca280c3f Leszek Koltunski
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
30 9530f6b0 Leszek Koltunski
  private final LockController mLockController;
31 b72b71a1 Leszek Koltunski
  private final MovesController mMovesController;
32 972f9eae Leszek Koltunski
  private String mKey;
33 9530f6b0 Leszek Koltunski
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36
  public BandagedPlayScreen()
37
    {
38
    mLockController = new LockController();
39
    mMovesController= new MovesController();
40
    }
41
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44
  private void setupBackButton(final BandagedPlayActivity act)
45
    {
46 88b94310 Leszek Koltunski
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
47 9530f6b0 Leszek Koltunski
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
48
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
49
50
    mBackButton.setOnClickListener( new View.OnClickListener()
51
      {
52
      @Override
53
      public void onClick(View v)
54
        {
55
        ObjectControl control = act.getControl();
56
        if( control!=null ) control.unblockEverything();
57
        act.finish();
58
        }
59
      });
60
    }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64 f3563327 Leszek Koltunski
  private void setupSolveButton(final BandagedPlayActivity act)
65 9530f6b0 Leszek Koltunski
    {
66 f3563327 Leszek Koltunski
    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);
67
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
68
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
69
70
    mSolveButton.setOnClickListener( new View.OnClickListener()
71
      {
72
      @Override
73
      public void onClick(View v)
74
        {
75 b72b71a1 Leszek Koltunski
        ObjectControl control = act.getControl();
76 ca280c3f Leszek Koltunski
        control.solveObject();
77 f3563327 Leszek Koltunski
        mMovesController.clearMoves(act);
78
        }
79
      });
80
    }
81
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83 9530f6b0 Leszek Koltunski
84 f3563327 Leszek Koltunski
  private void setupScrambleButton(final BandagedPlayActivity act)
85
    {
86
    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);
87
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
88
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
89
90
    mScrambleButton.setOnClickListener( new View.OnClickListener()
91
      {
92
      @Override
93
      public void onClick(View v)
94
        {
95 4844152a Leszek Koltunski
        ObjectControl control = act.getControl();
96 ca280c3f Leszek Koltunski
        control.fastScrambleObject(NUM_SCRAMBLES);
97
        mMovesController.clearMoves(act);
98 f3563327 Leszek Koltunski
        }
99
      });
100
    }
101
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
104 972f9eae Leszek Koltunski
  void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
105 f3563327 Leszek Koltunski
    {
106 972f9eae Leszek Koltunski
    mKey = "moveController_"+objectName;
107
108 f3563327 Leszek Koltunski
    int width = act.getScreenWidthInPixels();
109 9530f6b0 Leszek Koltunski
110
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
111
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
112
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
113
114
    LinearLayout layoutLeft = new LinearLayout(act);
115
    layoutLeft.setLayoutParams(paramsL);
116
    LinearLayout layoutMid  = new LinearLayout(act);
117
    layoutMid.setLayoutParams(paramsM);
118
    LinearLayout layoutRight= new LinearLayout(act);
119
    layoutRight.setLayoutParams(paramsR);
120
121
    setupBackButton(act);
122
    ObjectControl control = act.getControl();
123
    mMovesController.setupButton(act,control);
124
    layoutLeft.addView(mMovesController.getButton());
125
    mLockController.setupButton(act,control);
126
    layoutMid.addView(mLockController.getButton());
127
128
    layoutRight.addView(mBackButton);
129
130 f3563327 Leszek Koltunski
    LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
131
    layoutLower.removeAllViews();
132
    layoutLower.addView(layoutLeft);
133
    layoutLower.addView(layoutMid);
134
    layoutLower.addView(layoutRight);
135
136
    setupSolveButton(act);
137 1db19441 Leszek Koltunski
    setupScrambleButton(act);
138 f3563327 Leszek Koltunski
139
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
140
141
    LinearLayout layoutLeftU = new LinearLayout(act);
142
    layoutLeftU.setLayoutParams(paramsL);
143
    LinearLayout layoutMidU  = new LinearLayout(act);
144
    layoutMidU.setLayoutParams(paramsM);
145
    LinearLayout layoutRightU= new LinearLayout(act);
146
    layoutRightU.setLayoutParams(paramsR);
147
148
    layoutLeftU.addView(mSolveButton);
149
    layoutRightU.addView(mScrambleButton);
150
151 775d5361 Leszek Koltunski
    layoutUpper.removeAllViews();
152 f3563327 Leszek Koltunski
    layoutUpper.addView(layoutLeftU);
153
    layoutUpper.addView(layoutMidU);
154
    layoutUpper.addView(layoutRightU);
155 9530f6b0 Leszek Koltunski
    }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159 88b94310 Leszek Koltunski
  public void setLockState(final BandagedPlayActivity act)
160 9530f6b0 Leszek Koltunski
    {
161
    boolean locked = act.getControl().retLocked();
162
    mLockController.setState(act,locked);
163
    }
164
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
167 88b94310 Leszek Koltunski
  public void reddenLock(final BandagedPlayActivity act)
168 9530f6b0 Leszek Koltunski
    {
169
    ObjectControl control = act.getControl();
170
    mLockController.reddenLock(act,control);
171
    }
172 88b94310 Leszek Koltunski
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175
  public void addMove(Activity act, int axis, int row, int angle)
176
    {
177
    mMovesController.addMove(act,axis,row,angle);
178
    }
179
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182 972f9eae Leszek Koltunski
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
183 88b94310 Leszek Koltunski
    {
184 972f9eae Leszek Koltunski
    mMovesController.savePreferences(mKey,editor);
185
    ObjectControl control = act.getControl();
186
    control.savePreferences(editor);
187 88b94310 Leszek Koltunski
    }
188
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190
191 972f9eae Leszek Koltunski
  public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
192 88b94310 Leszek Koltunski
    {
193 972f9eae Leszek Koltunski
    mMovesController.restorePreferences(act,mKey,preferences);
194
    ObjectControl control = act.getControl();
195
    control.restorePreferences(preferences);
196 b72b71a1 Leszek Koltunski
    }
197 9530f6b0 Leszek Koltunski
}