Project

General

Profile

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

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

1 cb9d104d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 71c8884f Leszek Koltunski
// This file is part of Distorted.                                                               //
5 cb9d104d Leszek Koltunski
//                                                                                               //
6 71c8884f Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 cb9d104d Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 cb9d104d Leszek Koltunski
// 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 71c8884f Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 cb9d104d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.examples.glow;
21
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25 c658e742 Leszek Koltunski
import android.view.View;
26 cb9d104d Leszek Koltunski
import android.widget.SeekBar;
27
import android.widget.TextView;
28
29
import org.distorted.examples.R;
30 c658e742 Leszek Koltunski
import org.distorted.library.effect.EffectQuality;
31 e3900503 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
32 cb9d104d Leszek Koltunski
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35
public class GlowActivity extends Activity implements SeekBar.OnSeekBarChangeListener
36
{
37 3a4f3ae2 Leszek Koltunski
    private TextView textRadius, textAlpha;
38 6d896e0e leszek
    private int mQuality;
39 cb9d104d Leszek Koltunski
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42
    @Override
43
    protected void onCreate(Bundle savedState)
44
      {
45
      super.onCreate(savedState);
46 a9df241d Leszek Koltunski
      DistortedLibrary.onCreate();
47 cb9d104d Leszek Koltunski
      setContentView(R.layout.glowlayout);
48 3a4f3ae2 Leszek Koltunski
49 c0f27889 Leszek Koltunski
      textRadius  = findViewById(R.id.glowTextRadius);
50
      SeekBar bar = findViewById(R.id.glowSeekRadius);
51 3a4f3ae2 Leszek Koltunski
      bar.setOnSeekBarChangeListener(this);
52 6d896e0e leszek
      if( savedState==null ) bar.setProgress(50);
53 3a4f3ae2 Leszek Koltunski
54 c0f27889 Leszek Koltunski
      textAlpha = findViewById(R.id.glowTextAlpha);
55
      bar = findViewById(R.id.glowSeekAlpha);
56 cb9d104d Leszek Koltunski
      bar.setOnSeekBarChangeListener(this);
57 6d896e0e leszek
      if( savedState==null ) bar.setProgress(50);
58
59
      if( savedState==null ) mQuality = EffectQuality.HIGHEST.ordinal();
60 cb9d104d Leszek Koltunski
      }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
    
64
    @Override
65
    protected void onPause() 
66
      {
67 c0f27889 Leszek Koltunski
      super.onPause();
68
      GLSurfaceView view = findViewById(R.id.glowSurfaceView);
69 cb9d104d Leszek Koltunski
      view.onPause();
70 e3900503 Leszek Koltunski
      DistortedLibrary.onPause();
71 cb9d104d Leszek Koltunski
      }
72
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
    
75
    @Override
76
    protected void onResume() 
77
      {
78
      super.onResume();
79 c0f27889 Leszek Koltunski
      GLSurfaceView view = findViewById(R.id.glowSurfaceView);
80 cb9d104d Leszek Koltunski
      view.onResume();
81
      }
82
 
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
    
85
    @Override
86
    protected void onDestroy() 
87
      {
88 e3900503 Leszek Koltunski
      DistortedLibrary.onDestroy();
89 cb9d104d Leszek Koltunski
      super.onDestroy();
90
      }
91
92 6d896e0e leszek
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 c658e742 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
122 cb9d104d Leszek Koltunski
123
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
124
      {
125 77e66c58 Leszek Koltunski
      GlowSurfaceView v = findViewById(R.id.glowSurfaceView);
126
      GlowRenderer r = v.getRenderer();
127 cb9d104d Leszek Koltunski
128 77e66c58 Leszek Koltunski
      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 cb9d104d Leszek Koltunski
        {
137 77e66c58 Leszek Koltunski
        float alpha = r.setGlowAlpha(progress);
138
        textAlpha.setText(getString(R.string.glow_alpha_placeholder, alpha));
139 cb9d104d Leszek Koltunski
        }
140
      }
141
142 c658e742 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
143 cb9d104d Leszek Koltunski
144
    public void onStartTrackingTouch(SeekBar bar) { }
145
146 c658e742 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
147 cb9d104d Leszek Koltunski
148
    public void onStopTrackingTouch(SeekBar bar)  { }
149
150 c658e742 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
151
152
  public void quality0(View v)
153
    {
154 c0f27889 Leszek Koltunski
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
155 c658e742 Leszek Koltunski
    GlowRenderer renderer = view.getRenderer();
156
    renderer.setQuality(EffectQuality.HIGHEST);
157 6d896e0e leszek
    mQuality = EffectQuality.HIGHEST.ordinal();
158 c658e742 Leszek Koltunski
    }
159
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
  public void quality1(View v)
163
    {
164 c0f27889 Leszek Koltunski
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
165 c658e742 Leszek Koltunski
    GlowRenderer renderer = view.getRenderer();
166
    renderer.setQuality(EffectQuality.HIGH);
167 6d896e0e leszek
    mQuality = EffectQuality.HIGH.ordinal();
168 c658e742 Leszek Koltunski
    }
169
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
172
  public void quality2(View v)
173
    {
174 c0f27889 Leszek Koltunski
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
175 c658e742 Leszek Koltunski
    GlowRenderer renderer = view.getRenderer();
176
    renderer.setQuality(EffectQuality.MEDIUM);
177 6d896e0e leszek
    mQuality = EffectQuality.MEDIUM.ordinal();
178 c658e742 Leszek Koltunski
    }
179
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
182
  public void quality3(View v)
183
    {
184 c0f27889 Leszek Koltunski
    GlowSurfaceView view = findViewById(R.id.glowSurfaceView);
185 c658e742 Leszek Koltunski
    GlowRenderer renderer = view.getRenderer();
186
    renderer.setQuality(EffectQuality.LOW);
187 6d896e0e leszek
    mQuality = EffectQuality.LOW.ordinal();
188 c658e742 Leszek Koltunski
    }
189 cb9d104d Leszek Koltunski
}