Project

General

Profile

« Previous | Next » 

Revision f9afbbf3

Added by Leszek Koltunski over 8 years ago

Upgrade what used to be the 'Scratchpad' app; step 2: reorganize layout

View differences:

src/main/java/org/distorted/examples/TableOfContents.java
71 71
  public void onCreate(Bundle savedInstanceState) 
72 72
   {
73 73
   super.onCreate(savedInstanceState);
74
   setTitle(R.string.toc);
75 74
   setContentView(R.layout.table_of_contents);
76 75
      
77 76
   final List<Map<String, Object>> data = new ArrayList<>();
src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java
26 26
import android.opengl.GLSurfaceView;
27 27
import android.os.Bundle;
28 28
import android.view.View;
29
import android.widget.SeekBar.OnSeekBarChangeListener;
30
import android.widget.SeekBar;
31
import android.widget.TextView;
29
import android.widget.AdapterView;
30
import android.widget.ArrayAdapter;
31
import android.widget.Spinner;
32 32

  
33 33
///////////////////////////////////////////////////////////////////////////////////////////////////
34 34

  
35
public class Effects2DActivity extends Activity implements OnSeekBarChangeListener
35
public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener
36 36
  {
37
  private static final float D_MULT=200.0f;
38
  private static final float C_MULT=  0.1f;
39
   
40
  private long effectID;
41
   
42
  private SeekBar barD, barC, barI;
43
  private TextView textD, textC, textI;
44
   
37
  private Spinner mID, mName, mType;
38
  private ArrayAdapter<String> mAdapterID, mAdapterName, mAdapterType;
39

  
45 40
///////////////////////////////////////////////////////////////////////////////////////////////////
46 41

  
47 42
  @Override
......
49 44
    {
50 45
    super.onCreate(savedInstanceState);
51 46
 
52
    setContentView(R.layout.scratchpadlayout);
53
      
54
    barD = (SeekBar)findViewById(R.id.scratchpadSeekDuration);
55
    barD.setOnSeekBarChangeListener(this); 
56
    barC = (SeekBar)findViewById(R.id.scratchpadSeekCount);
57
    barC.setOnSeekBarChangeListener(this); 
58
    barI = (SeekBar)findViewById(R.id.scratchpadSeekID);
59
    barI.setOnSeekBarChangeListener(this); 
60
        
61
    textD = (TextView)findViewById(R.id.scratchpadTextDuration);
62
    textC = (TextView)findViewById(R.id.scratchpadTextCount);
63
    textI = (TextView)findViewById(R.id.scratchpadTextID);
64
      
65
    barD.setProgress(100);
66
    barC.setProgress(10);
67
    barI.setProgress(0);
68
      
69
    textD.setText("Dur: 20 s");
70
    textC.setText("Cou: 1.0");
71
    textI.setText("ID: 0");
47
    setContentView(R.layout.effects2dlayout);
48

  
49
    mID   = (Spinner)findViewById(R.id.effects2d_spinnerID  );
50
    mName = (Spinner)findViewById(R.id.effects2d_spinnerName);
51
    mType = (Spinner)findViewById(R.id.effects2d_spinnerType);
52

  
53
    mID.setOnItemSelectedListener(this);
54
    mName.setOnItemSelectedListener(this);
55
    mType.setOnItemSelectedListener(this);
56

  
57
    String[] itemsID   = new String[] {"1", "2", "3"};
58
    String[] itemsName = new String[] { getText(R.string.distort     ).toString(),
59
                                        getText(R.string.sink        ).toString(),
60
                                        getText(R.string.transparency).toString(),
61
                                        getText(R.string.macroblock  ).toString(),
62
                                        getText(R.string.chroma      ).toString()};
63
    String[] itemsType = new String[] {"VERTEX", "FRAGMENT"};
64

  
65
    mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID);
66
    mAdapterID.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
67
    mID.setAdapter(mAdapterID);
68

  
69
    mAdapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName);
70
    mAdapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
71
    mName.setAdapter(mAdapterName);
72

  
73
    mAdapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType);
74
    mAdapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
75
    mType.setAdapter(mAdapterType);
72 76
    }
73 77

  
74 78
///////////////////////////////////////////////////////////////////////////////////////////////////
......
140 144
 
141 145
///////////////////////////////////////////////////////////////////////////////////////////////////
142 146

  
143
  public void Brightness(View v)
147
  public void Chroma(View v)
144 148
    {
145 149
    Effects2DSurfaceView.setEffect(4);
146
    }       
147
     
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

  
150
  public void Print(View v)
151
    {
152
    Effects2DRenderer.mBackground.printEffect(effectID);
153 150
    }
