Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 21efc7d7

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.config;
21

    
22
import android.util.TypedValue;
23
import android.widget.ImageView;
24
import android.widget.LinearLayout;
25
import android.widget.RadioButton;
26
import android.widget.RadioGroup;
27
import android.widget.TextView;
28

    
29
import org.distorted.jsons.ObjectJson;
30
import org.distorted.main.R;
31
import org.distorted.objectlib.json.JsonReader;
32
import org.distorted.objects.RubikObject;
33
import org.distorted.objects.RubikObjectList;
34

    
35
import java.io.InputStream;
36

    
37
import static android.view.View.inflate;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
public class ConfigScreenPane
42
{
43
  private static final int[] IMAGES =
44
    {
45
    R.id.configDifficulty0,
46
    R.id.configDifficulty1,
47
    R.id.configDifficulty2,
48
    R.id.configDifficulty3,
49
    R.id.configDifficulty4
50
    };
51

    
52
  private static final int NUM_IMAGES = IMAGES.length;
53
  private static final float PADDING_RATIO = 0.015f;
54
  private static final float TEXT_RATIO    = 0.025f;
55
  private static final float RADIO_RATIO   = 0.900f;
56

    
57
  private JsonReader mReader;
58
  private int mObjectOrdinal;
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  private void switchMesh(ConfigActivity act, boolean simple)
63
    {
64

    
65
    }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
  void updatePane(ConfigActivity act, int objectOrdinal)
70
    {
71
    if( mReader==null ) mReader = new JsonReader();
72

    
73
    mObjectOrdinal = objectOrdinal;
74

    
75
    RubikObject object = RubikObjectList.getObject(objectOrdinal);
76
    int jsonID = object.getJsonID();
77
    InputStream stream = ObjectJson.getStream(jsonID,act);
78
    mReader.parseJsonFileMetadata(stream);
79

    
80
    String name = mReader.getObjectName();
81
    String author = mReader.getInventor();
82
    int year = mReader.getYearOfInvention();
83
    String both = year>0 ? author+" "+year : author;
84

    
85
    LinearLayout layout = act.findViewById(R.id.configLayout);
86
    TextView view = layout.findViewById(R.id.configDetailsName2);
87
    view.setText(name);
88
    view = layout.findViewById(R.id.configDetailsAuthor2);
89
    view.setText(both);
90

    
91
    int difficulty = mReader.getComplexity();
92

    
93
    if( difficulty<0          ) difficulty=0;
94
    if( difficulty>NUM_IMAGES ) difficulty=NUM_IMAGES;
95

    
96
    for(int i=0; i<NUM_IMAGES; i++)
97
      {
98
      ImageView image = layout.findViewById(IMAGES[i]);
99
      image.setImageResource( i==difficulty ? R.drawable.ui_difficulty_checked : R.drawable.ui_difficulty_unchecked );
100
      }
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
106
    {
107
    int height = act.getScreenHeightInPixels();
108
    float textSize = height*TEXT_RATIO;
109
    int padding = (int)(height*PADDING_RATIO);
110

    
111
    LinearLayout configLayout    = act.findViewById(R.id.configLayout);
112
    LinearLayout nameLayout      = configLayout.findViewById(R.id.configLayoutName);
113
    LinearLayout authorLayout    = configLayout.findViewById(R.id.configLayoutAuthor);
114
    LinearLayout difficultyLayout= configLayout.findViewById(R.id.configLayoutDifficulty);
115
    LinearLayout meshLayout      = configLayout.findViewById(R.id.configLayoutMesh);
116

    
117
    nameLayout.setPadding(padding,padding,padding,padding/2);
118
    authorLayout.setPadding(padding,padding/2,padding,padding/2);
119
    difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
120
    meshLayout.setPadding(padding,padding/2,padding,padding);
121

    
122
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
123
    params.bottomMargin = 0;
124
    params.topMargin    = padding;
125
    params.leftMargin   = padding;
126
    params.rightMargin  = padding;
127

    
128
    nameLayout.setLayoutParams(params);
129
    authorLayout.setLayoutParams(params);
130
    difficultyLayout.setLayoutParams(params);
131
    meshLayout.setLayoutParams(params);
132

    
133
    TextView text;
134
    text = nameLayout.findViewById(R.id.configDetailsName1);
135
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
136
    text = nameLayout.findViewById(R.id.configDetailsName2);
137
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
138
    text = authorLayout.findViewById(R.id.configDetailsAuthor1);
139
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
140
    text = authorLayout.findViewById(R.id.configDetailsAuthor2);
141
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
142
    text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
143
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
144
    text = meshLayout.findViewById(R.id.configMeshTitle);
145
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
146

    
147
    RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
148
    butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
149
    RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
150
    butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
151

    
152
    LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
153
    layoutDiff.setPadding(padding,padding,padding,padding);
154

    
155
    RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
156

    
157
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
158
      {
159
      @Override
160
      public void onCheckedChanged(RadioGroup group, int checkedId)
161
        {
162
        switchMesh( act, checkedId != R.id.meshNice );
163
        }
164
      });
165

    
166
    updatePane(act,objectOrdinal);
167
    }
168
}
(5-5/6)