Project

General

Profile

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

magiccube / src / main / java / org / distorted / magic / RubikScoresView.java @ cc5ec229

1 f2a9be6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.magic;
21
22
import android.content.Context;
23 cc5ec229 Leszek Koltunski
import android.content.res.Resources;
24
import android.graphics.BitmapFactory;
25 b8b38548 Leszek Koltunski
import android.support.v4.app.FragmentActivity;
26 f2a9be6d Leszek Koltunski
import android.util.AttributeSet;
27
import android.view.View;
28
import android.widget.FrameLayout;
29 cc5ec229 Leszek Koltunski
import android.widget.ImageView;
30 b8b38548 Leszek Koltunski
import android.widget.LinearLayout;
31
import android.widget.TextView;
32 f2a9be6d Leszek Koltunski
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
public class RubikScoresView extends FrameLayout
36
  {
37 cc5ec229 Leszek Koltunski
  private boolean mCreated;
38 f2a9be6d Leszek Koltunski
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
  public RubikScoresView(Context context, AttributeSet attrs, int defStyle)
42
    {
43
    super(context, attrs, defStyle);
44 cc5ec229 Leszek Koltunski
45
    mCreated = false;
46 f2a9be6d Leszek Koltunski
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50
  public RubikScoresView(Context context, AttributeSet attrs)
51
    {
52
    super(context, attrs);
53
    }
54
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57
  public RubikScoresView(Context context)
58
    {
59
    super(context);
60
61 b8b38548 Leszek Koltunski
    View view = inflate(context, R.layout.scores_downloading, null);
62
    addView(view);
63 f2a9be6d Leszek Koltunski
    }
64
65 a675474f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67
  void exception(final String exce)
68
    {
69
    TextView text = findViewById(R.id.downloading_text);
70
    text.setText(exce);
71
    }
72
73 f2a9be6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75 cc5ec229 Leszek Koltunski
  void prepareView(FragmentActivity act, final int[][] country, final String[][] name, final String[][] time)
76 b8b38548 Leszek Koltunski
    {
77 cc5ec229 Leszek Koltunski
    if( mCreated ) return;
78
79 b8b38548 Leszek Koltunski
    removeAllViews();
80
81
    View tab = inflate(act, R.layout.scores_tab, null);
82
    LinearLayout layout = tab.findViewById(R.id.tabLayout);
83
    addView(tab);
84
85 d8aa4ba8 Leszek Koltunski
    for(int i=0; i<RubikActivity.MAX_SCRAMBLE; i++)
86 b8b38548 Leszek Koltunski
      {
87 d8aa4ba8 Leszek Koltunski
      LinearLayout level = (LinearLayout)inflate(act, R.layout.level_records, null);
88 b8b38548 Leszek Koltunski
      TextView text = level.findViewById(R.id.levelTitle);
89 d8aa4ba8 Leszek Koltunski
      text.setText(act.getString(R.string.sc_placeholder,(i+1)));
90 b8b38548 Leszek Koltunski
91 d8aa4ba8 Leszek Koltunski
      for(int j=0; j<RubikScoresDownloader.MAX_PLACES; j++)
92
        {
93 cc5ec229 Leszek Koltunski
        if( name[i][j] != null )
94 d8aa4ba8 Leszek Koltunski
          {
95
          View row = inflate(act, R.layout.level_row, null);
96 b8b38548 Leszek Koltunski
97 cc5ec229 Leszek Koltunski
          ImageView imgCoun = row.findViewById(R.id.level_row_country);
98 d8aa4ba8 Leszek Koltunski
          TextView textName = row.findViewById(R.id.level_row_name);
99
          TextView textTime = row.findViewById(R.id.level_row_time);
100 b8b38548 Leszek Koltunski
101 cc5ec229 Leszek Koltunski
          imgCoun.setImageResource(country[i][j]);
102
          textName.setText(name[i][j]);
103
          textTime.setText(time[i][j]);
104 b8b38548 Leszek Koltunski
105 d8aa4ba8 Leszek Koltunski
          level.addView(row);
106
          }
107
        }
108 b8b38548 Leszek Koltunski
109 d8aa4ba8 Leszek Koltunski
      layout.addView(level);
110 b8b38548 Leszek Koltunski
      }
111 cc5ec229 Leszek Koltunski
112
    mCreated = true;
113 f2a9be6d Leszek Koltunski
    }
114
  }