Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.screens;
21

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

    
26
import org.distorted.helpers.TransparentImageButton;
27
import org.distorted.main.RubikActivity;
28
import org.distorted.objectlib.main.ObjectControl;
29

    
30
import org.distorted.helpers.LockController;
31
import org.distorted.helpers.MovesController;
32
import org.distorted.main.R;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
abstract class RubikScreenBase extends RubikScreenAbstract
37
  {
38
  private final LockController mLockController;
39
  protected MovesController mMovesController;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  void createBottomPane(final RubikActivity act, TransparentImageButton left, TransparentImageButton right)
44
    {
45
    mMovesController.clearMoves(act);
46

    
47
    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
    ObjectControl control = act.getControl();
60
    mMovesController.setupButton(act,control);
61
    layoutLeft.addView(mMovesController.getButton());
62
    mLockController.setupButton(act,control);
63
    layoutMid.addView(mLockController.getButton());
64

    
65
    if( left !=null ) layoutRight.addView(left);
66
    if( right!=null ) layoutRight.addView(right);
67

    
68
    layoutBot.addView(layoutLeft);
69
    layoutBot.addView(layoutMid);
70
    layoutBot.addView(layoutRight);
71
    }
72

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

    
75
  public void setLockState(final RubikActivity act)
76
    {
77
    boolean locked = act.getControl().retLocked();
78
    mLockController.setState(act,locked);
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
// PUBLIC API
83

    
84
  public RubikScreenBase()
85
    {
86
    mLockController = new LockController();
87
    mMovesController= new MovesController();
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  public void addMove(Activity act, int axis, int row, int angle)
93
    {
94
    mMovesController.addMove(act,axis,row,angle);
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  public void reddenLock(final RubikActivity act)
100
    {
101
    ObjectControl control = act.getControl();
102
    mLockController.reddenLock(act,control);
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public void saveMovePreferences(String key,SharedPreferences.Editor editor)
108
    {
109
    mMovesController.savePreferences(key,editor);
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public void restoreMovePreferences(Activity act, String key, SharedPreferences preferences)
115
    {
116
    mMovesController.restorePreferences(act,key,preferences);
117
    }
118
  }
(2-2/11)