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.fragment3d;
|
21
|
|
22
|
import android.app.Activity;
|
23
|
import android.view.View;
|
24
|
import android.widget.LinearLayout;
|
25
|
import android.widget.SeekBar;
|
26
|
import android.widget.TextView;
|
27
|
|
28
|
import org.distorted.examples.R;
|
29
|
import org.distorted.library.EffectNames;
|
30
|
import org.distorted.library.type.Dynamic1D;
|
31
|
import org.distorted.library.type.Dynamic3D;
|
32
|
import org.distorted.library.type.Static1D;
|
33
|
import org.distorted.library.type.Static3D;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
|
37
|
public class Fragment3DEffect implements SeekBar.OnSeekBarChangeListener
|
38
|
{
|
39
|
private EffectNames mName;
|
40
|
private int[] mInter;
|
41
|
private SeekBar[] mSeek;
|
42
|
private int mDimension;
|
43
|
private TextView mText;
|
44
|
|
45
|
private Dynamic1D mDyn1;
|
46
|
private Dynamic3D mDyn3;
|
47
|
private Static1D mSta1;
|
48
|
private Static3D mSta3;
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
|
52
|
private void fillStatics()
|
53
|
{
|
54
|
switch(mName)
|
55
|
{
|
56
|
case CHROMA : mSta1.set(mInter[0]/100.0f);
|
57
|
mSta3.set(255.0f*mInter[1]/100,
|
58
|
255.0f*mInter[2]/100,
|
59
|
255.0f*mInter[3]/100);
|
60
|
break;
|
61
|
case ALPHA : mSta1.set(mInter[0]/100.0f);
|
62
|
break;
|
63
|
case SATURATION: mSta1.set(mInter[0]/100.0f);
|
64
|
break;
|
65
|
case CONTRAST : mSta1.set(mInter[0]/100.0f);
|
66
|
break;
|
67
|
case BRIGHTNESS: mSta1.set(mInter[0]/100.0f);
|
68
|
break;
|
69
|
}
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
private void setDefaultInter()
|
75
|
{
|
76
|
switch(mName)
|
77
|
{
|
78
|
case CHROMA : mInter[0] = 0;
|
79
|
mInter[1] = 0;
|
80
|
mInter[2] = 0;
|
81
|
mInter[3] = 0;
|
82
|
break;
|
83
|
case ALPHA : mInter[0] = 100;
|
84
|
break;
|
85
|
case SATURATION: mInter[0] = 100;
|
86
|
break;
|
87
|
case CONTRAST : mInter[0] = 100;
|
88
|
break;
|
89
|
case BRIGHTNESS: mInter[0] = 100;
|
90
|
break;
|
91
|
}
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
private void setText()
|
97
|
{
|
98
|
switch(mName)
|
99
|
{
|
100
|
case CHROMA : mText.setText("chroma "+mSta1.getX()+"("+mSta3.getX()+","+mSta3.getY()+","+mSta3.getZ()+")");
|
101
|
break;
|
102
|
case ALPHA : mText.setText("alpha ("+mSta1.getX()+")");
|
103
|
break;
|
104
|
case SATURATION: mText.setText("saturation ("+mSta1.getX()+")");
|
105
|
break;
|
106
|
case CONTRAST : mText.setText("contrast ("+mSta1.getX()+")");
|
107
|
break;
|
108
|
case BRIGHTNESS: mText.setText("brightness ("+mSta1.getX()+")");
|
109
|
break;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public Fragment3DEffect(EffectNames name)
|
116
|
{
|
117
|
mName = name;
|
118
|
|
119
|
if( mName==EffectNames.CHROMA )
|
120
|
{
|
121
|
mDimension = 4;
|
122
|
mDyn3 = new Dynamic3D();
|
123
|
mSta3 = new Static3D(0,0,0);
|
124
|
mDyn3.add(mSta3);
|
125
|
}
|
126
|
else
|
127
|
{
|
128
|
mDimension = 1;
|
129
|
mDyn3 = null;
|
130
|
mSta3 = null;
|
131
|
}
|
132
|
|
133
|
mInter = new int[mDimension];
|
134
|
mSeek = new SeekBar[mDimension];
|
135
|
|
136
|
mDyn1 = new Dynamic1D();
|
137
|
mSta1 = new Static1D(0);
|
138
|
mDyn1.add(mSta1);
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
public Dynamic1D getDyn1()
|
144
|
{
|
145
|
return mDyn1;
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
|
150
|
public Dynamic3D getDyn3()
|
151
|
{
|
152
|
return mDyn3;
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
|
157
|
public View createView(Activity act)
|
158
|
{
|
159
|
View effect;
|
160
|
|
161
|
switch(mDimension)
|
162
|
{
|
163
|
case 1 : effect = act.getLayoutInflater().inflate(R.layout.effect1d, null);
|
164
|
mText = (TextView)effect.findViewById(R.id.effect1dText);
|
165
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect1dbar1);
|
166
|
break;
|
167
|
case 2 : effect = act.getLayoutInflater().inflate(R.layout.effect2d, null);
|
168
|
mText = (TextView)effect.findViewById(R.id.effect2dText);
|
169
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect2dbar1);
|
170
|
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect2dbar2);
|
171
|
break;
|
172
|
case 3 : effect = act.getLayoutInflater().inflate(R.layout.effect3d, null);
|
173
|
mText = (TextView)effect.findViewById(R.id.effect3dText);
|
174
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect3dbar1);
|
175
|
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect3dbar2);
|
176
|
mSeek[2] = (SeekBar)effect.findViewById(R.id.effect3dbar3);
|
177
|
break;
|
178
|
case 4 : effect = act.getLayoutInflater().inflate(R.layout.effect4d, null);
|
179
|
mText = (TextView)effect.findViewById(R.id.effect4dText);
|
180
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect4dbar1);
|
181
|
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect4dbar2);
|
182
|
mSeek[2] = (SeekBar)effect.findViewById(R.id.effect4dbar3);
|
183
|
mSeek[3] = (SeekBar)effect.findViewById(R.id.effect4dbar3);
|
184
|
break;
|
185
|
default: android.util.Log.e("Fragment3DEffect", "dimension "+mDimension+" not supported!");
|
186
|
return null;
|
187
|
}
|
188
|
|
189
|
setDefaultInter();
|
190
|
fillStatics();
|
191
|
setText();
|
192
|
|
193
|
for(int i=0; i<mDimension; i++)
|
194
|
{
|
195
|
mSeek[i].setOnSeekBarChangeListener(this);
|
196
|
mSeek[i].setProgress( mInter[i] );
|
197
|
}
|
198
|
|
199
|
return effect;
|
200
|
}
|
201
|
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
205
|
{
|
206
|
if ( mDimension>=1 && bar.getId()==mSeek[0].getId() ) mInter[0] = progress;
|
207
|
if ( mDimension>=2 && bar.getId()==mSeek[1].getId() ) mInter[1] = progress;
|
208
|
if ( mDimension>=3 && bar.getId()==mSeek[2].getId() ) mInter[2] = progress;
|
209
|
if ( mDimension>=4 && bar.getId()==mSeek[3].getId() ) mInter[3] = progress;
|
210
|
|
211
|
fillStatics();
|
212
|
setText();
|
213
|
}
|
214
|
|
215
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216
|
|
217
|
public void onStartTrackingTouch(SeekBar bar) { }
|
218
|
|
219
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220
|
|
221
|
public void onStopTrackingTouch(SeekBar bar) { }
|
222
|
}
|