154 151

  
155 152
///////////////////////////////////////////////////////////////////////////////////////////////////
156 153

  
157
  public void Abort(View v)
154
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
158 155
    {
159
    Effects2DRenderer.mBackground.abortEffect(effectID);
160
    }
156
    // An item was selected. You can retrieve the selected item using
157
    // parent.getItemAtPosition(pos)
161 158

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163
    
164
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
165
    {
166
    float v, t; 
167
    int i;
168
      
169
    switch (bar.getId()) 
159
    switch(parent.getId())
170 160
      {
171
      case R.id.scratchpadSeekDuration: v = progress*D_MULT;
172
                                        i = (int)(v/100);
173
                                        t = i/10.0f;
174
                                        Effects2DSurfaceView.setDuration((int)v);
175
                                        textD.setText("Dur: "+(int)t+" s");
176
                                        break;
177
      case R.id.scratchpadSeekCount   : v = progress*C_MULT;
178
                                        i = (int)(v*10);
179
                                        t = i/10.0f;
180
                                        Effects2DSurfaceView.setCount(v);
181
                                        textC.setText("Cou: "+t);
182
                                        break;
183
      case R.id.scratchpadSeekID      : effectID = progress;
184
                                        textI.setText("ID: "+progress);
185
                                        break;                        
161
      case R.id.effects2d_spinnerID  : android.util.Log.d("EFFECTS2D", "ID spinner!!"  ); break;
162
      case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "Name spinner!!"); break;
163
      case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "Type spinner!!"); break;
186 164
      }
187 165
    }
188 166

  
189 167
///////////////////////////////////////////////////////////////////////////////////////////////////
190 168

  
191
  public void onStartTrackingTouch(SeekBar bar) { }
192
    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

  
195
  public void onStopTrackingTouch(SeekBar bar)  { }
169
  public void onNothingSelected(AdapterView<?> parent)
170
    {
171
    switch(parent.getId())
172
      {
173
      case R.id.effects2d_spinnerID  : android.util.Log.d("EFFECTS2D", "(nothing) ID spinner!!"  ); break;
174
      case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "(nothing) Name spinner!!"); break;
175
      case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "(nothing) Type spinner!!"); break;
176
      }
177
    }
196 178
  }
src/main/java/org/distorted/examples/effects2d/Effects2DSurfaceView.java
46 46
  private static Static2D point;
47 47

  
48 48
  private static Static4D mRegion;
49
  private static Dynamic1D mInterA, mInterM, mInterB, mInterS;
49
  private static Dynamic1D mInterA, mInterM, mInterC, mInterS;
50 50

  
51 51
  private static Dynamic3D mInterD;
52 52
  private static Static3D v0, v1, v2, v3;
53
     
53

  
54
  private final static Static3D mRED = new Static3D(1,0,0);
55

  
54 56
///////////////////////////////////////////////////////////////////////////////////////////////////
55 57
    
56 58
  public Effects2DSurfaceView(Context c, AttributeSet attrs)
......
83 85
    mInterS.add(new Static1D(1.0f));
84 86
    mInterS.add(new Static1D(0.3f));
85 87

  
86
    mInterB = new Dynamic1D(mDuration,mCount);
87
    mInterB.add(new Static1D(1));
88
    mInterB.add(new Static1D(0));
88
    mInterC = new Dynamic1D(mDuration,mCount);
89
    mInterC.add(new Static1D(1));
90
    mInterC.add(new Static1D(0));
89 91

  
90 92
    mInterM = new Dynamic1D(mDuration,mCount);
91 93
    mInterM.add(new Static1D(1));
......
122 124
    mScrH = height;
123 125
    }
124 126

  
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

  
127
  public static int getEffect()
128
    {
129
    return mCurrentEffect;
130
    }
131
   
132 127
///////////////////////////////////////////////////////////////////////////////////////////////////
133 128

  
134 129
  public static void setEffect(int effect)
......
136 131
    mCurrentEffect = effect;
137 132
    }
138 133

  
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

  
141
  public static void setDuration(int duration)
142
    {
143
    mDuration = duration;
144
    mInterD.setDuration(duration);
145
    mInterA.setDuration(duration);
146
    mInterB.setDuration(duration);
147
    mInterM.setDuration(duration);
148
    mInterS.setDuration(duration);
149
    }
150

  
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

  
153
  public static void setCount(float count)
154
    {
155
    mCount = count;
156
    mInterD.setCount(count);
157
    mInterA.setCount(count);
158
    mInterB.setCount(count);
159
    mInterM.setCount(count);
160
    mInterS.setCount(count);
161
    }
