Project

General

Profile

« Previous | Next » 

Revision 0b458a90

Added by Leszek Koltunski over 2 years ago

Progress with central menu popup.

View differences:

src/main/java/org/distorted/main/RubikActivity.java
78 78
    public static final float TITLE_TEXT_SIZE     = 0.06f;
79 79
    public static final float SOLVER_BMP_H_SIZE   = 0.11f;
80 80
    public static final float SOLVER_BMP_V_SIZE   = 0.06f;
81
    public static final float MENU_ITEM_SIZE      = 0.11f;
82 81
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
83 82
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
84 83
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
......
90 89
    public static final float MENU_SMALL_TEXT_SIZE= 0.035f;
91 90
    public static final float TAB_WIDTH           = 0.100f;
92 91
    public static final float TAB_HEIGHT          = 0.100f;
92
    public static final float MENU_BUTTON_HEIGHT  = 0.120f;
93 93

  
94 94
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
95 95
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
src/main/java/org/distorted/screens/RubikScreenPlay.java
41 41
import org.distorted.dialogs.RubikDialogUpdates;
42 42
import org.distorted.external.RubikNetwork;
43 43
import org.distorted.external.RubikUpdates;
44
import org.distorted.objectlib.main.ObjectControl;
45 44

  
46 45
import org.distorted.main.R;
47 46
import org.distorted.main.RubikActivity;
......
49 48
import org.distorted.dialogs.RubikDialogPattern;
50 49
import org.distorted.dialogs.RubikDialogScores;
51 50
import org.distorted.dialogs.RubikDialogTutorial;
52
import org.distorted.helpers.TransparentButton;
53 51
import org.distorted.helpers.TransparentImageButton;
54
import org.distorted.external.RubikScores;
55 52
import org.distorted.objects.MainEntry;
56 53
import org.distorted.objects.MainEntryList;
57 54
import org.distorted.objects.RubikObject;
......
65 62
  {
66 63
  public static final int NUM_COLUMNS  = 5;
67 64
  public static final int LEVELS_SHOWN = 8;
65
  private static final int NUM_BUTTONS = 5;
68 66

  
69
  private static final int[] BUTTON_LABELS = { R.string.scores,
70
                                               R.string.patterns,
71
                                               R.string.solver,
72
                                               R.string.tutorials,
73
                                               R.string.about };
74
  private static final int NUM_BUTTONS = BUTTON_LABELS.length;
75

  
76
  private static final float BIG_BUTTON = 1.5f;
77 67
  private static final int[] mLocation = new int[2];
78 68

  
79 69
  private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
80
  private TransparentButton mPlayButton;
81 70
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
82
  private LinearLayout mPlayLayout;
71

  
83 72
  private TextView mBubbleUpdates;
84
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
73
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mMenuButtonHeight;
85 74
  private int mLevelValue;
86
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
87 75
  private int mColCount, mRowCount, mMaxRowCount;
88 76
  private int mUpperBarHeight;
89 77
  private boolean mShouldReactToEndOfScrambling;
......
107 95
    mScreenWidth = act.getScreenWidthInPixels();
108 96
    mUpperBarHeight = act.getHeightUpperBar();
109 97

  
110
    mMenuTextSize = mScreenWidth*RubikActivity.MENU_MED_TEXT_SIZE;
111
    mButtonSize   = mScreenWidth*RubikActivity.BUTTON_TEXT_SIZE;
112
    mMenuItemSize = mScreenWidth*RubikActivity.MENU_ITEM_SIZE;
98
    mMenuButtonHeight = (int)(mScreenWidth*RubikActivity.MENU_BUTTON_HEIGHT);
113 99

  
114 100
    mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
115 101
    mColCount = NUM_COLUMNS;
......
162 148
      });
163 149
    }
164 150

  
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

  
167
  private void setupPlayButton(final RubikActivity act, final float width)
168
    {
169
    final int margin = (int)(width*RubikActivity.SMALL_MARGIN);
170

  
171
    mPlayButton = new TransparentButton(act, R.string.play, mButtonSize);
172

  
173
    mPlayButton.setOnClickListener( new View.OnClickListener()
174
      {
175
      @Override
176
      public void onClick(View view)
177
        {
178
        if( mPlayPopup==null )
179
          {
180
          float width = act.getScreenWidthInPixels();
181
          setupPlayWindow(act,width);
182
          }
183

  
184
        if( act.getControl().isUINotBlocked())
185
          {
186
          adjustSolvedIcons();
187
          float height= act.getScreenHeightInPixels();
188
          final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) );
189
          View popupView = mPlayPopup.getContentView();
190
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
191
          final int object  = RubikObjectList.getCurrObject();
192
          final int dbLevel = RubikObjectList.getDBLevel(object);
193
          final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN)+1;
194
          final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+4*margin+2*mMenuItemSize*(BIG_BUTTON-1.0f));
195
          final int realHeight = Math.min(popupHeight,maxHeight);
196
          displayPopup(act,view,mPlayPopup,mPlayLayoutWidth,realHeight,margin,margin);
197
          }
198
        }
199
      });
200
    }
