Project

General

Profile

« Previous | Next » 

Revision e48ad1af

Added by Leszek Koltunski over 2 years ago

Bandaged 3x3: progress with saving.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
25 25
import android.view.View;
26 26
import android.view.ViewGroup;
27 27
import android.view.WindowManager;
28
import android.widget.HorizontalScrollView;
28 29
import android.widget.LinearLayout;
29 30

  
30 31
import androidx.appcompat.app.AppCompatActivity;
......
98 99
      paramsL.height = barHeight;
99 100
      layout.setLayoutParams(paramsL);
100 101

  
101
      LinearLayout view = findViewById(R.id.bandagedCreatorView);
102
      HorizontalScrollView view = findViewById(R.id.bandagedCreatorScrollView);
102 103
      ViewGroup.LayoutParams paramsS = view.getLayoutParams();
103 104
      paramsS.height = viewHeight;
104 105

  
......
221 222
      return view.getRenderer();
222 223
      }
223 224

  
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

  
227
    public void addObject(String name)
228
      {
229
      mScreen.addObject(this,name);
230
      }
231

  
224 232
///////////////////////////////////////////////////////////////////////////////////////////////////
225 233

  
226 234
    public int getHeightBar()
src/main/java/org/distorted/bandaged/BandagedCreatorObjectView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.bandaged;
21

  
22
import android.view.LayoutInflater;
23
import android.widget.LinearLayout;
24

  
25
import org.distorted.helpers.TransparentButton;
26
import org.distorted.helpers.TransparentImageButton;
27
import org.distorted.main.R;
28
import org.distorted.main.RubikActivity;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
public class BandagedCreatorObjectView
33
{
34
  private final LinearLayout mPane;
35
  private final String mName;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
  public BandagedCreatorObjectView(BandagedCreatorActivity act, String name, boolean leftmost)
40
    {
41
    mName = name;
42
    LayoutInflater inflater = act.getLayoutInflater();
43
    mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null);
44

  
45
    int width      = act.getScreenWidthInPixels();
46
    int lMargin    = (int)(width*RubikActivity.LARGE_MARGIN);
47
    int buttonSize = (int)(width*RubikActivity.BUTTON_TEXT_SIZE);
48

  
49
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( (int)(width*0.35f), LinearLayout.LayoutParams.MATCH_PARENT);
50
    params.bottomMargin = lMargin;
51
    params.topMargin    = lMargin;
52
    params.leftMargin   = leftmost ? lMargin : 0;
53
    params.rightMargin  = lMargin;
54

  
55
    mPane.setLayoutParams(params);
56

  
57
    LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout);
58

  
59
    TransparentButton plaButton = new TransparentButton(act, R.string.play, buttonSize);
60

  
61
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu);
62
    LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
63
    TransparentImageButton delButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, paramsB);
64

  
65
    bottom.addView(plaButton);
66
    bottom.addView(delButton);
67
    }
68

  
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

  
71
  public LinearLayout getPane()
72
    {
73
    return mPane;
74
    }
75
}
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
346 346
     TwistyObject obj = new TwistyBandagedGeneric();
347 347
     BandagedCreatorActivity act = (BandagedCreatorActivity) mView.getContext();
348 348

  
349
     createObjectJson(obj,act);
349
     boolean success = createObjectJson(obj,act);
350

  
351
     if( success )
352
       {
353
       act.addObject(obj.getShortName());
354
       }
350 355
     }
351 356

  
352 357
///////////////////////////////////////////////////////////////////////////////////////////////////
353 358

  
354
   private void createObjectJson(TwistyObject object, Activity act)
359
   private boolean createObjectJson(TwistyObject object, Activity act)
355 360
     {
356 361
     final String name = object.getShortName()+"_object.json";
357 362
     File file = new File(act.getFilesDir(), name);
......
362 367
       JsonWriter writer = JsonWriter.getInstance();
363 368
       String json = writer.createObjectString(object,24);
364 369
       writer.write(filename,json);
365

  
366
       act.runOnUiThread(new Runnable()
367
         {
368
         public void run()
369
           {
370
           String message = "Saving to \n\n"+filename+"\n\nsuccessful";
371
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
372
           }
373
         });
370
       return true;
374 371
       }
375 372
     catch(JSONException ex)
