Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogScores.java @ 7bb30586

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.dialogs;
11

    
12
import android.app.Dialog;
13
import androidx.fragment.app.FragmentActivity;
14
import androidx.viewpager.widget.ViewPager;
15
import com.google.android.material.tabs.TabLayout;
16

    
17
import android.view.View;
18
import android.view.ViewGroup;
19
import android.view.Window;
20
import android.view.WindowManager;
21
import android.widget.ImageView;
22

    
23
import org.distorted.main.R;
24
import org.distorted.objects.RubikObject;
25
import org.distorted.objects.RubikObjectList;
26

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

    
29
public class RubikDialogScores extends RubikDialogAbstract
30
  {
31
  private static final float TAB_WIDTH = 0.066f;
32
  private static final float TAB_HEIGHT= 0.066f;
33

    
34
  private RubikDialogScoresPagerAdapter mPagerAdapter;
35

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

    
38
  @Override
39
  public void onResume()
40
    {
41
    super.onResume();
42

    
43
    Window window = getDialog().getWindow();
44

    
45
    if( window!=null )
46
      {
47
      WindowManager.LayoutParams params = window.getAttributes();
48
      params.width  = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
49
      params.height = (int)( mHeight*0.90f);
50
      window.setAttributes(params);
51
      }
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  public int getResource()      { return R.layout.dialog_tabbed; }
57
  public int getTitleResource() { return R.string.scores; }
58
  public boolean hasArgument()  { return true; }
59
  public int getPositive()      { return R.string.ok; }
60
  public int getNegative()      { return -1; }
61
  public void positiveAction()  { RubikDialogScoresThread.getInstance().exit(); }
62
  public void negativeAction()  { }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
67
    {
68
    final int tabHeight= (int)(mHeight*TAB_HEIGHT);
69
    final int tabWidth = (int)(mHeight*TAB_WIDTH);
70

    
71
    ViewPager viewPager = view.findViewById(R.id.viewpager);
72
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
73
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,mArgument.equals("true"), this);
74
    tabLayout.setupWithViewPager(viewPager);
75

    
76
    viewPager.setCurrentItem(RubikObjectList.getCurrObject());
77
    int numObjects = RubikObjectList.getNumObjects();
78
    ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
79

    
80
    for (int object=0; object<numObjects; object++)
81
      {
82
      RubikObject robject = RubikObjectList.getObject(object);
83
      ImageView imageView = new ImageView(act);
84
      if( robject!=null ) robject.setIconTo(act,imageView);
85
      imageView.setLayoutParams(paramsView);
86
      TabLayout.Tab tab = tabLayout.getTabAt(object);
87
      if(tab!=null) tab.setCustomView(imageView);
88
      }
89
    }
90
  }
(13-13/24)