Project

General

Profile

Download (4.84 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / magic / RubikActivity.java @ 0c52af30

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.magic;
21

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

    
30
import org.distorted.library.main.Distorted;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

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

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

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

    
48
      markButton(DEFAULT_SIZE);
49
      }
50

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

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

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

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

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

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

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

    
98
    public void setSize(View v)
99
      {
100
      int size=0, id = v.getId();
101

    
102
      for(int b=0; b<button_ids.length; b++)
103
        if( button_ids[b] == id )
104
          {
105
          size = b+STARTING_SIZE;
106
          break;
107
          }
108

    
109
      markButton(size);
110

    
111
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
112
      view.setNewCubeSize(size);
113
      }
114

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

    
117
   private void markButton(int size)
118
     {
119
     for(int b=0; b<button_ids.length; b++)
120
       {
121
       Drawable d = findViewById(button_ids[b]).getBackground();
122

    
123
       if( size == b+STARTING_SIZE )
124
         {
125
         d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY);
126
         }
127
       else
128
         {
129
         d.clearColorFilter();
130
         }
131
       }
132
     }
133
}
(1-1/4)