Project

General

Profile

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

examples / src / main / java / org / distorted / examples / meshfile / MeshFileActivity.java @ acad428e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 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.meshfile;
21

    
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25
import android.view.View;
26
import android.widget.AdapterView;
27
import android.widget.ArrayAdapter;
28
import android.widget.Spinner;
29

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

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

    
35
public class MeshFileActivity extends Activity implements AdapterView.OnItemSelectedListener
36
{
37
    private int mResource;
38
    private String[] mNames = new String[] { "deferredjob",
39
                                             "meshjoin"   ,
40
                                             "predeform"  ,
41
                                             "cube2"      ,
42
                                             "cube3"      ,
43
                                             "cube4"      ,
44
                                             "cube5"      ,
45
                                             "pyra3"      ,
46
                                             "pyra4"      ,
47
                                             "pyra5"
48
                                           };
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
    @Override
53
    protected void onCreate(Bundle icicle) 
54
      {
55
      super.onCreate(icicle);
56
      setContentView(R.layout.meshfilelayout);
57

    
58
      Spinner meshSpinner  = findViewById(R.id.meshfileSpinner);
59
      meshSpinner.setOnItemSelectedListener(this);
60

    
61
      ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mNames);
62
      adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
63
      meshSpinner.setAdapter(adapterBitmap);
64
      }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
    
68
    @Override
69
    protected void onPause() 
70
      {
71
      GLSurfaceView view = this.findViewById(R.id.meshfileSurfaceView);
72
      view.onPause();
73
      DistortedLibrary.onPause();
74
      super.onPause();
75
      }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
    
79
    @Override
80
    protected void onResume() 
81
      {
82
      super.onResume();
83
      GLSurfaceView view = this.findViewById(R.id.meshfileSurfaceView);
84
      view.onResume();
85
      }
86
    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
    
89
    @Override
90
    protected void onDestroy() 
91
      {
92
      DistortedLibrary.onDestroy();
93
      super.onDestroy();
94
      }
95

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

    
98
    public void Open(View v)
99
      {
100
      MeshFileSurfaceView view = this.findViewById(R.id.meshfileSurfaceView);
101
      MeshFileRenderer renderer = view.getRenderer();
102

    
103
      renderer.open(mResource);
104
      }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
109
      {
110
      if( parent.getId()==R.id.meshfileSpinner )
111
        {
112
        switch(pos)
113
          {
114
          case  0: mResource = R.raw.deferredjob; break;
115
          case  1: mResource = R.raw.meshjoin   ; break;
116
          case  2: mResource = R.raw.predeform  ; break;
117
          case  3: mResource = R.raw.cube2      ; break;
118
          case  4: mResource = R.raw.cube3      ; break;
119
          case  5: mResource = R.raw.cube4      ; break;
120
          case  6: mResource = R.raw.cube5      ; break;
121
          case  7: mResource = R.raw.pyra3      ; break;
122
          case  8: mResource = R.raw.pyra4      ; break;
123
          case  9: mResource = R.raw.pyra5      ; break;
124
          }
125
        }
126
      }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
    public void onNothingSelected(AdapterView<?> parent)
131
      {
132
      }
133
}
(1-1/3)