Revision b91d4033
Added by Leszek Koltunski almost 5 years ago
| src/main/java/org/distorted/dialogs/RubikDialogTutorialView.java | ||
|---|---|---|
| 20 | 20 | package org.distorted.dialogs; | 
| 21 | 21 |  | 
| 22 | 22 | import android.content.Context; | 
| 23 | import android.content.res.Resources; | |
| 23 | 24 | import android.util.AttributeSet; | 
| 25 | import android.util.TypedValue; | |
| 24 | 26 | import android.view.View; | 
| 27 | import android.widget.Button; | |
| 25 | 28 | import android.widget.FrameLayout; | 
| 29 | import android.widget.ImageButton; | |
| 30 | import android.widget.ImageView; | |
| 31 | import android.widget.LinearLayout; | |
| 32 | import android.widget.TextView; | |
| 26 | 33 |  | 
| 27 | 34 | import androidx.fragment.app.FragmentActivity; | 
| 28 | 35 |  | 
| 29 | 36 | import org.distorted.main.R; | 
| 30 | 37 | import org.distorted.main.RubikActivity; | 
| 38 | import org.distorted.tutorial.TutorialList; | |
| 31 | 39 |  | 
| 32 | 40 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 33 | 41 |  | 
| 34 | 42 | public class RubikDialogTutorialView extends FrameLayout | 
| 35 | 43 |   {
 | 
| 36 | private RubikDialogTutorial mDialog; | |
| 37 | private int mTab, mPos; | |
| 44 | private TutorialList mList; | |
| 38 | 45 |  | 
| 39 | 46 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 40 | 47 |  | 
| ... | ... | |
| 56 | 63 |     {
 | 
| 57 | 64 | super(act); | 
| 58 | 65 |  | 
| 59 | final RubikActivity ract = (RubikActivity)getContext(); | |
| 66 | //int height = (int)(mWidth* RubikActivity.TUTORIAL_ITEM_TEXT); | |
| 67 | int height = 50; | |
| 60 | 68 |  | 
| 61 | mTab = position; | |
| 62 | mDialog = dialog; | |
| 69 | RubikActivity ract = (RubikActivity)getContext(); | |
| 70 | Resources res = act.getResources(); | |
| 71 | String packageName = act.getPackageName(); | |
| 72 |  | |
| 73 | mList = TutorialList.getObject(position); | |
| 63 | 74 |  | 
| 64 | 75 | View tab = inflate( act, R.layout.dialog_tutorial_tab, null); | 
| 76 | LinearLayout layout = tab.findViewById(R.id.tabLayout); | |
| 65 | 77 |  | 
| 66 |     // TODO: on click
 | |
| 78 |     int numTutorials = mList.getNumTutorials();
 | |
| 67 | 79 |  | 
| 68 | /* | |
| 69 | RubikActivity ract = (RubikActivity)getContext(); | |
| 70 |     if( ract!=null ) ract.switchTutorial("QMzeJobSu1M");
 | |
| 71 | */ | |
| 80 | for(int i=0; i<numTutorials; i++) | |
| 81 |       {
 | |
| 82 | String coun = mList.getTutorialLanguage(i); | |
| 83 | String desc = mList.getTutorialDescription(i); | |
| 84 | String url = mList.getTutorialURL(i); | |
| 85 |  | |
| 86 | int countryID = res.getIdentifier( coun, "drawable", packageName); | |
| 87 |  | |
| 88 | View row = createRow(ract,countryID,desc,url,height); | |
| 89 | layout.addView(row); | |
| 90 | } | |
| 72 | 91 |  | 
| 73 | 92 | addView(tab); | 
| 74 | 93 | } | 
| 94 |  | |
| 95 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 96 |  | |
| 97 | private View createRow(final RubikActivity act, int countryID, final String desc, final String url, int height) | |
| 98 |     {
 | |
| 99 | int id = countryID!=0 ? countryID : R.drawable.un; | |
| 100 |  | |
| 101 | View row = inflate( act, R.layout.dialog_tutorial_row, null); | |
| 102 | Button butt = row.findViewById(R.id.tutorialRowButton); | |
| 103 |  | |
| 104 | butt.setPadding(20,0,0,0); | |
| 105 |  | |
| 106 | butt.setCompoundDrawablesWithIntrinsicBounds(id,0,0,0); | |
| 107 | butt.setText(desc); | |
| 108 | butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.7f*height); | |
| 109 |  | |
| 110 | butt.setOnClickListener( new View.OnClickListener() | |
| 111 |       {
 | |
| 112 | @Override | |
| 113 | public void onClick(View v) | |
| 114 |         {
 | |
| 115 | act.switchTutorial(url); | |
| 116 | } | |
| 117 | }); | |
| 118 |  | |
| 119 | return row; | |
| 120 | } | |
| 75 | 121 | } | 
| src/main/java/org/distorted/tutorial/TutorialList.java | ||
|---|---|---|
| 27 | 27 | {
 | 
| 28 | 28 | CUBE2 ( ObjectList.CUBE, 2, | 
| 29 | 29 |           new String[][] {
 | 
| 30 |                           {"GB","rJlh5p2wAKA","How to Solve a 2x2 Rubik's Cube","Z3"},
 | |
| 30 |                           {"gb","rJlh5p2wAKA","How to Solve a 2x2 Rubik's Cube","Z3"},
 | |
| 31 | 31 | } | 
| 32 | 32 | ), | 
| 33 | 33 |  | 
| 34 | 34 | CUBE3 ( ObjectList.CUBE, 3, | 
| 35 | 35 |           new String[][] {
 | 
| 36 |                           {"GB","-8ohoCKN0Zw","How to Solve a Rubik's Cube","Z3"},
 | |
| 36 |                           {"gb","-8ohoCKN0Zw","How to Solve a Rubik's Cube","Z3"},
 | |
| 37 | 37 | } | 
| 38 | 38 | ), | 
| 39 | 39 |  | 
| 40 | 40 | CUBE4 ( ObjectList.CUBE, 4, | 
| 41 | 41 |           new String[][] {
 | 
| 42 |                           {"GB","RR77Md71Ymc","How to Solve the 4x4 Rubik's Cube","Z3"},
 | |
| 42 |                           {"gb","RR77Md71Ymc","How to Solve the 4x4 Rubik's Cube","Z3"},
 | |
| 43 | 43 | } | 
| 44 | 44 | ), | 
| 45 | 45 |  | 
| 46 | 46 | CUBE5 ( ObjectList.CUBE, 5, | 
| 47 | 47 |           new String[][] {
 | 
| 48 |                           {"GB","zMkNkXHzQts","How to Solve the 5x5 Rubik's Cube","Z3"},
 | |
| 48 |                           {"gb","zMkNkXHzQts","How to Solve the 5x5 Rubik's Cube","Z3"},
 | |
| 49 | 49 | } | 
| 50 | 50 | ), | 
| 51 | 51 |  | 
| 52 | 52 | PYRA3 ( ObjectList.PYRA, 3, | 
| 53 | 53 |           new String[][] {
 | 
| 54 |                           {"GB","xIQtn2qazvg","Pyraminx Layer By Layer","Z3"},
 | |
| 54 |                           {"gb","xIQtn2qazvg","Pyraminx Layer By Layer","Z3"},
 | |
| 55 | 55 | } | 
| 56 | 56 | ), | 
| 57 | 57 |  | 
| 58 | 58 | PYRA4 ( ObjectList.PYRA, 4, | 
| 59 | 59 |           new String[][] {
 | 
| 60 |                           {"GB","tGQDqDcSa6U","How to Solve the Master (4x4) Pyraminx","Z3"},
 | |
| 60 |                           {"gb","tGQDqDcSa6U","How to Solve the Master (4x4) Pyraminx","Z3"},
 | |
| 61 | 61 | } | 
| 62 | 62 | ), | 
| 63 | 63 |  | 
| 64 | 64 | PYRA5 ( ObjectList.PYRA, 5, | 
| 65 | 65 |           new String[][] {
 | 
| 66 |                           {"GB","2nsPEECDdN0","Professor Pyraminx Solve","RedKB"},
 | |
| 66 |                           {"gb","2nsPEECDdN0","Professor Pyraminx Solve","RedKB"},
 | |
| 67 | 67 | } | 
| 68 | 68 | ), | 
| 69 | 69 |  | 
| 70 | 70 | DIAM2 ( ObjectList.DIAM, 2, | 
| 71 | 71 |           new String[][] {
 | 
| 72 |                           {"GB","R2wrbJJ3izM","How to Solve a Skewb Diamond","Dr. Penguin^3"},
 | |
| 72 |                           {"gb","R2wrbJJ3izM","How to Solve a Skewb Diamond","Dr. Penguin^3"},
 | |
| 73 | 73 | } | 
| 74 | 74 | ), | 
| 75 | 75 |  | 
| 76 | 76 | DINO3 ( ObjectList.DINO, 3, | 
| 77 | 77 |           new String[][] {
 | 
| 78 |                           {"GB","puTJZqFBQwo","Dino Skewb Cube Tutorial","Bearded Cubing"},
 | |
| 78 |                           {"gb","puTJZqFBQwo","Dino Skewb Cube Tutorial","Bearded Cubing"},
 | |
| 79 | 79 | } | 
| 80 | 80 | ), | 
| 81 | 81 |  | 
| 82 | 82 | REDI3 ( ObjectList.REDI, 3, | 
| 83 | 83 |           new String[][] {
 | 
| 84 |                           {"GB","Qn7TJED6O-4","How to Solve the MoYu Redi Cube","Z3"},
 | |
| 84 |                           {"gb","Qn7TJED6O-4","How to Solve the MoYu Redi Cube","Z3"},
 | |
| 85 | 85 | } | 
| 86 | 86 | ), | 
| 87 | 87 |  | 
| 88 | 88 | HELI3 ( ObjectList.HELI, 3, | 
| 89 | 89 |           new String[][] {
 | 
| 90 |                           {"GB","-suwJpd_PO8","Helicopter Cube Tutorial","Bearded Cubing"},
 | |
| 90 |                           {"gb","-suwJpd_PO8","Helicopter Cube Tutorial","Bearded Cubing"},
 | |
| 91 | 91 | } | 
| 92 | 92 | ), | 
| 93 | 93 |  | 
| 94 | 94 | SKEW2 ( ObjectList.SKEW, 2, | 
| 95 | 95 |           new String[][] {
 | 
| 96 |                           {"GB","I6132yshkeU","How to Solve the Skewb","Z3"},
 | |
| 96 |                           {"gb","I6132yshkeU","How to Solve the Skewb","Z3"},
 | |
| 97 | 97 | } | 
| 98 | 98 | ), | 
| 99 | 99 |  | 
| 100 | 100 | SKEW3 ( ObjectList.SKEW, 3, | 
| 101 | 101 |           new String[][] {
 | 
| 102 |                           {"GB","Jiuf7zQyPYI","Master Skewb Cube Tutorial","Bearded Cubing"},
 | |
| 102 |                           {"gb","Jiuf7zQyPYI","Master Skewb Cube Tutorial","Bearded Cubing"},
 | |
| 103 | 103 | } | 
| 104 | 104 | ), | 
| 105 | 105 |  | 
| 106 | 106 | IVY2 ( ObjectList.IVY, 2, | 
| 107 | 107 |           new String[][] {
 | 
| 108 |                           {"GB","QMzeJobSu1M","How to Solve the Ivy Cube","Z3"},
 | |
| 108 |                           {"gb","QMzeJobSu1M","How to Solve the Ivy Cube","Z3"},
 | |
| 109 | 109 | } | 
| 110 | 110 | ); | 
| 111 | 111 |  | 
| ... | ... | |
| 165 | 165 | return -1; | 
| 166 | 166 | } | 
| 167 | 167 |  | 
| 168 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 169 |  | |
| 170 | public int getNumTutorials() | |
| 171 |     {
 | |
| 172 | return mNumTutorials; | |
| 173 | } | |
| 174 |  | |
| 168 | 175 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 169 | 176 |  | 
| 170 | 177 | public int getIconID() | 
| src/main/res/layout/dialog_tutorial_row.xml | ||
|---|---|---|
| 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | <Button xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | android:id="@+id/tutorialRowButton" | |
| 4 | android:layout_width="match_parent" | |
| 5 | android:layout_height="match_parent" | |
| 6 | android:paddingStart="5dp" | |
| 7 | android:paddingEnd="5dp" | |
| 8 | android:textSize="20sp" | |
| 9 | android:maxLines="1" | |
| 10 | android:gravity="center"/> | |
| 11 |  | |
Also available in: Unified diff
Progress creating the Tutorial Dialog.