Project

General

Profile

« Previous | Next » 

Revision b710a574

Added by Leszek Koltunski about 1 year ago

Progress with tutorials.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogTutorial.java
59 59
  public boolean hasArgument()  { return false; }
60 60
  public int getPositive()      { return R.string.ok; }
61 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
    }
62
  public void positiveAction()  { }
63
  public void negativeAction()  { }
76 64

  
77 65
///////////////////////////////////////////////////////////////////////////////////////////////////
78 66

  
src/main/java/org/distorted/dialogs/RubikDialogTutorialSingle.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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 static android.view.View.inflate;
13

  
14
import android.app.Dialog;
15
import android.content.res.Resources;
16
import android.util.TypedValue;
17
import android.view.View;
18
import android.view.Window;
19
import android.view.WindowManager;
20
import android.widget.Button;
21
import android.widget.ImageView;
22
import android.widget.LinearLayout;
23
import android.widget.TextView;
24

  
25
import androidx.fragment.app.FragmentActivity;
26

  
27
import org.distorted.main.R;
28
import org.distorted.objectlib.json.JsonReader;
29
import org.distorted.objects.RubikObject;
30
import org.distorted.objects.RubikObjectList;
31
import org.distorted.tutorials.TutorialActivity;
32

  
33
import java.io.InputStream;
34

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

  
37
public class RubikDialogTutorialSingle extends RubikDialogAbstract
38
  {
39
  public static final float PANE_HEIGHT  = 0.06f;
40
  private Dialog mDialog;
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
  @Override
45
  public void onResume()
46
    {
47
    super.onResume();
48

  
49
    Window window = getDialog().getWindow();
50

  
51
    if( window!=null )
52
      {
53
      WindowManager.LayoutParams params = window.getAttributes();
54
      params.width  = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
55
      //params.height = (int)Math.min( mHeight*0.85f,mWidth*1.30f );
56
      window.setAttributes(params);
57
      }
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
  public int getResource()      { return R.layout.dialog_tutorial_single; }
63
  public int getTitleResource() { return R.string.tutorials; }
64
  public boolean hasArgument()  { return true; }
65
  public int getPositive()      { return -1; }
66
  public int getNegative()      { return -1; }
67
  public void positiveAction()  { }
68
  public void negativeAction()  { }
69

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

  
72
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
73
    {
74
    mDialog = dialog;
75

  
76
    int objectOrdinal = RubikObjectList.getOrdinal(mArgument);
77

  
78
    android.util.Log.e("D", "dialog tutorial: object "+mArgument);
79

  
80
    if( objectOrdinal<0 )
81
      {
82
      android.util.Log.e("D", "object "+mArgument+" not found");
83
      return;
84
      }
85
    RubikObject robject = RubikObjectList.getObject(objectOrdinal);
86
    InputStream jsonStream = robject==null ? null : robject.getExtrasStream(act);
87
    String[][] tutorials=null;
88

  
89
    if( jsonStream!=null )
90
      {
91
      try
92
        {
93
        JsonReader reader = new JsonReader();
94
        reader.parseJsonTutorial(jsonStream);
95
        tutorials = reader.getTutorials();
96
        }
97
      catch(Exception ignored) { }
98
      }
99

  
100
    if( tutorials!=null )
101
      {
102
      int paneSize = (int)(mHeight*PANE_HEIGHT);
103
      Resources res = act.getResources();
104
      String packageName = act.getPackageName();
105

  
106
      LinearLayout layout = view.findViewById(R.id.tutLayout);
107

  
108
      int colorB = getResources().getColor(R.color.light_grey);
109
      int colorT = getResources().getColor(R.color.white);
110

  
111
      int numTuts = tutorials.length;
112

  
113
      for( int t=0; t<numTuts; t++)
114
        {
115
        String[] tutorial = tutorials[t];
116

  
117
        String coun = tutorial[0];
118
        String url  = tutorial[1];
119
        String desc = tutorial[2];
120
        String auth = tutorial[3];
121

  
122
        int countryID = res.getIdentifier(coun, "drawable", packageName);
123

  
124
        View row = createRow(act, countryID, desc, url, auth, paneSize, colorB, colorT, t==(numTuts-1) );
125
        layout.addView(row);
126
        }
127
      }
128
    }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
  private View createRow(final FragmentActivity act, int countryID, final String desc, final String url,
133
                         final String auth, int size, int colorB, int colorT, boolean last)
134
    {
135
    float textSize = 0.43f*size;
136
    View row = inflate( act, R.layout.dialog_tutorial_row, null);
137

  
138
    LinearLayout layout = row.findViewById(R.id.tutorialLayout);
139
    layout.setMinimumHeight(size);
140

  
141
    Button butt = row.findViewById(R.id.tutorialButton);
142
    butt.setText(R.string.view);
143
    butt.setTextColor(colorT);
144
    butt.setBackgroundColor(colorB);
145
    butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
146
    butt.setHeight(size);
147

  
148
    final TutorialActivity tact = (TutorialActivity)getContext();
149

  
150
    butt.setOnClickListener( new View.OnClickListener()
151
      {
152
      @Override
153
      public void onClick(View v)
154
        {
155
        mDialog.dismiss();
156
        if( tact!=null ) tact.loadTutorial(url);
157
        }
158
      });
159

  
160
    ImageView image = row.findViewById(R.id.tutorialCountry);
161
    int id = countryID!=0 ? countryID : org.distorted.flags.R.drawable.unknown;
162
    image.setImageResource(id);
163

  
164
    TextView author = row.findViewById(R.id.tutorialAuthor);
165
    author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
166
    author.setText(auth);
167

  
168
    TextView title  = row.findViewById(R.id.tutorialTitle);
169
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
170
    title.setText(desc);
171

  
172
    if( last )
173
      {
174
      int m = 20;
175
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
176
      params.bottomMargin = m;
177
      params.leftMargin   = m;
178
      params.rightMargin  = m;
179
      layout.setLayoutParams(params);
180
      }
181

  
182
    return row;
183
    }
184

  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

  
187
  public static String getDialogTag()
188
    {
189
    return "DialogTutorialSingle";
190
    }
191
  }
src/main/java/org/distorted/main/MainActivity.java
359 359

  
360 360
///////////////////////////////////////////////////////////////////////////////////////////////////
361 361

  
362
    public void switchToTutorial(String url, int objectOrdinal)
362
    public void switchToTutorial(int objectOrdinal)
363 363
      {
364 364
      Intent intent = new Intent(this, TutorialActivity.class);
365
      intent.putExtra("url", url);
366 365
      intent.putExtra("obj", objectOrdinal);
367 366
      startActivity(intent);
368 367
      }
src/main/java/org/distorted/main/MainObjectPopup.java
111 111
        @Override
112 112
        public void onClick(View v)
113 113
          {
114

  
114
          mPopup.dismiss();
115
          act.switchToTutorial(ordinal);
115 116
          }
116 117
        });