162
  
163 134
///////////////////////////////////////////////////////////////////////////////////////////////////
164 135
    
165 136
  @Override public boolean onTouchEvent(MotionEvent event) 
......
184 155
                                           break;  
185 156
                                      case 3: Effects2DRenderer.mBackground.macroblock(mInterM, mRegion);
186 157
                                           break;
187
                                      case 4: Effects2DRenderer.mBackground.brightness(mInterB, mRegion, false);
158
                                      case 4: Effects2DRenderer.mBackground.chroma(mInterC, mRED, mRegion, false);
188 159
                                           break;      
189 160
                                      }
190 161
                                    break;
src/main/res/layout/effects2dlayout.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:orientation="vertical" >
6

  
7
    <org.distorted.examples.effects2d.Effects2DSurfaceView
8
        android:id="@+id/scratchpadSurfaceView"
9
        android:layout_width="fill_parent"
10
        android:layout_height="0dp"
11
        android:layout_weight="1" />
12

  
13
    <LinearLayout
14
        android:id="@+id/linearLayout1"
15
        android:layout_width="fill_parent"
16
        android:layout_height="wrap_content"
17
        android:layout_weight="0.3"
18
        android:gravity="fill_horizontal|top"
19
        android:orientation="vertical"
20
        android:weightSum="1">
21

  
22
        <View
23
            android:layout_height="2dip"
24
            android:background="#FF0000"
25
            android:layout_width="match_parent"
26
            />
27

  
28
        <TextView
29
            android:layout_width="wrap_content"
30
            android:layout_height="wrap_content"
31
            android:text="@string/add"
32
            android:id="@+id/textView"
33
            android:layout_gravity="center_horizontal"/>
34

  
35
        <RadioGroup
36
            android:id="@+id/radioGroup1"
37
            android:layout_width="wrap_content"
38
            android:layout_height="wrap_content"
39
            android:paddingLeft="5dp"
40
            android:paddingRight="10dp"
41
            android:orientation="horizontal"
42
            android:layout_gravity="center_horizontal">
43

  
44
            <RadioButton
45
                android:id="@+id/scratchpadDistort"
46
                android:layout_width="wrap_content"
47
                android:layout_height="wrap_content"
48
                android:checked="true"
49
                android:onClick="Distort"
50
                android:text="@string/distort"
51
                android:textSize="12dp"/>
52

  
53
            <RadioButton
54
                android:id="@+id/scratchpadSink"
55
                android:layout_width="wrap_content"
56
                android:layout_height="wrap_content"
57
                android:onClick="Sink"
58
                android:text="@string/sink"
59
                android:textSize="12dp"/>
60

  
61
            <RadioButton
62
                android:id="@+id/scratchpadTransparency"
63
                android:layout_width="wrap_content"
64
                android:layout_height="wrap_content"
65
                android:onClick="Transparency"
66
                android:text="@string/transparency"
67
                android:textSize="12dp"/>
68

  
69
            <RadioButton
70
                android:id="@+id/scratchpadMacroblock"
71
                android:layout_width="wrap_content"
72
                android:layout_height="wrap_content"
73
                android:onClick="Macroblock"
74
                android:text="@string/macroblock"
75
                android:textSize="12dp"/>
76

  
77
            <RadioButton
78
                android:id="@+id/scratchpadBrightness"
79
                android:layout_width="wrap_content"
80
                android:layout_height="wrap_content"
81
                android:onClick="Chroma"
82
                android:text="@string/chroma"
83
                android:textSize="12dp"/>
84

  
85
        </RadioGroup>
86

  
87
        <View
88
            android:layout_height="2dip"
89
            android:background="#FF0000"
90
            android:layout_width="match_parent"/>
91

  
92
        <TextView
93
            android:layout_width="wrap_content"
94
            android:layout_height="wrap_content"
95
            android:text="@string/remove"
96
            android:id="@+id/textView2"
97
            android:layout_gravity="center_horizontal"/>
98

  
99
        <TableLayout
100
            android:layout_width="fill_parent"
101
            android:layout_height="wrap_content"
102
            android:paddingTop="10dp"
103
            android:paddingBottom="10dp"
104
            android:stretchColumns="0,1"
105
            android:paddingLeft="10dp"
106
            android:paddingRight="10dp">
107

  
108
            <TableRow
109
                android:layout_width="wrap_content"
110
                android:layout_height="wrap_content"
111
                android:layout_gravity="center"
112
                android:orientation="vertical">
113

  
114
                <TextView
115
                    android:layout_width="match_parent"
116
                    android:layout_height="wrap_content"
117
                    android:text="@string/id"
