Project

General

Profile

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

examples / src / main / java / org / distorted / examples / glow / GlowActivity.java @ 77e66c58

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
      DistortedLibrary.onCreate();
47
      setContentView(R.layout.glowlayout);
48

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

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

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

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

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

    
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

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

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

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

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

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

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
124
      {
125
      GlowSurfaceView v = findViewById(R.id.glowSurfaceView);
126
      GlowRenderer r = v.getRenderer();
127

    
128
      int id = bar.getId();
129

    
130
      if( id == R.id.glowSeekRadius )
131
        {
132
        int radius = r.setGlowRadius(progress);
133
        textRadius.setText(getString(R.string.glow_radius_placeholder,radius));
134
        }
135
      if( id == R.id.glowSeekAlpha )
136
        {
137
        float alpha = r.setGlowAlpha(progress);
138
        textAlpha.setText(getString(R.string.glow_alpha_placeholder, alpha));
139
        }
140
      }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
    public void onStartTrackingTouch(SeekBar bar) { }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
    public void onStopTrackingTouch(SeekBar bar)  { }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  public void quality0(View v)
153
    {
154
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
155
    GlowRenderer renderer = view.getRenderer();
156
    renderer.setQuality(EffectQuality.HIGHEST);
157
    mQuality = EffectQuality.HIGHEST.ordinal();
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  public void quality1(View v)
163
    {
164
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
165
    GlowRenderer renderer = view.getRenderer();
166
    renderer.setQuality(EffectQuality.HIGH);
167
    mQuality = EffectQuality.HIGH.ordinal();
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  public void quality2(View v)
173
    {
174
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
175
    GlowRenderer renderer = view.getRenderer();
176
    renderer.setQuality(EffectQuality.MEDIUM);
177
    mQuality = EffectQuality.MEDIUM.ordinal();
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  public void quality3(View v)
183
    {
184
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
185
    GlowRenderer renderer = view.getRenderer();
186
    renderer.setQuality(EffectQuality.LOW);
187
    mQuality = EffectQuality.LOW.ordinal();
188
    }
189
}
(1-1/3)