Project

General

Profile

« Previous | Next » 

Revision 2971588c

Added by Leszek Koltunski about 4 years ago

Progress creating the Tutorial Activity.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogInfo.java
21 21

  
22 22
import android.app.Dialog;
23 23
import android.content.DialogInterface;
24
import android.content.Intent;
25 24
import android.os.Bundle;
26 25
import android.util.DisplayMetrics;
27 26
import android.util.TypedValue;
......
39 38
import org.distorted.main.R;
40 39
import org.distorted.main.RubikActivity;
41 40
import org.distorted.objects.TwistyObject;
42
import org.distorted.tutorial.TutorialActivity;
43 41

  
44 42
///////////////////////////////////////////////////////////////////////////////////////////////////
45 43

  
......
75 73
      public void onClick(DialogInterface dialog, int which)
76 74
        {
77 75
        RubikActivity ract = (RubikActivity)getContext();
78
        if( ract!=null ) ract.switchTutorial();
76
        if( ract!=null ) ract.switchTutorial("QMzeJobSu1M");
79 77
        }
80 78
      });
81 79

  
src/main/java/org/distorted/main/RubikActivity.java
555 555

  
556 556
///////////////////////////////////////////////////////////////////////////////////////////////////
557 557

  
558
    public void switchTutorial()
558
    public void switchTutorial(String url)
559 559
      {
560 560
      Intent myIntent = new Intent(this, TutorialActivity.class);
561
    //myIntent.putExtra("", value); //Optional parameters
561
      myIntent.putExtra("url", url);
562 562
      startActivity(myIntent);
563 563
      }
564 564
}
src/main/java/org/distorted/states/RubikStateBase.java
23 23
import android.widget.ImageButton;
24 24
import android.widget.LinearLayout;
25 25

  
26
import org.distorted.dialogs.RubikDialogInfo;
27 26
import org.distorted.main.R;
28 27
import org.distorted.main.RubikActivity;
29 28
import org.distorted.main.RubikPreRender;
......
37 36
  {
38 37
  private static final int DURATION_MILLIS = 750;
39 38

  
40
  private ImageButton mPrevButton, mLockButton, mInfoButton;
39
  private ImageButton mPrevButton, mLockButton;
41 40

  
42 41
  private boolean mCanPrevMove;
43 42

  
......
133 132
    layoutLeft.addView(mPrevButton);
134 133
    setupLockButton(act,width);
135 134
    layoutMid.addView(mLockButton);
136
    setupInfoButton(act,width);
137
    layoutMid.addView(mInfoButton);
138 135
    layoutRight.addView(button);
139 136

  
140 137
    layoutBot.addView(layoutLeft);
......
159 156
      });
160 157
    }
161 158

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
  void setupInfoButton(final RubikActivity act, final float width)
165
    {
166
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_info,R.drawable.ui_medium_info, R.drawable.ui_big_info, R.drawable.ui_huge_info);
167
    mInfoButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
168

  
169
    mInfoButton.setOnClickListener( new View.OnClickListener()
170
      {
171
      @Override
172
      public void onClick(View v)
173
        {
174
        RubikDialogInfo infoDiag = new RubikDialogInfo();
175
        infoDiag.show(act.getSupportFragmentManager(), null);
176
        }
177
      });
178
    }
179

  
180 159
///////////////////////////////////////////////////////////////////////////////////////////////////
181 160

  
182 161
  void setupPrevButton(final RubikActivity act, final float width)
src/main/java/org/distorted/states/RubikStatePlay.java
35 35
import androidx.fragment.app.FragmentManager;
36 36

  
37 37
import org.distorted.dialogs.RubikDialogAbout;
38
import org.distorted.dialogs.RubikDialogInfo;
38 39
import org.distorted.dialogs.RubikDialogPattern;
39 40
import org.distorted.dialogs.RubikDialogScores;
40 41
import org.distorted.main.R;
......
50 51
  public  static final int DEF_OBJECT= ObjectList.CUBE.ordinal();
51 52
  public  static final int DEF_SIZE  =  3;
52 53

  
53
  private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about };
54
  private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.tutorials, R.string.about };
54 55
  private static final int NUM_BUTTONS = BUTTON_LABELS.length;
55 56

  
56 57
  private ImageButton mObjButton, mMenuButton, mSolveButton;
......
395 396
              break;
396 397
      case 2: StateList.switchState(act, StateList.SVER);
397 398
              break;
398
      case 3: RubikDialogAbout aDiag = new RubikDialogAbout();
399
      case 3: RubikDialogInfo infoDiag = new RubikDialogInfo();
400
              infoDiag.show(act.getSupportFragmentManager(), null);
401
              break;
402
      case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
