Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 93847dfc

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 detailsLayout    = (LinearLayout)inflate( act, R.layout.config_details   , null);
112
    LinearLayout difficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
113
    LinearLayout meshLayout       = (LinearLayout)inflate( act, R.layout.config_mesh      , null);
114

    
115
    detailsLayout.setPadding(padding,padding,padding,padding/2);
116
    difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
117
    meshLayout.setPadding(padding,padding/2,padding,padding);
118

    
119
    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
120
    LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
121
    LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.05f);
122

    
123
    detailsLayout.setLayoutParams(params1);
124
    difficultyLayout.setLayoutParams(params2);
125
    meshLayout.setLayoutParams(params3);
126

    
127
    TextView text;
128
    text = detailsLayout.findViewById(R.id.configDetailsTitle);
129
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
130
    text = detailsLayout.findViewById(R.id.configDetailsName1);
131
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
132
    text = detailsLayout.findViewById(R.id.configDetailsName2);
133
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
134
    text = detailsLayout.findViewById(R.id.configDetailsAuthor1);
135
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
136
    text = detailsLayout.findViewById(R.id.configDetailsAuthor2);
137
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
138

    
139
    text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
140
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
141
    text = meshLayout.findViewById(R.id.configMeshTitle);
142
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
143

    
144
    RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
145
    butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
146
    RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
147
    butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
148

    
149
    LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
150
    layoutDiff.setPadding(padding,padding,padding,padding);
151

    
152
    RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
153

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

    
163
    LinearLayout layout = act.findViewById(R.id.configLayout);
164
    layout.removeAllViews();
165
    layout.addView(detailsLayout);
166
    layout.addView(difficultyLayout);
167
    layout.addView(meshLayout);
168

    
169
    updatePane(act,objectOrdinal);
170
    }
171
}
(5-5/6)