Commit 95f9085e authored by Thomas Krex's avatar Thomas Krex

-searchResults werden per canvas markiert, muss aber bei jedem update

des imgV getan werden --> flimmert

-werden auch in thumbails markiert, dafür müssen die thumnails erst
wieder hochskaliert werden--> nicht performant
parent 672017b9
......@@ -128,6 +128,8 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
public void search(String word) {
if (recording.getIndex() != null)
recording.getIndex().search(word);
recording.highlightSearchResults(recording.graphicsContext()
.getCanvas());
}
@Override
......@@ -230,8 +232,8 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
@Override
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
return false;
// search(newText);
return true;
}
});
return true;
......@@ -276,8 +278,9 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
// extended View
if (index == 1) {
imgV = (ImageView) findViewById(R.id.playerView_extended);
// recording.graphicsContext().refresh();
recording.graphicsContext().setImageView(imgV);
recording.graphicsContext().refresh();
switcher.setDisplayedChild(1);
}
......
......@@ -12,6 +12,7 @@ import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
......@@ -61,16 +62,14 @@ public class GraphicsContext implements MessageConsumer {
prefs.framebufferWidth, prefs.framebufferHeight,
Config.ARGB_8888));
this.canvas = new Canvas(bitmapContainer.getBimap());
Paint p = new Paint();
p.setColor(Color.RED);
canvas.drawRect(new Rect(0, 0, 200, 200), p);
this.pixels = bitmapContainer.getPixels();
Log.d("Bitmap", "size: " + bitmapContainer.getBimap().getHeight()
+ bitmapContainer.getBimap().getWidth());
// Log.d("ImageView", " ScaleX " + imgView.getScaleX() + " , ScaleY "
// + imgView.getScaleY());
// updateView(bitmapContainer.getBimap());
hextile_bg_encoded = new byte[prefs.bytesPerPixel];
hextile_fg_encoded = new byte[prefs.bytesPerPixel];
......@@ -78,10 +77,11 @@ public class GraphicsContext implements MessageConsumer {
@Override
public void handleMessage(android.os.Message inputMessage) {
// Gets the image task from the incoming Message object.
Log.d("GraphicsContext", "updating Canvas");
imgView.draw(canvas);
imgView.invalidate();
imgView.setImageBitmap(bitmapContainer.getBimap());
// imgView.draw(canvas);
// imgView.invalidate();
}
};
......@@ -90,15 +90,27 @@ public class GraphicsContext implements MessageConsumer {
public void handleMessage(android.os.Message inputMessage) {
// Gets the image task from the incoming Message object.
Bitmap bitmap = (Bitmap) inputMessage.obj;
// Bitmap.createScaledBitmap(bitmap, screenWidth, screenHeight,
// true);
// TODO
// Canvas testCanvas = new Canvas(bitmap);
recording.highlightSearchResults(canvas);
imgView.setImageBitmap(bitmap);
// draw search results and annotations
// Canvas testCanvas = new Canvas(bitmap);
// testCanvas.drawRect(0, 0, 150, 200, new Pa);
// imgView.draw(canvas);
// imgView.invalidate();
}
};
}
public void drawOnBitmap(ColoredShape shape) {
}
public void enableRefresh(boolean refresh) {
this.refreshEnabled = refresh;
}
......@@ -150,7 +162,7 @@ public class GraphicsContext implements MessageConsumer {
message.sendToTarget();
}
public void updaView() {
public void updateView() {
android.os.Message message = canvasHandler.obtainMessage(0, null);
message.sendToTarget();
......@@ -182,31 +194,6 @@ public class GraphicsContext implements MessageConsumer {
}
// public Color decodeColor(byte[] colorField) {
// int color = 0;
// for (int i = 0, shift = 0; i < prefs.bytesPerPixel; i++, shift += 8) {
// color += (colorField[i] & 0xFF) << shift;
// }
//
// switch (prefs.bitsPerPixel) {
// case 16:
// if (prefs.bigEndian)
// // 16 bit big endian: swap bytes
// color = (color & 0xFF) << 8 | ((color & 0xFF00) >> 8);
// case 8:
// // use color table
// return colors[color];
// default:
// // use default color
// if (prefs.bigEndian) {
// // 24 bit big endian: swap bytes
// color = (color & 0xFF) << 24 | (color >> 8 & 0xFF) << 16
// | (color >> 16 & 0xFF) << 8 | color >> 24 & 0xFF;
// }
// return new Color(color);
// }
// }
public void setForeground(byte[] color, int offset) {
System.arraycopy(color, offset, hextile_fg_encoded, 0,
prefs.bytesPerPixel);
......@@ -237,7 +224,7 @@ public class GraphicsContext implements MessageConsumer {
}
public void handleUpdatedCanvas() {
updaView();
updateView();
}
public int getEncodedColor(byte[] colorField) {
......
......@@ -32,6 +32,7 @@ import tttclient.messages.Annotation;
import tttclient.messages.Message;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
......@@ -52,6 +53,7 @@ public class Index {
private Recording recording;
private final Context context;
private final double thumbnai_scale_factor = 0.2;
int getWidth() {
return recording.getProtocolPreferences().framebufferWidth;
......@@ -494,11 +496,10 @@ public class Index {
// create screenshot
Bitmap screenshot = recording.graphicsContext()
.getScreenshotWithoutAnnotations();
Bitmap scaled = Bitmap
.createScaledBitmap(screenshot, screenshot.getWidth() / 5,
screenshot.getHeight() / 5, true);
// set thumbnail
int scaledWidth = (int) (screenshot.getWidth() * thumbnai_scale_factor);
int scaledHeight = screenshot.getHeight() / 5;
Bitmap scaled = Bitmap.createScaledBitmap(screenshot, scaledWidth,
scaledHeight, true);
// recording.prefs.framebufferHeight
// / thumbnail_scale_factor);
......@@ -750,12 +751,19 @@ public class Index {
search_index.add(index.get(i));
Log.d("search", "number of hits: " + search_index.size());
highlightSearchResultsOnThumbnails();
// force repaint to highlight results
recording.graphicsContext().refresh();
// recording.graphicsContext().refresh();
}
public void highlightSearchResultsOfCurrentIndex() {
getCurrentIndex().highlightSearchResults();
public void highlightSearchResultsOfCurrentIndex(Canvas canvas) {
getCurrentIndex().highlightSearchResults(canvas);
}
public void highlightSearchResultsOnThumbnails() {
for (int i = 0; i < search_index.size(); i++) {
search_index.get(i).highlightSearchResultsOnThumbail();
}
}
}
......@@ -5,8 +5,12 @@ import java.io.IOException;
import java.util.ArrayList;
import tttclient.messages.Annotation;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.view.View;
import android.widget.ImageButton;
......@@ -147,16 +151,48 @@ public class IndexEntry extends ImageButton {
return results.size() > 0;
}
public void highlightSearchResults() {
// if (results != null)
// for (int i = 0; i < results.size(); i++) {
// ColoredShape shape = results.get(i);
// g.setColor(shape.color);
// if (shape.filled)
// g.fill(shape.shape);
// else
// g.draw(shape.shape);
// }
// draw the search results on the canvas
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void highlightSearchResults(Canvas canvas) {
if (results != null)
for (int i = 0; i < results.size(); i++) {
ColoredShape shape = results.get(i);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(shape.color);
if (shape.filled)
p.setStyle(Paint.Style.FILL);
else
p.setStyle(Paint.Style.STROKE);
canvas.drawRect(shape.rectangle, p);
}
}
public void highlightSearchResultsOnThumbail() {
if (results != null)
for (int i = 0; i < results.size(); i++) {
ColoredShape shape = results.get(i);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(shape.color);
if (shape.filled)
p.setStyle(Paint.Style.FILL);
else
p.setStyle(Paint.Style.STROKE);
Bitmap upScaled = Bitmap.createScaledBitmap(thumbnail,
thumbnail.getWidth() * 5, thumbnail.getHeight() * 5,
true);
Canvas searchCanvas = new Canvas(upScaled);
searchCanvas.drawRect(shape.rectangle, p);
setThumbnail(Bitmap.createScaledBitmap(upScaled,
thumbnail.getWidth(), thumbnail.getHeight(), true));
}
}
}
......@@ -27,13 +27,10 @@ package tttclient.ttt;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import tttclient.messages.Message;
......@@ -41,6 +38,7 @@ import tttclient.messages.MessageProducerAdapter;
import tttclient.messages.Messages;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Handler;
......@@ -436,9 +434,9 @@ public class Recording extends MessageProducerAdapter implements Runnable {
next_message = next;
}
// public void highlightSearchResults() {
// index.highlightSearchResultsOfCurrentIndex();
// }
public void highlightSearchResults(Canvas canvas) {
index.highlightSearchResultsOfCurrentIndex(canvas);
}
// /*******************************************************************************************************************
// * playback control *
......@@ -678,7 +676,11 @@ public class Recording extends MessageProducerAdapter implements Runnable {
public void fireIndexChangedEvent(int index) {
if (lastIndexFired != index) {
// focusCurrentIndexEntry(index);
Log.d("Index", " has changed to :" + index);
lastIndexFired = index;
highlightSearchResults(graphicsContext().getCanvas());
}
}
......@@ -708,85 +710,6 @@ public class Recording extends MessageProducerAdapter implements Runnable {
// setTime(0);
}
public boolean store(File OutputFile) {
tttFile = OutputFile;
return store();
}
public boolean store() {
// TODO: Progress Monitor (leave EventDispatchingThread)
// ProgressMonitor progressMonitor = null;
try {
// backup ttt file
File renameFile = null;
// first backup of original (unmodified) recording gets special name
if (original)
renameFile = new File(tttFile.getCanonicalPath() + ".orig");
if (renameFile == null || renameFile.exists())
renameFile = new File(tttFile.getCanonicalPath() + ".bak");
int i = 1;
while (renameFile.exists())
renameFile = new File(tttFile.getCanonicalPath() + ".bak."
+ i++);
tttFile.renameTo(renameFile);
FileOutputStream fileOut = new FileOutputStream(tttFile);
DataOutputStream out = new DataOutputStream(fileOut);
// progressMonitor.setProgress(1);
// write header
//
// write version message
out.write(Constants.VersionMessageTTT.getBytes());
// write compressed messages to file
out = new DataOutputStream(new DeflaterOutputStream(fileOut));
writeInit(out);
// writeExtensions(out);
// NOTE: badly designed - should be placed before extensions as part
// of init
out.writeLong(prefs.starttime);
// write body
messages.writeMessages(out);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
// if (progressMonitor != null)
// progressMonitor.close();
}
// initialization
void writeInit(DataOutputStream out) throws IOException {
// write protocol initialisation
out.writeShort(prefs.framebufferWidth);
out.writeShort(prefs.framebufferHeight);
out.writeByte(prefs.bitsPerPixel);
out.writeByte(prefs.depth);
out.writeByte(prefs.bigEndian ? 1 : 0);
out.writeByte(prefs.trueColour ? 1 : 0);
out.writeShort(prefs.redMax);
out.writeShort(prefs.greenMax);
out.writeShort(prefs.blueMax);
out.writeByte(prefs.redShift);
out.writeByte(prefs.greenShift);
out.writeByte(prefs.blueShift);
out.writeByte(0); // padding
out.writeByte(0);
out.writeByte(0);
out.writeInt(prefs.name.length());
out.write(prefs.name.getBytes());
}
// 4 = Thumbnails
public boolean createThumbnails() throws IOException {
return index.createScreenshots();
......
......@@ -89,7 +89,6 @@ public class SearchBaseEntry {
// TODO: return value not used / think about naming of method
// adds words from searchbase containing searchword to resultss
public boolean contains(String searchword, ArrayList<ColoredShape> results) {
// System.out.println(searchText);
if (searchText.indexOf(Constants.reduce(searchword)) >= 0) {
// highlight search results
......@@ -109,7 +108,7 @@ public class SearchBaseEntry {
results.add(new ColoredShape(borderColor, rectangle, false));
// underline results
boolean fixedSize = false;
boolean fixedSize = true;
if (fixedSize) {
// using fixed sized font
// TODO: use character specific letter size - variable sized
......@@ -142,6 +141,7 @@ public class SearchBaseEntry {
try {
// charWidths[i] =
// widths[searchTextOriginal.charAt(i)];
charWidths[i] = 5;
overall += charWidths[i];
} catch (IndexOutOfBoundsException e) {
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment