Project

General

Profile

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

magiccube / src / main / java / org / distorted / solverui / ScreenList.java @ 99c2e327

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.solverui;
11

    
12
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG;
13
import static org.distorted.objectlib.main.ObjectControl.MODE_REPLACE;
14

    
15
import android.content.SharedPreferences;
16

    
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18

    
19
public enum ScreenList
20
  {
21
  SVER ( null , MODE_REPLACE, new ScreenSolver()   ),
22
  SOLU ( SVER , MODE_DRAG   , new ScreenSolution() ),
23
  ;
24

    
25
  public static final int LENGTH = values().length;
26
  private static final ScreenList[] screens;
27
  private final ScreenList mBack;
28
  private final int mMode;
29
  private final ScreenAbstract mClass;
30

    
31
  private static ScreenList mCurrScreen;
32

    
33
  static
34
    {
35
    int i = 0;
36
    screens = new ScreenList[LENGTH];
37
    for(ScreenList state: ScreenList.values()) screens[i++] = state;
38
    }
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  public static ScreenList getScreen(int ordinal)
43
    {
44
    return ordinal>=0 && ordinal<LENGTH ?  screens[ordinal] : SVER;
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public static ScreenList getScreenFromName(String name)
50
    {
51
    for(int i=0; i<LENGTH; i++)
52
      {
53
      if( name.equals(screens[i].name()) )
54
        {
55
        return screens[i];
56
        }
57
      }
58

    
59
    return SVER;
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  public static ScreenList getCurrentScreen()
65
    {
66
    return mCurrScreen;
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  public static int getMode()
72
    {
73
    return mCurrScreen.mMode;
74
    }
75

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

    
78
  public static void savePreferences(SharedPreferences.Editor editor)
79
    {
80
    editor.putString("curr_state_name", mCurrScreen.name() );
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  public static void restorePreferences(SharedPreferences preferences)
86
    {
87
    String currScreenName = preferences.getString("curr_state_name", ScreenList.SVER.name() );
88
    mCurrScreen = getScreenFromName(currScreenName);
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  public static void goBack(SolverActivity act)
94
    {
95
    switchScreen(act, mCurrScreen.mBack );
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  public static void setScreen(SolverActivity act)
101
    {
102
    mCurrScreen.enterScreen(act);
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public static void switchScreen(SolverActivity act, ScreenList next)
108
    {
109
    if( next!=null )
110
      {
111
      if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
112
      next.enterScreen(act);
113
      mCurrScreen = next;
114
      }
115
    else
116
      {
117
      act.finish();
118
      }
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  ScreenList(ScreenList back, int mode, ScreenAbstract clazz)
124
    {
125
    mBack = back;
126
    mMode = mode;
127
    mClass= clazz;
128
    }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  public ScreenAbstract getScreenClass()
133
    {
134
    return mClass;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  public void leaveScreen(SolverActivity act)
140
    {
141
    mClass.leaveScreen(act);
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public void enterScreen(SolverActivity act)
147
    {
148
    mClass.enterScreen(act);
149
    }
150
  }
(2-2/8)