Project

General

Profile

« Previous | Next » 

Revision b9d062cf

Added by Leszek Koltunski over 2 years ago

Bandaged: progress.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
51 51
{
52 52
    private static final int ACTIVITY_NUMBER = 3;
53 53
    private static final float RATIO_BAR   = 0.10f;
54
    private static final float RATIO_BUT   = 0.07f;
54 55
    static final float RATIO_SCROLL= 0.30f;
55 56

  
56 57
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
......
97 98
    private void computeHeights()
98 99
      {
99 100
      int barHeight    = (int)(mScreenHeight*RATIO_BAR);
101
      int butHeight    = (int)(mScreenHeight*RATIO_BUT);
100 102
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
101 103
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR));
104
      int padding      = (int)(mScreenHeight* RubikActivity.PADDING);
102 105

  
103
      LinearLayout layout = findViewById(R.id.lowerBar);
104
      ViewGroup.LayoutParams paramsL = layout.getLayoutParams();
106
      LinearLayout botLayout = findViewById(R.id.lowerBar);
107
      ViewGroup.LayoutParams paramsL = botLayout.getLayoutParams();
105 108
      paramsL.height = barHeight;
106
      layout.setLayoutParams(paramsL);
109
      botLayout.setLayoutParams(paramsL);
110

  
111
      LinearLayout butLayout = findViewById(R.id.bandagedCreatorButtons);
112
      ViewGroup.LayoutParams paramsB = butLayout.getLayoutParams();
113
      paramsB.height = butHeight;
114
      butLayout.setPadding(padding,0,padding,padding);
115
      butLayout.setLayoutParams(paramsB);
107 116

  
108 117
      LinearLayout topLayout = findViewById(R.id.bandagedCreatorTopView);
109 118
      ViewGroup.LayoutParams paramsT = topLayout.getLayoutParams();
110 119
      paramsT.height = viewHeight;
111

  
112
      int p = (int)(mScreenHeight* RubikActivity.PADDING);
113
      topLayout.setPadding(p,p,p,p);
120
      topLayout.setPadding(padding,padding,padding,padding);
114 121
      topLayout.setLayoutParams(paramsT);
115 122

  
116 123
      BandagedCreatorView creator = findViewById(R.id.bandagedCreatorObjectView);
......
221 228
      {
222 229
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
223 230
      SharedPreferences.Editor editor = preferences.edit();
224
      String objects = mScreen.generateObjectStrings();
225
      editor.putString("bandagedObjects", objects );
231
      mScreen.savePreferences(editor);
226 232
      editor.apply();
227 233
      }
228 234

  
......
231 237
    private void restorePreferences()
232 238
      {
233 239
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
234
      String objects = preferences.getString("bandagedObjects","");
235
      mScreen.addObjects(this,objects);
240
      mScreen.restorePreferences(this,preferences);
236 241
      }
237 242

  
238 243
///////////////////////////////////////////////////////////////////////////////////////////////////
......
244 249
      return mFirebaseAnalytics;
245 250
      }
246 251

  
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

  
254
    public void changeObject(int x, int y, int z)
255
      {
256
      BandagedCreatorRenderer renderer = getRenderer();
257
      renderer.changeObject(x,y,z);
258
      }
259

  
247 260
///////////////////////////////////////////////////////////////////////////////////////////////////
248 261

  
249 262
    public BandagedCreatorRenderer getRenderer()
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
104 104
   private boolean mInitialPhase;
105 105
   private long mStartTime;
106 106
   private float mScaleValue;
107
   private float mX, mY, mZ, mW;
107
   private float mQuatX, mQuatY, mQuatZ, mQuatW;
108
   private int mX, mY, mZ;
108 109
   private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits;
109 110
   private int mIndex1, mIndex2;
110 111
   private int mSaveIcon;
111 112
   private DistortedFramebuffer mFramebuffer;
112 113
   private String mPath;
114
   private boolean mCubitsCreated;
113 115

  
114 116
///////////////////////////////////////////////////////////////////////////////////////////////////
115 117

  
......
124 126
     mSetQuatT         = false;
125 127
     mResettingObject  = false;
126 128
     mConnectingCubits = false;
129
     mCubitsCreated    = false;
127 130

  
128 131
     mSaveIcon = -1;
129 132

  
......
154 157

  
155 158
///////////////////////////////////////////////////////////////////////////////////////////////////
156 159

  
157
   private BandagedCubit[] createCubits()
160
   private void createCubits()
