Changeset 8:16f40c44c354
- Timestamp:
- 07/08/10 01:14:22 (14 years ago)
- Branch:
- default
- Tags:
- tip
- Convert:
- svn:f819dc9c-ca78-df11-852c-0018fe7759ca/trunk@9
- Location:
- android
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
android/res/layout/comiclist.xml
r7 r8 6 6 android:paddingLeft="8dp" 7 7 android:paddingRight="8dp"> 8 9 <ListView android:id="@android:id/android:list"10 android:layout_width="fill_parent"11 android:layout_height="fill_parent"12 android:layout_weight="1"13 android:drawSelectorOnTop="false"/>14 8 15 9 <LinearLayout android:id="@android:id/android:empty" … … 26 20 27 21 </LinearLayout> 22 23 <ListView android:id="@android:id/android:list" 24 android:layout_width="fill_parent" 25 android:layout_height="fill_parent" 26 android:layout_weight="1" 27 android:drawSelectorOnTop="false"/> 28 28 </LinearLayout> -
android/res/layout/comicviewer.xml
r2 r8 1 1 <?xml version="1.0" encoding="utf-8"?> 2 <FrameLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:layout_width="wrap_content" 5 android:layout_height="wrap_content"> 6 <org.webstrips.android.StripPane 7 class="org.webstrips.android.StripPane" 8 android:layout_width="fill_parent" 9 android:layout_height="fill_parent" 10 android:padding="10dip" 11 android:scrollbars="vertical" 12 android:fadingEdge="vertical" android:id="@+id/comicPane"> 13 </org.webstrips.android.StripPane> 14 <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/comicCenterLayout"><ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:id="@+id/transferProgress" android:max="100"></ProgressBar> 2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_height="fill_parent" android:layout_width="fill_parent"> 4 <org.webstrips.android.StripPane class="org.webstrips.android.StripPane" 5 android:layout_width="fill_parent" android:layout_height="fill_parent" 6 android:padding="10dip" android:scrollbars="vertical" 7 android:fadingEdge="vertical" android:id="@+id/comicPane"> 8 </org.webstrips.android.StripPane> 9 <RelativeLayout android:id="@+id/comicCenterLayout" 10 android:layout_gravity="center" android:layout_height="fill_parent" 11 android:layout_width="fill_parent"> 12 <ProgressBar android:layout_width="wrap_content" 13 android:layout_height="wrap_content" android:layout_centerInParent="true" 14 android:id="@+id/transferProgress" android:max="100"></ProgressBar> 15 </RelativeLayout> 16 <RelativeLayout android:id="@+id/viewer.overlaylayout" 17 android:layout_height="fill_parent" android:layout_width="fill_parent" 18 android:visibility="visible"> 19 <ImageView android:id="@+id/ImageView01" 20 android:layout_height="wrap_content" android:layout_width="wrap_content" 21 android:src="@drawable/overlay_previous" 22 android:layout_centerVertical="true" android:layout_marginLeft="5px"></ImageView> 23 <RelativeLayout android:layout_height="wrap_content" 24 android:id="@+id/RelativeLayout01" android:layout_alignParentTop="true" 25 android:layout_width="fill_parent" android:padding="5px" 26 android:background="#99FFFFFF"> 27 <TextView android:layout_height="wrap_content" 28 android:layout_above="@+id/ImageView01" android:id="@+id/view.title" 29 android:text="aaa" android:textStyle="bold" android:lines="1" 30 android:layout_width="fill_parent" android:textColor="#FF000000"></TextView> 31 </RelativeLayout> 32 <ImageView android:id="@+id/ImageView03" 33 android:layout_width="wrap_content" android:layout_height="wrap_content" 34 android:src="@drawable/overlay_next" android:layout_gravity="right" 35 android:layout_alignParentRight="true" android:layout_centerVertical="true" 36 android:layout_marginRight="5px"></ImageView> 15 37 16 </RelativeLayout>17 38 18 <RelativeLayout android:id="@+id/viewer.overlaylayout" android:layout_height="fill_parent" android:layout_width="fill_parent" android:padding="5px" android:visibility="invisible"><ImageView android:id="@+id/ImageView01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/overlay_previous" android:layout_centerVertical="true"></ImageView><ImageView android:id="@+id/ImageView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/overlay_info" android:layout_gravity="top" android:layout_centerHorizontal="true"></ImageView><ImageView android:id="@+id/ImageView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/overlay_next" android:layout_gravity="right" android:layout_alignParentRight="true" android:layout_centerVertical="true"></ImageView>19 39 20 40 </RelativeLayout> -
android/src/org/webstrips/android/ComicViewerActivity.java
r2 r8 35 35 import android.widget.ProgressBar; 36 36 import android.widget.RelativeLayout; 37 import android.widget.TextView; 37 38 38 39 public class ComicViewerActivity extends Activity { 39 40 41 private CanvasThread thread; 42 40 43 private StripPane pane; 41 44 45 private TextView title; 46 42 47 private RelativeLayout overlay; 43 48 … … 87 92 } 88 93 progress.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); 94 pane.setFrozen(visible); 89 95 } 90 96 }; 91 97 98 final Handler overlayHandler = new Handler() { 99 public void handleMessage(Message msg) { 100 boolean visible = msg.getData().getBoolean("visible"); 101 overlay.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); 102 } 103 }; 104 105 final Handler comicHandler = new Handler() { 106 public void handleMessage(Message msg) { 107 String t = msg.getData().getString("title"); 108 title.setText(t); 109 } 110 }; 111 92 112 final Handler errorHandler = new Handler() { 93 113 public void handleMessage(Message msg) { … … 246 266 247 267 progress.setVisibility(View.INVISIBLE); 268 269 title = (TextView) findViewById(R.id.view_title); 248 270 } 249 271 … … 253 275 254 276 } 255 277 256 278 @Override 257 279 protected void onPause() { 280 if (thread != null) { 281 boolean retry = true; 282 thread.run = false; 283 while (retry) { 284 try { 285 thread.join(); 286 retry = false; 287 } catch (InterruptedException e) { 288 // we will try it again and again... 289 } 290 } 291 } 292 258 293 super.onPause(); 259 294 try { … … 268 303 expectedStrip = null; 269 304 305 270 306 } 271 307 … … 292 328 0); 293 329 330 thread = new CanvasThread(); 331 thread.run = true; 332 thread.start(); 294 333 } 295 334 … … 483 522 String title = EscapeSequences 484 523 .stripAmpersandSequence(((strip == null) ? "" : strip 485 .getTitle() 486 + " - ")); 524 .getTitle())); 487 525 488 526 setTitle(control.getComic().getComicName() + " - " + title); 489 527 528 Message msg = comicHandler.obtainMessage(); 529 Bundle b = new Bundle(); 530 b.putString("title", title); 531 msg.setData(b); 532 comicHandler.sendMessage(msg); 533 490 534 currentStrip = strip; 491 535 expectedStrip = currentStrip.getIdentifier(); … … 622 666 } 623 667 668 private static final long FRAME_LENGTH = 1000 / 25; 669 670 private static final int OVERLAY_DELAY = 80; 671 672 private int overlayCountdown = OVERLAY_DELAY; 673 674 class CanvasThread extends Thread { 675 676 private boolean run = false; 677 678 @Override 679 public void run() { 680 681 while (run) { 682 683 long miliseconds = System.currentTimeMillis(); 684 685 if (pane != null) 686 pane.tick(); 687 688 if (!dragging && !pane.isEmpty() && !pane.isFrozen()) { 689 if (overlayCountdown > -1) 690 overlayCountdown--; 691 } else { 692 if (overlayCountdown != OVERLAY_DELAY) { 693 Message msg = overlayHandler.obtainMessage(); 694 Bundle b = new Bundle(); 695 b.putBoolean("visible", false); 696 msg.setData(b); 697 overlayHandler.sendMessage(msg); 698 } 699 700 overlayCountdown = OVERLAY_DELAY; 701 } 702 703 if (overlayCountdown == 0) { 704 Message msg = overlayHandler.obtainMessage(); 705 Bundle b = new Bundle(); 706 b.putBoolean("visible", true); 707 msg.setData(b); 708 overlayHandler.sendMessage(msg); 709 } 710 711 try { 712 long sl = Math.max(0, FRAME_LENGTH - Math.abs(System.currentTimeMillis() - miliseconds)); 713 sleep(sl); 714 } catch (InterruptedException e) { 715 break; 716 } 717 718 } 719 720 } 721 722 } 624 723 } -
android/src/org/webstrips/android/StripPane.java
r2 r8 14 14 public class StripPane extends SurfaceView implements SurfaceHolder.Callback { 15 15 16 private CanvasThread thread;17 16 18 17 private boolean dirty = true; 19 18 20 19 private static Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 21 22 private static class StipPaneData { 23 20 21 private static Paint frozenpaint; 22 23 static { 24 25 frozenpaint = new Paint(Paint.ANTI_ALIAS_FLAG); 26 27 frozenpaint.setAlpha(100); 28 29 } 30 31 private boolean frozen = false; 32 33 private static class StipPaneData { 34 24 35 public PointF offset = new PointF(); 25 36 26 37 public FloatTracker zoom = new FloatTracker(1, 1); 27 38 28 39 public Bitmap comicStrip; 29 40 30 41 } 31 42 32 private FloatTracker velocityX = new FloatTracker(0, 0, 0.2f, 0.5f), velocityY = new FloatTracker(0, 0, 0.2f, 0.5f); 33 43 private FloatTracker velocityX = new FloatTracker(0, 0, 0.2f, 0.5f), 44 velocityY = new FloatTracker(0, 0, 0.2f, 0.5f); 45 34 46 private StipPaneData data = new StipPaneData(); 35 47 … … 37 49 super(context, attr); 38 50 getHolder().addCallback(this); 39 thread = new CanvasThread(getHolder());40 41 51 42 52 } 43 53 44 54 private RectF canvasRect = new RectF(); 45 55 46 56 public void setDirty() { 47 57 dirty = true; 48 58 } 49 59 50 60 public void setVelocity(float vx, float vy) { 51 61 52 62 velocityX.setValue(vx); 53 63 velocityY.setValue(vy); 54 64 dirty = true; 55 65 } 56 66 67 public void setFrozen(boolean frozen) { 68 this.frozen = frozen; 69 this.dirty = true; 70 } 71 57 72 public Object getPersistentData() { 58 73 return data; 59 74 } 60 75 61 76 public void setPersistentData(Object o) { 62 77 if (o instanceof StripPane.StipPaneData) { … … 65 80 } 66 81 } 67 82 68 83 @Override 69 84 public void onDraw(Canvas canvas) { … … 71 86 return; 72 87 canvas.drawColor(Color.BLACK); 73 74 canvas.drawBitmap(data.comicStrip, null, canvasRect, paint); 88 89 canvas.drawBitmap(data.comicStrip, null, canvasRect, 90 frozen ? frozenpaint : paint); 75 91 } 76 92 … … 80 96 81 97 data.comicStrip = strip; 82 98 83 99 data.offset.x = 0; 84 100 data.offset.y = 0; … … 86 102 } 87 103 } 88 104 89 105 public Bitmap getComicStrip() { 90 106 return data.comicStrip; 91 107 } 108 109 public boolean isEmpty() { 110 return data.comicStrip == null; 111 } 112 113 public boolean isFrozen() { 114 return frozen; 115 } 92 116 93 117 public void surfaceChanged(SurfaceHolder holder, int format, int width, … … 97 121 98 122 public void surfaceCreated(SurfaceHolder holder) { 99 thread = new CanvasThread(getHolder());100 thread.run = true;101 thread.start();102 123 dirty = true; 124 canDraw = true; 103 125 } 104 126 105 127 public void surfaceDestroyed(SurfaceHolder holder) { 106 boolean retry = true; 107 thread.run = false; 108 while (retry) { 128 canDraw = false; 129 } 130 131 private boolean canDraw = false; 132 133 private static final long FRAME_LENGTH = 1000 / 20; 134 135 public void tick() { 136 137 if (!canDraw) 138 return; 139 140 if (!frozen) 141 dirty |= !data.zoom.onGoal() || !velocityX.onGoal() 142 || !velocityY.onGoal(); 143 144 Canvas c = null; 145 146 if (dirty) { 147 109 148 try { 110 thread.join(); 111 retry = false; 112 } catch (InterruptedException e) { 113 // we will try it again and again... 149 150 data.zoom.track(); 151 152 c = getHolder().lockCanvas(null); 153 synchronized (this) { 154 155 if (data.comicStrip != null) { 156 float width = data.zoom.getValue() 157 * data.comicStrip.getWidth(); 158 float height = data.zoom.getValue() 159 * data.comicStrip.getHeight(); 160 161 if (!frozen) { 162 data.offset.x -= velocityX.track(); 163 data.offset.y -= velocityY.track(); 164 } 165 166 data.offset.x = c.getWidth() > width ? -((c.getWidth() - width) / 2) 167 : Math.min(width - c.getWidth(), Math.max(0, 168 data.offset.x)); 169 170 data.offset.y = c.getHeight() > height ? -((c 171 .getHeight() - height) / 2) : Math.min(height 172 - c.getHeight(), Math.max(0, data.offset.y)); 173 174 canvasRect.left = -data.offset.x; 175 canvasRect.top = -data.offset.y; 176 canvasRect.right = -data.offset.x + width; 177 canvasRect.bottom = -data.offset.y + height; 178 } 179 180 onDraw(c); 181 dirty = false; 182 } 183 184 } finally { 185 186 // do this in a finally so that if an exception is 187 // thrown 188 // during the above, we don't leave the Surface in an 189 // inconsistent state 190 191 if (c != null) { 192 193 getHolder().unlockCanvasAndPost(c); 194 195 } 196 114 197 } 115 198 } 116 } 117 118 private static final long FRAME_LENGTH = 1000 / 20; 119 120 class CanvasThread extends Thread { 121 122 private SurfaceHolder surfaceHolder; 123 124 private boolean run = false; 125 126 public CanvasThread(SurfaceHolder surfaceHolder) { 127 this.surfaceHolder = surfaceHolder; 128 } 129 130 @Override 131 public void run() { 132 133 Canvas c; 134 135 while (run) { 136 137 c = null; 138 139 long miliseconds = System.currentTimeMillis(); 140 141 dirty |= !data.zoom.onGoal() || !velocityX.onGoal() || !velocityY.onGoal(); 142 143 if (dirty) { 144 145 try { 146 147 data.zoom.track(); 148 149 c = surfaceHolder.lockCanvas(null); 150 synchronized (surfaceHolder) { 151 152 if (data.comicStrip != null) { 153 float width = data.zoom.getValue() * data.comicStrip.getWidth(); 154 float height = data.zoom.getValue() * data.comicStrip.getHeight(); 155 156 data.offset.x -= velocityX.track(); 157 data.offset.y -= velocityY.track(); 158 159 data.offset.x = c.getWidth() > width ? -((c.getWidth() - width) / 2) : 160 Math.min(width - c.getWidth(), Math.max(0, data.offset.x)); 161 162 data.offset.y = c.getHeight() > height ? -((c.getHeight() - height) / 2) : 163 Math.min(height - c.getHeight(), Math.max(0, data.offset.y)); 164 165 canvasRect.left = -data.offset.x; 166 canvasRect.top = -data.offset.y; 167 canvasRect.right = -data.offset.x + width; 168 canvasRect.bottom = -data.offset.y + height; 169 } 170 171 172 173 onDraw(c); 174 dirty = false; 175 } 176 177 } finally { 178 179 // do this in a finally so that if an exception is 180 // thrown 181 // during the above, we don't leave the Surface in an 182 // inconsistent state 183 184 if (c != null) { 185 186 surfaceHolder.unlockCanvasAndPost(c); 187 188 } 189 190 } 191 } 192 193 try { 194 sleep(Math.min(FRAME_LENGTH, Math.abs(System.currentTimeMillis() - miliseconds))); 195 } catch (InterruptedException e) { 196 break; 197 } 198 199 } 200 201 } 202 203 } 204 205 206 207 199 200 } 201 208 202 } -
android/svg/overlay_next.svg
r2 r8 8 8 xmlns:svg="http://www.w3.org/2000/svg" 9 9 xmlns="http://www.w3.org/2000/svg" 10 xmlns:xlink="http://www.w3.org/1999/xlink"11 10 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" 12 11 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" … … 18 17 sodipodi:docname="overlay_next.svg" 19 18 inkscape:export-filename="/home/lukacu/workspace/webstrips-android/res/drawable/overlay_next.png" 20 inkscape:export-xdpi=" 90"21 inkscape:export-ydpi=" 90">19 inkscape:export-xdpi="100.15425" 20 inkscape:export-ydpi="100.15425"> 22 21 <defs 23 22 id="defs4582"> … … 47 46 inkscape:vp_x="0 : 0.5 : 1" 48 47 sodipodi:type="inkscape:persp3d" /> 49 <linearGradient50 inkscape:collect="always"51 xlink:href="#linearGradient5126"52 id="linearGradient5132"53 x1="24.201178"54 y1="27.802748"55 x2="12.859667"56 y2="5.9234533"57 gradientUnits="userSpaceOnUse" />58 48 <filter 59 49 inkscape:collect="always" … … 85 75 inkscape:pageshadow="2" 86 76 inkscape:zoom="11.197802" 87 inkscape:cx=" 11.31158"77 inkscape:cx="-4.5397451" 88 78 inkscape:cy="25.198234" 89 79 inkscape:current-layer="layer1" … … 93 83 inkscape:window-width="1348" 94 84 inkscape:window-height="917" 95 inkscape:window-x=" 535"96 inkscape:window-y="1 65"85 inkscape:window-x="131" 86 inkscape:window-y="137" 97 87 inkscape:window-maximized="0" /> 98 88 <metadata … … 113 103 inkscape:groupmode="layer"> 114 104 <path 115 transform="matrix(1,0,0,1.0028275,-1.2502454,-0.09069038)"116 d="m 31.702651,16.282629 a 14.377822,14.377822 0 1 1 -28.7556438,0 14.377822,14.377822 0 1 1 28.7556438,0 z"117 sodipodi:ry="14.377822"118 sodipodi:rx="14.377822"119 sodipodi:cy="16.282629"120 sodipodi:cx="17.324829"121 id="path5140"122 style="fill:#000000;fill-opacity:1;stroke:none;filter:url(#filter5142)"123 sodipodi:type="arc" />124 <path125 105 sodipodi:type="arc" 126 style="fill: url(#linearGradient5132);fill-opacity:1;stroke:none"106 style="fill:#f1f1f1;fill-opacity:0.65490198;stroke:none" 127 107 id="path5124" 128 108 sodipodi:cx="17.324829" -
android/svg/overlay_previous.svg
r2 r8 8 8 xmlns:svg="http://www.w3.org/2000/svg" 9 9 xmlns="http://www.w3.org/2000/svg" 10 xmlns:xlink="http://www.w3.org/1999/xlink"11 10 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" 12 11 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" … … 16 15 version="1.1" 17 16 inkscape:version="0.47pre4 r22446" 18 sodipodi:docname=" New document 10">17 sodipodi:docname="overlay_previous.svg"> 19 18 <defs 20 19 id="defs4582"> … … 44 43 inkscape:vp_x="0 : 0.5 : 1" 45 44 sodipodi:type="inkscape:persp3d" /> 46 <linearGradient47 inkscape:collect="always"48 xlink:href="#linearGradient5126"49 id="linearGradient5132"50 x1="24.201178"51 y1="27.802748"52 x2="12.859667"53 y2="5.9234533"54 gradientUnits="userSpaceOnUse" />55 45 <filter 56 46 inkscape:collect="always" … … 82 72 inkscape:pageshadow="2" 83 73 inkscape:zoom="11.197802" 84 inkscape:cx=" 0.14867489"85 inkscape:cy="1 6"74 inkscape:cx="11.266928" 75 inkscape:cy="14.303238" 86 76 inkscape:current-layer="layer1" 87 77 showgrid="true" … … 90 80 inkscape:window-width="1348" 91 81 inkscape:window-height="917" 92 inkscape:window-x=" 254"93 inkscape:window-y=" 138"82 inkscape:window-x="67" 83 inkscape:window-y="230" 94 84 inkscape:window-maximized="0" /> 95 85 <metadata … … 101 91 <dc:type 102 92 rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> 103 <dc:title ></dc:title>93 <dc:title /> 104 94 </cc:Work> 105 95 </rdf:RDF> … … 110 100 inkscape:groupmode="layer"> 111 101 <path 112 transform="matrix(1,0,0,1.0028275,-1.2502454,-0.09069038)"113 d="m 31.702651,16.282629 a 14.377822,14.377822 0 1 1 -28.7556438,0 14.377822,14.377822 0 1 1 28.7556438,0 z"114 sodipodi:ry="14.377822"115 sodipodi:rx="14.377822"116 sodipodi:cy="16.282629"117 sodipodi:cx="17.324829"118 id="path5140"119 style="fill:#000000;fill-opacity:1;stroke:none;filter:url(#filter5142)"120 sodipodi:type="arc" />121 <path122 102 sodipodi:type="arc" 123 style="fill: url(#linearGradient5132);fill-opacity:1;stroke:none"103 style="fill:#f1f1f1;fill-opacity:0.65652174;stroke:none" 124 104 id="path5124" 125 105 sodipodi:cx="17.324829"
Note: See TracChangeset
for help on using the changeset viewer.