Project

General

Profile

Download (4.97 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / rubik / RubikActivity.java @ 5d8a1d51

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.examples.rubik;
21

    
22
import android.app.Activity;
23
import android.graphics.PorterDuff;
24
import android.opengl.GLSurfaceView;
25
import android.os.Bundle;
26
import android.support.v4.content.ContextCompat;
27
import android.view.View;
28
import android.widget.ImageButton;
29

    
30
import org.distorted.examples.R;
31
import org.distorted.library.main.Distorted;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
public class RubikActivity extends Activity
36
{
37
    static final int DEFAULT_CUBE_SIZE = 3;
38
    private static final int STARTING_SIZE = 2;
39
    private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
    @Override
44
    protected void onCreate(Bundle icicle)
45
      {
46
      super.onCreate(icicle);
47
      setContentView(R.layout.rubiklayout);
48

    
49
      markButton(DEFAULT_CUBE_SIZE);
50
      }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
    
54
    @Override
55
    protected void onPause() 
56
      {
57
      GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
58
      view.onPause();
59
      Distorted.onPause();
60
      super.onPause();
61
      }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
    
65
    @Override
66
    protected void onResume() 
67
      {
68
      super.onResume();
69
      GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
70
      view.onResume();
71
      }
72
    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
    
75
    @Override
76
    protected void onDestroy() 
77
      {
78
      Distorted.onDestroy();  
79
      super.onDestroy();
80
      }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
    public void Scramble(View v)
85
      {
86
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
87
      view.scrambleCube();
88
      }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
    public void Credits(View v)
93
      {
94
      android.util.Log.e("rubik", "credits...");
95
      }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
    public void setSize(View v)
100
      {
101
      int size=0;
102
      int id = v.getId();
103
      int numButtons = button_ids.length;
104

    
105
      for(int b=0; b<numButtons; b++)
106
        if( button_ids[b] == id )
107
          {
108
          size = b+STARTING_SIZE;
109
          break;
110
          }
111

    
112
      markButton(size);
113

    
114
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
115
      view.setNewCubeSize(size);
116
      }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
   private void markButton(int size)
121
     {
122
     int color, numButtons = button_ids.length;
123
     ImageButton[] button = new ImageButton[numButtons];
124

    
125
     for(int b=0; b<numButtons; b++)
126
       {
127
       button[b] = findViewById(button_ids[b]);
128
       color = (b==size-STARTING_SIZE ? R.color.red : R.color.gray);
129
       button[b].getBackground().setColorFilter(ContextCompat.getColor(this,color), PorterDuff.Mode.MULTIPLY);
130
       }
131
     }
132
}
(1-1/4)