117 118
      }
src/main/java/org/distorted/tutorials/TutorialActivity.java
11 11

  
12 12
import java.io.InputStream;
13 13

  
14
import android.content.Intent;
15 14
import android.os.Build;
16 15
import android.os.Bundle;
17 16
import android.util.DisplayMetrics;
......
23 22

  
24 23
import androidx.appcompat.app.AppCompatActivity;
25 24

  
25
import org.distorted.dialogs.RubikDialogTutorialSingle;
26 26
import org.distorted.library.main.DistortedLibrary;
27 27

  
28
import org.distorted.main_old.RubikActivity;
28
import org.distorted.main.MainActivity;
29 29
import org.distorted.objectlib.main.InitAssets;
30 30
import org.distorted.objectlib.main.ObjectControl;
31 31
import org.distorted.objectlib.main.TwistyObject;
......
35 35
import org.distorted.objects.RubikObject;
36 36
import org.distorted.objects.RubikObjectList;
37 37
import org.distorted.os.OSInterface;
38
import org.distorted.purchase.PurchaseActivity;
39 38

  
40 39
///////////////////////////////////////////////////////////////////////////////////////////////////
41 40

  
......
44 43
    private static final String URL = "https://www.youtube.com/embed/";
45 44
    private static final int ACTIVITY_NUMBER = 1;
