Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Flame on.

  • Loading branch information...
commit 9fcf72c199a3b6f7c8e79344bb8c41bf09a0af4e 1 parent 2cb6bd4
Sam Corder authored
BIN  CincyBluesFest-Android/.cache
Binary file not shown
2  CincyBluesFest-Android/AndroidManifest.xml
@@ -15,6 +15,6 @@
15 15 </intent-filter>
16 16 </activity>
17 17 <activity android:name=".ShowDetailActivity" android:theme="@style/CBlues"></activity>
18   -
  18 + <activity android:name=".lighter.FlameActivity" android:theme="@style/CBlues" android:screenOrientation="portrait"></activity>
19 19 </application>
20 20 </manifest>
282 CincyBluesFest-Android/_src/org/cincyblues/fest/lighter/Flame.scala
@@ -11,6 +11,7 @@ import javax.microedition.khronos.opengles.GL10
11 11 import javax.microedition.khronos.opengles.GL11
12 12 import scala.runtime.RichInt
13 13 import javax.microedition.khronos.opengles.GL11Ext
  14 +import android.util.Log
14 15
15 16 class Flame {
16 17 val random: Random = new Random()
@@ -24,14 +25,16 @@ class Flame {
24 25 var textureHeight: Int = 0
25 26 var textureWidth: Int = 0
26 27 var lastFpsTime = -1L
27   - var intensityMap: Array[Byte]
  28 + var intensityMap: Array[Byte] = null
28 29 var pixelBuffer: ByteBuffer = null
29 30 var colors: Array[Int] = null
30 31 var glTextureId = -1;
31 32 var textureCrop = new Array[Int](4);
32 33 var glInited = false;
33 34 var lastSeedTime = -1L;
34   - var frameCounter = 0;
  35 + var frameCounter = 0
  36 +
  37 + val topic: String = "Flame"
35 38
36 39 generateColors()
37 40
@@ -48,6 +51,8 @@ class Flame {
48 51 textureCrop(2) = textureWidth
49 52 textureCrop(3) = textureHeight
50 53
  54 + Log.d(topic, "Iniializing with a textureWidth & height of " + textureWidth + ", " + textureHeight)
  55 +
51 56 // init the intensity map
52 57 intensityMap = new Array[Byte](textureWidth * textureHeight)
53 58
@@ -86,10 +91,10 @@ class Flame {
86 91 gl.glPushMatrix();
87 92 gl.glLoadIdentity();
88 93
89   - glInited = false;
  94 + glInited = true;
90 95 }
91 96
92   - def initGlTexture(gl: GL11):Unit = {
  97 + def initGlTexture(gl: GL11): Unit = {
93 98 releaseTexture(gl);
94 99
95 100 var textures = new Array[Int](1);
@@ -134,113 +139,192 @@ class Flame {
134 139
135 140 // we need to output the pixels upside down due to glDrawTex peculiarities
136 141 for (y <- (intensityMap.length - textureWidth) until (0, (-1 * textureWidth))) {
137   - for (x <- 1 until textureWidth) {
138   - var pixel = pixelFromIntensity(intensityMap(y + x));
139   - pixelBuffer.put((pixel >> 16).asInstanceOf[Byte]);
140   - pixelBuffer.put(((pixel >> 8) & 0xff).asInstanceOf[Byte]);
141   - pixelBuffer.put((pixel & 0xff).asInstanceOf[Byte]);
  142 + Log.d(topic, "Updating pixels in row " + y / textureWidth)
  143 + for (x <- 0 until textureWidth) {
  144 + var pixel = pixelFromIntensity(intensityMap(y + x))
  145 +
  146 + //if(pixel > 0) Log.d(topic, x + "," + y + " pixel value is " + pixel)
  147 +
  148 + pixelBuffer.put((pixel >> 16).asInstanceOf[Byte])
  149 + pixelBuffer.put(((pixel >> 8) & 0xff).asInstanceOf[Byte])
  150 + pixelBuffer.put((pixel & 0xff).asInstanceOf[Byte])
  151 + }
  152 + }
  153 + }
  154 +
  155 + def pixelFromIntensity(intensity: Byte): Int = {
  156 + return colors(unsignedByte(intensity))
  157 + }
  158 +
  159 + def unsignedByte(v: Byte): Int = {
  160 + if (v >= 0) v else 256 + v
  161 + }
  162 +
  163 + def performFrame(gl: GL11, surfaceWidth: Int, surfaceHeight: Int): Unit = {
  164 + Log.d(topic, "performing Frame")
  165 + val frameStartTime = System.currentTimeMillis()
  166 + if (lastSeedTime == -1L || (frameStartTime - lastSeedTime) >= seedInterval) {
  167 + seedIntensity();
  168 + lastSeedTime = frameStartTime
  169 + }
  170 +
  171 + for (i <- 0 until iterationsPerFrame) {
  172 + iterateIntensity();
  173 + }
  174 +
  175 + updatePixelsFromIntensity();
  176 +
  177 + // Clear the surface
  178 + gl.glClearColorx(0, 0, 0, 0);
  179 + gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  180 +
  181 + // Choose the texture
  182 + gl.glBindTexture(GL10.GL_TEXTURE_2D, glTextureId);
  183 +
  184 + // Update the texture
  185 + Log.d(topic, "Updating texture")
  186 + gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight,
  187 + GL10.GL_RGB, GL10.GL_UNSIGNED_BYTE, pixelBuffer);
  188 +
  189 + // Draw the texture on the surface
  190 + gl.glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, textureCrop, 0);
  191 + gl.asInstanceOf[GL11Ext].glDrawTexiOES(0, 0, 0, surfaceWidth, surfaceHeight);
  192 +
  193 + // Sleep the extra time
  194 + val frameEndTime = System.currentTimeMillis();
  195 + val delta = frameEndTime - frameStartTime;
  196 + if (targetFrameInterval - delta > 10L) {
  197 + try {
  198 + Log.d(topic, "Sleeping")
  199 + Thread.sleep(targetFrameInterval - delta);
  200 + } catch {
  201 + case e: InterruptedException => {
  202 + Log.d(topic, "Interrupted")
  203 + }
142 204 }
143 205 }
  206 +
  207 + // Output FPS if necessary
  208 + frameCounter += 1;
  209 + if (lastFpsTime == -1L) {
  210 + lastFpsTime = frameEndTime;
  211 + } else if ((frameEndTime - lastFpsTime) >= fpsInterval) {
  212 + val fps: Float = frameCounter / ((frameEndTime - lastFpsTime) / 1000.0f);
  213 + Log.d("FPS", fps.toString())
  214 +
  215 + frameCounter = 0;
  216 + lastFpsTime = frameEndTime;
  217 + }
144 218 }
145 219
146   - def pixelFromIntensity(intensity:Byte):Int = {
147   - return colors(unsignedByte(intensity))
  220 + def iterateIntensity(): Unit = {
  221 + var y = intensityMap.length - textureWidth * 2;
  222 +
  223 + var v1: Int = 0
  224 + var v2: Int = 0
  225 + var v3: Int = 0
  226 + var v4: Int = 0
  227 + while (y > 0) {
  228 + for (x <- 0 until textureWidth) {
  229 +
  230 + // now take the current value, the values from both sides
  231 + // and the one from the bottom
  232 + v1 = unsignedByte(intensityMap(y + x))
  233 + if (x < textureWidth - 1) {
  234 + v2 = unsignedByte(intensityMap(y + x + 1))
  235 + } else {
  236 + v2 = 0
  237 + }
  238 + if (x > 0) {
  239 + v3 = unsignedByte(intensityMap(y + x - 1))
  240 + } else {
  241 + v3 = 0
  242 + }
  243 + v4 = unsignedByte(intensityMap(y + textureWidth + x))
  244 +
  245 + var v: Int = (v1 + v2 + v3 + v4) / (if ((x != 0) && (x != textureWidth - 1)) 4 else 3)
  246 +
  247 + // magic values - needed for good decay
  248 + v = v - 2 * (255 - v) / 128;
  249 +
  250 + // now clip the value
  251 + if (v > 0xff) {
  252 + v = 0xff;
  253 + } else if (v < 0x00) {
  254 + v = 0;
  255 + }
  256 +
  257 + intensityMap(y + x) = v.asInstanceOf[Byte];
  258 + }
  259 +
  260 + y -= textureWidth;
  261 + }
148 262 }
149 263
  264 + def seedIntensity(): Unit = {
  265 + // var y = intensityMap.length - textureWidth;
  266 + //
  267 + // for (line <- 0 until seedLines) {
  268 + // var on = random.nextBoolean();
  269 + // for (x <- 0 until textureWidth) {
  270 + // // magic settings for good looking fire
  271 + // if ((on && nextRandomInt(20 / (line + 1)) == 0)
  272 + // || ((!on) && nextRandomInt(9) == 0)) {
  273 + //
  274 + // on = !on;
  275 + // }
  276 + // intensityMap(y + x) = (if (on) 0xff else 0x00).asInstanceOf[Byte]
  277 + // }
  278 + // y -= textureWidth
  279 + // }
  280 +
  281 + //attempt to make a column of seeds
  282 + val flameWidth = 18
  283 + val textureCenter = textureWidth / 2
  284 + val flameHalfWidth = flameWidth / 2
  285 + var maxHeight = 20
  286 +
  287 + val textureMaxHeight = ((intensityMap.length - textureWidth) / 2).asInstanceOf[Int]
  288 + var y = intensityMap.length - textureWidth
  289 + for(line <- 0 until maxHeight){
  290 +
  291 + //Turn on the middles full
  292 + for (x <- (textureCenter - flameHalfWidth) to (textureCenter + flameHalfWidth)) {
  293 + intensityMap(y + x) = 0xff.asInstanceOf[Byte]
  294 + }
  295 + val farLeft = (textureCenter - flameHalfWidth) - 8
  296 + val rightOffset = flameWidth + 8
  297 + for (x <- farLeft until (textureCenter - flameHalfWidth)) {
  298 + var on = random.nextBoolean()
  299 + intensityMap(y + x) = (if (on) 0xaa else 0x00).asInstanceOf[Byte]
  300 + //intensityMap(y + x) = 0xaa.asInstanceOf[Byte]
  301 +
  302 + on = random.nextBoolean()
  303 + intensityMap(y + x + rightOffset) = (if (on) 0xaa else 0x00).asInstanceOf[Byte]
  304 + }
  305 + }
  306 + }
150 307
151   - def unsignedByte(v:Byte):Int = {
152   - if(v >= 0) v else 256 + v
153   - }
154   -
155   -
156   - def performFrame(gl: GL11, surfaceWidth:Int, surfaceHeight:Int): Unit = {
157   - val frameStartTime = System.currentTimeMillis()
158   - if (lastSeedTime == -1L || (frameStartTime - lastSeedTime) >= seedInterval) {
159   - seedIntensity();
160   - lastSeedTime = frameStartTime
161   - }
162   -
163   - for(i <- 1 until iterationsPerFrame){
164   - iterateIntensity();
165   - }
166   -
167   - updatePixelsFromIntensity();
168   -
169   - // Clear the surface
170   - gl.glClearColorx(0, 0, 0, 0);
171   - gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
172   -
173   - // Choose the texture
174   - gl.glBindTexture(GL10.GL_TEXTURE_2D, glTextureId);
175   -
176   - // Update the texture
177   - gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight,
178   - GL10.GL_RGB, GL10.GL_UNSIGNED_BYTE, pixelBuffer);
179   -
180   - // Draw the texture on the surface
181   - gl.glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, textureCrop, 0);
182   - gl.asInstanceOf[GL11Ext].glDrawTexiOES(0, 0, 0, surfaceWidth, surfaceHeight);
183   -
184   - // Sleep the extra time
185   - val frameEndTime = System.currentTimeMillis();
186   - val delta = frameEndTime - frameStartTime;
187   - if (targetFrameInterval - delta > 10L) {
188   - try {
189   - Thread.sleep(targetFrameInterval - delta);
190   - } catch {
191   - case e:InterruptedException {}
192   - }
193   -
194   - // Output FPS if necessary
195   - frameCounter++;
196   - if (lastFpsTime == -1L) {
197   - lastFpsTime = frameEndTime;
198   - } else if ((frameEndTime - lastFpsTime) >= fpsInterval) {
199   - float fps = frameCounter / ((frameEndTime - lastFpsTime) / 1000.0f);
200   - Log.d("FPS", String.format("%1.0f", fps));
201   -
202   - frameCounter = 0;
203   - lastFpsTime = frameEndTime;
204   - }
  308 + def nextRandomInt(max: Int): Int = {
  309 + if (max == 0) 0 else random.nextInt(max)
205 310 }
206 311
207   - def iterateIntensity():Unit = {
208   -
209   - }
210   - def seedIntensity():Unit = {
211   - var y = intensityMap.length - textureWidth;
212   -
213   - for(line <- 1 until seedLines){
214   - var on = random.nextBoolean();
215   - for(x <- 1 until textureWidth){
216   - // magic settings for good looking fire
217   - if ((on && nextRandomInt(20 / (line + 1)) == 0)
218   - || ((! on) && nextRandomInt(9) == 0)) {
219   -
220   - on = !on;
221   - }
222   - intensityMap(y + x) = (if(on) 0xff else 0x00).asInstanceOf[Byte];
223   - }
224   - y -= textureWidth;
225   - }
226   - }
227   -
228   - def nextRandomInt(max:Int):Int = {
229   - if(max == 0) 0 else random.nextInt(max)
230   - }
231   -
232 312 def generateColors(): Unit = {
233 313 colors = new Array[Int](256)
234   -
  314 + //Swap offsets below to change up color patterns
  315 + val redOffSet = 16
  316 + val greenOffSet = 8
  317 + val blueOffSet = 0
  318 +
235 319 var gg = 200.0f;
236 320
237 321 for (i <- 0xff until (0x00, -1)) {
238   - var red = 0
239   - red = i << 16
  322 + var highColor = 0
  323 + highColor = i << blueOffSet
240 324
241   - var green = 0;
  325 + var midColor = 0;
242 326 if (gg > 0) {
243   - green = (gg.asInstanceOf[Int]) << 8;
  327 + midColor = (gg.asInstanceOf[Int]) << greenOffSet
244 328 if (i < 0xe0) {
245 329 gg -= 2.0f;
246 330 } else {
@@ -248,10 +332,14 @@ class Flame {
248 332 }
249 333 }
250 334
251   - val blue = 0;
  335 + val zeroColor = 0 << redOffSet;
252 336
253   - colors(i) = (red | green | blue);
  337 + //rgb
  338 + colors(i) = (highColor | midColor | zeroColor)
254 339 }
255 340 }
256 341
  342 + def dispose(gl: GL11) = {
  343 + releaseTexture(gl);
  344 + }
257 345 }
5 CincyBluesFest-Android/_src/org/cincyblues/fest/lighter/FlameActivity.scala
... ... @@ -1,6 +1,7 @@
1 1 package org.cincyblues.fest.lighter
2 2
3 3 import android.os.Bundle
  4 +import android.util.Log;
4 5 import android.opengl.GLSurfaceView;
5 6
6 7 import roboguice.activity.RoboActivity
@@ -8,15 +9,17 @@ import roboguice.inject.InjectExtra
8 9
9 10 import org.cincyblues.fest.utils.FindView
10 11
11   -class FlameActivity extends RoboActivity with FindView {
  12 +class FlameActivity extends RoboActivity{
12 13
13 14 var glView: GLSurfaceView = null
14 15
15 16 override def onCreate(savedInstanceState: Bundle) = {
  17 + super.onCreate(savedInstanceState)
16 18 glView = new GLSurfaceView(this)
17 19 glView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR)
18 20 glView.setRenderer(new FlameRenderer())
19 21 setContentView(glView)
  22 + Log.d("Flame", "Created GL Surface");
20 23 }
21 24
22 25 override def onPause() = {
22 CincyBluesFest-Android/_src/org/cincyblues/fest/lighter/FlameRenderer.scala
@@ -4,24 +4,36 @@ import javax.microedition.khronos.egl.EGLConfig
4 4 import javax.microedition.khronos.opengles.GL10
5 5 import javax.microedition.khronos.opengles.GL11
6 6 import javax.microedition.khronos.opengles.GL11Ext
7   -
8 7 import android.opengl.GLSurfaceView.Renderer
  8 +import android.util.Log
9 9
10 10 class FlameRenderer extends Renderer {
11   - var flame:Flame = new Flame()
12   -
  11 + var flame: Flame = new Flame()
  12 + //var fire: Fire = new Fire()
  13 +
  14 + var surfaceWidth: Int = 0
  15 + var surfaceHeight: Int = 0
  16 + var topic: String = "FlameRender"
  17 +
13 18 def onSurfaceCreated(gl10: GL10, arg1: EGLConfig): Unit = {
14   - if(gl10.isInstanceOf[GL11Ext] == false){
  19 + if (gl10.isInstanceOf[GL11Ext] == false) {
15 20 throw new RuntimeException("GL11Ext not supported")
16 21 }
  22 + Log.d(topic, "SurfaceCreated")
17 23 }
18 24
19 25 def onSurfaceChanged(gl10: GL10, width: Int, height: Int): Unit = {
  26 + Log.d(topic, "Initializing flame with width:" + width + " height: " + height)
20 27 flame.initialize(width, height, gl10.asInstanceOf[GL11]);
  28 + //fire.initialize(width, height, gl10.asInstanceOf[GL11])
  29 + this.surfaceWidth = width
  30 + this.surfaceHeight = height
21 31 }
22 32
23 33 def onDrawFrame(gl10: GL10): Unit = {
24   - flame.performFrame(gl10.asInstanceOf[GL11]);
  34 + Log.d(topic, "performing Frame " + surfaceWidth + "," + surfaceHeight)
  35 + flame.performFrame(gl10.asInstanceOf[GL11], surfaceWidth, surfaceHeight);
  36 + //fire.performFrame(gl10.asInstanceOf[GL11], surfaceWidth, surfaceHeight);
25 37 }
26 38
27 39 }
2  CincyBluesFest-Android/res/layout/main.xml
@@ -4,7 +4,7 @@
4 4 android:layout_height="fill_parent" android:weightSum="1">
5 5 <LinearLayout android:id="@+id/linearLayout2"
6 6 android:layout_width="match_parent" android:layout_height="57dp">
7   - <ImageView android:id="@+id/imageView1" android:src="@drawable/banner"
  7 + <ImageView android:id="@+id/logo" android:src="@drawable/banner"
8 8 android:layout_height="match_parent" android:layout_width="fill_parent" android:layout_weight="4" android:scaleType="fitCenter"></ImageView>
9 9 <TextView android:textAppearance="?android:attr/textAppearanceLarge"
10 10 android:id="@+id/tvTitle" android:layout_height="match_parent"
55 CincyBluesFest-Android/src/org/cincyblues/fest/CincyBluesFestActivity.java
@@ -3,36 +3,62 @@
3 3 import java.io.BufferedReader;
4 4 import java.io.IOException;
5 5 import java.io.InputStreamReader;
  6 +import java.io.Serializable;
6 7 import java.util.ArrayList;
7 8 import java.util.LinkedHashMap;
8 9
  10 +import org.cincyblues.fest.lighter.FlameActivity;
  11 +
9 12 import roboguice.activity.RoboActivity;
10 13 import roboguice.inject.InjectView;
  14 +import android.content.Context;
  15 +import android.content.Intent;
11 16 import android.os.Bundle;
12 17 import android.util.Log;
13 18 import android.view.LayoutInflater;
14 19 import android.view.View;
  20 +import android.view.View.OnClickListener;
  21 +import android.widget.AdapterView;
  22 +import android.widget.ImageView;
15 23 import android.widget.TabHost;
  24 +import android.widget.AdapterView.OnItemClickListener;
16 25 import android.widget.TabHost.TabSpec;
17 26 import android.widget.TextView;
18 27
19 28 import com.google.inject.Inject;
20 29
21   -public class CincyBluesFestActivity extends RoboActivity {
  30 +public class CincyBluesFestActivity extends RoboActivity {
22 31 private String topic = CincyBluesFestActivity.class.getSimpleName();
23 32 private LinkedHashMap<String, ArrayList<Show>> stages;
24 33
25   - @InjectView(android.R.id.tabhost) TabHost tabs;
26   - @Inject ShowTabFactory tabFactory;
27   -
  34 + @InjectView(R.id.logo)
  35 + ImageView logo;
  36 + @InjectView(android.R.id.tabhost)
  37 + TabHost tabs;
  38 + @Inject
  39 + ShowTabFactory tabFactory;
  40 +
  41 + @Inject
  42 + Context context;
  43 +
28 44 /** Called when the activity is first created. */
29 45 @Override
30 46 public void onCreate(Bundle savedInstanceState) {
31   - super.onCreate(savedInstanceState); // @Inject, @InjectResource, and @InjectExtra injection happens during super.onCreate()
32   - setContentView(R.layout.main); // @InjectView injection happens when you call setContentView()
33   -
34   - initStages();
  47 + super.onCreate(savedInstanceState); // @Inject, @InjectResource, and
  48 + // @InjectExtra injection happens
  49 + // during super.onCreate()
  50 + setContentView(R.layout.main); // @InjectView injection happens when you
  51 + // call setContentView()
  52 + initStages();
35 53 initTabs();
  54 +
  55 + logo.setOnClickListener(new OnClickListener() {
  56 + public void onClick(View v) {
  57 + Intent showIntent = new Intent(getApplicationContext(),
  58 + FlameActivity.class);
  59 + context.startActivity(showIntent);
  60 + }
  61 + });
36 62 }
37 63
38 64 private void initStages() {
@@ -73,7 +99,7 @@ private void initTabs() {
73 99 String key = new Integer(idx).toString();
74 100 tabFactory.addTabContent(key, stages.get(stage));
75 101 TabSpec tspec = tabs.newTabSpec(key);
76   -
  102 +
77 103 tspec.setIndicator(createTabIndicator(stage));
78 104 tspec.setContent(tabFactory);
79 105 tabs.addTab(tspec);
@@ -81,11 +107,12 @@ private void initTabs() {
81 107
82 108 }
83 109 }
84   -
  110 +
85 111 private View createTabIndicator(final String text) {
86   - View view = LayoutInflater.from(this.getApplicationContext()).inflate(R.layout.tabs_bg, null);
87   - TextView tv = (TextView) view.findViewById(R.id.tabsText);
88   - tv.setText(text);
89   - return view;
  112 + View view = LayoutInflater.from(this.getApplicationContext()).inflate(
  113 + R.layout.tabs_bg, null);
  114 + TextView tv = (TextView) view.findViewById(R.id.tabsText);
  115 + tv.setText(text);
  116 + return view;
90 117 }
91 118 }
70 CincyBluesFest-Android/src/org/cincyblues/fest/ShowTabFactory.java
@@ -17,37 +17,41 @@
17 17
18 18 import com.google.inject.Inject;
19 19
20   - public class ShowTabFactory implements TabContentFactory {
21   - @Inject Application application;
22   - @Inject Context context;
23   -
24   - private HashMap<String, ArrayList<Show>> tabMap = new HashMap<String, ArrayList<Show>>();
25   -
26   - public void addTabContent(String key, ArrayList<Show> content) {
27   - tabMap.put(key, content);
28   - }
29   -
30   - public View createTabContent(String key) {
31   - Log.v("tabfactory", "creating content for " + key);
32   - ListView lsv = new ListView(context);
33   - if (tabMap.containsKey(key) == false)
34   - throw new java.util.NoSuchElementException(key
35   - + " was not in the tab map");
36   -
37   - ListAdapter adapter = new ShowAdapter(context,R.layout.show_list_heading,
38   - R.layout.show_list_item,tabMap.get(key));
39   -
40   - lsv.setAdapter(adapter);
41   - lsv.setOnItemClickListener(new OnItemClickListener() {
42   - public void onItemClick(AdapterView<?> parent, View view,
43   - int position, long id) {
44   - // When clicked, show the showDetailActivity with the show data
45   - Show show = (Show) parent.getAdapter().getItem(position);
46   - Intent showIntent = new Intent(application.getApplicationContext(), ShowDetailActivity.class);
47   - showIntent.putExtra("show", (Serializable)show);
48   - context.startActivity(showIntent);
49   - }
50   - });
51   - return lsv;
52   - }
  20 +public class ShowTabFactory implements TabContentFactory {
  21 + @Inject
  22 + Application application;
  23 + @Inject
  24 + Context context;
  25 +
  26 + private HashMap<String, ArrayList<Show>> tabMap = new HashMap<String, ArrayList<Show>>();
  27 +
  28 + public void addTabContent(String key, ArrayList<Show> content) {
  29 + tabMap.put(key, content);
  30 + }
  31 +
  32 + public View createTabContent(String key) {
  33 + Log.v("tabfactory", "creating content for " + key);
  34 + ListView lsv = new ListView(context);
  35 + if (tabMap.containsKey(key) == false)
  36 + throw new java.util.NoSuchElementException(key
  37 + + " was not in the tab map");
  38 +
  39 + ListAdapter adapter = new ShowAdapter(context,
  40 + R.layout.show_list_heading, R.layout.show_list_item,
  41 + tabMap.get(key));
  42 +
  43 + lsv.setAdapter(adapter);
  44 + lsv.setOnItemClickListener(new OnItemClickListener() {
  45 + public void onItemClick(AdapterView<?> parent, View view,
  46 + int position, long id) {
  47 + // When clicked, show the showDetailActivity with the show data
  48 + Show show = (Show) parent.getAdapter().getItem(position);
  49 + Intent showIntent = new Intent(application
  50 + .getApplicationContext(), ShowDetailActivity.class);
  51 + showIntent.putExtra("show", (Serializable) show);
  52 + context.startActivity(showIntent);
  53 + }
  54 + });
  55 + return lsv;
53 56 }
  57 +}

0 comments on commit 9fcf72c

Please sign in to comment.
Something went wrong with that request. Please try again.