Project

General

Profile

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

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

1 234a7582 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 b91d4033 Leszek Koltunski
import android.content.res.Resources;
24 5b4eaf7e Leszek Koltunski
import android.graphics.drawable.Drawable;
25 234a7582 Leszek Koltunski
import android.util.AttributeSet;
26 b91d4033 Leszek Koltunski
import android.util.TypedValue;
27 234a7582 Leszek Koltunski
import android.view.View;
28 b91d4033 Leszek Koltunski
import android.widget.Button;
29 234a7582 Leszek Koltunski
import android.widget.FrameLayout;
30 b91d4033 Leszek Koltunski
import android.widget.ImageView;
31
import android.widget.LinearLayout;
32 234a7582 Leszek Koltunski
33 5b4eaf7e Leszek Koltunski
import androidx.core.content.ContextCompat;
34 234a7582 Leszek Koltunski
import androidx.fragment.app.FragmentActivity;
35
36
import org.distorted.main.R;
37
import org.distorted.main.RubikActivity;
38 79bf5d8b Leszek Koltunski
import org.distorted.objects.ObjectList;
39 b91d4033 Leszek Koltunski
import org.distorted.tutorial.TutorialList;
40 234a7582 Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43
public class RubikDialogTutorialView extends FrameLayout
44
  {
45 b91d4033 Leszek Koltunski
  private TutorialList mList;
46 234a7582 Leszek Koltunski
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 5b4eaf7e Leszek Koltunski
  public RubikDialogTutorialView(FragmentActivity act, int height, int position)
64 234a7582 Leszek Koltunski
    {
65
    super(act);
66
67 5b4eaf7e Leszek Koltunski
    int heightT = (int)(height* RubikActivity.TUTORIAL_ITEM_TEXT);
68 234a7582 Leszek Koltunski
69 b91d4033 Leszek Koltunski
    RubikActivity ract = (RubikActivity)getContext();
70
    Resources res = act.getResources();
71
    String packageName = act.getPackageName();
72
73
    mList = TutorialList.getObject(position);
74 79bf5d8b Leszek Koltunski
    ObjectList objList = mList.getObjectList();
75
    int size           = mList.getSize();
76 234a7582 Leszek Koltunski
77
    View tab = inflate( act, R.layout.dialog_tutorial_tab, null);
78 b91d4033 Leszek Koltunski
    LinearLayout layout = tab.findViewById(R.id.tabLayout);
79 234a7582 Leszek Koltunski
80 b91d4033 Leszek Koltunski
    int numTutorials = mList.getNumTutorials();
81 234a7582 Leszek Koltunski
82 b91d4033 Leszek Koltunski
    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 5b4eaf7e Leszek Koltunski
      String auth = mList.getTutorialAuthor(i);
88 b91d4033 Leszek Koltunski
89
      int countryID = res.getIdentifier( coun, "drawable", packageName);
90
91 5b4eaf7e Leszek Koltunski
      View row = createRow(ract,countryID,desc,url,auth,heightT,objList,size);
92 b91d4033 Leszek Koltunski
      layout.addView(row);
93
      }
94 234a7582 Leszek Koltunski
95
    addView(tab);
96
    }
97 b91d4033 Leszek Koltunski
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100 5b4eaf7e Leszek Koltunski
  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 b91d4033 Leszek Koltunski
    {
102
    View row = inflate( act, R.layout.dialog_tutorial_row, null);
103
    Button butt = row.findViewById(R.id.tutorialRowButton);
104
105 5b4eaf7e Leszek Koltunski
    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 b91d4033 Leszek Koltunski
111 5b4eaf7e Leszek Koltunski
    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 b91d4033 Leszek Koltunski
115
    butt.setOnClickListener( new View.OnClickListener()
116
      {
117
      @Override
118
      public void onClick(View v)
119
        {
120 79bf5d8b Leszek Koltunski
        act.switchTutorial(url,obj,size);
121 b91d4033 Leszek Koltunski
        }
122
      });
123
124
    return row;
125
    }
126 234a7582 Leszek Koltunski
  }