Project

General

Profile

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

examples / src / main / java / org / distorted / examples / rubik / RubikActivity.java @ 377e1873

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.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.examples.R;
31
import org.distorted.library.main.Distorted;
32

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

    
35
public class RubikActivity extends Activity
36
{
37
            static final int DEFAULT_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_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, id = v.getId();
102

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

    
110
      markButton(size);
111

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

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

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

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