Project

General

Profile

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

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

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.support.v4.view.ViewPager;
25
import android.util.AttributeSet;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
class RubikScoresViewPager extends ViewPager implements RubikScoresDownloader.Receiver
30
  {
31
  FragmentActivity mAct;
32
  private RubikScoresView[] mViews;
33
  private int mSelected;
34

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

    
37
  public RubikScoresViewPager(Context context, AttributeSet attrs)
38
    {
39
    super(context,attrs);
40

    
41
    mViews = new RubikScoresView[RubikSize.LENGTH];
42
    mSelected = 0;
43

    
44
    addOnPageChangeListener(new ViewPager.OnPageChangeListener()
45
      {
46
      @Override
47
      public void onPageSelected(int position)
48
        {
49
        mSelected = position;
50
        }
51

    
52
      @Override
53
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
54
        { }
55

    
56
      @Override
57
      public void onPageScrollStateChanged(int state)
58
        { }
59
      });
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  void startDownload(FragmentActivity act)
65
    {
66
    mAct = act;
67

    
68
    RubikScoresDownloader downloader = new RubikScoresDownloader();
69
    downloader.download(this, mAct.getResources(), mAct.getPackageName());
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  void setView(int position, RubikScoresView view)
75
    {
76
    if( position>=0 && position<RubikSize.LENGTH )
77
      {
78
      mViews[position] = view;
79
      }
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  public void receive(final int[][][] country, final String[][][] name, final String[][][] time)
85
    {
86
    mAct.runOnUiThread(new Runnable()
87
      {
88
      @Override
89
      public void run()
90
        {
91
        long time1 = System.currentTimeMillis();
92

    
93
        for(int i=0; i<RubikSize.LENGTH; i++)
94
          {
95
          mViews[i].prepareView(mAct, country[i], name[i], time[i]);
96
          }
97

    
98
        long time2 = System.currentTimeMillis();
99

    
100
        android.util.Log.e("dd", "time="+(time2-time1));
101
        }
102
      });
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  public void exception(final String exce)
108
    {
109
    mAct.runOnUiThread(new Runnable()
110
      {
111
      @Override
112
      public void run()
113
        {
114
        for(int i=0; i<RubikSize.LENGTH; i++)
115
          {
116
          mViews[i].exception(exce);
117
          }
118
        }
119
      });
120
    }
121
  }
(9-9/12)