Project

General

Profile

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

magiccube / src / main / java / org / distorted / uistate / RubikStateMain.java @ d18993ac

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
///////////////////////////////////////////////////////////////////////////////////////////////////
35

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

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  void enterState(RubikActivity act, RubikState prev)
56
    {
57
    FragmentManager mana = act.getSupportFragmentManager();
58
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
59

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

    
66
    LayoutInflater inflater = act.getLayoutInflater();
67

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

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

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

    
86
    Button buttonR = new Button(act);
87
    buttonR.setLayoutParams(params);
88
    buttonR.setId(BUTTON_ID_BACK);
89
    buttonR.setPadding(padding,0,padding,0);
90
    buttonR.setText(R.string.exit);
91
    buttonR.setOnClickListener(act);
92
    layoutRight.addView(buttonR);
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  public void savePreferences(SharedPreferences.Editor editor)
98
    {
99

    
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  public void restorePreferences(SharedPreferences preferences)
105
    {
106

    
107
    }
108
  }
(3-3/5)