158 161
     {
159
     boolean roundCorners = false;//DistortedLibrary.fastCompilationTF();
162
     android.util.Log.e("D", "creating cubits : "+mX+" "+mY+" "+mZ);
163

  
160 164
     int len = POSITIONS.length;
161
     BandagedCubit[] cubits = new BandagedCubit[len];
165
     mCubits = new BandagedCubit[len];
162 166

  
163 167
     for(int c=0; c<len; c++)
164 168
       {
165
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuatT,mQuatA,mScale,roundCorners);
169
       mCubits[c] = new BandagedCubit(POSITIONS[c],mQuatT,mQuatA,mScale,false);
166 170
       }
167 171

  
168
     return cubits;
172
     mView.setCubits(mCubits);
169 173
     }
170 174

  
171 175
///////////////////////////////////////////////////////////////////////////////////////////////////
......
202 206
     if( mSetQuatT )
203 207
       {
204 208
       mSetQuatT = false;
205
       mQuatT.set(mX,mY,mZ,mW);
209
       mQuatT.set(mQuatX,mQuatY,mQuatZ,mQuatW);
206 210
       }
207 211

  
208 212
     if( mResetQuats )
......
293 297
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
294 298
      DistortedLibrary.setCull(true);
295 299

  
296
      mCubits= createCubits();
297
      mView.setCubits(mCubits);
300
      createCubits();
301
      mCubitsCreated = true;
298 302
      }
299 303

  
300 304
///////////////////////////////////////////////////////////////////////////////////////////////////
......
356 360

  
357 361
   public void setQuatTemp(float x, float y, float z, float w)
358 362
     {
359
     mX = x;
360
     mY = y;
361
     mZ = z;
362
     mW = w;
363
     mQuatX = x;
364
     mQuatY = y;
365
     mQuatZ = z;
366
     mQuatW = w;
363 367

  
364 368
     mSetQuatT = true;
365 369
     }
......
530 534
     mSaveIcon = -1;
531 535
     }
532 536

  
537
///////////////////////////////////////////////////////////////////////////////////////////////////
538

  
539
   public void changeObject(int x, int y, int z)
540
     {
541
     if( mX!=x || mY!=y || mZ!=z )
542
       {
543
       android.util.Log.e("D", "really changing object to : "+x+" "+y+" "+z);
544

  
545
       mX = x;
546
       mY = y;
547
       mZ = z;
548

  
549
       if( mCubitsCreated )
550
         {
551
         createCubits();
552

  
553
         mScreen.detachAll();
554
         int len = POSITIONS.length;
555
         mView.resetCubits();
556

  
557
         for(int i=0; i<len; i++)
558
           {
559
           mCubits[i].scaleMove(mScaleValue);
560
           DistortedNode node = mCubits[i].getNode();
561
           mScreen.attach(node);
562
           }
563
         }
564
       }
565
     }
566

  
533 567
///////////////////////////////////////////////////////////////////////////////////////////////////
534 568

  
535 569
   public void displaySavingDialog()
src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java
19 19

  
20 20
package org.distorted.bandaged;
21 21

  
22
import java.lang.ref.WeakReference;
22 23
import java.util.ArrayList;
23 24

  
24 25
import android.app.Activity;
26
import android.content.SharedPreferences;
25 27
import android.graphics.Bitmap;
26 28
import android.view.View;
29
import android.view.ViewGroup;
30
import android.widget.AdapterView;
31
import android.widget.ArrayAdapter;
27 32
import android.widget.ImageView;
28 33
import android.widget.LinearLayout;
34
import android.widget.Spinner;
29 35

  
30 36
import org.distorted.external.RubikFiles;
31 37
import org.distorted.helpers.TransparentImageButton;
......
34 40

  
35 41
///////////////////////////////////////////////////////////////////////////////////////////////////
36 42

  
37
public class BandagedCreatorScreen
43
public class BandagedCreatorScreen implements AdapterView.OnItemSelectedListener
38 44
{
45
  public static final int MAX_SUPPORTED_SIZE = 5;
46

  
47
  private WeakReference<BandagedCreatorActivity> mAct;
39 48
  private TransparentImageButton mBackButton, mResetButton, mDoneButton;
40 49
  private LinearLayout mObjectView;
41
  private int mNumObjects;
42
  private ArrayList<BandagedCreatorObjectView> mViews;
50
  private int mNumObjects, mX, mY, mZ;
51
  private final ArrayList<BandagedCreatorObjectView> mViews;
52
  private Spinner mSpinnerX, mSpinnerY, mSpinnerZ;
53
  private boolean mSpinnersReady;
43 54

  
44 55
///////////////////////////////////////////////////////////////////////////////////////////////////
45 56

  
46 57
  public BandagedCreatorScreen()
47 58
    {
59
    mSpinnersReady = false;
48 60
    mNumObjects = 0;
49 61
    mViews = new ArrayList<>();
50 62
    }
......
105 117
      });