399 403
              aDiag.show(act.getSupportFragmentManager(), null);
400 404
              break;
401 405
      }
src/main/java/org/distorted/tutorial/TutorialActivity.java
46 46

  
47 47
public class TutorialActivity extends AppCompatActivity
48 48
{
49
    private static final String URL = "https://www.youtube.com/embed/";
50

  
49 51
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
50 52
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
51 53

  
......
62 64
    private FirebaseAnalytics mFirebaseAnalytics;
63 65
    private static int mScreenWidth, mScreenHeight;
64 66
    private int mCurrentApiVersion;
65
    private WebView mWebView;
66 67
    private TutorialState mState;
68
    private String mURL;
67 69

  
68 70
///////////////////////////////////////////////////////////////////////////////////////////////////
69 71

  
......
75 77
      setTheme(R.style.CustomActivityThemeNoActionBar);
76 78
      setContentView(R.layout.tutorial);
77 79

  
80
      Bundle b = getIntent().getExtras();
81

  
82
      if(b != null) mURL = b.getString("url");
83

  
78 84
      mIsLocked = false;
79 85
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
80 86

  
......
128 134
      paramsL.width = (int)(width*(1.0f-RATIO));
129 135
      viewL.setLayoutParams(paramsL);
130 136

  
131
      LinearLayout viewR = findViewById(R.id.rightBar);
137
      LinearLayout viewR = findViewById(R.id.tutorialRightBar);
132 138
      ViewGroup.LayoutParams paramsR = viewR.getLayoutParams();
133 139
      paramsR.width = (int)(width*RATIO);
134 140
      viewR.setLayoutParams(paramsR);
......
139 145
      if( mState==null ) mState = new TutorialState();
140 146

  
141 147
      mState.createRightPane(this,width);
148

  
149
      WebView videoView = findViewById(R.id.tutorialVideoView);
150
      TutorialWebView webView = new TutorialWebView(this,videoView);
151
      webView.load(URL+mURL);
142 152
      }
143 153

  
144 154
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/tutorial/TutorialState.java
213 213
    if( mMoves==null ) mMoves = new ArrayList<>();
214 214
    else               mMoves.clear();
215 215

  
216
    LinearLayout layout = act.findViewById(R.id.rightBar);
216
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
217 217
    layout.removeAllViews();
218 218

  
219 219
    setupPrevButton(act,width);
src/main/java/org/distorted/tutorial/TutorialSurfaceView.java
1 1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
2
// Copyright 2020 Leszek Koltunski                                                               //
3 3
//                                                                                               //
4 4
// This file is part of Magic Cube.                                                              //
5 5
//                                                                                               //
......
32 32

  
33 33
import org.distorted.library.type.Static2D;
34 34
import org.distorted.library.type.Static4D;
35
import org.distorted.main.RubikActivity;
36 35
import org.distorted.objects.Movement;
37 36
import org.distorted.objects.TwistyObject;
38
import org.distorted.states.RubikStateSolving;
39
import org.distorted.states.StateList;
40 37

  
41 38
///////////////////////////////////////////////////////////////////////////////////////////////////
42 39

  
src/main/java/org/distorted/tutorial/TutorialWebView.java
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.tutorial;
21

  
22
import android.annotation.SuppressLint;
23
import android.content.Context;
24
import android.content.res.Resources;
25
import android.webkit.WebSettings;
26
import android.webkit.WebView;
27

  
28
import org.distorted.main.R;
29

  
30
import java.io.BufferedReader;
31
import java.io.InputStream;
32
import java.io.InputStreamReader;
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
public class TutorialWebView
37
{
38
    private String  mUrl;
39
    private Context mContext;
40
    private WebView mWebView;
41

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

  
44
    @SuppressLint("SetJavaScriptEnabled")
45
    public TutorialWebView(Context context, WebView webview)
46
      {
47
      mWebView = webview;
48
      mContext = context;
49
      mWebView.setBackgroundColor(0);
50
      mWebView.getSettings().setJavaScriptEnabled(true);
51
      }
52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
    public void load(String url)
56
      {
57
      mUrl = url;
58
      String data = readFromfile(mContext);
59
      data = data.replace("%1", url);
60

  
61
android.util.Log.e("webview", "data= "+data);
62

  
63
mWebView.getSettings().setAppCacheMaxSize( 10 * 1024 * 1024 ); // 10MB
64
mWebView.getSettings().setAppCachePath(mContext.getCacheDir().getAbsolutePath() );
65
mWebView.getSettings().setAllowFileAccess( true );
66
mWebView.getSettings().setAppCacheEnabled( true );
67
mWebView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT );
68

  
69
      mWebView.loadData(data, "text/html", "UTF-8");
70
      }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
    public String readFromfile(Context context)
