Project

General

Profile

« Previous | Next » 

Revision a2cb31e9

Added by Leszek Koltunski almost 8 years ago

Beginnings of support for the 'Save' app.

View differences:

src/main/AndroidManifest.xml
34 34
        <activity android:name=".cubes.CubesActivity" />       
35 35
        <activity android:name=".quaternion.QuaternionActivity" />          
36 36
        <activity android:name=".effects3d.Effects3DActivity" />  
37
        <activity android:name=".plainmonalisa.PlainMonaLisaActivity" />  
37
        <activity android:name=".plainmonalisa.PlainMonaLisaActivity" />
38
        <activity android:name=".save.SaveActivity"/>
38 39
    </application>
39 40
</manifest>
src/main/java/org/distorted/examples/TableOfContents.java
15 15
import android.widget.AdapterView.OnItemClickListener;
16 16
import android.widget.SimpleAdapter;
17 17

  
18
import org.distorted.examples.R;
19 18
import org.distorted.examples.monalisa.MonaLisaActivity;
20 19
import org.distorted.examples.sink.SinkActivity;
21 20
import org.distorted.examples.fov.FOVActivity;
......
37 36
import org.distorted.examples.quaternion.QuaternionActivity;
38 37
import org.distorted.examples.effects3d.Effects3DActivity;
39 38
import org.distorted.examples.plainmonalisa.PlainMonaLisaActivity;
39
import org.distorted.examples.save.SaveActivity;
40 40

  
41 41
///////////////////////////////////////////////////////////////////////////////////////////////////
42 42

  
......
55 55
   setTitle(R.string.toc);
56 56
   setContentView(R.layout.table_of_contents);
57 57
      
58
   final List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
59
   final SparseArray<Class<? extends Activity>> activityMapping = new SparseArray<Class<? extends Activity>>();
58
   final List<Map<String, Object>> data = new ArrayList<>();
59
   final SparseArray<Class<? extends Activity>> activityMapping = new SparseArray<>();
60 60
      
61 61
   int i = 0;
62 62
   
63 63
   {
64
      final Map<String, Object> item = new HashMap<String, Object>();
64
      final Map<String, Object> item = new HashMap<>();
65 65
      item.put(ITEM_IMAGE, R.drawable.icon_example_monalisa);
66 66
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_monalisa));
67 67
      item.put(ITEM_SUBTITLE, getText(R.string.example_monalisa_subtitle));
......
70 70
   }
71 71
      
72 72
   {
73
      final Map<String, Object> item = new HashMap<String, Object>();
73
      final Map<String, Object> item = new HashMap<>();
74 74
      item.put(ITEM_IMAGE, R.drawable.icon_example_sink);
75 75
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_sink));
76 76
      item.put(ITEM_SUBTITLE, getText(R.string.example_sink_subtitle));
......
79 79
   }
80 80
   
81 81
   {
82
      final Map<String, Object> item = new HashMap<String, Object>();
82
      final Map<String, Object> item = new HashMap<>();
83 83
      item.put(ITEM_IMAGE, R.drawable.icon_example_bean);
84 84
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_bean));
85 85
      item.put(ITEM_SUBTITLE, getText(R.string.example_bean_subtitle));
......
88 88
   }
89 89
   
90 90
   {
91
      final Map<String, Object> item = new HashMap<String, Object>();
91
      final Map<String, Object> item = new HashMap<>();
92 92
      item.put(ITEM_IMAGE, R.drawable.icon_example_fov);
93 93
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fov));
94 94
      item.put(ITEM_SUBTITLE, getText(R.string.example_fov_subtitle));
......
97 97
   }
98 98
         
99 99
   {
100
      final Map<String, Object> item = new HashMap<String, Object>();
100
      final Map<String, Object> item = new HashMap<>();
101 101
      item.put(ITEM_IMAGE, R.drawable.icon_example_deform);
102 102
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_deform));
103 103
      item.put(ITEM_SUBTITLE, getText(R.string.example_deform_subtitle));
......
106 106
   }
107 107
  
