Project

General

Profile

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

magiccube / src / main / java / org / distorted / uistate / RubikStateMain.java @ 329c0aeb

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.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
import android.widget.TextView;
29

    
30
import org.distorted.dialog.RubikDialogMain;
31
import org.distorted.magic.R;
32
import org.distorted.magic.RubikActivity;
33

    
34
import static android.view.View.INVISIBLE;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
public class RubikStateMain extends RubikStateAbstract
39
  {
40
  void leaveState(RubikActivity act)
41
    {
42
    FragmentManager mana = act.getSupportFragmentManager();
43
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
44

    
45
    if( diag!=null )
46
      {
47
      diag.dismiss();
48
      }
49
    else
50
      {
51
      android.util.Log.e("act", "cannot find main dialog!");
52
      }
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  void enterState(RubikActivity act)
58
    {
59
    FragmentManager mana = act.getSupportFragmentManager();
60
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
61

    
62
    if( diag==null )
63
      {
64
      RubikDialogMain diag2 = new RubikDialogMain();
65
      diag2.show( mana, RubikDialogMain.getDialogTag() );
66
      }
67

    
68
    LayoutInflater inflater = act.getLayoutInflater();
69

    
70
    // TOP ////////////////////////////
71
    LinearLayout layoutTop = act.findViewById(R.id.mainTitle);
72
    layoutTop.removeAllViews();
73
    final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
74
    text.setText(R.string.app_name);
75
    layoutTop.addView(text);
76

    
77
    // BOT ////////////////////////////
78
    LinearLayout layoutBot = act.findViewById(R.id.mainBar);
79
    layoutBot.removeAllViews();
80

    
81
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
82
    float scale = metrics.density;
83
    int size = (int)(60*scale +0.5f);
84
    int padding = (int)(5*scale + 0.5f);
85
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,size,0.5f);
86

    
87
    Button buttonL = new Button(act);
88
    buttonL.setLayoutParams(params);
89
    buttonL.setId(BUTTON_ID_BACK);
90
    buttonL.setPadding(padding,0,padding,0);
91
    buttonL.setText(R.string.back);
92
    buttonL.setOnClickListener(act);
93
    layoutBot.addView(buttonL);
94

    
95
    Button buttonR = new Button(act);
96
    buttonR.setLayoutParams(params);
97
    buttonR.setId(BUTTON_ID_BACK);
98
    buttonR.setPadding(padding,0,padding,0);
99
    buttonR.setText(R.string.exit);
100
    buttonR.setOnClickListener(act);
101
    layoutBot.addView(buttonR);
102

    
103
    buttonL.setVisibility(INVISIBLE);
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public void savePreferences(SharedPreferences.Editor editor)
109
    {
110

    
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public void restorePreferences(SharedPreferences preferences)
116
    {
117

    
118
    }
119
  }
(3-3/5)