Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / MainObjectPopup.java @ b45b986a

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.main;
11

    
12
import static android.view.View.GONE;
13

    
14
import android.app.Activity;
15
import android.content.Context;
16
import android.util.TypedValue;
17
import android.view.Gravity;
18
import android.view.LayoutInflater;
19
import android.view.View;
20
import android.widget.Button;
21
import android.widget.LinearLayout;
22
import android.widget.PopupWindow;
23
import android.widget.TextView;
24

    
25
import org.distorted.objects.RubikObject;
26
import org.distorted.objects.RubikObjectList;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class MainObjectPopup
31
  {
32
  private static final float MENU_TEXT_SIZE= 0.024f;
33
  private static final float MENU_MARGIN   = 0.008f;
34
  private static final float BUTTON_HEIGHT = 0.150f;
35
  private static final float MENU_WIDTH    = 0.550f;
36

    
37
  public static final int LEVELS_SHOWN = 8;
38

    
39
  private final PopupWindow mPopup;
40
  private final int mMenuTextSize;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
  MainObjectPopup(MainActivity act, int ordinal, int width, int height)
45
    {
46
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
47
    final View layout = layoutInflater.inflate(R.layout.object_popup, null);
48
    mPopup = new PopupWindow(act);
49
    mPopup.setContentView(layout);
50
    mPopup.setFocusable(true);
51

    
52
    mMenuTextSize = (int)(height*MENU_TEXT_SIZE);
53
    int padding   = (int)(height*MENU_MARGIN);
54
    int marginH   = padding/2;
55
    int marginV   =-padding/4;
56
    layout.setPadding(padding,0,padding,0);
57
    int levelHeight = (int)(width*BUTTON_HEIGHT);
58

    
59
    RubikObject object = RubikObjectList.getObject(ordinal);
60

    
61
    Button b1 = layout.findViewById(R.id.objectSolver);
62

    
63
    if( object!=null && object.hasSolver() )
64
      {
65
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,levelHeight);
66
      params.setMargins(marginH,marginV,marginH,marginV);
67
      b1.setLayoutParams(params);
68
      b1.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
69
      b1.setOnClickListener(new View.OnClickListener()
70
        {
71
        @Override
72
        public void onClick(View v)
73
          {
74

    
75
          }
76
        });
77
      }
78
    else b1.setVisibility(GONE);
79

    
80
    Button b2 = layout.findViewById(R.id.objectPattern);
81

    
82
    if( object!=null && object.hasPatterns() )
83
      {
84
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,levelHeight);
85
      params.setMargins(marginH,marginV,marginH,marginV);
86
      b2.setLayoutParams(params);
87
      b2.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
88
      b2.setOnClickListener(new View.OnClickListener()
89
        {
90
        @Override
91
        public void onClick(View v)
92
          {
93

    
94
          }
95
        });
96
      }
97
    else b2.setVisibility(GONE);
98

    
99
    Button b3 = layout.findViewById(R.id.objectTutorial);
100

    
101
    if( object!=null && object.hasExtras() )
102
      {
103
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,levelHeight);
104
      params.setMargins(marginH,marginV,marginH,marginV);
105
      b3.setLayoutParams(params);
106
      b3.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
107
      b3.setOnClickListener(new View.OnClickListener()
108
        {
109
        @Override
110
        public void onClick(View v)
111
          {
112

    
113
          }
114
        });
115
      }
116
    else b3.setVisibility(GONE);
117

    
118
    Button b4 = layout.findViewById(R.id.objectInfo);
119

    
120
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,levelHeight);
121
    params.setMargins(marginH,marginV,marginH,marginV);
122
    b4.setLayoutParams(params);
123
    b4.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
124
    b4.setOnClickListener( new View.OnClickListener()
125
      {
126
      @Override
127
      public void onClick(View v)
128
        {
129
        mPopup.dismiss();
130
        act.switchToConfig(ordinal);
131
        }
132
      });
133

    
134
    TextView levels = layout.findViewById(R.id.objectLevels);
135
    levels.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
136

    
137
    setupLevelButtons(act,object,layout,width,padding,marginH);
138
    }
139

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

    
142
  private void setupLevelButtons(Activity act, RubikObject object, View layout, int width,int padding, int margin)
143
    {
144
    int layoutWidth = (int)(width*MENU_WIDTH);
145
    int levelHeight = (int)(width*BUTTON_HEIGHT);
146
    int levelWidth  = (layoutWidth-4*padding)/3;
147

    
148
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(levelWidth,levelHeight);
149
    params.setMargins(margin,-margin,margin,-margin);
150

    
151
    Button[] level = new Button[LEVELS_SHOWN+1];
152

    
153
    level[0] = layout.findViewById(R.id.level0);
154
    level[1] = layout.findViewById(R.id.level1);
155
    level[2] = layout.findViewById(R.id.level2);
156
    level[3] = layout.findViewById(R.id.level3);
157
    level[4] = layout.findViewById(R.id.level4);
158
    level[5] = layout.findViewById(R.id.level5);
159
    level[6] = layout.findViewById(R.id.level6);
160
    level[7] = layout.findViewById(R.id.level7);
161
    level[8] = layout.findViewById(R.id.levelM);
162

    
163
    int numScramble = object==null ? 1 : object.getNumScramble();
164
    int min = Math.min(numScramble,LEVELS_SHOWN);
165

    
166
    if( numScramble>=1 && numScramble<=7 )
167
      {
168
      level[numScramble].setText(R.string.levelM);
169
      for(int i=numScramble+1; i<=8; i++) level[i].setVisibility(GONE);
170
      }
171

    
172
    for(int i=0; i<=min; i++)
173
      {
174
      final int ii = i;
175
      level[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
176
      level[i].setLayoutParams(params);
177
      level[i].setPadding(0,0,0,0);
178
      level[i].setOnClickListener( new View.OnClickListener()
179
        {
180
        @Override
181
        public void onClick(View v)
182
          {
183

    
184
          }
185
        });
186
      }
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  void show(View v)
192
    {
193
    View popupView = mPopup.getContentView();
194
    popupView.setSystemUiVisibility(MainActivity.FLAGS);
195
    mPopup.showAtLocation(v, Gravity.CENTER, 0, 0);
196
    }
197
  }
198

    
(2-2/3)