Commit b74b0cef by Thomas Krex

indexview in die Klasse index verschoben

parent 3a48ce9d
......@@ -369,7 +369,7 @@ public class FeedDetailActivity extends SherlockActivity implements
int progress = resultData.getInt("progress");
progressDialog.setMessage(progress + "% donwloaded");
progressDialog.setMessage(progress + "% downloaded");
}
......
......@@ -65,9 +65,10 @@ public class PlayerActivity extends SherlockActivity implements
File audioFile = new File(filePath + "/" + fileName + ".mp3");
audioPlayer = MediaPlayer.create(this, Uri.fromFile(audioFile));
audioController = new MediaController(this);
// creates a MediaController without fastforward and rewind buttons
audioController = new MediaController(this, false);
audioController.setMediaPlayer(this);
audioController.setHorizontalScrollBarEnabled(false);
final ProgressDialog dialog = new ProgressDialog(PlayerActivity.this);
dialog.setTitle("Please Wait");
dialog.setMessage("Prepare File ...");
......@@ -134,6 +135,7 @@ public class PlayerActivity extends SherlockActivity implements
}
// delegates search to index and updates the view
public void search(String word) {
if (recording.getIndex() != null)
recording.getIndex().search(word);
......@@ -231,28 +233,31 @@ public class PlayerActivity extends SherlockActivity implements
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.player_menu, menu);
MenuItem item = menu.findItem(R.id.search);
// set up search View in Actionbar
searchView = (SearchView) item.getActionView();
//
// for API level >14 you can hide fullscreen textfield when input is
// made
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
// set up methods to react on user input
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// search(query);
// if (query.isEmpty())
// searchView.clearFocus();
// recording.getIndex().highlightSearchResultsOnThumbnails();
recording.getIndex().nextSearchResult();
searchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
// search after String during the input
search(newText);
recording.getIndex().highlightSearchResultsOnThumbnails();
// update thumbnail to mark new search results
recording.getIndex().updateThumbnails();
return true;
}
});
......@@ -266,11 +271,10 @@ public class PlayerActivity extends SherlockActivity implements
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
// handle layout switch
case R.id.extend:
if (!isExtendend) {
switchLayout(1);
// switchSurface(1);
item.setIcon(getResources().getDrawable(
R.drawable.ic_action_full_screen));
isExtendend = true;
......@@ -284,6 +288,7 @@ public class PlayerActivity extends SherlockActivity implements
}
return true;
// go to next search result
case R.id.next:
if (!searchView.getQuery().toString().isEmpty())
Log.d("Player", "next invoked");
......
......@@ -3,8 +3,6 @@ package tttclient.core;
import java.util.ArrayList;
import tttclient.messages.Annotation;
import tttclient.messages.CursorMessage;
import tttclient.messages.CursorPositionMessage;
import tttclient.messages.Message;
import tttclient.messages.MessageConsumer;
import tttclient.messages.MessageProducer;
......@@ -17,23 +15,15 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.media.Image;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.ImageView;
import android.widget.LinearLayout;
@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 Handler scrollHandler;
private final BitmapContainer bitmapContainer;
private ImageView imgView;
......@@ -73,15 +63,12 @@ public class GraphicsContext implements MessageConsumer {
prefs.framebufferWidth, prefs.framebufferHeight,
Config.ARGB_4444));
// canvas to Bitmap
this.pixels = bitmapContainer.getPixels();
hextile_bg_encoded = new byte[prefs.bytesPerPixel];
hextile_fg_encoded = new byte[prefs.bytesPerPixel];
// hanlder do tasks, which has to be done in the UI-Thread
// Updating of ImageView
// Handler for Updating the ImageView
viewHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(android.os.Message inputMessage) {
......@@ -92,47 +79,9 @@ public class GraphicsContext implements MessageConsumer {
}
};
// Updating of ScrollView
scrollHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(android.os.Message inputMessage) {
// Gets the image task from the incoming Message object.
int indexNumber = inputMessage.arg1;
int color = inputMessage.arg2;
IndexEntry entry = recording.getIndex().get(indexNumber - 1);
entry.setBackgroundColor(color);
LinearLayout parent = (LinearLayout) entry.getParent();
recording.getIndexViewer().scrollTo(0,
parent.getTop() - parent.getHeight() / 2);
}
};
}
// public static void borderRect(int[] array, Rect r, int color,
// int screenWidth) {
// int x = r.left;
// int y = r.top;
// int w = r.width();
// int h = r.height();
//
// for (int i = y; i < y + h; i++) {
// int offset = i * screenWidth + x;
// if (i == y || i == y + h - 1) {
// for (int j = 0; j < w; j++) {
//
// array[offset + j] = color;
// }
// } else {
// for (int j = 0; j < w; j++) {
// if (j == 0 || j == w - 1)
// array[offset + j] = color;
// }
//
// }
// }
// }
public void enableRefresh(boolean refresh) {
this.refreshEnabled = refresh;
}
......@@ -167,18 +116,10 @@ public class GraphicsContext implements MessageConsumer {
return hextile_fg_encoded;
}
public Handler getScrollHandler() {
return this.scrollHandler;
}
// TODO welche Methoden werden wann ben??tigt
// draw Canvas on current Bitmap
// painting is done here
public void updateView() {
if (refreshEnabled) {
// Thread paintThread = new Thread(new Runnable() {
//
// @Override
// public void run() {
Bitmap bitmap = bitmapContainer.getBitmap();
Canvas canvas = new Canvas(bitmap);
......@@ -189,18 +130,6 @@ public class GraphicsContext implements MessageConsumer {
android.os.Message message = viewHandler.obtainMessage(0, bitmap);
message.sendToTarget();
// }
// });
// paintThread.start();
}
}
// set new Bitmap
public void updateView(final Bitmap bitmap) {
if (refreshEnabled) {
android.os.Message message = viewHandler.obtainMessage(0, bitmap);
message.sendToTarget();
}
}
......@@ -222,34 +151,7 @@ public class GraphicsContext implements MessageConsumer {
}
//
// public int 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);
//
// }
// return color;
// }
// used by hextile message
public void setForeground(byte[] color, int offset) {
System.arraycopy(color, offset, hextile_fg_encoded, 0,
prefs.bytesPerPixel);
......@@ -275,9 +177,6 @@ public class GraphicsContext implements MessageConsumer {
// if recording is adjusting, messages are not painted one by one but
// only the final image
if (!recording.adjusting) {
// bitmapContainer.getCurBitmap().setPixels(pixels,
// x + y * prefs.framebufferWidth, prefs.framebufferWidth, x,
// y, w, h);
updateView();
}
......@@ -353,31 +252,23 @@ public class GraphicsContext implements MessageConsumer {
}
public Bitmap getScreenshotWithoutAnnotations() {
public Bitmap createScreenshotWithoutAnnotations() {
// create new mutable bitmap
Bitmap screenshot = Bitmap.createBitmap(prefs.framebufferWidth,
prefs.framebufferHeight, Config.ARGB_4444);
// show blank page if whiteboard activated
if (isWhiteboardEnabled()) {
Log.d("Screenshot", "WhiteBoard enabled");
Canvas canvas = new Canvas(screenshot);
canvas.drawColor(Color.WHITE);
paintWhiteboard(canvas);
} else
} else {
screenshot.setPixels(pixels, 0, prefs.framebufferWidth, 0, 0,
prefs.framebufferWidth, prefs.framebufferHeight);
// Bitmap scaledScreenshot = Bitmap
// .createScaledBitmap(
// screenshot,
// (int) (prefs.framebufferWidth *
// IndexEntry.THUMBNAIL_SCALE_FACTOR),
// (int) (prefs.framebufferHeight *
// IndexEntry.THUMBNAIL_SCALE_FACTOR),
// false);
// screenshot.recycle();
// System.gc();
}
return screenshot;
}
......@@ -405,18 +296,9 @@ public class GraphicsContext implements MessageConsumer {
return new WhiteboardMessage(0, whiteboardPage, prefs);
}
// fill the canvas with white color and set the page number
public void paintWhiteboard(Canvas canvas) {
// int[] whitePixel = new int[prefs.framebufferHeight
// * prefs.framebufferWidth];
// for (int i = 0; i < whitePixel.length; i++) {
// whitePixel[i] = Color.WHITE;
// }
//
// bitmapContainer.getBimap().setPixels(whitePixel, 0,
// prefs.framebufferWidth, 0, 0, prefs.framebufferWidth,
// prefs.framebufferHeight);
canvas.drawColor(Color.WHITE);
Paint p = new Paint(Color.BLACK);
......@@ -426,92 +308,4 @@ public class GraphicsContext implements MessageConsumer {
}
// ////////////////////////////////////////////////////////////////
// Cursor
// ////////////////////////////////////////////////////////////////
private boolean showSoftCursor;
public int[] softCursorPixels;
public Image softCursor;
public Bitmap softCursorSource;
public int cursorX, cursorY;
public int cursorWidth, cursorHeight;
public int hotX, hotY;
// Remove soft cursor, dispose resources.
// Moves soft cursor into a particular location.
synchronized public void softCursorMove(int x, int y) {
if (showSoftCursor) {
int old_cursorX = cursorX;
int old_cursorY = cursorY;
// set new position
cursorX = x;
cursorY = y;
// clear old and paint new cursor
// refresh(old_cursorX - hotX, old_cursorY - hotY, cursorWidth,
// cursorHeight);
// refresh(x - hotX, y - hotY, cursorWidth, cursorHeight);
updateView();
} else {
// just set new position
cursorX = x;
cursorY = y;
}
}
// Remove soft cursor, dispose resources.
synchronized public void softCursorFree() {
if (showSoftCursor) {
showSoftCursor = false;
softCursor = null;
softCursorSource = null;
softCursorPixels = null;
// refresh(cursorX - hotX, cursorY - hotY, cursorWidth,
// cursorHeight);
updateView();
}
}
public void showSoftCursor(boolean show) {
if (show) {
// show soft cursor (if available)
if (softCursor != null) {
showSoftCursor = true;
// refresh(cursorX - hotX, cursorY - hotY, cursorWidth,
// cursorHeight);
updateView();
;
}
} else {
// disable soft cursor
if (showSoftCursor) {
showSoftCursor = false;
// refresh(cursorX - hotX, cursorY - hotY, cursorWidth,
// cursorHeight);
updateView();
}
}
}
// updates for late comers and recorders
public Message getCurrentCursorPositionMessage() {
return new CursorPositionMessage(0, cursorX, cursorY);
}
// updates for late comers and recorders
private CursorMessage bufferedCursorMessage;
public void setCurrentCursorMessage(CursorMessage cursorMessage) {
bufferedCursorMessage = cursorMessage;
}
public Message getCurrentCursorMessage() {
return bufferedCursorMessage;
}
}
\ No newline at end of file
......@@ -36,8 +36,17 @@ import tttclient.messages.WhiteboardMessage;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class Index {
......@@ -54,6 +63,8 @@ public class Index {
private Recording recording;
private final Context context;
private final ScrollView indexViewer;
private final Handler scrollHandler;
int getWidth() {
return recording.getProtocolPreferences().framebufferWidth;
......@@ -63,14 +74,26 @@ public class Index {
return recording;
}
public Index(Recording recording, Context context) {
public Index(Recording recording, ScrollView scrollView, Context context) {
this.recording = recording;
this.context = context;
// must contain at least one entry
// TODO: needed?
this.indexViewer = scrollView;
index.add(new IndexEntry(context, this));
scrollHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(android.os.Message inputMessage) {
// Gets the image task from the incoming Message object.
int indexNumber = inputMessage.arg1;
int color = inputMessage.arg2;
IndexEntry entry = get(indexNumber - 1);
entry.setBackgroundColor(color);
LinearLayout parent = (LinearLayout) entry.getParent();
indexViewer.scrollTo(0, parent.getTop() - parent.getHeight()
/ 2);
}
};
}
public void close() {
......@@ -282,52 +305,6 @@ public class Index {
}
}
// ///////////////////////////////////////////
// thumbnail defaults
// ///////////////////////////////////////////
// private int thumbnail_scale_factor =
// Constants.default_thumbnail_scale_factor;
//
// public int getThumbnailScaleFactor() {
// return thumbnail_scale_factor;
// }
//
// private Image defaultThumbnail;
//
// public Image getDefaultThumbnail() {
// if (defaultThumbnail == null)
// createDefaultThumbnail();
// return defaultThumbnail;
// }
//
// private void createDefaultThumbnail() {
// // define default thumbnail icon
//
// // get image
// Image image = Constants.getIcon("77.kitty.jpg").getImage();
//
// // wait until image is fully loaded and image dimensions can be
// // determined
// while (!Toolkit.getDefaultToolkit().prepareImage(image, -1, -1, null))
// try {
// Thread.sleep(10);
// } catch (InterruptedException e) {
// }
//
// // scale image to thumbnail size
// image = ScriptCreator.getScaledInstance(image,
// 1024 / thumbnail_scale_factor, 768 / thumbnail_scale_factor);
//
// // was:
// // image = image.getScaledInstance(1024 / thumbnail_scale_factor, 768 /
// // thumbnail_scale_factor,
// // Image.SCALE_DEFAULT);
//
// defaultThumbnail = image;
//
// }
// //////////////////////////////////////////////
// Annotations
// //////////////////////////////////////////////
......@@ -452,20 +429,20 @@ public class Index {
// set time of index
IndexEntry indexEntry = index.get(i);
int timestamp = indexEntry.getTimestamp();
// for screenshots Bitmap has to set but not the display/audio
// for screenshots only the pixel array has to set but not the
// display/audio
recording.setTime(timestamp, false);
// create screenshot
Bitmap screenshot = recording.graphicsContext()
.getScreenshotWithoutAnnotations();
.createScreenshotWithoutAnnotations();
// insert the bitmap in the indexEntry
indexEntry.setThumbnail(screenshot);
}
// reset playback
// TODO: reset mode pause/play
// recording.setTime(previousTime, true);
return isCanceled == false;
}
......@@ -595,6 +572,51 @@ public class Index {
}
// //////////////////////////////////////////////////////////////////
// Index View
// //////////////////////////////////////////////////////////////////
public void initIndexView() {
// needed because scrollview can only have one direct child
LinearLayout layout = new LinearLayout(context);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundColor(Color.WHITE);
int length = size();
for (int i = 0; i < length; i++) {
IndexEntry entry = index.get(i);
layout.addView(addTitle(i));
layout.addView(insertEntry(entry));
}
indexViewer.addView(layout);
}
public View insertEntry(IndexEntry entry) {
LinearLayout layout = new LinearLayout(context);
layout.setBackgroundColor(Color.WHITE);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
layout.setGravity(Gravity.CENTER);
layout.addView(entry);
return layout;
}
View addTitle(int number) {
TextView title = new TextView(context);
title.setText(String.valueOf(number + 1));
title.setTextAppearance(context, android.R.style.TextAppearance_Large);
title.setTextColor(Color.BLACK);
return title;
}
// //////////////////////////////////////////////////////////////////
// controlling
// //////////////////////////////////////////////////////////////////
......@@ -622,7 +644,7 @@ public class Index {
// set index
nowPlayingIndex_startingAtZero = i;
recording.fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
}
public IndexEntry get(int i) {
......@@ -658,15 +680,41 @@ public class Index {
nowPlayingIndex_startingAtZero = i;
// fire event (index event starting at one)
recording
.fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
// update search result highligting
// recording.graphicsContext().refresh();
break;
}
}
// ///////////////////////////////////////////////////////////////////////////////////
// Index Listeners
// ///////////////////////////////////////////////////////////////////////////////////
private int lastIndexFired = -1;
public int getLastIndexFired() {
return lastIndexFired;
}
public void fireIndexChangedEvent(int indexNumber) {
if (lastIndexFired != indexNumber) {
// highlighting of index entry and scrolling has to be done in ui
// thread
if (lastIndexFired > 0) {
android.os.Message unMarkMessage = scrollHandler.obtainMessage(
0, lastIndexFired, Color.WHITE);
unMarkMessage.sendToTarget();
}
lastIndexFired = indexNumber;
android.os.Message markMessage = scrollHandler.obtainMessage(0,
indexNumber, Color.RED);
markMessage.sendToTarget();
}
}
// //////////////////////////////////////////////////////////////////
// search
// //////////////////////////////////////////////////////////////////
......@@ -715,9 +763,8 @@ public class Index {
getCurrentIndex().highlightSearchResults(canvas);
}
public void highlightSearchResultsOnThumbnails() {
public void updateThumbnails() {
for (int i = 0; i < index.size(); i++) {
// index.get(i).highlightSearchResultsOnThumbail();
index.get(i).updateThumbail();
}
......
......@@ -21,7 +21,6 @@ import android.widget.LinearLayout;
public class IndexEntry extends ImageButton {
private final int timestamp;
private final Index index;
private int[] pixel;
private BitmapContainer bitmapContainer;
private String title = "";
private String searchbase_of_page;
......@@ -80,17 +79,19 @@ public class IndexEntry extends ImageButton {
hasThumbnail = true;
}
// setImageBitmap(thumbnail);
updateThumbail();
// set src of ImageButton
Canvas canvas = new Canvas(thumbnail);
paintAnnotations(canvas);
setImageBitmap(thumbnail);
}
// paint searchresults and annotations on Bitmap and display it
public void updateThumbail() {
Bitmap bitmap = bitmapContainer.getBitmap();
final Bitmap bitmap = bitmapContainer.getBitmap();
Canvas canvas = new Canvas(bitmap);
paintAnnotations(canvas);
highlightSearchResultsOnThumbail(canvas);
paintAnnotations(canvas);
setImageBitmap(bitmap);
}
......@@ -219,14 +220,14 @@ public class IndexEntry extends ImageButton {
boolean paintHighlightAnnotations = index.getAnnotationsPaintMode() == Index.PAINT_ALL_ANNOTATIONS;
if (annotations != null) {
Log.d("IndexEntry", "annotaion to thumbnail");
if (index.getAnnotationsPaintMode() != Index.PAINT_NO_ANNOTATIONS)
for (int i = 0; i < annotations.size(); i++) {
Annotation annotation = annotations.get(i);
if (paintHighlightAnnotations
|| !(annotation instanceof HighlightAnnotation))
|| !(annotation instanceof HighlightAnnotation)) {
Log.d("IndexEntry", "annotaion to thumbnail");
annotation.paintToThumbnail(canvas);
;
}
}
}
}
......
......@@ -30,8 +30,6 @@ import java.io.IOException;
import java.util.ArrayList;
import tttclient.messages.Annotation;
import tttclient.messages.CursorMessage;
import tttclient.messages.CursorPositionMessage;
import tttclient.messages.DeleteAllAnnotation;
import tttclient.messages.FramebufferUpdateMessage;