Project

General

Profile

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

magiccube / src / main / java / org / distorted / states / RubikStateMain.java @ 00ffccc4

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 androidx.fragment.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 com.google.firebase.crashlytics.FirebaseCrashlytics;
32

    
33
import org.distorted.dialogs.RubikDialogMain;
34
import org.distorted.main.BuildConfig;
35
import org.distorted.main.R;
36
import org.distorted.main.RubikActivity;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

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

    
47
    if( diag!=null )
48
      {
49
      try
50
        {
51
        diag.dismiss();
52
        }
53
      catch(IllegalStateException ex)
54
        {
55
        if( !BuildConfig.DEBUG )
56
          {
57
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
58
          crashlytics.setCustomKey("MainDialog", ex.toString());
59
          crashlytics.recordException(ex);
60
          }
61
        }
62
      }
63
    else
64
      {
65
      if( !BuildConfig.DEBUG )
66
        {
67
        Exception ex = new Exception("Cannot find MainDialog");
68
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
69
        crashlytics.setCustomKey("MainDialog", ex.toString());
70
        crashlytics.recordException(ex);
71
        }
72
      }
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  void enterState(final RubikActivity act)
78
    {
79
    FragmentManager mana = act.getSupportFragmentManager();
80
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
81

    
82
    if( diag==null )
83
      {
84
      RubikDialogMain diag2 = new RubikDialogMain();
85
      diag2.show( mana, RubikDialogMain.getDialogTag() );
86
      }
87

    
88
    LayoutInflater inflater = act.getLayoutInflater();
89

    
90
    // TOP ////////////////////////////
91
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
92
    layoutTop.removeAllViews();
93
    final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
94
    text.setText(R.string.app_name);
95
    layoutTop.addView(text);
96

    
97
    // BOT ////////////////////////////
98
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
99
    layoutLeft.removeAllViews();
100
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
101
    layoutRight.removeAllViews();
102

    
103
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
104
    float scale = metrics.density;
105
    int padding = (int)( 5*scale + 0.5f);
106
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
107

    
108
    Button buttonR = new Button(act);
109
    buttonR.setLayoutParams(params);
110
    buttonR.setPadding(padding,0,padding,0);
111
    buttonR.setText(R.string.exit);
112

    
113
    buttonR.setOnClickListener( new View.OnClickListener()
114
      {
115
      @Override
116
      public void onClick(View v)
117
        {
118
        RubikState.goBack(act);
119
        }
120
      });
121

    
122
    layoutRight.addView(buttonR);
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  public void savePreferences(SharedPreferences.Editor editor)
128
    {
129

    
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public void restorePreferences(SharedPreferences preferences)
135
    {
136

    
137
    }
138
  }
(4-4/10)