Project

General

Profile

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

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

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 211b48f2 Leszek Koltunski
package org.distorted.dialog;
21 f2a9be6d Leszek Koltunski
22
import android.content.Context;
23 7aff6aa7 Leszek Koltunski
import android.content.res.Resources;
24 b8b38548 Leszek Koltunski
import android.support.v4.app.FragmentActivity;
25 f2a9be6d Leszek Koltunski
import android.util.AttributeSet;
26
import android.view.View;
27
import android.widget.FrameLayout;
28 cc5ec229 Leszek Koltunski
import android.widget.ImageView;
29 b8b38548 Leszek Koltunski
import android.widget.LinearLayout;
30
import android.widget.TextView;
31 f2a9be6d Leszek Koltunski
32 211b48f2 Leszek Koltunski
import org.distorted.magic.R;
33 0333d81e Leszek Koltunski
import static org.distorted.network.RubikScoresDownloader.MAX_PLACES;
34 211b48f2 Leszek Koltunski
35 f2a9be6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 0fd3ac1f Leszek Koltunski
public class RubikDialogScoresView extends FrameLayout
38 f2a9be6d Leszek Koltunski
  {
39 946d9762 Leszek Koltunski
  LinearLayout mLayout;
40 f2a9be6d Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 0fd3ac1f Leszek Koltunski
  public RubikDialogScoresView(Context context, AttributeSet attrs, int defStyle)
44 f2a9be6d Leszek Koltunski
    {
45
    super(context, attrs, defStyle);
46
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50 0fd3ac1f Leszek Koltunski
  public RubikDialogScoresView(Context context, AttributeSet attrs)
51 f2a9be6d Leszek Koltunski
    {
52
    super(context, attrs);
53
    }
54
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57 0fd3ac1f Leszek Koltunski
  public RubikDialogScoresView(Context context)
58 f2a9be6d Leszek Koltunski
    {
59
    super(context);
60
61 0fd3ac1f Leszek Koltunski
    View view = inflate(context, R.layout.dialog_scores_downloading, null);
62 b8b38548 Leszek Koltunski
    addView(view);
63 f2a9be6d Leszek Koltunski
    }
64
65 a675474f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67 7aff6aa7 Leszek Koltunski
  LinearLayout createSection(FragmentActivity act, int scramble, final String[] country, final String[] name, final String[] time)
68 a675474f Leszek Koltunski
    {
69 7aff6aa7 Leszek Koltunski
    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 0333d81e Leszek Koltunski
    for(int j=0; j<MAX_PLACES; j++)
77 7aff6aa7 Leszek Koltunski
      {
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 a675474f Leszek Koltunski
    }
98
99 f2a9be6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
100 7aff6aa7 Leszek Koltunski
// needs to run on UI thread
101 f2a9be6d Leszek Koltunski
102 946d9762 Leszek Koltunski
  void prepareView(FragmentActivity act)
103 b8b38548 Leszek Koltunski
    {
104
    removeAllViews();
105
106 0fd3ac1f Leszek Koltunski
    View tab = inflate(act, R.layout.dialog_scores_tab, null);
107 946d9762 Leszek Koltunski
    mLayout = tab.findViewById(R.id.tabLayout);
108 b8b38548 Leszek Koltunski
    addView(tab);
109 946d9762 Leszek Koltunski
    }
110 b8b38548 Leszek Koltunski
111 946d9762 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
112 7aff6aa7 Leszek Koltunski
// needs to run on UI thread
113 b8b38548 Leszek Koltunski
114 d5fb0e7e Leszek Koltunski
  void addSection(LinearLayout section)
115
    {
116
    mLayout.addView(section);
117
    }
118
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120 7aff6aa7 Leszek Koltunski
// needs to run on UI thread
121 d5fb0e7e Leszek Koltunski
122 7aff6aa7 Leszek Koltunski
  void exception(final String exce)
123 946d9762 Leszek Koltunski
    {
124 7aff6aa7 Leszek Koltunski
    TextView text = findViewById(R.id.downloading_text);
125
    text.setText(exce);
126 f2a9be6d Leszek Koltunski
    }
127
  }