108 108
   {
109
      final Map<String, Object> item = new HashMap<String, Object>();
109
      final Map<String, Object> item = new HashMap<>();
110 110
      item.put(ITEM_IMAGE, R.drawable.icon_example_listener);
111 111
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_listener));
112 112
      item.put(ITEM_SUBTITLE, getText(R.string.example_listener_subtitle));
......
115 115
   }
116 116
   
117 117
   {
118
      final Map<String, Object> item = new HashMap<String, Object>();
118
      final Map<String, Object> item = new HashMap<>();
119 119
      item.put(ITEM_IMAGE, R.drawable.icon_example_interpolator);
120 120
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_interpolator));
121 121
      item.put(ITEM_SUBTITLE, getText(R.string.example_interpolator_subtitle));
......
124 124
   }
125 125
   
126 126
   {
127
      final Map<String, Object> item = new HashMap<String, Object>();
127
      final Map<String, Object> item = new HashMap<>();
128 128
      item.put(ITEM_IMAGE, R.drawable.icon_example_girl);
129 129
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_girl));
130 130
      item.put(ITEM_SUBTITLE, getText(R.string.example_girl_subtitle));
......
133 133
   }
134 134
   
135 135
   {
136
      final Map<String, Object> item = new HashMap<String, Object>();
136
      final Map<String, Object> item = new HashMap<>();
137 137
      item.put(ITEM_IMAGE, R.drawable.icon_example_macroblock);
138 138
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_macroblock));
139 139
      item.put(ITEM_SUBTITLE, getText(R.string.example_macroblock_subtitle));
......
142 142
   }
143 143
   
144 144
   {
145
      final Map<String, Object> item = new HashMap<String, Object>();
145
      final Map<String, Object> item = new HashMap<>();
146 146
      item.put(ITEM_IMAGE, R.drawable.icon_example_movingeffects);
147 147
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_movingeffects));
148 148
      item.put(ITEM_SUBTITLE, getText(R.string.example_movingeffects_subtitle));
......
151 151
   }
152 152
   
153 153
   {
154
      final Map<String, Object> item = new HashMap<String, Object>();
154
      final Map<String, Object> item = new HashMap<>();
155 155
      item.put(ITEM_IMAGE, R.drawable.icon_example_differenteffects);
156 156
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_differenteffects));
157 157
      item.put(ITEM_SUBTITLE, getText(R.string.example_differenteffects_subtitle));
......
160 160
   }
161 161
   
162 162
   {
163
      final Map<String, Object> item = new HashMap<String, Object>();
163
      final Map<String, Object> item = new HashMap<>();
164 164
      item.put(ITEM_IMAGE, R.drawable.icon_example_differentbitmaps);
165 165
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_differentbitmaps));
166 166
      item.put(ITEM_SUBTITLE, getText(R.string.example_differentbitmaps_subtitle));
......
169 169
   }
170 170
   
171 171
   {
172
      final Map<String, Object> item = new HashMap<String, Object>();
172
      final Map<String, Object> item = new HashMap<>();
173 173
      item.put(ITEM_IMAGE, R.drawable.icon_example_scratchpad);
174 174
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_scratchpad));
175 175
      item.put(ITEM_SUBTITLE, getText(R.string.example_scratchpad_subtitle));
......
178 178
   }
179 179
   
180 180
   {
181
      final Map<String, Object> item = new HashMap<String, Object>();
181
      final Map<String, Object> item = new HashMap<>();
182 182
      item.put(ITEM_IMAGE, R.drawable.icon_example_check);
183 183
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_check));
184 184
      item.put(ITEM_SUBTITLE, getText(R.string.example_check_subtitle));
......
187 187
   }
188 188
   
189 189
   {
190
      final Map<String, Object> item = new HashMap<String, Object>();
190
      final Map<String, Object> item = new HashMap<>();
191 191
      item.put(ITEM_IMAGE, R.drawable.icon_example_fbo);
192 192
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fbo));
193 193
      item.put(ITEM_SUBTITLE, getText(R.string.example_fbo_subtitle));
......
196 196
   }
197 197
      
