Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPattern.java @ dd874ae8

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.content.SharedPreferences;
23
import androidx.fragment.app.FragmentManager;
24
import android.util.TypedValue;
25
import android.view.Gravity;
26
import android.view.LayoutInflater;
27
import android.view.View;
28
import android.widget.LinearLayout;
29
import android.widget.TextView;
30

    
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.ObjectType;
33

    
34
import org.distorted.main.R;
35
import org.distorted.dialogs.RubikDialogPattern;
36
import org.distorted.helpers.TransparentImageButton;
37
import org.distorted.main.RubikActivity;
38
import org.distorted.patterns.RubikPattern;
39
import org.distorted.patterns.RubikPatternList;
40

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

    
43
public class RubikScreenPattern extends RubikScreenAbstract
44
  {
45
  private TextView mText;
46
  private TransparentImageButton mPrevButton, mNextButton, mBackButton;
47
  private TextView mMovesText;
48
  private int mNumMoves;
49
  private int mPatternOrdinal, mCategory, mPattern;
50
  private float mButtonSize;
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  RubikScreenPattern()
55
    {
56

    
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  void leaveScreen(RubikActivity act)
62
    {
63
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
64
    ObjectType object = RubikPatternList.getObject(mPatternOrdinal);
65

    
66
    if( !play.setObject(act,object) )
67
      {
68
      act.changeObject(play.getObject(),false);
69
      }
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  void enterScreen(final RubikActivity act)
75
    {
76
    float width = act.getScreenWidthInPixels();
77
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
78
    float titleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
79
    LayoutInflater inflater = act.getLayoutInflater();
80

    
81
    // TOP ////////////////////////////
82
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
83
    layoutTop.removeAllViews();
84
    mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);
85
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
86
    mText.setText(R.string.patterns);
87
    layoutTop.addView(mText);
88

    
89
    // BOT ////////////////////////////
90
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
91
    layoutBot.removeAllViews();
92

    
93
    setupPrevButton(act);
94
    setupNextButton(act);
95
    setupTextView(act,width);
96

    
97
    setTrioState(false);
98

    
99
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);
100
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);
101
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);
102

    
103
    LinearLayout layoutLeft = new LinearLayout(act);
104
    layoutLeft.setLayoutParams(paramsL);
105
    LinearLayout layoutMid = new LinearLayout(act);
106
    layoutMid.setLayoutParams(paramsM);
107
    LinearLayout layoutRight = new LinearLayout(act);
108
    layoutRight.setLayoutParams(paramsR);
109

    
110
    layoutLeft.addView(mPrevButton);
111
    layoutLeft.addView(mMovesText);
112
    layoutLeft.addView(mNextButton);
113

    
114
    setupBackButton(act);
115

    
116
    layoutRight.addView(mBackButton);
117

    
118
    layoutBot.addView(layoutLeft);
119
    layoutBot.addView(layoutMid);
120
    layoutBot.addView(layoutRight);
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
  private void showDialog(FragmentManager manager)
126
    {
127
    RubikDialogPattern diag = new RubikDialogPattern();
128
    diag.show( manager, RubikDialogPattern.getDialogTag() );
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  private void setTrioState(boolean enable)
134
    {
135
    int state = enable ? View.VISIBLE : View.INVISIBLE;
136

    
137
    if( mPrevButton!=null ) mPrevButton.setVisibility(state);
138
    if( mNextButton!=null ) mNextButton.setVisibility(state);
139
    if( mMovesText !=null ) mMovesText.setVisibility(state);
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  private void setupBackButton(final RubikActivity act)
145
    {
146
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);
147
    mBackButton = new TransparentImageButton(act, icon, LinearLayout.LayoutParams.MATCH_PARENT, TransparentImageButton.GRAVITY_MIDDLE);
148

    
149
    mBackButton.setOnClickListener( new View.OnClickListener()
150
      {
151
      @Override
152
      public void onClick(View v)
153
        {
154
        FragmentManager mana = act.getSupportFragmentManager();
155
        ScreenList.goBack(act);
156
        showDialog(mana);
157
        }
158
      });
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  private void setupPrevButton(final RubikActivity act)
164
    {
165
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_left,R.drawable.ui_medium_left, R.drawable.ui_big_left, R.drawable.ui_huge_left);
166
    mPrevButton = new TransparentImageButton(act,icon,0,TransparentImageButton.GRAVITY_MIDDLE);
167

    
168
    mPrevButton.setOnClickListener( new View.OnClickListener()
169
      {
170
      @Override
171
      public void onClick(View v)
172
        {
173
        RubikPattern pattern = RubikPattern.getInstance();
174
        ObjectControl control = act.getControl();
175
        pattern.backMove( control, mPatternOrdinal, mCategory, mPattern);
176
        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
177
        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
178
        }
179
      });
180
    }
181

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

    
184
  private void setupNextButton(final RubikActivity act)
185
    {
186
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_right,R.drawable.ui_medium_right, R.drawable.ui_big_right, R.drawable.ui_huge_right);
187
    mNextButton = new TransparentImageButton(act,icon,0,TransparentImageButton.GRAVITY_MIDDLE);
188

    
189
    mNextButton.setOnClickListener( new View.OnClickListener()
190
      {
191
      @Override
192
      public void onClick(View v)
193
        {
194
        RubikPattern pattern = RubikPattern.getInstance();
195
        ObjectControl control = act.getControl();
196
        pattern.makeMove( control, mPatternOrdinal, mCategory, mPattern);
197
        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
198
        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
199
        }
200
      });
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  private void setupTextView(final RubikActivity act, final float width)
206
    {
207
    int padding = (int)(width*RubikActivity.PADDING);
208
    int margin  = (int)(width*RubikActivity.MARGIN);
209

    
210
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);
211
    params.topMargin    = margin;
212
    params.bottomMargin = margin;
213
    params.leftMargin   = margin;
214
    params.rightMargin  = margin;
215

    
216
    mMovesText = new TextView(act);
217
    mMovesText.setTextSize(20);
218
    mMovesText.setLayoutParams(params);
219
    mMovesText.setPadding(padding,0,padding,0);
220
    mMovesText.setGravity(Gravity.CENTER);
221
    mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
222
    mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  public void setPattern(final RubikActivity act, int ordinal, int category, int pattern)
228
    {
229
    mPatternOrdinal = ordinal;
230
    mCategory       = category;
231
    mPattern        = pattern;
232

    
233
    setTrioState(true);
234

    
235
    RubikPattern patt = RubikPattern.getInstance();
236
    String patternName = patt.getPatternName(ordinal,category,pattern);
237
    mText.setText(patternName);
238

    
239
    mNumMoves   = patt.getNumMoves(ordinal,category,pattern);
240
    int currMove= patt.getCurMove(ordinal,category,pattern);
241

    
242
    mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
  public void savePreferences(SharedPreferences.Editor editor)
248
    {
249

    
250
    }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

    
254
  public void restorePreferences(SharedPreferences preferences)
255
    {
256

    
257
    }
258
  }
(4-4/10)