1 |
50f58197
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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] = 100;
|
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 |
|
|
mDimension = name.getDimension();
|
119 |
|
|
|
120 |
|
|
mInter = new int[mDimension];
|
121 |
|
|
mSeek = new SeekBar[mDimension];
|
122 |
|
|
|
123 |
|
|
mDyn1 = new Dynamic1D();
|
124 |
|
|
mSta1 = new Static1D(0);
|
125 |
|
|
mDyn1.add(mSta1);
|
126 |
|
|
|
127 |
|
|
if( mName==EffectNames.CHROMA )
|
128 |
|
|
{
|
129 |
|
|
mDyn3 = new Dynamic3D();
|
130 |
|
|
mSta3 = new Static3D(0,0,0);
|
131 |
|
|
mDyn3.add(mSta3);
|
132 |
|
|
}
|
133 |
|
|
else
|
134 |
|
|
{
|
135 |
|
|
mDyn3 = null;
|
136 |
|
|
mSta3 = null;
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
|
|
|
142 |
|
|
public void addView(Activity act, LinearLayout layout)
|
143 |
|
|
{
|
144 |
|
|
View effect;
|
145 |
|
|
|
146 |
|
|
switch(mDimension)
|
147 |
|
|
{
|
148 |
|
|
case 1 : effect = act.getLayoutInflater().inflate(R.layout.effect1d, null);
|
149 |
|
|
mText = (TextView)effect.findViewById(R.id.effect1dText);
|
150 |
|
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect1dbar1);
|
151 |
|
|
break;
|
152 |
|
|
case 2 : effect = act.getLayoutInflater().inflate(R.layout.effect2d, null);
|
153 |
|
|
mText = (TextView)effect.findViewById(R.id.effect2dText);
|
154 |
|
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect2dbar1);
|
155 |
|
|
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect2dbar2);
|
156 |
|
|
break;
|
157 |
|
|
case 3 : effect = act.getLayoutInflater().inflate(R.layout.effect3d, null);
|
158 |
|
|
mText = (TextView)effect.findViewById(R.id.effect3dText);
|
159 |
|
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect3dbar1);
|
160 |
|
|
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect3dbar2);
|
161 |
|
|
mSeek[2] = (SeekBar)effect.findViewById(R.id.effect3dbar3);
|
162 |
|
|
break;
|
163 |
|
|
case 4 : effect = act.getLayoutInflater().inflate(R.layout.effect4d, null);
|
164 |
|
|
mText = (TextView)effect.findViewById(R.id.effect4dText);
|
165 |
|
|
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect4dbar1);
|
166 |
|
|
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect4dbar2);
|
167 |
|
|
mSeek[2] = (SeekBar)effect.findViewById(R.id.effect4dbar3);
|
168 |
|
|
mSeek[3] = (SeekBar)effect.findViewById(R.id.effect4dbar3);
|
169 |
|
|
break;
|
170 |
|
|
default: android.util.Log.e("Fragment3DEffect", "dimension "+mDimension+" not supported!");
|
171 |
|
|
return;
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
setDefaultInter();
|
175 |
|
|
fillStatics();
|
176 |
|
|
setText();
|
177 |
|
|
|
178 |
|
|
for(int i=0; i<mDimension; i++)
|
179 |
|
|
{
|
180 |
|
|
mSeek[i].setOnSeekBarChangeListener(this);
|
181 |
|
|
mSeek[i].setProgress( mInter[i] );
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
layout.addView(effect, 0);
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188 |
|
|
|
189 |
|
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
190 |
|
|
{
|
191 |
|
|
if ( mDimension>=1 && bar.getId()==mSeek[0].getId() ) mInter[0] = progress;
|
192 |
|
|
if ( mDimension>=2 && bar.getId()==mSeek[1].getId() ) mInter[1] = progress;
|
193 |
|
|
if ( mDimension>=3 && bar.getId()==mSeek[2].getId() ) mInter[2] = progress;
|
194 |
|
|
if ( mDimension>=4 && bar.getId()==mSeek[3].getId() ) mInter[3] = progress;
|
195 |
|
|
|
196 |
|
|
fillStatics();
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200 |
|
|
|
201 |
|
|
public void onStartTrackingTouch(SeekBar bar) { }
|
202 |
|
|
|
203 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204 |
|
|
|
205 |
|
|
public void onStopTrackingTouch(SeekBar bar) { }
|
206 |
|
|
}
|