Project

General

Profile

« Previous | Next » 

Revision 5b4eaf7e

Added by Leszek Koltunski about 4 years ago

Progress creating the Tutorial Dialog.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogScoresView.java
43 43
public class RubikDialogScoresView extends FrameLayout
44 44
  {
45 45
  private LinearLayout mLayout;
46
  private int mWidth;
46
  private int mHeight;
47 47

  
48 48
///////////////////////////////////////////////////////////////////////////////////////////////////
49 49

  
......
61 61

  
62 62
///////////////////////////////////////////////////////////////////////////////////////////////////
63 63

  
64
  public RubikDialogScoresView(Context context, int width, boolean isSubmitting)
64
  public RubikDialogScoresView(Context context, int height, boolean isSubmitting)
65 65
    {
66 66
    super(context);
67 67

  
68
    mWidth = width;
68
    mHeight = height;
69 69

  
70 70
    View view = inflate(context, R.layout.dialog_scores_downloading, null);
71 71
    addView(view);
......
82 82
    TextView text = levelLayout.findViewById(R.id.scoresScrambleTitle);
83 83
    text.setText(act.getString(R.string.lv_placeholder,level+1));
84 84

  
85
    int size = (int)(mWidth* RubikActivity.SCORES_LEVEL_TEXT);
85
    int size = (int)(mHeight*RubikActivity.SCORES_LEVEL_TEXT);
86 86
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
87 87

  
88 88
    Resources res = act.getResources();
......
103 103
    String theirTime;
104 104
    int theirCountryID;
105 105

  
106
    int height = (int)(mWidth* RubikActivity.SCORES_ITEM_TEXT);
106
    int height = (int)(mHeight* RubikActivity.SCORES_ITEM_TEXT);
107 107
    int white = res.getColor(R.color.white);
108 108
    int red   = res.getColor(R.color.red);
109 109
    boolean equals;
src/main/java/org/distorted/dialogs/RubikDialogTutorial.java
98 98

  
99 99
    ViewPager viewPager = view.findViewById(R.id.viewpager);
100 100
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
101
    mPagerAdapter = new RubikDialogTutorialPagerAdapter(act, viewPager, this);
101
    mPagerAdapter = new RubikDialogTutorialPagerAdapter(act,viewPager);
102 102
    tabLayout.setupWithViewPager(viewPager);
103 103
    viewPager.setCurrentItem(curTab);
104 104

  
src/main/java/org/distorted/dialogs/RubikDialogTutorialPagerAdapter.java
19 19

  
20 20
package org.distorted.dialogs;
21 21

  
22
import android.util.DisplayMetrics;
22 23
import android.view.View;
23 24
import android.view.ViewGroup;
24 25

  
......
35 36
  {
36 37
  private FragmentActivity mAct;
37 38
  private RubikDialogTutorialView[] mViews;
38
  private RubikDialogTutorial mDialog;
39
  private int mNumTabs;
39

  
40
  private int mNumTabs, mHeight;
40 41

  
41 42
///////////////////////////////////////////////////////////////////////////////////////////////////
42 43

  
43
  RubikDialogTutorialPagerAdapter(FragmentActivity act, ViewPager viewPager, RubikDialogTutorial dialog)
44
  RubikDialogTutorialPagerAdapter(FragmentActivity act, ViewPager viewPager)
44 45
    {
45 46
    mAct = act;
46
    mDialog = dialog;
47 47
    mNumTabs = TutorialList.NUM_OBJECTS;
48 48
    mViews = new RubikDialogTutorialView[mNumTabs];
49 49

  
......
64 64
  @NonNull
65 65
  public Object instantiateItem(@NonNull ViewGroup collection, final int position)
66 66
    {
67
    mViews[position] = new RubikDialogTutorialView(mAct, mDialog, position);
67
    DisplayMetrics metrics = mAct.getResources().getDisplayMetrics();
68

  
69
    mViews[position] = new RubikDialogTutorialView(mAct, metrics.heightPixels, position);
68 70
    collection.addView(mViews[position]);
69 71

  
70 72
    return mViews[position];
src/main/java/org/distorted/dialogs/RubikDialogTutorialView.java
21 21

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

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

  
36 36
import org.distorted.main.R;
......
60 60

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

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

  
67
    //int height = (int)(mWidth* RubikActivity.TUTORIAL_ITEM_TEXT);
68
    int height = 50;
67
    int heightT = (int)(height* RubikActivity.TUTORIAL_ITEM_TEXT);
69 68

  
70 69
    RubikActivity ract = (RubikActivity)getContext();
71 70
    Resources res = act.getResources();
......
85 84
      String coun = mList.getTutorialLanguage(i);
86 85
      String desc = mList.getTutorialDescription(i);
87 86
      String url  = mList.getTutorialURL(i);
87
      String auth = mList.getTutorialAuthor(i);
88 88

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

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

  
......
97 97

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

  
100
  private View createRow(final RubikActivity act, int countryID, final String desc, final String url, int height, final ObjectList obj, final int size)
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 101
    {
102
    int id = countryID!=0 ? countryID : R.drawable.un;
103

  
104 102
    View row = inflate( act, R.layout.dialog_tutorial_row, null);
105 103
    Button butt = row.findViewById(R.id.tutorialRowButton);
106 104

  
107
    butt.setPadding(20,0,0,0);
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);
108 110

  
109
    butt.setCompoundDrawablesWithIntrinsicBounds(id,0,0,0);
110
    butt.setText(desc);
111
    butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.7f*height);
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);
112 114

  
113 115
    butt.setOnClickListener( new View.OnClickListener()
114 116
      {
src/main/java/org/distorted/main/RubikActivity.java
67 67
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
68 68
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
69 69
    public static final float SCORES_ITEM_TEXT    = 0.030f;
70
    public static final float TUTORIAL_ITEM_TEXT  = 0.050f;
70 71
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
71 72
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
72 73
    public static final float MENU_MED_TEXT_SIZE  = 0.04f;
src/main/java/org/distorted/tutorial/TutorialActivity.java
37 37
import org.distorted.main.R;
38 38
import org.distorted.objects.ObjectList;
39 39
import org.distorted.objects.TwistyObject;
40
import org.distorted.states.RubikStatePlay;
41 40
import org.distorted.states.StateList;
42 41

  
43 42
import static org.distorted.main.RubikRenderer.BRIGHTNESS;
......
67 66
    private TutorialState mState;
68 67
    private String mURL;
69 68
    private int mObjectOrdinal, mObjectSize;
69
    private TutorialWebView mWebView;
70 70

  
71 71
///////////////////////////////////////////////////////////////////////////////////////////////////
72 72

  
......
153 153
      mState.createRightPane(this,width);
154 154

  
155 155
      WebView videoView = findViewById(R.id.tutorialVideoView);
156
      TutorialWebView webView = new TutorialWebView(this,videoView);
157
      webView.load(URL+mURL);
156
      mWebView = new TutorialWebView(this,videoView);
157
      mWebView.load(URL+mURL);
158 158
      }
159 159

  
160 160
///////////////////////////////////////////////////////////////////////////////////////////////////
......
189 189
      super.onPause();
190 190
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
191 191
      view.onPause();
192
      mWebView.onPause();
192 193
      DistortedLibrary.onPause(1);
193 194
      }
194 195

  
src/main/java/org/distorted/tutorial/TutorialList.java
34 34
  CUBE3 ( ObjectList.CUBE, 3,
35 35
          new String[][] {
36 36
                          {"gb","-8ohoCKN0Zw","How to Solve a Rubik's Cube","Z3"},
37
                          {"pl","cBU9Y729nQM","Jak ułożyć kostkę Rubika 3x3x3","DżoDżo"},
37 38
                         }
38 39
        ),
39 40

  
src/main/java/org/distorted/tutorial/TutorialWebView.java
102 102
      return returnString.toString();
103 103
      }
104 104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

  
107
    public void onPause()
108
      {
109
      mWebView.onPause();
110
      }
111

  
105 112
///////////////////////////////////////////////////////////////////////////////////////////////////
106 113

  
107 114
    public void reload()
src/main/res/layout/dialog_tutorial_row.xml
2 2
<Button xmlns:android="http://schemas.android.com/apk/res/android"
3 3
    android:id="@+id/tutorialRowButton"
4 4
    android:layout_width="match_parent"
5
    android:layout_height="100dp"
6
    android:paddingStart="5dp"
7
    android:paddingEnd="5dp"
8
    android:maxLines="1"
9
    android:gravity="center"/>
10

  
5
    android:layout_height="wrap_content"
6
    android:paddingRight="15dp"
7
    android:paddingLeft="15dp"
8
    android:singleLine="true"
9
    android:textAllCaps="false"
10
    android:gravity="center"/>

Also available in: Unified diff