Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenBase.java @ 6b64f9f8

1 a8576d91 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 fcd5b990 Leszek Koltunski
package org.distorted.screens;
21 a8576d91 Leszek Koltunski
22 e019c70b Leszek Koltunski
import android.app.Activity;
23 2e3488f6 Leszek Koltunski
import android.content.SharedPreferences;
24 a8576d91 Leszek Koltunski
import android.widget.LinearLayout;
25
26 dd874ae8 Leszek Koltunski
import org.distorted.helpers.TransparentImageButton;
27 e019c70b Leszek Koltunski
import org.distorted.main.RubikActivity;
28 9523ae28 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
29
30 dd1a65c1 Leszek Koltunski
import org.distorted.helpers.LockController;
31
import org.distorted.helpers.MovesController;
32 a8576d91 Leszek Koltunski
import org.distorted.main.R;
33
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 55e6be1d Leszek Koltunski
abstract class RubikScreenBase extends RubikScreenAbstract
37 a8576d91 Leszek Koltunski
  {
38 dd1a65c1 Leszek Koltunski
  private final LockController mLockController;
39
  protected MovesController mMovesController;
40 a8576d91 Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 dd874ae8 Leszek Koltunski
  void createBottomPane(final RubikActivity act, TransparentImageButton left, TransparentImageButton right)
44 a8576d91 Leszek Koltunski
    {
45 dd1a65c1 Leszek Koltunski
    mMovesController.clearMoves(act);
46 9f006481 Leszek Koltunski
47 a8576d91 Leszek Koltunski
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
48
    layoutBot.removeAllViews();
49
50
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
51
52
    LinearLayout layoutLeft = new LinearLayout(act);
53
    layoutLeft.setLayoutParams(params);
54
    LinearLayout layoutMid = new LinearLayout(act);
55
    layoutMid.setLayoutParams(params);
56
    LinearLayout layoutRight = new LinearLayout(act);
57
    layoutRight.setLayoutParams(params);
58
59 e019c70b Leszek Koltunski
    ObjectControl control = act.getControl();
60 dd874ae8 Leszek Koltunski
    mMovesController.setupButton(act,control);
61 dd1a65c1 Leszek Koltunski
    layoutLeft.addView(mMovesController.getButton());
62 dd874ae8 Leszek Koltunski
    mLockController.setupButton(act,control);
63 dd1a65c1 Leszek Koltunski
    layoutMid.addView(mLockController.getButton());
64 dd874ae8 Leszek Koltunski
65
    if( left !=null ) layoutRight.addView(left);
66
    if( right!=null ) layoutRight.addView(right);
67 a8576d91 Leszek Koltunski
68
    layoutBot.addView(layoutLeft);
69
    layoutBot.addView(layoutMid);
70
    layoutBot.addView(layoutRight);
71
    }
72
73 8badfe2a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75 e019c70b Leszek Koltunski
  public void setLockState(final RubikActivity act)
76 8badfe2a Leszek Koltunski
    {
77 9523ae28 Leszek Koltunski
    boolean locked = act.getControl().retLocked();
78
    mLockController.setState(act,locked);
79 8badfe2a Leszek Koltunski
    }
80
81 146661ec Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
82
// PUBLIC API
83
84
  public RubikScreenBase()
85
    {
86 dd1a65c1 Leszek Koltunski
    mLockController = new LockController();
87
    mMovesController= new MovesController();
88 146661ec Leszek Koltunski
    }
89
90 a8576d91 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92 e019c70b Leszek Koltunski
  public void addMove(Activity act, int axis, int row, int angle)
93 a8576d91 Leszek Koltunski
    {
94 dd1a65c1 Leszek Koltunski
    mMovesController.addMove(act,axis,row,angle);
95 a8576d91 Leszek Koltunski
    }
96 cc88f2fa Leszek Koltunski
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99 e019c70b Leszek Koltunski
  public void reddenLock(final RubikActivity act)
100 cc88f2fa Leszek Koltunski
    {
101 9523ae28 Leszek Koltunski
    ObjectControl control = act.getControl();
102
    mLockController.reddenLock(act,control);
103 cc88f2fa Leszek Koltunski
    }
104 2e3488f6 Leszek Koltunski
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
107 972f9eae Leszek Koltunski
  public void saveMovePreferences(String key,SharedPreferences.Editor editor)
108 2e3488f6 Leszek Koltunski
    {
109 972f9eae Leszek Koltunski
    mMovesController.savePreferences(key,editor);
110 2e3488f6 Leszek Koltunski
    }
111
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
114 972f9eae Leszek Koltunski
  public void restoreMovePreferences(Activity act, String key, SharedPreferences preferences)
115 2e3488f6 Leszek Koltunski
    {
116 972f9eae Leszek Koltunski
    mMovesController.restorePreferences(act,key,preferences);
117 2e3488f6 Leszek Koltunski
    }
118 a8576d91 Leszek Koltunski
  }