46 45
    public static final float BAR_RATIO = 0.17f;
47
    public static final int FLAGS = RubikActivity.FLAGS;
46
    public static final int FLAGS = MainActivity.FLAGS;
48 47

  
49 48
    private static int mScreenWidth, mScreenHeight;
50 49
    private int mCurrentApiVersion;
51 50
    private TutorialScreen mScreen;
52
    private String mURL;
53 51
    private int mObjectOrdinal;
54 52
    private TutorialWebView mWebView;
55 53
    private boolean mIsFree;
......
70 68

  
71 69
      if(b != null)
72 70
        {
73
        mURL           = b.getString("url");
74 71
        mObjectOrdinal = b.getInt("obj");
75 72
        RubikObject obj= RubikObjectList.getObject(mObjectOrdinal);
76 73
        mIsFree = (obj!=null && obj.isFree());
......
83 80

  
84 81
      hideNavigationBar();
85 82
      cutoutHack();
83
      showDialog();
84
      }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
    private void showDialog()
89
      {
90
      RubikObjectList.setCurrObject(mObjectOrdinal);
91
      Bundle bundle = new Bundle();
92
      bundle.putString("argument",RubikObjectList.getCurrentName());
93
      RubikDialogTutorialSingle diag = new RubikDialogTutorialSingle();
94
      diag.setArguments(bundle);
95
      diag.show( getSupportFragmentManager(), RubikDialogTutorialSingle.getDialogTag() );
86 96
      }
87 97

  
88 98
///////////////////////////////////////////////////////////////////////////////////////////////////
......
113 123

  
114 124
///////////////////////////////////////////////////////////////////////////////////////////////////
115 125

  
116
    @Override
117
    public void onAttachedToWindow()
126
    public void loadTutorial(String url)
118 127
      {
119
      super.onAttachedToWindow();
120

  
121 128
      if( mWebView==null )
122 129
        {
123 130
        WebView videoView = findViewById(R.id.tutorialVideoView);
124 131
        mWebView = new TutorialWebView(videoView);
125
        mWebView.load(URL+mURL);
132
        mWebView.load(URL+url);
126 133
        }
127 134
      }
128 135

  
......
262 269
      TutorialSurfaceView view = findViewById(R.id.tutorialSurfaceView);
263 270
      return view.getObjectControl();
264 271
      }
265

  
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267

  
268
    public void switchToPurchase()
269
      {
270
      Intent intent = new Intent(this, PurchaseActivity.class);
271
      intent.putExtra("obj", mObjectOrdinal);
272
      startActivity(intent);
273
      }
274 272
}
src/main/java/org/distorted/tutorials/TutorialScreen.java
42 42
      @Override
43 43
      public void onClick(View v)
44 44
        {
45
        act.switchToPurchase();
45
        //act.switchToPurchase();
46 46
        }
47 47
      });
48 48
    }
src/main/res/layout/dialog_tutorial_single.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:id="@+id/tutScrollView"
4
    android:layout_width="match_parent"
5
    android:layout_height="match_parent">
6

  
7
    <LinearLayout
8
        android:id="@+id/tutLayout"
9
        android:layout_width="match_parent"
10
        android:layout_height="wrap_content"
11
        android:orientation="vertical" >
12
    </LinearLayout>
13

  
14
</ScrollView>

Also available in: Unified diff