Project

General

Profile

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

magiccube / src / main / java / org / distorted / uistate / RubikStateMain.java @ 0a57000c

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.view.View;
27
import android.widget.Button;
28
import android.widget.LinearLayout;
29
import android.widget.TextView;
30

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

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

    
37
public class RubikStateMain extends RubikStateAbstract
38
  {
39
  void leaveState(RubikActivity act)
40
    {
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
  void enterState(final RubikActivity act)
57
    {
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
    LayoutInflater inflater = act.getLayoutInflater();
68

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

    
76
    // BOT ////////////////////////////
77
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
78
    layoutLeft.removeAllViews();
79
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
80
    layoutRight.removeAllViews();
81

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

    
87
    Button buttonR = new Button(act);
88
    buttonR.setLayoutParams(params);
89
    buttonR.setPadding(padding,0,padding,0);
90
    buttonR.setText(R.string.exit);
91

    
92
    buttonR.setOnClickListener( new View.OnClickListener()
93
      {
94
      @Override
95
      public void onClick(View v)
96
        {
97
        RubikState.goBack(act);
98
        }
99
      });
100

    
101
    layoutRight.addView(buttonR);
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  public void savePreferences(SharedPreferences.Editor editor)
107
    {
108

    
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  public void restorePreferences(SharedPreferences preferences)
114
    {
115

    
116
    }
117
  }
(3-3/6)