201

  
202 151
///////////////////////////////////////////////////////////////////////////////////////////////////
203 152

  
204 153
  private void setupMenuButton(final RubikActivity act, final float width)
......
223 172
          {
224 173
          View popupView = mMenuPopup.getContentView();
225 174
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
226
          displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-width/12),margin);
175
          displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-mMenuLayoutWidth/2 + width/6),margin);
227 176
          }
228 177
        }
229 178
      });
......
290 239
              int ordinal = mainEntry.getOrdinal();
291 240
              RubikObjectList.setCurrObject(act,ordinal);
292 241
              act.changeObject(ordinal,true);
293
              if( mPlayLayout!=null ) adjustLevels(act);
242
              if( mMenuPopup!=null ) adjustLevels(act);
294 243
              mMovesController.clearMoves(act);
295 244
              }
296 245
            else if( type==MainEntry.TYPE_CREATOR )
......
427 376
    {
428 377
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
429 378
    final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
430
    LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
431 379

  
432 380
    mMenuPopup = new PopupWindow(act);
433 381
    mMenuPopup.setContentView(layout);
434 382
    mMenuPopup.setFocusable(true);
435 383
    int margin  = (int)(width*RubikActivity.SMALL_MARGIN);
436
    int padding = (int)(width*RubikActivity.PADDING);
437

  
438
    mMenuLayoutWidth = (int)(width/2);
439
    mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
384
    int padding = (int)(width*RubikActivity.MEDIUM_MARGIN);
440 385

  
441
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
386
    mMenuLayoutWidth = (int)(width*0.6f);
387
    mMenuLayoutHeight= (int)(2*padding + NUM_BUTTONS*(mMenuButtonHeight+margin));
442 388

  
443
    for(int i=0; i<NUM_BUTTONS; i++)
444
      {
445
      final int but = i;
446
      Button button = new Button(act);
447
      button.setLayoutParams(p);
448
      button.setText(BUTTON_LABELS[i]);
449
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
389
    layout.setPadding(padding,0,padding,0);
450 390

  
451
      button.setOnClickListener( new View.OnClickListener()
391
    Button highScores = layout.findViewById(R.id.menuHighScores);
392
    highScores.setOnClickListener( new View.OnClickListener()
452 393
        {
453 394
        @Override
454 395
        public void onClick(View v)
455 396
          {
456 397
          mMenuPopup.dismiss();
457
          MenuAction(act,but);
398
          Bundle sBundle = new Bundle();
399
          int currObject = RubikObjectList.getCurrObject();
400
          sBundle.putInt("tab", currObject );
401
          sBundle.putBoolean("submitting", false);
402
          RubikDialogScores scores = new RubikDialogScores();
403
          scores.setArguments(sBundle);
404
          scores.show(act.getSupportFragmentManager(), null);
458 405
          }
459 406
        });
460 407

  
461
      menuLayout.addView(button);
462
      }
463
    }
464

  
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

  
467
  private void setupPlayWindow(final RubikActivity act, final float width)
468
    {
469
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
470
    final View layout = layoutInflater.inflate(R.layout.popup_play, null);
471
    mPlayLayout = layout.findViewById(R.id.playGrid);
472

  
473
    mPlayLayoutWidth = (int)(width*0.4f);
474

  
475
    mPlayPopup = new PopupWindow(act);
476
    mPlayPopup.setContentView(layout);
477
    mPlayPopup.setFocusable(true);
408
    Button prettyPatterns = layout.findViewById(R.id.menuPrettyPatterns);
409
    prettyPatterns.setOnClickListener( new View.OnClickListener()
410
        {
411
        @Override
412
        public void onClick(View v)
413
          {
414
          mMenuPopup.dismiss();
415
          RubikDialogPattern pDiag = new RubikDialogPattern();
416
          pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
417
          }
418
        });
478 419

  
479
    adjustLevels(act);
480
    }
420
    Button solver = layout.findViewById(R.id.menuSolver);
421
    solver.setOnClickListener( new View.OnClickListener()
422
        {
423
        @Override
424
        public void onClick(View v)
425
          {
426
          mMenuPopup.dismiss();
427
          ScreenList.switchScreen(act, ScreenList.SVER);
428
          }
429
        });
481 430

  
482
///////////////////////////////////////////////////////////////////////////////////////////////////
431
    Button tutorials = layout.findViewById(R.id.menuTutorials);
432
    tutorials.setOnClickListener( new View.OnClickListener()
433
        {
434
        @Override
435
        public void onClick(View v)
436
          {
437
          mMenuPopup.dismiss();
438
          RubikDialogTutorial tDiag = new RubikDialogTutorial();
439
          tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
440
          }
441
        });
483 442

  
484
  private void MenuAction(RubikActivity act, int button)
485
    {
486
    switch(button)
487
      {
488
      case 0: Bundle sBundle = new Bundle();
489
              int currObject = RubikObjectList.getCurrObject();
490
              sBundle.putInt("tab", currObject );
491
              sBundle.putBoolean("submitting", false);
492
              RubikDialogScores scores = new RubikDialogScores();
493
              scores.setArguments(sBundle);
494
              scores.show(act.getSupportFragmentManager(), null);
495
              break;
496
      case 1: RubikDialogPattern pDiag = new RubikDialogPattern();
497
              pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
498
              break;
499
      case 2: ScreenList.switchScreen(act, ScreenList.SVER);
500
              break;
501
      case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
502
              tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
503
              break;
504
      case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
505
              aDiag.show(act.getSupportFragmentManager(), null);
506
              break;
507
      }
443
    Button about = layout.findViewById(R.id.menuAbout);
444
    about.setOnClickListener( new View.OnClickListener()
445
        {
446
        @Override
447
        public void onClick(View v)
448
          {
449
          mMenuPopup.dismiss();
450
          RubikDialogAbout aDiag = new RubikDialogAbout();
451
          aDiag.show(act.getSupportFragmentManager(), null);
452
          }
453
        });
508 454
    }
509 455

  
510 456
///////////////////////////////////////////////////////////////////////////////////////////////////
......
565 511

  
566 512
  public void setCurrObject(RubikActivity act)
567 513
    {
568
    if( mPlayLayout!=null ) adjustLevels(act);
514
    if( mMenuPopup!=null ) adjustLevels(act);
569 515
    }
570 516

  
571 517
///////////////////////////////////////////////////////////////////////////////////////////////////
......
614 560
    }
