Project

General

Profile

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

magiccube / src / main / java / org / distorted / states / RubikStateMain.java @ e3c74c0f

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

    
32
import com.google.firebase.crashlytics.FirebaseCrashlytics;
33

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

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

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

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  void enterState(final RubikActivity act)
79
    {
80
    float width = act.getScreenWidthInPixels();
81
    float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
82
    float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;
83

    
84
    FragmentManager mana = act.getSupportFragmentManager();
85
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
86

    
87
    if( diag==null )
88
      {
89
      RubikDialogMain diag2 = new RubikDialogMain();
90
      diag2.show( mana, RubikDialogMain.getDialogTag() );
91
      }
92

    
93
    LayoutInflater inflater = act.getLayoutInflater();
94

    
95
    // TOP ////////////////////////////
96
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
97
    layoutTop.removeAllViews();
98
    final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
99

    
100
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
101
    text.setText(R.string.app_name);
102
    layoutTop.addView(text);
103

    
104
    // BOT ////////////////////////////
105
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
106
    layoutLeft.removeAllViews();
107
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
108
    layoutRight.removeAllViews();
109

    
110
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
111
    float scale = metrics.density;
112
    int padding = (int)( 5*scale + 0.5f);
113
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
114

    
115
    Button buttonR = new Button(act);
116
    buttonR.setLayoutParams(params);
117
    buttonR.setPadding(padding,0,padding,0);
118
    buttonR.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonSize);
119
    buttonR.setText(R.string.exit);
120

    
121
    buttonR.setOnClickListener( new View.OnClickListener()
122
      {
123
      @Override
124
      public void onClick(View v)
125
        {
126
        RubikState.goBack(act);
127
        }
128
      });
129

    
130
    layoutRight.addView(buttonR);
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  public void savePreferences(SharedPreferences.Editor editor)
136
    {
137

    
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  public void restorePreferences(SharedPreferences preferences)
143
    {
144

    
145
    }
146
  }
(4-4/10)