Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorialView.java @ e314f6ae

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.dialogs;
21

    
22
import android.content.Context;
23
import android.content.res.Resources;
24
import android.graphics.drawable.Drawable;
25
import android.util.AttributeSet;
26
import android.util.TypedValue;
27
import android.view.View;
28
import android.widget.Button;
29
import android.widget.FrameLayout;
30
import android.widget.ImageView;
31
import android.widget.LinearLayout;
32

    
33
import androidx.core.content.ContextCompat;
34
import androidx.fragment.app.FragmentActivity;
35

    
36
import org.distorted.main.R;
37
import org.distorted.main.RubikActivity;
38
import org.distorted.objects.ObjectList;
39
import org.distorted.tutorial.TutorialList;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
public class RubikDialogTutorialView extends FrameLayout
44
  {
45
  private TutorialList mList;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  public RubikDialogTutorialView(Context context, AttributeSet attrs, int defStyle)
50
    {
51
    super(context, attrs, defStyle);
52
    }
53

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

    
56
  public RubikDialogTutorialView(Context context, AttributeSet attrs)
57
    {
58
    super(context, attrs);
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  public RubikDialogTutorialView(FragmentActivity act, int height, int position)
64
    {
65
    super(act);
66

    
67
    int heightT = (int)(height* RubikActivity.TUTORIAL_ITEM_TEXT);
68

    
69
    RubikActivity ract = (RubikActivity)getContext();
70
    Resources res = act.getResources();
71
    String packageName = act.getPackageName();
72

    
73
    mList = TutorialList.getObject(position);
74
    ObjectList objList = mList.getObjectList();
75
    int size           = mList.getSize();
76

    
77
    View tab = inflate( act, R.layout.dialog_tutorial_tab, null);
78
    LinearLayout layout = tab.findViewById(R.id.tabLayout);
79

    
80
    int numTutorials = mList.getNumTutorials();
81

    
82
    for(int i=0; i<numTutorials; i++)
83
      {
84
      String coun = mList.getTutorialLanguage(i);
85
      String desc = mList.getTutorialDescription(i);
86
      String url  = mList.getTutorialURL(i);
87
      String auth = mList.getTutorialAuthor(i);
88

    
89
      int countryID = res.getIdentifier( coun, "drawable", packageName);
90

    
91
      View row = createRow(ract,countryID,desc,url,auth,heightT,objList,size);
92
      layout.addView(row);
93
      }
94

    
95
    addView(tab);
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  private View createRow(final RubikActivity act, int countryID, final String desc, final String url, String auth, int height, final ObjectList obj, final int size)
101
    {
102
    View row = inflate( act, R.layout.dialog_tutorial_row, null);
103
    Button butt = row.findViewById(R.id.tutorialRowButton);
104

    
105
    int id = countryID!=0 ? countryID : R.drawable.un;
106

    
107
    butt.setText(desc+" ("+auth+")");
108
    butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*height);
109
    butt.setHeight(height);
110

    
111
    Drawable img = ContextCompat.getDrawable(act,id);
112
    img.setBounds(0, 0, (int)(1.0f*height), (int)(0.66f*height) );
113
    butt.setCompoundDrawables(img,null,null,null);
114

    
115
    butt.setOnClickListener( new View.OnClickListener()
116
      {
117
      @Override
118
      public void onClick(View v)
119
        {
120
        act.switchTutorial(url,obj,size);
121
        }
122
      });
123

    
124
    return row;
125
    }
126
  }
(18-18/18)