118
                    android:id="@+id/textView3"
119
                    android:layout_gravity="center"/>
120

  
121
                <Spinner
122
                    android:layout_width="fill_parent"
123
                    android:layout_height="40dp"
124
                    android:id="@+id/effects2d_spinnerID"/>
125
            </TableRow>
126

  
127
            <TableRow
128
                android:layout_width="wrap_content"
129
                android:layout_height="wrap_content"
130
                android:layout_gravity="center">
131

  
132
                <TextView
133
                    android:layout_width="match_parent"
134
                    android:layout_height="wrap_content"
135
                    android:text="@string/name"
136
                    android:id="@+id/textView4"
137
                    android:layout_gravity="center"/>
138

  
139
                <Spinner
140
                    android:layout_width="fill_parent"
141
                    android:layout_height="40dp"
142
                    android:id="@+id/effects2d_spinnerName"/>
143
            </TableRow>
144

  
145
            <TableRow
146
                android:layout_width="wrap_content"
147
                android:layout_height="wrap_content"
148
                android:layout_gravity="center">
149

  
150
                <TextView
151
                    android:layout_width="wrap_content"
152
                    android:layout_height="wrap_content"
153
                    android:text="@string/type"
154
                    android:id="@+id/textView5"
155
                    android:layout_gravity="center"/>
156

  
157
                <Spinner
158
                    android:layout_width="fill_parent"
159
                    android:layout_height="40dp"
160
                    android:id="@+id/effects2d_spinnerType"/>
161
            </TableRow>
162

  
163
        </TableLayout>
164
        <View
165
            android:layout_height="2dip"
166
            android:background="#FF0000"
167
            android:layout_width="match_parent"
168
            />
169

  
170
        <TextView
171
            android:layout_width="wrap_content"
172
            android:layout_height="wrap_content"
173
            android:text="@string/list"
174
            android:id="@+id/textView6"
175
            android:layout_gravity="center_horizontal"/>
176
    </LinearLayout>
177

  
178
</LinearLayout>
src/main/res/layout/scratchpadlayout.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:onClick="Brightness"
6
    android:orientation="vertical" >
7

  
8
    <org.distorted.examples.effects2d.Effects2DSurfaceView
9
        android:id="@+id/scratchpadSurfaceView"
10
        android:layout_width="fill_parent"
11
        android:layout_height="0dp"
12
        android:layout_weight="1" />
13

  
14
    <LinearLayout
15
        android:id="@+id/linearLayout1"
16
        android:layout_width="fill_parent"
17
        android:layout_height="wrap_content"
18
        android:layout_weight="0.07"
19
        android:gravity="center|fill_horizontal" >
20

  
21
        <RadioGroup
22
            android:id="@+id/radioGroup1"
23
            android:layout_width="wrap_content"
24
            android:layout_height="wrap_content"
25
            android:paddingLeft="5dp"
26
            android:paddingRight="10dp" >
27
			
28
            <RadioButton
29
                android:id="@+id/scratchpadDistort"
30
                android:layout_width="wrap_content"
31
                android:layout_height="wrap_content"
32
                android:checked="true"
33
                android:onClick="Distort"
34
                android:text="@string/distort" />
35

  
36
            <RadioButton
37
                android:id="@+id/scratchpadSink"
38
                android:layout_width="wrap_content"
39
                android:layout_height="wrap_content"
40
                android:onClick="Sink"
41
                android:text="@string/sink" />
42

  
43
            <RadioButton
44
                android:id="@+id/scratchpadTransparency"
45
                android:layout_width="wrap_content"
46
                android:layout_height="wrap_content"
47
                android:onClick="Transparency"
48
                android:text="@string/transparency" />
49

  
50
            <RadioButton
51
                android:id="@+id/scratchpadMacroblock"
52
                android:layout_width="wrap_content"
53
                android:layout_height="wrap_content"
54
                android:onClick="Macroblock"
55
                android:text="@string/macroblock" />
56

  
57
            <RadioButton
58
                android:id="@+id/scratchpadBrightness"
59
                android:layout_width="wrap_content"
60
                android:layout_height="wrap_content"
61
                android:onClick="Brightness"
62
                android:text="@string/brightness" />
63

  
64
        </RadioGroup>
65

  
66
        <LinearLayout
67
            android:layout_width="match_parent"
68
            android:layout_height="match_parent"
69
            android:gravity="center_vertical|right"
70
            android:orientation="vertical"
71
            android:paddingLeft="10dp"
72
            android:paddingRight="5dp" >
73

  
74
            <LinearLayout
75
                android:layout_width="match_parent"
76
                android:layout_height="45dp"
