Project

General

Profile

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

examples / src / main / java / org / distorted / examples / glow / GlowActivity.java @ c0f27889

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.glow;
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.SeekBar;
27
import android.widget.TextView;
28

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

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

    
35
public class GlowActivity extends Activity implements SeekBar.OnSeekBarChangeListener
36
{
37
    private TextView textRadius, textAlpha;
38
    private int mQuality;
39

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

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

    
48
      textRadius  = findViewById(R.id.glowTextRadius);
49
      SeekBar bar = findViewById(R.id.glowSeekRadius);
50
      bar.setOnSeekBarChangeListener(this);
51
      if( savedState==null ) bar.setProgress(50);
52

    
53
      textAlpha = findViewById(R.id.glowTextAlpha);
54
      bar = findViewById(R.id.glowSeekAlpha);
55
      bar.setOnSeekBarChangeListener(this);
56
      if( savedState==null ) bar.setProgress(50);
57

    
58
      if( savedState==null ) mQuality = EffectQuality.HIGHEST.ordinal();
59
      }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
    
63
    @Override
64
    protected void onPause() 
65
      {
66
      super.onPause();
67
      GLSurfaceView view = findViewById(R.id.glowSurfaceView);
68
      view.onPause();
69
      DistortedLibrary.onPause();
70
      }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
    
74
    @Override
75
    protected void onResume() 
76
      {
77
      super.onResume();
78
      GLSurfaceView view = findViewById(R.id.glowSurfaceView);
79
      view.onResume();
80
      }
81
 
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
    
84
    @Override
85
    protected void onDestroy() 
86
      {
87
      DistortedLibrary.onDestroy();
88
      super.onDestroy();
89
      }
90

    
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
    @Override
95
    public void onSaveInstanceState(Bundle savedInstanceState)
96
      {
97
      super.onSaveInstanceState(savedInstanceState);
98
      savedInstanceState.putInt("quality", mQuality);
99
      }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
    @Override
104
    public void onRestoreInstanceState(Bundle savedInstanceState)
105
      {
106
      super.onRestoreInstanceState(savedInstanceState);
107

    
108
      mQuality = savedInstanceState.getInt("quality");
109

    
110
      switch(mQuality)
111
        {
112
        case 0 : quality0(null); break;
113
        case 1 : quality1(null); break;
114
        case 2 : quality2(null); break;
115
        case 3 : quality3(null); break;
116
        default: android.util.Log.e("Glow", "error - unknown quality!");
117
        }
118
      }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
123
      {
124
      GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
125

    
126
      switch (bar.getId())
127
        {
128
        case R.id.glowSeekRadius: int radius = view.getRenderer().setGlowRadius(progress);
129
                                  textRadius.setText(getString(R.string.glow_radius_placeholder,radius));
130
                                  break;
131
        case R.id.glowSeekAlpha : float alpha = view.getRenderer().setGlowAlpha(progress);
132
                                  textAlpha.setText(getString(R.string.glow_alpha_placeholder, alpha));
133
                                  break;
134
        }
135
      }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
    public void onStartTrackingTouch(SeekBar bar) { }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
    public void onStopTrackingTouch(SeekBar bar)  { }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  public void quality0(View v)
148
    {
149
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
150
    GlowRenderer renderer = view.getRenderer();
151
    renderer.setQuality(EffectQuality.HIGHEST);
152
    mQuality = EffectQuality.HIGHEST.ordinal();
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public void quality1(View v)
158
    {
159
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
160
    GlowRenderer renderer = view.getRenderer();
161
    renderer.setQuality(EffectQuality.HIGH);
162
    mQuality = EffectQuality.HIGH.ordinal();
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  public void quality2(View v)
168
    {
169
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
170
    GlowRenderer renderer = view.getRenderer();
171
    renderer.setQuality(EffectQuality.MEDIUM);
172
    mQuality = EffectQuality.MEDIUM.ordinal();
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  public void quality3(View v)
178
    {
179
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
180
    GlowRenderer renderer = view.getRenderer();
181
    renderer.setQuality(EffectQuality.LOW);
182
    mQuality = EffectQuality.LOW.ordinal();
183
    }
184
}
(1-1/3)