106 118
    }
107 119

  
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

  
122
  private String[] createSizes(String mark)
123
    {
124
    String[] ret = new String[MAX_SUPPORTED_SIZE];
125

  
126
    for(int i=1; i<=MAX_SUPPORTED_SIZE; i++)
127
      {
128
      ret[i-1] = mark+" : "+i;
129
      }
130

  
131
    return ret;
132
    }
133

  
134

  
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

  
137
  private void changeObject()
138
    {
139
    if( mSpinnersReady )
140
      {
141
      BandagedCreatorActivity act = mAct.get();
142
      if( act!=null ) act.changeObject(mX+1,mY+1,mZ+1);
143
      }
144
    }
145

  
108 146
///////////////////////////////////////////////////////////////////////////////////////////////////
109 147

  
110 148
  void onAttachedToWindow(final BandagedCreatorActivity act)
111 149
    {
150
    mAct = new WeakReference<>(act);
112 151
    mObjectView = act.findViewById(R.id.bandagedCreatorView);
113 152

  
114
    int width = act.getScreenWidthInPixels();
153
    int width  = act.getScreenWidthInPixels();
154
    int height = act.getScreenHeightInPixels();
155
    int padding= (int)(height*RubikActivity.PADDING/3);
115 156

  
116 157
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
117 158
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
......
136 177
    layout.addView(layoutLeft);
137 178
    layout.addView(layoutMid);
138 179
    layout.addView(layoutRight);
180

  
181
    mSpinnerX = act.findViewById(R.id.bandagedCreatorX);
182
    mSpinnerX.setOnItemSelectedListener(this);
183
    ArrayAdapter<String> adX = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, createSizes("X") );
184
    adX.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
185
    mSpinnerX.setAdapter(adX);
186

  
187
    mSpinnerY = act.findViewById(R.id.bandagedCreatorY);
188
    mSpinnerY.setOnItemSelectedListener(this);
189
    ArrayAdapter<String> adY = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, createSizes("Y") );
190
    adY.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
191
    mSpinnerY.setAdapter(adY);
192

  
193
    mSpinnerZ = act.findViewById(R.id.bandagedCreatorZ);
194
    mSpinnerZ.setOnItemSelectedListener(this);
195
    ArrayAdapter<String> adZ = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, createSizes("Z") );
196
    adZ.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
197
    mSpinnerZ.setAdapter(adZ);
198

  
199
    ViewGroup.MarginLayoutParams paramsX = (ViewGroup.MarginLayoutParams) mSpinnerX.getLayoutParams();
200
    paramsX.setMargins(0,0,2*padding,0);
201
    ViewGroup.MarginLayoutParams paramsY = (ViewGroup.MarginLayoutParams) mSpinnerY.getLayoutParams();
202
    paramsY.setMargins(padding,0,padding,0);
203
    ViewGroup.MarginLayoutParams paramsZ = (ViewGroup.MarginLayoutParams) mSpinnerZ.getLayoutParams();
204
    paramsZ.setMargins(2*padding,0,0,0);
139 205
    }
140 206

  
141 207
///////////////////////////////////////////////////////////////////////////////////////////////////
......
153 219

  
154 220
///////////////////////////////////////////////////////////////////////////////////////////////////
155 221

  
156
  void addObjects(BandagedCreatorActivity act, String objectString)
222
  private void addObjects(BandagedCreatorActivity act, String objectString)