615 561

  
616 562
///////////////////////////////////////////////////////////////////////////////////////////////////
617

  
563
/*
618 564
  private void adjustSolvedIcons()
619 565
    {
620 566
    if( mPlayLayout!=null )
......
634 580
        }
635 581
      }
636 582
    }
637

  
583
*/
638 584
///////////////////////////////////////////////////////////////////////////////////////////////////
639 585

  
640 586
  private void adjustLevels(final RubikActivity act)
641 587
    {
588
    /*
642 589
    int currObject = RubikObjectList.getCurrObject();
643 590
    int dbLevel = RubikObjectList.getDBLevel(currObject);
644 591
    RubikObject object = RubikObjectList.getObject(currObject);
......
656 603
    float width  = act.getScreenWidthInPixels();
657 604
    int margin   = (int)(width*RubikActivity.SMALL_MARGIN);
658 605
    int padding  = (int)(width*RubikActivity.PADDING);
659
    int butWidth = mPlayLayoutWidth - 2*padding;
606
    int butWidth = 0;//mPlayLayoutWidth - 2*padding;
660 607
    int butHeight= (int)mMenuItemSize;
661 608
    int bigButH  = (int)(mMenuItemSize*BIG_BUTTON) ;
662 609

  
......
705 652

  
706 653
      mPlayLayout.addView(button);
707 654
      }
655

  
656
     */
708 657
    }
709 658

  
710 659
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/layout/popup_menu.xml
5 5
   android:layout_height="wrap_content"
6 6
   android:gravity="center"
7 7
   android:orientation="vertical">
8

  
9
   <Button
10
      android:id="@+id/menuHighScores"
11
      android:text="@string/scores"
12
      android:layout_width="match_parent"
13
      android:layout_height="0dp"
14
      android:layout_weight="1.0"
15
      android:paddingRight="10dp"
16
      android:paddingLeft="10dp"
17
      android:singleLine="true"
18
      android:backgroundTint="@color/dark_grey"
19
      android:gravity="center"/>
20

  
21
   <Button
22
      android:id="@+id/menuPrettyPatterns"
23
      android:text="@string/patterns"
24
      android:layout_width="match_parent"
25
      android:layout_height="0dp"
26
      android:layout_weight="1.0"
27
      android:paddingRight="10dp"
28
      android:paddingLeft="10dp"
29
      android:singleLine="true"
30
      android:backgroundTint="@color/dark_grey"
31
      android:gravity="center"/>
32

  
33
   <Button
34
      android:id="@+id/menuSolver"
35
      android:text="@string/solver"
36
      android:layout_width="match_parent"
37
      android:layout_height="0dp"
38
      android:layout_weight="1.0"
39
      android:paddingRight="10dp"
40
      android:paddingLeft="10dp"
41
      android:singleLine="true"
42
      android:backgroundTint="@color/dark_grey"
43
      android:gravity="center"/>
44

  
45
   <Button
46
      android:id="@+id/menuTutorials"
47
      android:text="@string/tutorials"
48
      android:layout_width="match_parent"
49
      android:layout_height="0dp"
50
      android:layout_weight="1.0"
51
      android:paddingRight="10dp"
52
      android:paddingLeft="10dp"
53
      android:singleLine="true"
54
      android:backgroundTint="@color/dark_grey"
55
      android:gravity="center"/>
56

  
57
   <Button
58
      android:id="@+id/menuAbout"
59
      android:text="@string/about"
60
      android:layout_width="match_parent"
61
      android:layout_height="0dp"
62
      android:layout_weight="1.0"
63
      android:paddingRight="10dp"
64
      android:paddingLeft="10dp"
65
      android:singleLine="true"
66
      android:backgroundTint="@color/dark_grey"
67
      android:gravity="center"/>
8 68
</LinearLayout>

Also available in: Unified diff