Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogCreators.java @ de697069

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

    
12
import android.app.Dialog;
13
import android.view.View;
14
import android.view.Window;
15
import android.view.WindowManager;
16
import android.widget.LinearLayout;
17
import android.widget.TextView;
18

    
19
import androidx.fragment.app.FragmentActivity;
20

    
21
import org.distorted.main.R;
22
import org.distorted.main.RubikActivity;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

    
26
public class RubikDialogCreators extends RubikDialogAbstract
27
  {
28
  private enum BandagedObjectDescription
29
    {
30
    CUBOID     ( org.distorted.objectlib.R.drawable.cu_232, R.string.creator_cuboid_title  , R.string.creator_cuboid_desc   ),
31
    PYRAMINX   ( org.distorted.objectlib.R.drawable.pyra_3, R.string.creator_pyraminx_title, R.string.creator_pyraminx_desc ),
32
    MEGAMINX   ( org.distorted.objectlib.R.drawable.mega_3, R.string.creator_megaminx_title, R.string.creator_megaminx_desc ),
33
    OCTAHEDRON ( org.distorted.objectlib.R.drawable.diam_2, R.string.creator_octahedron_title, R.string.creator_octahedron_desc ),
34
    ;
35

    
36
    public static final int NUM_OBJECTS = values().length;
37
    private static final BandagedObjectDescription[] objects;
38

    
39
    final int mIcon, mTitle, mDescription;
40

    
41
    BandagedObjectDescription(int icon, int title, int descripton)
42
      {
43
      mIcon        = icon;
44
      mTitle       = title;
45
      mDescription = descripton;
46
      }
47

    
48
    static
49
      {
50
      int i=0;
51
      objects = new BandagedObjectDescription[NUM_OBJECTS];
52
      for( BandagedObjectDescription object: BandagedObjectDescription.values() ) objects[i++] = object;
53
      }
54

    
55
    ////////////////////////////////////////////////////////////////////////
56

    
57
    static int getIcon(int ordinal)
58
      {
59
      return objects[ordinal].mIcon;
60
      }
61

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

    
64
    static int getTitle(int ordinal)
65
      {
66
      return objects[ordinal].mTitle;
67
      }
68

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

    
71
    static int getDescription(int ordinal)
72
      {
73
      return objects[ordinal].mDescription;
74
      }
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  @Override
80
  public void onResume()
81
    {
82
    super.onResume();
83

    
84
    Window window = getDialog().getWindow();
85

    
86
    if( window!=null )
87
      {
88
      WindowManager.LayoutParams params = window.getAttributes();
89
      params.width  = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
90
      window.setAttributes(params);
91
      }
92
    }
93

    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

    
96
  public int getResource()            { return R.layout.dialog_scrollable_panes; }
97
  public int getTitleResource()       { return R.string.creators; }
98
  public boolean hasArgument()        { return false; }
99
  public int getPositive()            { return R.string.ok; }
100
  public int getNegative()            { return -1; }
101
  public void positiveAction()        { }
102
  public void negativeAction()        { }
103
  public static String getDialogTag() { return "DialogCreators"; }
104

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

    
107
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
108
    {
109
    int margin= (int)(mHeight*0.010f);
110
    int padd  = (int)(mHeight*0.010f);
111
    int font  = (int)(mHeight*0.025f);
112

    
113
    LinearLayout layout= view.findViewById(R.id.dialog_scrollable_main_layout);
114
    TextView text  = view.findViewById(R.id.dialog_scrollable_message);
115
    text.setVisibility(View.GONE);
116

    
117
    LinearLayout.LayoutParams pV = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
118
    pV.setMargins(margin, margin, margin, 0);
119
    LinearLayout.LayoutParams pL = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
120
    pL.setMargins(margin, margin, margin, margin);
121
    LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
122
    pT.setMargins(0,0,0,2*margin);
123
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
124
    pB.setMargins(0,2*margin,0,0);
125

    
126
    int num = BandagedObjectDescription.NUM_OBJECTS;
127
    RubikActivity ract = (RubikActivity) getContext();
128

    
129
    for(int i=0; i<num; i++)
130
      {
131
      int icon        = BandagedObjectDescription.getIcon(i);
132
      int title       = BandagedObjectDescription.getTitle(i);
133
      int description = BandagedObjectDescription.getDescription(i);
134
      RubikDialogCreatorView pane = new RubikDialogCreatorView(ract,this,i,icon,title,description, padd, font, (i==num-1?pL:pV),pT,pB);
135
      layout.addView(pane.getView());
136
      }
137
    }
138
  }
(7-7/29)