Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogCreators.java @ 65a24dca

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
    SKEWB      ( org.distorted.objectlib.R.drawable.skew_2, R.string.creator_skewb_title, R.string.creator_skewb_desc ),
35
    ;
36

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

    
40
    final int mIcon, mTitle, mDescription;
41

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

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

    
56
    ////////////////////////////////////////////////////////////////////////
57

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

    
63
    ////////////////////////////////////////////////////////////////////////
64

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

    
70
    ////////////////////////////////////////////////////////////////////////
71

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

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

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

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

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

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

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

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

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

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

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

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

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