Project

General

Profile

« Previous | Next » 

Revision 946d9762

Added by Leszek Koltunski over 4 years ago

Downloading High Scores: more dynamic way of displaying scores

View differences:

src/main/java/org/distorted/magic/RubikScoresView.java
20 20
package org.distorted.magic;
21 21

  
22 22
import android.content.Context;
23
import android.content.res.Resources;
24
import android.graphics.BitmapFactory;
25 23
import android.support.v4.app.FragmentActivity;
26 24
import android.util.AttributeSet;
27 25
import android.view.View;
......
34 32

  
35 33
public class RubikScoresView extends FrameLayout
36 34
  {
37
  private boolean mCreated;
35
  LinearLayout mLayout;
38 36

  
39 37
///////////////////////////////////////////////////////////////////////////////////////////////////
40 38

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

  
45
    mCreated = false;
46 42
    }
47 43

  
48 44
///////////////////////////////////////////////////////////////////////////////////////////////////
......
72 68

  
73 69
///////////////////////////////////////////////////////////////////////////////////////////////////
74 70

  
75
  void prepareView(FragmentActivity act, final int[][] country, final String[][] name, final String[][] time)
71
  void prepareView(FragmentActivity act)
76 72
    {
77
    if( mCreated ) return;
78

  
79 73
    removeAllViews();
80 74

  
81 75
    View tab = inflate(act, R.layout.scores_tab, null);
82
    LinearLayout layout = tab.findViewById(R.id.tabLayout);
76
    mLayout = tab.findViewById(R.id.tabLayout);
83 77
    addView(tab);
78
    }
84 79

  
85
    for(int i=0; i<RubikActivity.MAX_SCRAMBLE; i++)
86
      {
87
      LinearLayout level = (LinearLayout)inflate(act, R.layout.level_records, null);
88
      TextView text = level.findViewById(R.id.levelTitle);
89
      text.setText(act.getString(R.string.sc_placeholder,(i+1)));
80
///////////////////////////////////////////////////////////////////////////////////////////////////
90 81

  
91
      for(int j=0; j<RubikScoresDownloader.MAX_PLACES; j++)
82
  void addScramble(FragmentActivity act, int scramble, final int[] country, final String[] name, final String[] time)
83
    {
84
    LinearLayout level = (LinearLayout)inflate(act, R.layout.level_records, null);
85
    TextView text = level.findViewById(R.id.levelTitle);
86
    text.setText(act.getString(R.string.sc_placeholder,(scramble+1)));
87

  
88
    for(int j=0; j<RubikScoresDownloader.MAX_PLACES; j++)
89
      {
90
      if( name[j] != null )
92 91
        {
93
        if( name[i][j] != null )
94
          {
95
          View row = inflate(act, R.layout.level_row, null);
92
        View row = inflate(act, R.layout.level_row, null);
96 93

  
97
          ImageView imgCoun = row.findViewById(R.id.level_row_country);
98
          TextView textName = row.findViewById(R.id.level_row_name);
99
          TextView textTime = row.findViewById(R.id.level_row_time);
94
        ImageView imgCoun = row.findViewById(R.id.level_row_country);
95
        TextView textName = row.findViewById(R.id.level_row_name);
96
        TextView textTime = row.findViewById(R.id.level_row_time);
100 97

  
101
          imgCoun.setImageResource(country[i][j]);
102
          textName.setText(name[i][j]);
103
          textTime.setText(time[i][j]);
98
        imgCoun.setImageResource(country[j]);
99
        textName.setText(name[j]);
100
        textTime.setText(time[j]);
104 101

  
105
          level.addView(row);
106
          }
102
        level.addView(row);
107 103
        }
108

  
109
      layout.addView(level);
110 104
      }
111 105

  
112
    mCreated = true;
106
    mLayout.addView(level);
113 107
    }
114 108
  }

Also available in: Unified diff