75
      {
76
      StringBuilder returnString = new StringBuilder();
77
      InputStream fIn       = null;
78
      InputStreamReader isr = null;
79
      BufferedReader input  = null;
80

  
81
      try
82
        {
83
        Resources res = context.getResources();
84
        fIn = res.openRawResource(R.raw.webvideo);
85
        isr = new InputStreamReader(fIn);
86
        input = new BufferedReader(isr);
87
        String line;
88

  
89
        while ((line = input.readLine()) != null)
90
          {
91
          returnString.append(line);
92
          }
93
        }
94
      catch (Exception e)
95
        {
96
        e.getMessage();
97
        }
98
      finally
99
        {
100
        try
101
          {
102
          if (isr   != null) isr.close();
103
          if (fIn   != null) fIn.close();
104
          if (input != null) input.close();
105
          }
106
        catch (Exception e2)
107
          {
108
          e2.getMessage();
109
          }
110
        }
111

  
112
      return returnString.toString();
113
      }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
    public void reload()
118
      {
119
      if (mUrl!=null)
120
        {
121
        load(mUrl);
122
        }
123
      }
124
}
src/main/res/layout/tutorial.xml
8 8
    android:orientation="vertical" >
9 9

  
10 10
    <WebView
11
        android:id="@+id/videoview"
11
        android:id="@+id/tutorialVideoView"
12 12
        android:layout_width="match_parent"
13 13
        android:layout_height="0dp"
14 14
        android:layout_weight="1"/>
15 15

  
16 16
    <LinearLayout
17
        android:id="@+id/lowerPart"
17
        android:id="@+id/tutorialLowerPart"
18 18
        android:layout_width="match_parent"
19 19
        android:layout_height="0dp"
20 20
        android:layout_weight="1.2"
......
27 27
           android:layout_height="match_parent"/>
28 28

  
29 29
        <LinearLayout
30
           android:id="@+id/rightBar"
30
           android:id="@+id/tutorialRightBar"
31 31
           android:layout_width="0dp"
32 32
           android:layout_height="match_parent"
33 33

  
src/main/res/raw/webvideo.html
1
<!DOCTYPE html>
2
<html lang="en">
3
    <head>
4
        <meta charset="utf-8">
5
        <style>
6
            iframe   { border: 0; position:fixed; width:100%; height:100%; bgcolor="#000000"; }
7
            body     { margin: 0; bgcolor="#000000"; }
8
        </style>
9
    </head>
10
    <body>
11
        <iframe src="%1" frameborder="0" allowfullscreen></iframe>
12
    </body>
13
</html>
src/main/res/values-de/strings.xml
34 34
    <string name="new_name_try_again">Der von Ihnen ausgewählte Name %s ist bereits vergeben. Versuchen Sie es noch einmal:</string>
35 35
    <string name="downloading">Wird heruntergeladen…</string>
36 36
    <string name="submitting">Einreichen…</string>
37
    <string name="tutorial">Sehen Sie sich ein Tutorial an?</string>
37
    <string name="tutorial">Sehen Sie sich ein Lernprogramm an?</string>
38
    <string name="tutorials">Lernprogrammen</string>
38 39

  
39 40
    <string name="credits1">Open Source App, die mit der Distorted Graphics Library entwickelt wurde. Lizenziert unter <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL Version 2</a> oder wie gewünscht einer späteren Version.</string>
40 41
    <string name="credits2">Hübsche Muster von Walter Randelshofer. Sehen Sie <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-es/strings.xml
35 35
    <string name="downloading">Descargando…</string>
36 36
    <string name="submitting">Enviando…</string>
37 37
    <string name="tutorial">¿Ver un tutorial?</string>
38
    <string name="tutorials">Tutoriales</string>
38 39

  
39 40
    <string name="credits1">Aplicación de código abierto desarrollada con la biblioteca de gráficos de Distorted. Con licencia <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL versión 2</a> o, a tu elección, cualquier versión posterior.</string>
40 41
    <string name="credits2">Pretty Patterns por Walter Randelshofer. Mira <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-fr/strings.xml
35 35
    <string name="downloading">Téléchargement…</string>
36 36
    <string name="submitting">Soumission…</string>
37 37
    <string name="tutorial">Regarder un tutoriel?</string>
38
    <string name="tutorials">Tutoriels</string>
38 39

  
39 40
    <string name="credits1">Appli Open Source développée à l\'aide de la bibliothèque graphique Distorted. Sous licence <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL version 2</a> ou - à votre choix - toute version ultérieure.</string>
40 41
    <string name="credits2">Pretty Patterns par Walter Randelshofer. Voir <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-it/strings.xml
35 35
    <string name="downloading">Download in corso…</string>