198 198
   {
199
      final Map<String, Object> item = new HashMap<String, Object>();
199
      final Map<String, Object> item = new HashMap<>();
200 200
      item.put(ITEM_IMAGE, R.drawable.icon_example_starwars);
201 201
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_starwars));
202 202
      item.put(ITEM_SUBTITLE, getText(R.string.example_starwars_subtitle));
......
205 205
   }
206 206
         
207 207
   {
208
      final Map<String, Object> item = new HashMap<String, Object>();
208
      final Map<String, Object> item = new HashMap<>();
209 209
      item.put(ITEM_IMAGE, R.drawable.icon_example_olimpic);
210 210
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_olimpic));
211 211
      item.put(ITEM_SUBTITLE, getText(R.string.example_olimpic_subtitle));
......
214 214
   }
215 215
   
216 216
   {
217
      final Map<String, Object> item = new HashMap<String, Object>();
217
      final Map<String, Object> item = new HashMap<>();
218 218
      item.put(ITEM_IMAGE, R.drawable.icon_example_quaternion);
219 219
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_quaternion));
220 220
      item.put(ITEM_SUBTITLE, getText(R.string.example_quaternion_subtitle));
......
223 223
   }
224 224
   
225 225
   {
226
      final Map<String, Object> item = new HashMap<String, Object>();
226
      final Map<String, Object> item = new HashMap<>();
227 227
      item.put(ITEM_IMAGE, R.drawable.icon_example_cubes);
228 228
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_cubes));
229 229
      item.put(ITEM_SUBTITLE, getText(R.string.example_cubes_subtitle));
......
232 232
   }
233 233
   
234 234
   {
235
      final Map<String, Object> item = new HashMap<String, Object>();
235
      final Map<String, Object> item = new HashMap<>();
236 236
      item.put(ITEM_IMAGE, R.drawable.icon_example_effects3d);
237 237
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_effects3d));
238 238
      item.put(ITEM_SUBTITLE, getText(R.string.example_effects3d_subtitle));
......
241 241
   }
242 242

  
243 243
   {
244
      final Map<String, Object> item = new HashMap<String, Object>();
244
      final Map<String, Object> item = new HashMap<>();
245 245
      item.put(ITEM_IMAGE, R.drawable.icon_example_monalisa);
246 246
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_plainmonalisa));
247 247
      item.put(ITEM_SUBTITLE, getText(R.string.example_plainmonalisa_subtitle));
248 248
      data.add(item);
249 249
      activityMapping.put(i++, PlainMonaLisaActivity.class);
250 250
   }
251
     
251

  
252
   {
253
      final Map<String, Object> item = new HashMap<>();
254
      item.put(ITEM_IMAGE, R.drawable.icon_example_girl);
255
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_save));
256
      item.put(ITEM_SUBTITLE, getText(R.string.example_save_subtitle));
257
      data.add(item);
258
      activityMapping.put(i++, SaveActivity.class);
259
   }
260

  
252 261
   final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
253 262
   setListAdapter(dataAdapter);  
254 263
      
src/main/java/org/distorted/examples/save/SaveActivity.java
1

  
2
package org.distorted.examples.save;
3

  
4
import org.distorted.library.Distorted;
5
import org.distorted.examples.R;
6

  
7
import android.app.Activity;
8
import android.opengl.GLSurfaceView;
9
import android.os.Bundle;
10
import android.view.View;
11
import android.widget.Button;
12
import android.widget.SeekBar;
13

  
14
///////////////////////////////////////////////////////////////////////////////////////////////////
15

  
16
public class SaveActivity extends Activity implements SeekBar.OnSeekBarChangeListener
17
{
18
    private Button mSave;
19
    private SeekBar barSize;
20

  
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22
    
23
    @Override
24
    protected void onCreate(Bundle icicle) 
25
      {
26
      super.onCreate(icicle);
27
      
28
      setContentView(R.layout.savelayout);
29
           
30
      mSave = (Button)findViewById(R.id.saveButton);
31

  
32
      barSize  = (SeekBar)findViewById(R.id.saveSeekBar);
33
      barSize.setOnSeekBarChangeListener(this);
34
      barSize.setProgress(50);
35
      }
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
    
39
    @Override
40
    protected void onPause() 
41
      {
42
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
43
      mView.onPause();
44
      
45
      super.onPause();
46
      }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
    
50
    @Override
51
    protected void onResume() 
52
      {
53
      super.onResume();
54
      
55
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView);
56
      mView.onResume();
57
      }
