Project

General

Profile

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

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

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.magic;
21

    
22
import android.content.Context;
23
import android.support.v4.app.FragmentActivity;
24
import android.util.AttributeSet;
25
import android.view.View;
26
import android.widget.FrameLayout;
27
import android.widget.LinearLayout;
28
import android.widget.TextView;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public class RubikScoresView extends FrameLayout
33
  {
34
  int mPosition;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
  public RubikScoresView(Context context, AttributeSet attrs, int defStyle)
39
    {
40
    super(context, attrs, defStyle);
41
    }
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  public RubikScoresView(Context context, AttributeSet attrs)
46
    {
47
    super(context, attrs);
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  public RubikScoresView(Context context)
53
    {
54
    super(context);
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  public RubikScoresView(Context context, int position)
60
    {
61
    super(context);
62

    
63
    mPosition = position;
64
    View view = inflate(context, R.layout.scores_downloading, null);
65
    addView(view);
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
  private int getLevelLayoutID(int level)
71
    {
72
    return 100+level;
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public void prepareView(FragmentActivity act)
78
    {
79
    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
    for(int i=1; i<=RubikActivity.MAX_SCRAMBLE; i++)
86
      {
87
      View level = inflate(act, R.layout.level_records, null);
88
      level.setId(getLevelLayoutID(i));
89
      TextView text = level.findViewById(R.id.levelTitle);
90
      text.setText(act.getString(R.string.sc_placeholder,i));
91

    
92
      layout.addView(level);
93
      }
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
  public void fillRow(FragmentActivity act, int level, String place, int time, String name, String country)
99
    {
100
    if( level>=0 && level<RubikActivity.MAX_SCRAMBLE )
101
      {
102
      LinearLayout layout = findViewById(getLevelLayoutID(level+1));
103
      View rowLay = inflate(act, R.layout.level_row, null);
104

    
105
      TextView textName    = rowLay.findViewById(R.id.level_row_name);
106
      TextView textTime    = rowLay.findViewById(R.id.level_row_time);
107
      TextView textCountry = rowLay.findViewById(R.id.level_row_country);
108

    
109
      float real_time = time/10.0f;
110

    
111
      textName.setText(name);
112
      textTime.setText( String.valueOf(real_time) );
113
      textCountry.setText(country);
114

    
115
      layout.addView(rowLay);
116
      }
117
    else
118
      {
119
      android.util.Log.e("receive", "level invalid: "+level);
120
      }
121
    }
122
  }
(7-7/11)