376 373
       {
......
382 379
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
383 380
           }
384 381
         });
382

  
383
       return false;
385 384
       }
386 385
     catch(FileNotFoundException ex)
387 386
       {
......
393 392
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
394 393
           }
395 394
         });
395

  
396
       return false;
396 397
       }
397 398
     catch(IOException ex)
398 399
       {
......
404 405
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
405 406
           }
406 407
         });
408

  
409
       return false;
407 410
       }
408 411
     }
409 412

  
src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java
31 31
public class BandagedCreatorScreen
32 32
{
33 33
  private TransparentImageButton mBackButton, mResetButton, mDoneButton;
34
  private int mBarHeight;
35
  private float mButtonSize;
34
  private LinearLayout mObjectView;
35
  private int mNumObjects;
36 36

  
37 37
///////////////////////////////////////////////////////////////////////////////////////////////////
38 38

  
39 39
  public BandagedCreatorScreen()
40 40
    {
41

  
41
    mNumObjects = 0;
42 42
    }
43 43

  
44 44
///////////////////////////////////////////////////////////////////////////////////////////////////
......
101 101

  
102 102
  void onAttachedToWindow(final BandagedCreatorActivity act)
103 103
    {
104
    mObjectView = act.findViewById(R.id.bandagedCreatorView);
105

  
104 106
    int width = act.getScreenWidthInPixels();
105
    mBarHeight = act.getHeightBar();
106
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
107 107

  
108 108
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
109 109
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
......
129 129
    layout.addView(layoutMid);
130 130
    layout.addView(layoutRight);
131 131
    }
132

  
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

  
135
  void addObject(BandagedCreatorActivity act, String name)
136
    {
137
    BandagedCreatorObjectView view = new BandagedCreatorObjectView(act,name,mNumObjects==0);
138
    LinearLayout pane = view.getPane();
139
    mObjectView.addView(pane);
140
    mNumObjects++;
141
    }
132 142
}
src/main/res/layout/bandaged.xml
4 4
    android:layout_width="match_parent"
5 5
    android:layout_height="match_parent" >
6 6

  
7

  
8 7
    <org.distorted.bandaged.BandagedCreatorView
9 8
        android:id="@+id/bandagedCreatorObjectView"
10 9
        android:layout_width="match_parent"
......
12 11
        android:layout_alignParentBottom="true"
13 12
        android:layout_alignParentStart="true"/>
14 13

  
15
    <LinearLayout
16
        android:id="@+id/bandagedCreatorView"
14
    <HorizontalScrollView
15
        android:id="@+id/bandagedCreatorScrollView"
17 16
        android:layout_width="match_parent"
18 17
        android:layout_height="0dp"
19 18
        android:background="@color/light_grey"
20 19
        android:layout_alignParentStart="true"
21 20
        android:layout_alignParentTop="true">
22 21

  
23
        <ScrollView
24
            android:id="@+id/bandagedCreatorScrollView"
22
        <LinearLayout
23
            android:id="@+id/bandagedCreatorView"
24
            android:layout_width="wrap_content"
25
            android:layout_height="match_parent"
25 26
            android:background="@color/black"
26
            android:layout_width="match_parent"
27
            android:layout_height="match_parent"/>
28

  
29
    </LinearLayout>
27
            android:orientation="horizontal"/>
28
    </HorizontalScrollView>
30 29

  
31 30
    <LinearLayout
32 31
        android:id="@+id/lowerBar"
src/main/res/layout/bandaged_pane.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:id="@+id/bandagedCreatorObjectPane"
4
    android:layout_width="200dp"
5
    android:layout_height="match_parent"
6
    android:background="@color/light_grey"
7
    android:orientation="vertical">
8

  
9
    <ImageView
10
        android:id="@+id/bandagedCreatorObjectIcon"
11
        android:layout_width="match_parent"
12
        android:layout_height="0dp"
13
        android:layout_weight="3.0"
14
        android:src="@drawable/ui_difficulty_unchecked"/>
15

  
16
    <LinearLayout
17
        android:id="@+id/bandagedCreatorObjectLayout"
18
        android:layout_width="match_parent"
19
        android:layout_height="0dp"
20
        android:layout_weight="1.0"
21
        android:orientation="horizontal"/>
22

  
23
</LinearLayout>

Also available in: Unified diff