58
 
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
    
61
    @Override
62
    protected void onDestroy() 
63
      {
64
      Distorted.onDestroy();  
65
      super.onDestroy();
66
      }
67
   
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
    public void Save(View v)
71
      {
72
      android.util.Log.e("SAVE", "Save button!!");
73
      }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
78
      {
79
      float s = (progress>50 ? ((progress-50)/16.0f + 1.0f):(0.015f*progress + 0.25f));
80
      SaveRenderer.setSize(s);
81
      }
82

  
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

  
85
    public void onStartTrackingTouch(SeekBar bar) { }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
    public void onStopTrackingTouch(SeekBar bar)  { }
90

  
91
}
src/main/java/org/distorted/examples/save/SaveRenderer.java
1

  
2
package org.distorted.examples.save;
3

  
4
import java.io.IOException;
5
import java.io.InputStream;
6

  
7
import javax.microedition.khronos.egl.EGLConfig;
8
import javax.microedition.khronos.opengles.GL10;
9

  
10
import org.distorted.examples.R;
11

  
12
import org.distorted.library.Distorted;
13
import org.distorted.library.DistortedBitmap;
14
import org.distorted.library.EffectTypes;
15
import org.distorted.library.Float1D;
16
import org.distorted.library.Float2D;
17
import org.distorted.library.Float4D;
18
import org.distorted.library.Interpolator1D;
19

  
20
import android.graphics.Bitmap;
21
import android.graphics.BitmapFactory;
22
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
24

  
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

  
27
class SaveRenderer implements GLSurfaceView.Renderer 
28
{
29
    private GLSurfaceView mView;
30
    private DistortedBitmap mGirl;
31
    private Float2D pLeft, pRight;
32
    private Float4D sinkRegion;
33
    private static Interpolator1D diSink;
34
    private static Float1D s0;
35
    
36
    private int bmpHeight, bmpWidth;
37
    
38
    private static float boobsSink;
39
    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
   public SaveRenderer(GLSurfaceView v) 
43
      {
44
      mView = v;
45
      
46
      boobsSink  = 1.0f;
47
      
48
      pLeft = new Float2D(132, 264);
49
      pRight= new Float2D(247, 264);
50
      
51
      // Make the boobs bigger
52
      sinkRegion = new Float4D(0,0,60,60);
53
      
54
      s0 = new Float1D(boobsSink);
55
      
56
      diSink = new Interpolator1D(); 
57
      diSink.setCount(0.5f);
58
      diSink.setDuration(0);
59
      diSink.add(s0);
60
      }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
   public static void setSize(float s)
65
     {
66
     boobsSink = s;
67
     s0.set(boobsSink);
68
     }
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
   
72
   public void onDrawFrame(GL10 glUnused) 
73
      {
74
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
75
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
76
      
77
      mGirl.draw(System.currentTimeMillis());
78
      }
79

  
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
    
82
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
83
      { 
84
      mGirl.abortEffects(EffectTypes.MATRIX);
85
      
86
      if( bmpHeight/bmpWidth > height/width )
87
        {
88
        int w = (height*bmpWidth)/bmpHeight;
89
        mGirl.move((width-w)/2 ,0, 0);
90
        mGirl.scale((float)height/bmpHeight);
91
        }
92
      else
93
        {
94
        int h = (width*bmpHeight)/bmpWidth;
95
        mGirl.move(0 ,(height-h)/2, 0);
96
        mGirl.scale((float)width/bmpWidth);
97
        }
98
      
99
      Distorted.onSurfaceChanged(width, height); 
100
      }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
    
104
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
105
      {    
106
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
107
      Bitmap bitmap;
108
        
109
      try 
110
        {
111
        bitmap = BitmapFactory.decodeStream(is);
112
        } 
113
      finally 
114
        {
115
        try 
116
          {
117
          is.close();
118
          } 
119
        catch(IOException e) { }
120
        }  
121
      
122
      bmpHeight = bitmap.getHeight();
123
      bmpWidth  = bitmap.getWidth();
124
      
125
      mGirl = new DistortedBitmap(bitmap, 30);
126

  
127
      mGirl.sink( diSink, sinkRegion, pLeft );
128
      mGirl.sink( diSink, sinkRegion, pRight);
129

  
130
      try
131
        {
132
        Distorted.onSurfaceCreated(mView.getContext());
133
        }
134
      catch(Exception ex)
135
        {
136
        android.util.Log.e("Renderer", ex.getMessage() );
137
        }
138
      }
139
}
src/main/java/org/distorted/examples/save/SaveSurfaceView.java
1

  
2
package org.distorted.examples.save;
3

  
4
import android.content.Context;
5
import android.opengl.GLSurfaceView;
6
import android.os.Build;
7
import android.util.AttributeSet;
8

  
9
///////////////////////////////////////////////////////////////////////////////////////////////////
10

  
11
class SaveSurfaceView extends GLSurfaceView 
12
{
13
///////////////////////////////////////////////////////////////////////////////////////////////////
14
   
15
  public SaveSurfaceView(Context c, AttributeSet attrs)
16
      {
17
      super(c, attrs);
18
     
19
      setEGLContextClientVersion(2);
20
        
21
      if( Build.FINGERPRINT.startsWith("generic") )
22
        { 
23
        setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
24
        }
25
        
26
      setRenderer(new SaveRenderer(this));
27
      }
28
}
29

  
src/main/res/layout/savelayout.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.save.SaveSurfaceView
8
        android:id="@+id/saveSurfaceView"