157 223
    {
158 224
    if( objectString.length()>0 )
159 225
      {
......
251 317

  
252 318
///////////////////////////////////////////////////////////////////////////////////////////////////
253 319

  
254
  String generateObjectStrings()
320
  private String generateObjectStrings()
255 321
    {
256 322
    String result = "";
257 323
    int numViews = mViews.size();
......
267 333

  
268 334
    return result;
269 335
    }
336

  
337
///////////////////////////////////////////////////////////////////////////////////////////////////
338

  
339
    @Override
340
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
341
      {
342
      int spinnerID = parent.getId();
343

  
344
      if( spinnerID==R.id.bandagedCreatorX )
345
        {
346
        mX = pos;
347
        }
348
      else if( spinnerID==R.id.bandagedCreatorY )
349
        {
350
        mY = pos;
351
        }
352
      else if( spinnerID==R.id.bandagedCreatorZ )
353
        {
354
        mZ = pos;
355
        }
356

  
357
      changeObject();
358
      }
359

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

  
362
    @Override
363
    public void onNothingSelected(AdapterView<?> parent) { }
364

  
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366

  
367
    public void savePreferences(SharedPreferences.Editor editor)
368
      {
369
      String objects = generateObjectStrings();
370
      editor.putString("bandagedObjects", objects );
371

  
372
      editor.putInt("bandagedX", mX);
373
      editor.putInt("bandagedY", mY);
374
      editor.putInt("bandagedZ", mZ);
375
      }
376

  
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378

  
379
    public void restorePreferences(BandagedCreatorActivity act, SharedPreferences preferences)
380
      {
381
      String objects = preferences.getString("bandagedObjects","");
382
      addObjects(act,objects);
383

  
384
      mX = preferences.getInt("bandagedX", 2);
385
      mY = preferences.getInt("bandagedY", 2);
386
      mZ = preferences.getInt("bandagedZ", 2);
387

  
388
      mSpinnerX.setSelection(mX);
389
      mSpinnerY.setSelection(mY);
390
      mSpinnerZ.setSelection(mZ);
391

  
392
      mSpinnersReady = true;
393
      changeObject();
394
      }
270 395
}
src/main/res/layout/bandaged.xml
1 1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:id="@+id/relativeLayout"
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4 3
    android:layout_width="match_parent"
5
    android:layout_height="match_parent" >
6

  
7
    <org.distorted.bandaged.BandagedCreatorView
8
        android:id="@+id/bandagedCreatorObjectView"
9
        android:layout_width="match_parent"
10
        android:layout_height="0dp"
11
        android:layout_alignParentBottom="true"
12
        android:layout_alignParentStart="true"/>
4
    android:layout_height="match_parent"
5
    android:background="@android:color/transparent"
6
    android:orientation="vertical">
13 7

  
14 8
    <LinearLayout
15 9
        android:id="@+id/bandagedCreatorTopView"
16 10
        android:layout_width="match_parent"
17
        android:layout_height="0dp"
11
        android:layout_height="100dp"
18 12
        android:background="@color/light_grey"
19
        android:orientation="horizontal"
20
        android:layout_alignParentStart="true"
21
        android:layout_alignParentTop="true">
13
        android:orientation="horizontal">
22 14

  
23 15
        <HorizontalScrollView
24 16
            android:id="@+id/bandagedCreatorScrollView"
......
35 27
        </HorizontalScrollView>
36 28
    </LinearLayout>
37 29

  
38
    <LinearLayout
39
        android:id="@+id/lowerBar"
40
        android:layout_alignParentBottom="true"
41
        android:layout_alignParentStart="true"
42
        android:layout_width="match_parent"
43
        android:layout_height="0dp"
44
        android:orientation="horizontal"
45
        android:background="@android:color/transparent">
46
    </LinearLayout>
30
    <RelativeLayout
31
       android:id="@+id/relativeLayout"
32
       android:layout_width="match_parent"
33
       android:layout_height="match_parent">
34

  
35
       <org.distorted.bandaged.BandagedCreatorView
36
           android:id="@+id/bandagedCreatorObjectView"
37
           android:layout_width="match_parent"
38
           android:layout_height="0dp"
39
           android:layout_alignParentBottom="true"
40
           android:layout_alignParentStart="true"/>
41

  
42
       <LinearLayout
43
           android:id="@+id/bandagedCreatorButtons"
44
           android:layout_width="match_parent"
45
           android:layout_height="0dp"
46
           android:background="@android:color/transparent"
47
           android:orientation="horizontal"
48
           android:layout_alignParentTop="true">
49

  
50
           <Spinner
51
               android:id="@+id/bandagedCreatorX"
52
               android:layout_width="0dp"
53
               android:layout_height="match_parent"
54
               android:layout_weight="1.0"
55
               android:textAlignment="center"/>
56
           <Spinner
57
               android:id="@+id/bandagedCreatorY"
58
               android:layout_width="0dp"
59
               android:layout_height="match_parent"
60
               android:layout_weight="1.0"
61
               android:textAlignment="center"/>
62
           <Spinner
63
               android:id="@+id/bandagedCreatorZ"
64
               android:layout_width="0dp"
65
               android:layout_height="match_parent"
66
               android:layout_weight="1.0"
67
               android:textAlignment="center"/>
68
       </LinearLayout>
47 69

  
48
</RelativeLayout>
70
       <LinearLayout
71
           android:id="@+id/lowerBar"
72
           android:layout_alignParentBottom="true"
73
           android:layout_alignParentStart="true"
74
           android:layout_width="match_parent"
75
           android:layout_height="0dp"
76
           android:orientation="horizontal"
77
           android:background="@android:color/transparent">
78
       </LinearLayout>
79
    </RelativeLayout>
80
</LinearLayout>
src/main/res/values-de/strings.xml
50 50
    <string name="solver">3x3x3 Löser</string>
51 51
    <string name="tutorials">Lernprogrammen</string>
52 52
    <string name="about">Über die App</string>
53
    <string name="bandaged">Bandaged 3x3</string>
53
    <string name="bandaged">Bandaged</string>
54 54
    <string name="updates">Aktualisierungen</string>
55 55
    <string name="no_updates">Nicht gefunden</string>
56 56
    <string name="install">Installieren</string>
src/main/res/values-es/strings.xml
50 50
    <string name="solver">Solucionador</string>
51 51
    <string name="tutorials">Tutoriales</string>
52 52
    <string name="about">Acerca de</string>
53
    <string name="bandaged">Bandaged 3x3</string>
53
    <string name="bandaged">Bandaged</string>
54 54
    <string name="updates">Actualizaciones</string>
55 55
    <string name="no_updates">Extraviado</string>
56 56
    <string name="install">Instalar</string>
src/main/res/values-fr/strings.xml
50 50
    <string name="solver">Solutionneur</string>
51 51
    <string name="tutorials">Tutoriels</string>
52 52
    <string name="about">À propos de</string>
53
    <string name="bandaged">Bandaged 3x3</string>
53
    <string name="bandaged">Bandaged</string>
54 54
    <string name="updates">Mises à jour</string>
55 55
    <string name="no_updates">Pas trouvé</string>
56 56
    <string name="install">Installer</string>
src/main/res/values-ja/strings.xml
50 50
    <string name="solver">3x3x3 ソルバー</string>
51 51
    <string name="tutorials">チュートリアル</string>
52 52
    <string name="about">アプリについて</string>
53
    <string name="bandaged">包帯3x3</string>
53
    <string name="bandaged">包帯</string>
54 54
    <string name="updates">更新</string>
55 55
    <string name="no_updates">見つかりません</string>
56 56
    <string name="install">インストール</string>
src/main/res/values-ko/strings.xml
50 50
    <string name="solver">3x3x3 해결사</string>
51 51
    <string name="tutorials">튜토리얼</string>
52 52
    <string name="about">정보</string>
53
    <string name="bandaged">밴디지 큐브</string>
53
    <string name="bandaged">밴디지</string>
54 54
    <string name="updates">업데이트</string>
55 55
    <string name="no_updates">업데이트가 없습니다</string>
56 56
    <string name="install">설치</string>
src/main/res/values-pl/strings.xml
50 50
    <string name="solver">Rozwiązywacz</string>
51 51
    <string name="tutorials">Tutoriale</string>
52 52
    <string name="about">O aplikacji</string>
53
    <string name="bandaged">Bandaged 3x3</string>
53
    <string name="bandaged">Bandaged</string>
54 54
    <string name="updates">Aktualizacje</string>
55 55
    <string name="no_updates">Nie znaleziono</string>
56 56
    <string name="install">Zainstaluj</string>
src/main/res/values-ru/strings.xml
50 50
    <string name="solver">Решебник 3х3х3</string>
51 51
    <string name="tutorials">Учебники</string>
52 52
    <string name="about">О нас</string>
53
    <string name="bandaged">Bandaged 3x3</string>
53
    <string name="bandaged">Bandaged</string>
54 54
    <string name="updates">Обновления</string>
55 55
    <string name="no_updates">Не найдено</string>
56 56
    <string name="install">Установите</string>
src/main/res/values/strings.xml
51 51
    <string name="solver">3x3x3 Solver</string>
52 52
    <string name="tutorials">Tutorials</string>
53 53
    <string name="about">About</string>
54
    <string name="bandaged">Bandaged 3x3</string>
54
    <string name="bandaged">Bandaged</string>
55 55
    <string name="updates">Updates</string>
56 56
    <string name="no_updates">No update found</string>
57 57
    <string name="install">Install</string>

Also available in: Unified diff