Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialog / RubikDialogScoresView.java @ 0333d81e

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

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

    
32
import org.distorted.magic.R;
33
import static org.distorted.network.RubikScoresDownloader.MAX_PLACES;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class RubikDialogScoresView extends FrameLayout
38
  {
39
  LinearLayout mLayout;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  public RubikDialogScoresView(Context context, AttributeSet attrs, int defStyle)
44
    {
45
    super(context, attrs, defStyle);
46
    }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  public RubikDialogScoresView(Context context, AttributeSet attrs)
51
    {
52
    super(context, attrs);
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  public RubikDialogScoresView(Context context)
58
    {
59
    super(context);
60

    
61
    View view = inflate(context, R.layout.dialog_scores_downloading, null);
62
    addView(view);
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  LinearLayout createSection(FragmentActivity act, int scramble, final String[] country, final String[] name, final String[] time)
68
    {
69
    LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null);
70
    TextView text = level.findViewById(R.id.scoresScrambleTitle);
71
    text.setText(act.getString(R.string.sc_placeholder,(scramble+1)));
72

    
73
    Resources res = act.getResources();
74
    String packageName = act.getPackageName();
75

    
76
    for(int j=0; j<MAX_PLACES; j++)
77
      {
78
      if( name[j] != null )
79
        {
80
        View row = inflate(act, R.layout.dialog_scores_scramble_row, null);
81

    
82
        ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry);
83
        TextView textName = row.findViewById(R.id.scoresScrambleRowName);
84
        TextView textTime = row.findViewById(R.id.scoresScrambleRowTime);
85

    
86
        int resID = res.getIdentifier( country[j], "drawable", packageName);
87

    
88
        imgCoun.setImageResource(resID!=0 ? resID : R.drawable.unk);
89
        textName.setText(name[j]);
90
        textTime.setText(time[j]);
91

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

    
96
    return level;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
// needs to run on UI thread
101

    
102
  void prepareView(FragmentActivity act)
103
    {
104
    removeAllViews();
105

    
106
    View tab = inflate(act, R.layout.dialog_scores_tab, null);
107
    mLayout = tab.findViewById(R.id.tabLayout);
108
    addView(tab);
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112
// needs to run on UI thread
113

    
114
  void addSection(LinearLayout section)
115
    {
116
    mLayout.addView(section);
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
// needs to run on UI thread
121

    
122
  void exception(final String exce)
123
    {
124
    TextView text = findViewById(R.id.downloading_text);
125
    text.setText(exce);
126
    }
127
  }
(5-5/6)