77
                android:gravity="center_vertical"
78
                android:orientation="horizontal" >
79

  
80
                <TextView
81
                    android:id="@+id/scratchpadTextCount"
82
                    android:layout_width="wrap_content"
83
                    android:layout_height="wrap_content"
84
                    android:layout_weight="1"
85
                    android:text="@string/count"
86
                    android:textAppearance="?android:attr/textAppearanceMedium" />
87

  
88
                <SeekBar
89
                    android:id="@+id/scratchpadSeekCount"
90
                    android:layout_width="105dp"
91
                    android:layout_height="wrap_content"
92
                    android:layout_weight="1"
93
                    android:paddingLeft="0dp"
94
                    android:paddingRight="3dp" />
95
            </LinearLayout>
96

  
97
            <LinearLayout
98
                android:layout_width="match_parent"
99
                android:layout_height="wrap_content"
100
                android:gravity="center_vertical"
101
                android:orientation="horizontal" >
102

  
103
                <TextView
104
                    android:id="@+id/scratchpadTextDuration"
105
                    android:layout_width="0dp"
106
                    android:layout_height="wrap_content"
107
                    android:layout_weight="1"
108
                    android:text="@string/duration"
109
                    android:textAppearance="?android:attr/textAppearanceMedium" />
110

  
111
                <SeekBar
112
                    android:id="@+id/scratchpadSeekDuration"
113
                    android:layout_width="106dp"
114
                    android:layout_height="wrap_content"
115
                    android:paddingLeft="0dp"
116
                    android:paddingRight="3dp" />
117

  
118
            </LinearLayout>
119

  
120
            <LinearLayout
121
                android:layout_width="match_parent"
122
                android:layout_height="wrap_content"
123
                android:orientation="horizontal" >
124

  
125
                <Button
126
                    android:id="@+id/scratchpadButtonPrint"
127
                    android:layout_width="24dp"
128
                    android:layout_height="match_parent"
129
                    android:layout_weight="0.77"
130
                    android:onClick="Print"
131
                    android:text="@string/print" />
132

  
133
                <Button
134
                    android:id="@+id/scratchpadButtonAbort"
135
                    android:layout_width="wrap_content"
136
                    android:layout_height="match_parent"
137
                    android:layout_weight="0.39"
138
                    android:onClick="Abort"
139
                    android:text="@string/abort" />
140
            </LinearLayout>
141

  
142
            <LinearLayout
143
                android:layout_width="match_parent"
144
                android:layout_height="45dp"
145
                android:gravity="center_vertical"
146
                android:orientation="horizontal" >
147

  
148
                <TextView
149
                    android:id="@+id/scratchpadTextID"
150
                    android:layout_width="0dp"
151
                    android:layout_height="wrap_content"
152
                    android:layout_weight="1"
153
                    android:text="@string/id"
154
                    android:textAppearance="?android:attr/textAppearanceMedium" />
155

  
156
                <SeekBar
157
                    android:id="@+id/scratchpadSeekID"
158
                    android:layout_width="110dp"
159
                    android:layout_height="wrap_content" />
160

  
161
            </LinearLayout>
162

  
163
        </LinearLayout>
164

  
165
    </LinearLayout>
166

  
167
</LinearLayout>
src/main/res/values/strings.xml
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<resources>    
3 3
    <string name="app_name">Distorted Examples</string>
4
    <string name="toc">Table of Contents</string>
5 4
    <string name="tocHeader">Welcome to the Distorted Examples!\nCode, Tutorials, Wiki: http://distorted.org/</string>
6 5
    
7 6
    <string name="continu">Continue</string>
......
19 18
    <string name="sink">Sink</string>
20 19
    <string name="transparency">Trans</string>
21 20
    <string name="macroblock">Macro</string>
22
    <string name="brightness">Bright</string>
21
    <string name="chroma">Chroma</string>
22
    <string name="add">Touch screen to add new</string>
23
    <string name="remove">Remove existing effect(s) by</string>
24
    <string name="name">Name</string>
25
    <string name="type">Type</string>
26
    <string name="id">ID</string>
27
    <string name="list">List of all existing effects</string>
23 28
    <string name="swirl">Swirl</string>
24 29
    <string name="print">Print</string>
25 30
    <string name="abort">Abort</string>
26 31
    <string name="count">Count</string>
27
    <string name="id">ID</string>
28 32
    <string name="maxv">vertex:</string>
29 33
    <string name="maxf">fragment:</string>
30 34
    <string name="introduction">Set maximum number of vertex and fragment effects and press \'Check\' to see if shaders compile:</string>

Also available in: Unified diff