36 36
    <string name="submitting">Invio in corso…</string>
37 37
    <string name="tutorial">Guarda un tutorial?</string>
38
    <string name="tutorials">Tutorial</string>
38 39

  
39 40
    <string name="credits1">App open source sviluppata utilizzando la libreria grafica distorta. Licenza sotto <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL versione 2</a> o - a tua scelta - qualsiasi versione successiva.</string>
40 41
    <string name="credits2">Pretty Patterns di Walter Randelshofer. Vedere <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-ja/strings.xml
35 35
    <string name="downloading">ダウンロードしています…</string>
36 36
    <string name="submitting">送信しています…</string>
37 37
    <string name="tutorial">チュートリアルを見ますか?</string>
38
    <string name="tutorials">チュートリアル</string>
38 39

  
39 40
    <string name="credits1">ディストートグラフィックのライブラリを使用して開発されたオープンソースアプリ。<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL バージョン 2</a>でライセンスされているか、または-オプション-それ以降のすべてのバージョン。</string>
40 41
    <string name="credits2">Pretty Patterns 沿って Walter Randelshofer. 見る <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-ko/strings.xml
35 35
    <string name="downloading">다운로드 중…</string>
36 36
    <string name="submitting">제출 중…</string>
37 37
    <string name="tutorial">튜토리얼을 보시겠습니까?</string>
38
    <string name="tutorials">튜토리얼</string>
38 39

  
39 40
    <string name="credits1">왜곡된 그래픽 라이브러리를 사용하여 개발된 오픈 소스 앱. <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL 버전 2</a> 또는 귀하의 선택에 따라 최신 버전으로 라이센스가 부여됩니다.</string>
40 41
    <string name="credits2">Pretty Patterns 으로 Walter Randelshofer. 보다 <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-pl/strings.xml
35 35
    <string name="downloading">Ściąganie…</string>
36 36
    <string name="submitting">Przesyłanie…</string>
37 37
    <string name="tutorial">Zobacz tutorial?</string>
38
    <string name="tutorials">Tutoriale</string>
38 39

  
39 40
    <string name="credits1">Aplikacja open-source napisana wykorzystując bibliotekę Distorted. Licencja: <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL wersja 2</a> albo jakakolwiek poźniejsza.</string>
40 41
    <string name="credits2">Piękne Wzory Waltera Randelshofera. Zobacz <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-ru/strings.xml
35 35
    <string name="downloading">Загрузка…</string>
36 36
    <string name="submitting">Добавляю…</string>
37 37
    <string name="tutorial">Смотрите учебник?</string>
38
    <string name="tutorials">Учебники</string>
38 39

  
39 40
    <string name="credits1">Приложение с открытым исходным кодом, разработанное с использованием библиотеки графики Искажений. Лицензируется согласно <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">версии 2 GPL</a> или любой более поздней версии по вашему выбору.</string>
40 41
    <string name="credits2">Pretty Patterns по Walter Randelshofer. Смотри <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-zh-rCN/strings.xml
35 35
    <string name="downloading">正在下载……</string>
36 36
    <string name="submitting">正在提交……</string>
37 37
    <string name="tutorial">观看教程?</string>
38
    <string name="tutorials">讲解</string>
38 39

  
39 40
    <string name="credits1">此应用程式原始码开发使用Distorted图型库。根据<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">通用公共许可版本2</a>或者任何更新版本(根据您的选择)进行许可。</string>
40 41
    <string name="credits2">Pretty Patterns by Werner Randelshofer. 請看 <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values-zh-rTW/strings.xml
35 35
    <string name="downloading">正在下載……</string>
36 36
    <string name="submitting">正在傳送……</string>
37 37
    <string name="tutorial">觀看教程?</string>
38
    <string name="tutorials">講解</string>
38 39

  
39 40
    <string name="credits1">此應用程式原始碼開發使用Distorted圖型庫。根據<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">通用公共許可版本2</a>或者任何更新版本(根據您的選擇)進行許可。</string>
40 41
    <string name="credits2">Pretty Patterns by Werner Randelshofer. 請看 <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>
src/main/res/values/strings.xml
36 36
    <string name="downloading">Downloading…</string>
37 37
    <string name="submitting">Submitting…</string>
38 38
    <string name="tutorial">Watch a tutorial?</string>
39
    <string name="tutorials">Tutorials</string>
39 40

  
40 41
    <string name="credits1">Open Source app developed using the Distorted graphics library. Licensed under <a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">GPL version 2</a> or - at your option - any later version.</string>
41 42
    <string name="credits2">Pretty Patterns by Walter Randelshofer. See <a href="http://www.randelshofer.ch">http://www.randelshofer.ch</a></string>

Also available in: Unified diff