Project

General

Profile

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

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

1 5b4a2d76 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 8647eae2 Leszek Koltunski
// Copyright 2019 Leszek Koltunski                                                               //
3 5b4a2d76 Leszek Koltunski
//                                                                                               //
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 5d8a1d51 Leszek Koltunski
import android.graphics.PorterDuff;
24 377e1873 Leszek Koltunski
import android.graphics.drawable.Drawable;
25 201376f3 Leszek Koltunski
import android.opengl.GLSurfaceView;
26 5b4a2d76 Leszek Koltunski
import android.os.Bundle;
27 5d8a1d51 Leszek Koltunski
import android.support.v4.content.ContextCompat;
28 201376f3 Leszek Koltunski
import android.view.View;
29 5b4a2d76 Leszek Koltunski
30 201376f3 Leszek Koltunski
import org.distorted.examples.R;
31 5b4a2d76 Leszek Koltunski
import org.distorted.library.main.Distorted;
32
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
public class RubikActivity extends Activity
36
{
37 377e1873 Leszek Koltunski
            static final int DEFAULT_SIZE  = 3;
38 5d8a1d51 Leszek Koltunski
    private static final int STARTING_SIZE = 2;
39 377e1873 Leszek Koltunski
    private static final int[] button_ids  = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
40 5d8a1d51 Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 5b4a2d76 Leszek Koltunski
    @Override
44
    protected void onCreate(Bundle icicle)
45
      {
46
      super.onCreate(icicle);
47 201376f3 Leszek Koltunski
      setContentView(R.layout.rubiklayout);
48 5d8a1d51 Leszek Koltunski
49 377e1873 Leszek Koltunski
      markButton(DEFAULT_SIZE);
50 5b4a2d76 Leszek Koltunski
      }
51
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
    
54
    @Override
55
    protected void onPause() 
56
      {
57 201376f3 Leszek Koltunski
      GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
58
      view.onPause();
59 5b4a2d76 Leszek Koltunski
      Distorted.onPause();
60
      super.onPause();
61
      }
62
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
    
65
    @Override
66
    protected void onResume() 
67
      {
68
      super.onResume();
69 201376f3 Leszek Koltunski
      GLSurfaceView view = findViewById(R.id.rubikSurfaceView);
70
      view.onResume();
71 5b4a2d76 Leszek Koltunski
      }
72
    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
    
75
    @Override
76
    protected void onDestroy() 
77
      {
78
      Distorted.onDestroy();  
79
      super.onDestroy();
80
      }
81 201376f3 Leszek Koltunski
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
84
    public void Scramble(View v)
85
      {
86 5d8a1d51 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
87
      view.scrambleCube();
88 201376f3 Leszek Koltunski
      }
89
90 0094886e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
    public void Credits(View v)
93
      {
94
      android.util.Log.e("rubik", "credits...");
95
      }
96
97 201376f3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
    public void setSize(View v)
100
      {
101 377e1873 Leszek Koltunski
      int size=0, id = v.getId();
102 5d8a1d51 Leszek Koltunski
103 377e1873 Leszek Koltunski
      for(int b=0; b<button_ids.length; b++)
104 5d8a1d51 Leszek Koltunski
        if( button_ids[b] == id )
105
          {
106
          size = b+STARTING_SIZE;
107
          break;
108
          }
109 0094886e Leszek Koltunski
110 5d8a1d51 Leszek Koltunski
      markButton(size);
111 0094886e Leszek Koltunski
112 5d8a1d51 Leszek Koltunski
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
113
      view.setNewCubeSize(size);
114 201376f3 Leszek Koltunski
      }
115 5d8a1d51 Leszek Koltunski
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
   private void markButton(int size)
119
     {
120 377e1873 Leszek Koltunski
     for(int b=0; b<button_ids.length; b++)
121 5d8a1d51 Leszek Koltunski
       {
122 377e1873 Leszek Koltunski
       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 5d8a1d51 Leszek Koltunski
       }
133
     }
134 5b4a2d76 Leszek Koltunski
}