9
        android:layout_width="fill_parent"
10
        android:layout_height="0dp"
11
        android:layout_weight="0.85" />
12

  
13
    <LinearLayout
14
        android:orientation="horizontal"
15
        android:layout_width="match_parent"
16
        android:layout_height="wrap_content"
17
        android:gravity="bottom"
18
        android:layout_weight="0.03">
19

  
20
        <Button
21
            android:id="@+id/saveButton"
22
            android:layout_width="132dp"
23
            android:layout_height="wrap_content"
24
            android:gravity="center_vertical|center"
25
            android:text="@string/save"
26
            android:onClick="Save"
27
            android:textAppearance="?android:attr/textAppearanceMedium"
28
            android:layout_gravity="center_vertical"/>
29

  
30
        <SeekBar
31
            android:layout_width="fill_parent"
32
            android:layout_height="wrap_content"
33
            android:id="@+id/saveSeekBar"
34
            android:layout_gravity="center_vertical"
35
            android:layout_margin="5dp"/>
36

  
37
    </LinearLayout>
38

  
39
</LinearLayout>
src/main/res/values/strings.xml
39 39
    <string name="dim3DXZ">3DXZ</string>
40 40
    <string name="Up">Up</string>
41 41
    <string name="Default">Default</string>
42
     
42
    <string name="save">Save</string>
43

  
43 44
    <string name="example_monalisa">Mona Lisa</string>  
44 45
    <string name="example_monalisa_subtitle">The basics of Distortions.</string>
45 46
    <string name="example_sink">Dog</string>  
......
82 83
    <string name="example_effects3d_subtitle">Test results of all effects on a 3D object.</string>
83 84
    <string name="example_plainmonalisa">PlainMonaLisa</string>  
84 85
    <string name="example_plainmonalisa_subtitle">MonaLisa rendered on a plain SurfaceView</string>
86
    <string name="example_save">Save to PNG</string>
87
    <string name="example_save_subtitle">Saving the output to a PNG file.</string>
85 88

  
86 89
    <string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string>
87 90
    <string name="example_cubes_toast">Rotate the cubes by swiping the screen</string>

Also available in: Unified diff