Project

General

Profile

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

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

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 view = findViewById(R.id.glowSurfaceView);
126

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

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
    public void onStartTrackingTouch(SeekBar bar) { }
141

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

    
144
    public void onStopTrackingTouch(SeekBar bar)  { }
145

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

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

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

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

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

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

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

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