Project

General

Profile

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

magiccube / src / main / java / org / distorted / states / RubikStateReady.java @ 15846fe4

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.states;
21

    
22
import android.content.SharedPreferences;
23
import android.util.DisplayMetrics;
24
import android.util.TypedValue;
25
import android.view.LayoutInflater;
26
import android.view.View;
27
import android.widget.Button;
28
import android.widget.ImageButton;
29
import android.widget.LinearLayout;
30
import android.widget.TextView;
31

    
32
import org.distorted.main.R;
33
import org.distorted.main.RubikActivity;
34

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

    
37
public class RubikStateReady extends RubikStateAbstract
38
  {
39
  private ImageButton mPrevButton;
40

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

    
43
  void leaveState(RubikActivity act)
44
    {
45

    
46
    }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  void enterState(final RubikActivity act)
51
    {
52
    float width = act.getScreenWidthInPixels();
53
    float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
54
    float titleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
55

    
56
    LayoutInflater inflater = act.getLayoutInflater();
57
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
58
    float scale = metrics.density;
59

    
60
    // TOP ////////////////////////////
61
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
62
    layoutTop.removeAllViews();
63
    TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);
64
    label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
65
    label.setText(R.string.ready);
66
    layoutTop.addView(label);
67

    
68
    // BOT ////////////////////////////
69
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
70
    layoutLeft.removeAllViews();
71

    
72
    setupPrevMoveButtom(act,scale,width);
73
    layoutLeft.addView(mPrevButton);
74

    
75
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
76
    layoutRight.removeAllViews();
77

    
78
    int padding = (int)(5*scale + 0.5f);
79
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
80

    
81
    Button back = new Button(act);
82
    back.setLayoutParams(params);
83
    back.setPadding(padding,0,padding,0);
84
    back.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonSize);
85
    back.setText(R.string.back);
86

    
87
    back.setOnClickListener( new View.OnClickListener()
88
      {
89
      @Override
90
      public void onClick(View v)
91
        {
92
        RubikState.goBack(act);
93
        }
94
      });
95

    
96
    layoutRight.addView(back);
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  private void setupPrevMoveButtom(final RubikActivity act, float scale, float width)
102
    {
103
    int padding = (int)( 3*scale + 0.5f);
104
    int widthBut= (int)(width/6);
105

    
106
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(widthBut,LinearLayout.LayoutParams.MATCH_PARENT);
107
    mPrevButton = new ImageButton(act);
108
    mPrevButton.setLayoutParams(params);
109
    mPrevButton.setPadding(padding,0,padding,0);
110
    mPrevButton.setImageResource(R.drawable.cube_back);
111

    
112
    mPrevButton.setOnClickListener( new View.OnClickListener()
113
      {
114
      @Override
115
      public void onClick(View v)
116
        {
117
        // empty
118
        }
119
      });
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  public void savePreferences(SharedPreferences.Editor editor)
125
    {
126

    
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public void restorePreferences(SharedPreferences preferences)
132
    {
133

    
134
    }
135
  }
(6-6/9)