Project

General

Profile

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

magiccube / src / main / java / org / distorted / uistate / RubikStateMain.java @ 4f470e00

1 211b48f2 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
package org.distorted.uistate;
21
22
import android.content.SharedPreferences;
23
import android.support.v4.app.FragmentManager;
24
import android.util.DisplayMetrics;
25
import android.view.LayoutInflater;
26
import android.widget.Button;
27
import android.widget.LinearLayout;
28 ad9e8bb3 Leszek Koltunski
import android.widget.TextView;
29 211b48f2 Leszek Koltunski
30
import org.distorted.dialog.RubikDialogMain;
31 4f470e00 Leszek Koltunski
import org.distorted.dialog.RubikDialogPattern;
32 211b48f2 Leszek Koltunski
import org.distorted.magic.R;
33
import org.distorted.magic.RubikActivity;
34
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37
public class RubikStateMain extends RubikStateAbstract
38
  {
39 329c0aeb Leszek Koltunski
  void leaveState(RubikActivity act)
40 211b48f2 Leszek Koltunski
    {
41
    FragmentManager mana = act.getSupportFragmentManager();
42
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
43
44
    if( diag!=null )
45
      {
46
      diag.dismiss();
47
      }
48
    else
49
      {
50
      android.util.Log.e("act", "cannot find main dialog!");
51
      }
52
    }
53
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56 d18993ac Leszek Koltunski
  void enterState(RubikActivity act, RubikState prev)
57 211b48f2 Leszek Koltunski
    {
58
    FragmentManager mana = act.getSupportFragmentManager();
59
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
60
61
    if( diag==null )
62
      {
63
      RubikDialogMain diag2 = new RubikDialogMain();
64
      diag2.show( mana, RubikDialogMain.getDialogTag() );
65
      }
66
67 4f470e00 Leszek Koltunski
    if( prev==RubikState.PATT )
68
      {
69
      RubikDialogPattern diag2 = new RubikDialogPattern();
70
      diag2.show( mana, RubikDialogPattern.getDialogTag() );
71
      }
72
73 211b48f2 Leszek Koltunski
    LayoutInflater inflater = act.getLayoutInflater();
74
75
    // TOP ////////////////////////////
76
    LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
77
    layoutTop.removeAllViews();
78 ad9e8bb3 Leszek Koltunski
    final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
79
    text.setText(R.string.app_name);
80
    layoutTop.addView(text);
81 211b48f2 Leszek Koltunski
82
    // BOT ////////////////////////////
83 4c0cd600 Leszek Koltunski
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
84
    layoutLeft.removeAllViews();
85
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
86
    layoutRight.removeAllViews();
87 211b48f2 Leszek Koltunski
88
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
89
    float scale = metrics.density;
90 4c0cd600 Leszek Koltunski
    int padding = (int)( 5*scale + 0.5f);
91
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
92 211b48f2 Leszek Koltunski
93
    Button buttonR = new Button(act);
94
    buttonR.setLayoutParams(params);
95
    buttonR.setId(BUTTON_ID_BACK);
96
    buttonR.setPadding(padding,0,padding,0);
97
    buttonR.setText(R.string.exit);
98
    buttonR.setOnClickListener(act);
99 4c0cd600 Leszek Koltunski
    layoutRight.addView(buttonR);
100 211b48f2 Leszek Koltunski
    }
101
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
104
  public void savePreferences(SharedPreferences.Editor editor)
105
    {
106
107
    }
108
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111
  public void restorePreferences(SharedPreferences preferences)
112
    {
113
114
    }
115
  }