1 |
211b48f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
a6d3b158
|
Leszek Koltunski
|
import android.view.View;
|
27 |
211b48f2
|
Leszek Koltunski
|
import android.widget.Button;
|
28 |
|
|
import android.widget.LinearLayout;
|
29 |
ad9e8bb3
|
Leszek Koltunski
|
import android.widget.TextView;
|
30 |
211b48f2
|
Leszek Koltunski
|
|
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 |
329c0aeb
|
Leszek Koltunski
|
void leaveState(RubikActivity act)
|
40 |
211b48f2
|
Leszek Koltunski
|
{
|
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 |
a6d3b158
|
Leszek Koltunski
|
void enterState(final RubikActivity act)
|
57 |
211b48f2
|
Leszek Koltunski
|
{
|
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 |
ad9e8bb3
|
Leszek Koltunski
|
final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
|
73 |
|
|
text.setText(R.string.app_name);
|
74 |
|
|
layoutTop.addView(text);
|
75 |
211b48f2
|
Leszek Koltunski
|
|
76 |
|
|
// BOT ////////////////////////////
|
77 |
4c0cd600
|
Leszek Koltunski
|
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
|
78 |
|
|
layoutLeft.removeAllViews();
|
79 |
|
|
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
80 |
|
|
layoutRight.removeAllViews();
|
81 |
211b48f2
|
Leszek Koltunski
|
|
82 |
|
|
DisplayMetrics metrics = act.getResources().getDisplayMetrics();
|
83 |
|
|
float scale = metrics.density;
|
84 |
4c0cd600
|
Leszek Koltunski
|
int padding = (int)( 5*scale + 0.5f);
|
85 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
86 |
211b48f2
|
Leszek Koltunski
|
|
87 |
|
|
Button buttonR = new Button(act);
|
88 |
|
|
buttonR.setLayoutParams(params);
|
89 |
|
|
buttonR.setPadding(padding,0,padding,0);
|
90 |
|
|
buttonR.setText(R.string.exit);
|
91 |
a6d3b158
|
Leszek Koltunski
|
|
92 |
|
|
buttonR.setOnClickListener( new View.OnClickListener()
|
93 |
|
|
{
|
94 |
|
|
@Override
|
95 |
|
|
public void onClick(View v)
|
96 |
|
|
{
|
97 |
|
|
RubikState.goBack(act);
|
98 |
|
|
}
|
99 |
|
|
});
|
100 |
|
|
|
101 |
4c0cd600
|
Leszek Koltunski
|
layoutRight.addView(buttonR);
|
102 |
211b48f2
|
Leszek Koltunski
|
}
|
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 |
|
|
}
|