Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorial.java @ 58990dfd

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 android.view.View;
14
import android.view.ViewGroup;
15
import android.view.Window;
16
import android.view.WindowManager;
17
import android.widget.ImageView;
18

    
19
import androidx.fragment.app.FragmentActivity;
20
import androidx.viewpager.widget.ViewPager;
21

    
22
import com.google.android.material.tabs.TabLayout;
23

    
24
import org.distorted.main.R;
25
import org.distorted.main.RubikActivity;
26
import org.distorted.objects.RubikObject;
27
import org.distorted.objects.RubikObjectList;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class RubikDialogTutorial extends RubikDialogAbstract
32
  {
33
  private RubikDialogTutorialPagerAdapter mPagerAdapter;
34

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

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

    
42
    if( mPagerAdapter!=null ) mPagerAdapter.clickPossible();
43

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

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

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

    
57
  public int getResource()      { return R.layout.dialog_tabbed; }
58
  public int getTitleResource() { return R.string.tutorials; }
59
  public boolean hasArgument()  { return false; }
60
  public int getPositive()      { return R.string.ok; }
61
  public int getNegative()      { return -1; }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  public void positiveAction()
66
    {
67

    
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  public void negativeAction()
73
    {
74

    
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
80
    {
81
    final int tabHeight= (int)(mHeight*RubikActivity.TAB_HEIGHT);
82
    final int tabWidth = (int)(mHeight*RubikActivity.TAB_WIDTH);
83

    
84
    ViewPager viewPager = view.findViewById(R.id.viewpager);
85
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
86
    mPagerAdapter = new RubikDialogTutorialPagerAdapter(act,viewPager);
87
    tabLayout.setupWithViewPager(viewPager);
88
    int obj = RubikObjectList.getCurrObject();
89
    int ord = RubikObjectList.getTutorialOrdinal(obj);
90
    viewPager.setCurrentItem(ord);
91

    
92
    ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
93
    int numObjects = RubikObjectList.getNumTutorialObjects();
94

    
95
    for(int i=0; i<numObjects; i++)
96
      {
97
      int oOrdinal = RubikObjectList.getObjectOrdinal(i);
98
      RubikObject object = RubikObjectList.getObject(oOrdinal);
99
      ImageView imageView = new ImageView(act);
100
      imageView.setLayoutParams(paramsView);
101
      if( object!=null ) object.setIconTo(act,imageView);
102
      TabLayout.Tab tab = tabLayout.getTabAt(i);
103
      if(tab!=null) tab.setCustomView(imageView);
104
      }
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public static String getDialogTag()
110
    {
111
    return "DialogTutorial";
112
    }
113
  }
(22-22/26)