Commit 83dad761 authored by Thomas Krex's avatar Thomas Krex

surfaceview:

1. Versuch: SSurfaceView über imageview legen
	+Annotations und search results bleiben bei message update erhalten
	- sv bleibt nich transparent
	
2. Bitmap in surfaceView zeichnen , dann annotations drüber:
	+kein Flimmern
	-skalierung als problem: ganzer bildschirm wird ausgefüllt =>
		Seitenverhältnis geht verloren
	-wechsel zwischen fullscreen/extended nicht möglich, alter sf bleibt
	bestehen
	
	=> Direkt auf bitmap malen
		+ korrekte Skalierung
		+bei normalen Message aufkommen kein flimmern erkennbar
		+vllt kann man flimmern noch abstellen
		
-außerdem setTime methode korriegiert, framebufferupdates werden jetzt
berücksichtigt
=> enormer performance gewinn beim spulen und bein initialisieren der
Indizes
	
parent 3bc7b455
......@@ -17,6 +17,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
......@@ -25,7 +26,6 @@ import android.widget.MediaController.MediaPlayerControl;
import android.widget.ScrollView;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.SeekBar;
import android.widget.ViewSwitcher;
import com.example.test.R;
......@@ -40,7 +40,7 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
private Recording recording;
private MediaPlayer audioPlayer;
private MediaController audioController;
private SeekBar seekbar;
private SurfaceView surfaceView;
private int imgVHeight;
private int imgVWidth;
private SearchView searchView;
......@@ -51,11 +51,12 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player_main);
scrollView = (ScrollView) findViewById(R.id.indexScrollView);
// surfaceView = (SurfaceView) findViewById(R.id.playerView_fullscreen);
switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
// desfault fullscreen
// default fullscreen
imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
// switchLayout(0);
fileName = getIntent().getStringExtra(DownloadService.FILE_NAME);
setTitle(fileName);
......@@ -72,9 +73,6 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
final int screenHeight = display.getHeight(); // deprecated
audioController = new MediaController(this);
final int topContainerId1 = getResources().getIdentifier(
"mediacontroller_progress", "id", "android");
seekbar = (SeekBar) audioController.findViewById(topContainerId1);
audioController.setMediaPlayer(this);
audioController.setHorizontalScrollBarEnabled(false);
......@@ -83,60 +81,50 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
// dialog.setMessage("Reading File");
// dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// TODO ProgressDialog anzeigen lassen
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// dialog.show();
try {
recording = new Recording(getApplicationContext(), tttFile,
audioPlayer, imgV, scrollView, screenWidth,
screenHeight);
OnClickListener prevListener = new OnClickListener() {
// dialog.show();
try {
recording = new Recording(getApplicationContext(), tttFile,
audioPlayer, imgV, surfaceView, scrollView, screenWidth,
screenHeight);
@Override
public void onClick(View v) {
recording.previous();
OnClickListener prevListener = new OnClickListener() {
}
};
OnClickListener nextListener = new OnClickListener() {
@Override
public void onClick(View v) {
recording.previous();
@Override
public void onClick(View v) {
recording.next();
}
};
audioController.setPrevNextListeners(nextListener,
prevListener);
}
};
OnClickListener nextListener = new OnClickListener() {
audioController.setAnchorView(imgV);
@Override
public void onClick(View v) {
recording.next();
// dialog.dismiss();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
audioController.setPrevNextListeners(nextListener, prevListener);
}
});
t.start();
audioController.setAnchorView(imgV);
// dialog.dismiss();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// android.os.Message message = recording.graphicsContext().sizeHandler
// .obtainMessage(0, imgVArray);
// message.sendToTarget();
}
public void search(String word) {
if (recording.getIndex() != null)
recording.getIndex().search(word);
recording.highlightSearchResults(recording.graphicsContext()
.getCanvas());
// update display if recording is not playing
// if (!recording.isPlaying())
recording.graphicsContext().updateCanvas();
if (!recording.isPlaying())
recording.graphicsContext().updateCanvas();
}
......@@ -258,11 +246,13 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
case R.id.extend:
if (!isExtendend) {
switchLayout(1);
// switchSurface(1);
item.setIcon(getResources().getDrawable(
android.R.drawable.ic_input_delete));
isExtendend = true;
} else if (isExtendend) {
switchLayout(0);
// switchSurface(0);
item.setIcon(getResources().getDrawable(
android.R.drawable.ic_input_add));
isExtendend = false;
......@@ -281,14 +271,15 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
if (index == 0) {
imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
recording.graphicsContext().setImageView(imgV);
recording.focusCurrentIndexEntry(recording.getLastIndexFired() - 1);
// recording.focusCurrentIndexEntry(recording.getLastIndexFired() -
// 1);
switcher.setDisplayedChild(0);
}
// extended View
if (index == 1) {
imgV = (ImageView) findViewById(R.id.playerView_extended);
recording.graphicsContext().setImageView(imgV);
recording.graphicsContext().setImageView(imgV);
recording.graphicsContext().refresh();
switcher.setDisplayedChild(1);
......@@ -297,4 +288,21 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
}
void switchSurface(int index) {
if (index == 0) {
surfaceView.setVisibility(View.INVISIBLE);
surfaceView = (SurfaceView) findViewById(R.id.playerView_fullscreen);
recording.graphicsContext().setSurfaceView(surfaceView);
// recording.focusCurrentIndexEntry(recording.getLastIndexFired() -
// 1);
switcher.setDisplayedChild(0);
}
if (index == 1) {
surfaceView.setVisibility(View.INVISIBLE);
surfaceView = (SurfaceView) findViewById(R.id.playerView_extended);
recording.graphicsContext().setSurfaceView(surfaceView);
recording.graphicsContext().updateOverlay();
}
}
}
......@@ -229,9 +229,9 @@ public abstract class Message {
// break;
default:
System.out.println("skipping unsupported message: Encoding = "
+ Constants.encodingToString(encoding) + "\t" + size
+ " bytes");
// System.out.println("skipping unsupported message: Encoding = "
// + Constants.encodingToString(encoding) + "\t" + size
// + " bytes");
do {
size -= in.skipBytes(size);
} while (size > 0);
......
......@@ -34,6 +34,7 @@ import tttclient.messages.annotations.Annotation;
import tttclient.messages.annotations.DeleteAllAnnotation;
import tttclient.ttt.Constants;
import tttclient.ttt.Recording;
import android.graphics.Rect;
import android.util.Log;
public class Messages {
......@@ -287,49 +288,52 @@ public class Messages {
}
// message is part of keyframe, because it covers unset pixels
// if (message instanceof FramebufferUpdateMessage) {
// if (coveredCounter < full) {
// update covered area
// TODO convert to android
// Rect rectangle = ((FramebufferUpdateMessage) message)
// .getBounds();
// if (message instanceof WhiteboardMessage)
// rectangle = new Rect(0, 0,
// recording.prefs.framebufferWidth,
// recording.prefs.framebufferHeight);
//
// // graphicsContext.memGraphics.setColor(Color.CYAN);
// //
// graphicsContext.memGraphics.fillRect(rectangle.x,rectangle.y,rectangle.width,rectangle.height);
//
// boolean add = false;
//
// // set covered pixels
// for (int y = 0; y < rectangle.height(); y++)
// for (int x = 0; x < rectangle.width(); x++)
// try {
// if (!covered[rectangle.left + x][rectangle.top
// + y]) {
// // add only once (outside loop)
// add = true;
//
// // mark pixel
// coveredCounter++;
// covered[rectangle.left + x][rectangle.top
// + y] = true;
// }
// } catch (ArrayIndexOutOfBoundsException e) {
// // possibly caused by changing the screen
// // resolution (which is not supported by the
// // TTT)
// }
// // add at beginning
// if (add)
// collected.add(0, message);
// }
// }
if (message instanceof FramebufferUpdateMessage) {
if (coveredCounter < full) {
// update covered area
// TODO convert to android
Rect rectangle = ((FramebufferUpdateMessage) message)
.getBounds();
if (message instanceof WhiteboardMessage)
rectangle = new Rect(
0,
0,
recording.getProtocolPreferences().framebufferWidth,
recording.getProtocolPreferences().framebufferHeight);
// graphicsContext.memGraphics.setColor(Color.CYAN);
//
// graphicsContext.memGraphics.fillRect(rectangle.left,
// rectangle.y, rectangle.width, rectangle.height);
boolean add = false;
// set covered pixels
for (int y = 0; y < rectangle.height(); y++)
for (int x = 0; x < rectangle.width(); x++)
try {
if (!covered[rectangle.left + x][rectangle.top
+ y]) {
// add only once (outside loop)
add = true;
// mark pixel
coveredCounter++;
covered[rectangle.left + x][rectangle.top
+ y] = true;
}
} catch (ArrayIndexOutOfBoundsException e) {
// possibly caused by changing the screen
// resolution (which is not supported by the
// TTT)
}
// add at beginning
if (add)
collected.add(0, message);
}
}
// all annotation since last deleteAll
else if (message instanceof Annotation) {
......@@ -379,7 +383,6 @@ public class Messages {
Log.d("Messages", "setting recording next message to " + newNext);
}
}
/*******************************************************************************************************************
......
......@@ -27,6 +27,8 @@ public class ParseService extends IntentService {
static final String DESCRIPTION = "description";
static final String LINK = "link";
static final String TITLE = "title";
static final String ENCLOSURE = "enclosure";
static final String LENGTH = "length";
private URL feedUrl;
......
......@@ -20,14 +20,27 @@ import android.media.Image;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.ImageView;
@SuppressLint("NewApi")
public class GraphicsContext implements MessageConsumer {
static float SCALE_X_FULLSCREEN;
static float SCALE_Y_FULLSCREEN;
static float SCALE_X_EXTENDED;
static float SCALE_Y_EXTENDED;
private final Handler viewHandler;
private final Canvas canvas;
public Handler sizeHandler;
private final BitmapContainer bitmapContainer;
private final Canvas canvas;
private ImageView imgView;
private SurfaceView overlay;
private SurfaceHolder sHolder;
private boolean refreshEnabled = false;
private final MessageProducer producer;
private final ProtocolPreferences prefs;
......@@ -44,16 +57,17 @@ public class GraphicsContext implements MessageConsumer {
return recording;
}
public GraphicsContext(ImageView imgV, Recording record, int width,
int height) {
public GraphicsContext(ImageView imgV, SurfaceView surfaceView,
Recording record, int width, int height) {
setImageView(imgV);
this.producer = record;
this.recording = record;
producer.addMessageConsumer(this);
this.prefs = record.getProtocolPreferences();
Log.d("GraphicContext", "framebuffer size: " + prefs.framebufferWidth
+ " , " + prefs.framebufferHeight);
// // init SurfaceView
// setSurfaceView(surfaceView);
//
// compute scale factor
this.screenWidth = width;
......@@ -81,21 +95,11 @@ 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;
// TODO
// Canvas testCanvas = new Canvas(bitmap);
// highlight search Results
// TODO
// updateOverlay();
// int[] pixelCopy = new int[getPixels().length];
// System.arraycopy(getPixels(), 0, pixelCopy, 0,
// getPixels().length);
// recording.getIndex().highlightSearchResultsOfCurrentIndex(
// pixelCopy);
// handleUpdatedPixels(pixelCopy);
// draw annotations
paintAnnotations(canvas);
// update display
recording.highlightSearchResults(canvas);
imgView.setImageBitmap(bitmap);
......@@ -103,6 +107,14 @@ public class GraphicsContext implements MessageConsumer {
};
}
public void setSurfaceView(SurfaceView surfaceView) {
this.overlay = surfaceView;
overlay.setZOrderOnTop(true);
sHolder = overlay.getHolder();
sHolder.setFixedSize(prefs.framebufferWidth, prefs.framebufferHeight);
}
public static void fillRect(int[] array, Rect r, int color, int screenWidth) {
int x = r.left;
int y = r.top;
......@@ -142,6 +154,18 @@ public class GraphicsContext implements MessageConsumer {
}
}
public void updateOverlay() {
Canvas canvas = sHolder.lockCanvas();
if (canvas != null) {
canvas.drawBitmap(bitmapContainer.getBimap(), 0, 0, null);
paintAnnotations(canvas);
recording.highlightSearchResults(canvas);
sHolder.unlockCanvasAndPost(canvas);
}
}
public void enableRefresh(boolean refresh) {
this.refreshEnabled = refresh;
}
......@@ -172,10 +196,6 @@ public class GraphicsContext implements MessageConsumer {
return hextile_fg_encoded;
}
public Canvas getCanvas() {
return this.canvas;
}
// draw Canvas on current Bitmap
public void updateCanvas() {
if (refreshEnabled) {
......@@ -324,6 +344,7 @@ public class GraphicsContext implements MessageConsumer {
// display all annotations
synchronized public void paintAnnotations(Canvas canvas) {
for (int i = 0; i < currentAnnotations.size(); i++) {
currentAnnotations.get(i).paint(canvas);
}
......
......@@ -231,16 +231,12 @@ public class Index {
// header
int number_of_table_entries = in.readShort();
if (true)
System.out.println("Index with " + number_of_table_entries
+ " entries.");
// index table
for (int i = 0; i < number_of_table_entries; i++) {
// timestamp
int timestamp = in.readInt();
// title
int titelLength = in.readByte();
System.out.println("title length " + titelLength);
byte[] titleArray = new byte[titelLength];
in.readFully(titleArray);
String title = new String(titleArray);
......@@ -260,12 +256,6 @@ public class Index {
index.add(new IndexEntry(context, this, title, timestamp,
searchable, null));
if (true)
System.out.println("Index " + (i < 9 ? " " : "") + (i + 1)
+ ": " + Constants.getStringFromTime(timestamp, true));
// + (image == null ? " - no thumb" : " - thumb")
// + (searchable.length() > 0 ? " - search"
// : " - no search") + " - Title: " + title);
}
// check if valid
......@@ -718,10 +708,6 @@ public class Index {
getCurrentIndex().highlightSearchResults(canvas);
}
// public void highlightSearchResultsOfCurrentIndex(int[] pixel) {
// getCurrentIndex().highlightSearchResults(pixel);
// }
public void highlightSearchResultsOnThumbnails() {
for (int i = 0; i < search_index.size(); i++) {
search_index.get(i).highlightSearchResultsOnThumbail();
......
......@@ -41,10 +41,9 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
......@@ -85,8 +84,8 @@ public class Recording extends MessageProducerAdapter implements Runnable {
}
public Recording(Context context, File tttFile, MediaPlayer audioPlayer,
ImageView imgV, ScrollView scrollView, int screenWidth,
int screenHeight) throws IOException {
ImageView imgV, SurfaceView surfaceView, ScrollView scrollView,
int screenWidth, int screenHeight) throws IOException {
// read
this.context = context;
this.indexViewer = scrollView;
......@@ -99,9 +98,8 @@ public class Recording extends MessageProducerAdapter implements Runnable {
// read messages + extensions
read(tttFile);
graphicsContext = new GraphicsContext(imgV, this, screenWidth,
screenHeight);
// TODO readExtensions to get index thumbnail
graphicsContext = new GraphicsContext(imgV, surfaceView, this,
screenWidth, screenHeight);
if (!index.isValid())
index.computeIndex();
......@@ -490,26 +488,26 @@ public class Recording extends MessageProducerAdapter implements Runnable {
return title;
}
public void focusCurrentIndexEntry(int i) {
if (index.thumbnailsAvailable()) {
final IndexEntry entry = index.get(i);
// display is not being updated to avoid to much work load
graphicsContext.enableRefresh(false);
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
int[] position = new int[2];
entry.getLocationInWindow(position);
// indexViewer.scrollTo(0, position[1] + entry.getWidth());
Log.d("Index", " scroll to x: " + position[1]);
}
});
graphicsContext.enableRefresh(true);
}
}
// public void focusCurrentIndexEntry(int i) {
// if (index.thumbnailsAvailable()) {
// final IndexEntry entry = index.get(i);
//
// // display is not being updated to avoid to much work load
// graphicsContext.enableRefresh(false);
// // new Handler(Looper.getMainLooper()).post(new Runnable() {
// // @Override
// // public void run() {
// // int[] position = new int[2];
// // entry.getLocationInWindow(position);
// // // indexViewer.scrollTo(0, position[1] + entry.getWidth());
// // Log.d("Index", " scroll to x: " + position[1]);
// //
// // }
// // });
//
// graphicsContext.enableRefresh(true);
// }
// }
//
// start playback
......@@ -672,7 +670,7 @@ public class Recording extends MessageProducerAdapter implements Runnable {
lastIndexFired = index;
this.index.get(index - 1).setBackgroundColor(Color.RED);
focusCurrentIndexEntry(index - 1);
// focusCurrentIndexEntry(index - 1);
// highlightSearchResults(graphicsContext().getCanvas());
......
......@@ -29,56 +29,6 @@ import java.io.IOException;
public class SearchbaseExtension {
//
// // write searchbase extension
// static public void writeSearchbaseExtension(DataOutputStream out, Index
// index) throws IOException {
// if (index != null && index.getSearchbaseFormat() == Index.XML_SEARCHBASE
// && index.size() > 0) {
// // buffer output to determine its length
// ByteArrayOutputStream byteArrayOutputStream = new
// ByteArrayOutputStream();
// DataOutputStream buffer = new DataOutputStream(byteArrayOutputStream);
//
// // header
// buffer.writeByte(Constants.EXTENSION_SEARCHBASE_TABLE_WITH_COORDINATES);
//
// // number of index entries
// buffer.writeShort(index.size());
//
// // ratio
// // NOTE: this is Omnipage XML Document specific, where coordinates differ
// from input screenshot.
// // However, it seems to be persistent for all pages (will fail, if not)
// // TODO: think about this
// double ratio = 0;
// // TODO: ugly hack
// // NOTE: ratio of 1 might be returned for pages without searchable text
// for (int i = 0; ((ratio == 0) || (ratio == 1)) && (i < index.size());
// i++)
// ratio = index.get(i).getRatio();
//
// if (ratio == 0)
// System.out.println("Bad ratio (zero) written. This should never habben!!!!!!!! (Now is never;-)");
//
// buffer.writeDouble(ratio);
//
// // write searchbase for each index
// for (int i = 0; i < index.size(); i++)
// index.get(i).writeSearchbase(buffer);
//
// // force write
// buffer.flush();
//
// // write length of extension
// out.writeInt(byteArrayOutputStream.size());
// // write extension
// out.write(byteArrayOutputStream.toByteArray());
//
// index.searchbaseFormatStored = Index.XML_SEARCHBASE;
// } // else no index available
// }
//
// // TODO: return value??
// read searchbase extension
static public void readSearchbaseExtension(DataInputStream in, Index index)
......
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