Commit 7c8554e4 authored by Thomas Krex's avatar Thomas Krex

neue variante mit surfaceview

parent d851d885
......@@ -18,6 +18,7 @@
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ttt24"
android:label="@string/app_name"
android:largeHeap="true"
......
......@@ -18,6 +18,7 @@
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ttt24"
android:label="@string/app_name"
android:largeHeap="true"
......
......@@ -338,22 +338,22 @@ int id itemTitle 0x7f040042
int id listMode 0x7f040002
int id next 0x7f040047
int id normal 0x7f040001
int id playerView_extended 0x7f040034
int id playerView_fullscreen 0x7f040036
int id playerView_extended 0x7f040035
int id playerView_fullscreen 0x7f040037
int id port_tx 0x7f040039
int id progressBar 0x7f040041
int id scrollView1 0x7f040035
int id search 0x7f040046
int id server_tx 0x7f040038
int id showCustom 0x7f040008
int id showHome 0x7f040005
int id showTitle 0x7f040007
int id statusIcon 0x7f040043
int id surfaceContainer 0x7f040034
int id tabMode 0x7f040003
int id tx_name 0x7f04003d
int id tx_url 0x7f04003c
int id useLogo 0x7f040004
int id viewSwitcher 0x7f040037
int id viewSwitcher 0x7f040036
int id watch_button 0x7f040032
int id wrap_content 0x7f040000
int integer abs__max_action_buttons 0x7f080000
......
......@@ -6,23 +6,27 @@
<ScrollView
android:id="@+id/indexScrollView"
android:layout_width="200dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:paddingLeft="5dip" >
</ScrollView>
<ImageView
android:id="@+id/playerView_extended"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/scrollView1"
android:layout_weight="5"
android:layout_weight="1"
android:background="@drawable/my_border"
android:padding="10dip"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
android:fillViewport="false"
android:paddingLeft="5dip"
android:paddingRight="5dip" >
</ScrollView>
<LinearLayout
android:id="@+id/surfaceContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="@android:color/black"
android:gravity="center" >
<SurfaceView android:id="" />
<SurfaceView
android:id="@+id/playerView_extended"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/playerView_fullscreen"
<LinearLayout
android:id="@+id/surfaceContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
android:layout_weight="2"
android:background="@android:color/black"
android:padding="10dip" >
<SurfaceView
android:id="@+id/playerView_extended"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:id="@+id/indexScrollView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:fillViewport="false"
android:paddingLeft="5dip"
android:visibility="gone" >
</ScrollView>
</LinearLayout>
\ No newline at end of file
package tttclient.activities;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.PixelFormat;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MySurfaceView extends SurfaceView implements
SurfaceHolder.Callback {
private final SurfaceHolder sHolder;
private final SurfaceHolder sh;
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Canvas canvas;
public MySurfaceView(Context context) {
super(context);
sh = getHolder();
sh.addCallback(this);
paint.setColor(Color.BLUE);
paint.setStyle(Style.FILL);
public MySurfaceView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
sHolder = getHolder();
sHolder.addCallback(this);
sHolder.setFormat(PixelFormat.RGBA_4444);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// Canvas canvas = sh.lockCanvas();
// canvas.drawColor(Color.WHITE);
// canvas.drawCircle(100, 200, 50, paint);
// sh.unlockCanvasAndPost(canvas);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
......@@ -46,11 +34,14 @@ public class MySurfaceView extends SurfaceView implements
}
public void drawRec(int x, int y, int w, int h, Paint p) {
canvas = sh.lockCanvas();
canvas.drawRect(new Rect(x, y, x + w, y + h), p);
sh.unlockCanvasAndPost(canvas);
public void setSize(int width, int height) {
sHolder.setFixedSize(width, height);
}
@Override
public SurfaceHolder getHolder() {
return sHolder;
}
}
......@@ -14,10 +14,15 @@ import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.MediaController;
import android.widget.MediaController.MediaPlayerControl;
import android.widget.ScrollView;
......@@ -33,98 +38,62 @@ import com.actionbarsherlock.widget.SearchView.OnQueryTextListener;
import de.tum.in.tttclient.R;
public class PlayerActivity extends SherlockActivity implements
MediaPlayerControl {
MediaPlayerControl, Callback {
final public static int FULLSCREEN_MODE = 0;
final public static int EXTENDED_MODE = 1;
public String fileName;
public String filePath;
private File tttFile;
private ProgressDialog dialog;
public ImageView imgV;
private ViewSwitcher switcher;
private ScrollView scrollView;
private Recording recording;
private MediaPlayer audioPlayer;
private MediaController audioController;
private LinearLayout container;
private SearchView searchView;
private SurfaceView surfaceView;
private SurfaceHolder mHolder;
LayoutParams fullParams;
LayoutParams extendedParams;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player_main);
scrollView = (ScrollView) findViewById(R.id.indexScrollView);
setContentView(R.layout.activity_player_extended);
switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
//
// switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
// default fullscreen
imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
// imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
fileName = getIntent().getStringExtra(DownloadService.FILE_NAME);
setTitle(fileName);
filePath = getIntent().getStringExtra(DownloadService.FILE_PATH);
final File tttFile = new File(filePath + "/" + fileName + ".ttt");
tttFile = new File(filePath + "/" + fileName + ".ttt");
File audioFile = new File(filePath + "/" + fileName + ".mp3");
audioPlayer = MediaPlayer.create(this, Uri.fromFile(audioFile));
audioController = new MediaController(this);
audioController.setMediaPlayer(this);
audioController.setHorizontalScrollBarEnabled(false);
final ProgressDialog dialog = new ProgressDialog(PlayerActivity.this);
dialog.setTitle("Please Wait");
dialog.setMessage("Prepare File ...");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
AsyncTask<Void, Void, Void> initTask = new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
recording = new Recording(getApplicationContext(), tttFile,
audioPlayer, imgV, scrollView);
OnClickListener prevListener = new OnClickListener() {
@Override
public void onClick(View v) {
recording.previous();
}
};
OnClickListener nextListener = new OnClickListener() {
@Override
public void onClick(View v) {
recording.next();
}
};
audioController.setPrevNextListeners(nextListener,
prevListener);
audioController.setAnchorView(imgV);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
container = (LinearLayout) findViewById(R.id.surfaceContainer);
surfaceView = (SurfaceView) findViewById(R.id.playerView_extended);
surfaceView.setZOrderMediaOverlay(true);
@Override
protected void onPostExecute(Void result) {
mHolder = surfaceView.getHolder();
mHolder.addCallback(this);
dialog.dismiss();
audioController.show(5000);
}
};
initTask.execute();
scrollView = (ScrollView) findViewById(R.id.indexScrollView);
fullParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT);
extendedParams = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
}
......@@ -262,13 +231,13 @@ public class PlayerActivity extends SherlockActivity implements
case R.id.extend:
if (!isExtendend) {
switchLayout(1);
switchLayout(EXTENDED_MODE);
// switchSurface(1);
item.setIcon(getResources().getDrawable(
R.drawable.ic_action_full_screen));
isExtendend = true;
} else if (isExtendend) {
switchLayout(0);
switchLayout(FULLSCREEN_MODE);
// switchSurface(0);
item.setIcon(getResources().getDrawable(
R.drawable.ic_action_return_from_full_screen));
......@@ -289,25 +258,24 @@ public class PlayerActivity extends SherlockActivity implements
void switchLayout(int index) {
// fullscreen
// switch to fullscreen
if (index == 0) {
imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
recording.graphicsContext().setImageView(imgV);
// recording.focusCurrentIndexEntry(recording.getLastIndexFired() -
// 1);
switcher.setDisplayedChild(0);
// hide ScrollView
scrollView.setVisibility(View.GONE);
surfaceView.setLayoutParams(fullParams);
// container.recomputeViewAttributes(surfaceView);
}
// extended View
if (index == 1) {
imgV = (ImageView) findViewById(R.id.playerView_extended);
recording.graphicsContext().setImageView(imgV);
recording.graphicsContext().updateView();
switcher.setDisplayedChild(1);
scrollView.setVisibility(View.VISIBLE);
surfaceView.setLayoutParams(extendedParams);
}
// if (recording != null)
// surfaceView.getHolder().setFixedSize(
// recording.getProtocolPreferences().framebufferWidth,
// recording.getProtocolPreferences().framebufferHeight);
}
@Override
......@@ -317,4 +285,99 @@ public class PlayerActivity extends SherlockActivity implements
recording.close();
}
public SurfaceView getSurfaceView() {
return surfaceView;
}
public void setSurfaceView(SurfaceView surfaceView) {
this.surfaceView = surfaceView;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if (recording != null) {
holder.setFixedSize(
recording.getProtocolPreferences().framebufferWidth,
recording.getProtocolPreferences().framebufferHeight);
if (recording.graphicsContext() != null) {
recording.graphicsContext().setHolder(holder);
}
}
}
@Override
public void surfaceCreated(final SurfaceHolder holder) {
AsyncTask<Void, Void, Void> initTask = new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog = new ProgressDialog(PlayerActivity.this);
dialog.setTitle("Please Wait");
dialog.setMessage("Prepare File ...");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
recording = new Recording(getApplicationContext(), tttFile,
audioPlayer, surfaceView, mHolder, scrollView);
OnClickListener prevListener = new OnClickListener() {
@Override
public void onClick(View v) {
recording.previous();
}
};
OnClickListener nextListener = new OnClickListener() {
@Override
public void onClick(View v) {
recording.next();
}
};
audioController.setPrevNextListeners(nextListener,
prevListener);
audioController.setAnchorView((LinearLayout) container
.getParent());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
dialog.dismiss();
holder.setFixedSize(
recording.getProtocolPreferences().framebufferWidth,
recording.getProtocolPreferences().framebufferHeight);
recording.graphicsContext().setHolder(holder);
holder.setKeepScreenOn(true);
}
};
initTask.execute();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
......@@ -21,7 +21,8 @@ import android.media.Image;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.ImageView;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.LinearLayout;
@SuppressLint("NewApi")
......@@ -37,8 +38,8 @@ public class GraphicsContext implements MessageConsumer {
private final Handler scrollHandler;
private final BitmapContainer bitmapContainer;
private final Canvas canvas;
private ImageView imgView;
private SurfaceView surfaceView;
private SurfaceHolder holder;
private boolean refreshEnabled = false;
private final MessageProducer producer;
......@@ -64,8 +65,11 @@ public class GraphicsContext implements MessageConsumer {
}
}
public GraphicsContext(ImageView imgV, Recording record) {
public GraphicsContext(SurfaceView imgV, final SurfaceHolder holder,
Recording record) {
setImageView(imgV);
this.setHolder(holder);
this.producer = record;
this.recording = record;
producer.addMessageConsumer(this);
......@@ -76,7 +80,8 @@ public class GraphicsContext implements MessageConsumer {
Config.ARGB_4444));
// canvas to Bitmap
this.canvas = new Canvas(bitmapContainer.getBimap());
// this.canvas = new Canvas(bitmapContainer.getBimap());
this.pixels = bitmapContainer.getPixels();
hextile_bg_encoded = new byte[prefs.bytesPerPixel];
......@@ -89,14 +94,27 @@ public class GraphicsContext implements MessageConsumer {
@Override
public void handleMessage(android.os.Message inputMessage) {
// Gets the image task from the incoming Message object.
Bitmap bitmap = (Bitmap) inputMessage.obj;
if (isWhiteboardEnabled())
paintWhiteboard();
paintAnnotations();
recording.highlightSearchResults(canvas);
imgView.setImageBitmap(bitmap);
final int[] pixels = (int[]) inputMessage.obj;
// if (isWhiteboardEnabled())
// paintWhiteboard();
// paintAnnotations();
// recording.highlightSearchResults(canvas);
// Thread paintThread = new Thread(new Runnable() {
//
// @Override
// public void run() {
// try {
//
paintCanvas(holder);
//
// } catch (OutOfMemoryError e) {
//
// }
//
// }
// });
// paintThread.start();
}
};
......@@ -158,8 +176,28 @@ public class GraphicsContext implements MessageConsumer {
// recording.highlightSearchResults(canvas);
// sHolder.unlockCanvasAndPost(canvas);
// }
//
// }
public void paintCanvas(SurfaceHolder sHolder) {
Canvas canvas = sHolder.lockCanvas();
if (canvas != null) {
if (isWhiteboardEnabled())
paintWhiteboard(canvas);
else
canvas.drawBitmap(pixels, 0,
recording.getProtocolPreferences().framebufferWidth, 0,
0, recording.getProtocolPreferences().framebufferWidth,
recording.getProtocolPreferences().framebufferHeight,
false, null);
paintAnnotations(canvas);
recording.highlightSearchResults(canvas);
sHolder.unlockCanvasAndPost(canvas);
}
}
public void enableRefresh(boolean refresh) {
this.refreshEnabled = refresh;
......@@ -169,10 +207,10 @@ public class GraphicsContext implements MessageConsumer {
return refreshEnabled;
}
public void setImageView(ImageView imgV) {
this.imgView = imgV;
public void setImageView(SurfaceView imgV) {
this.surfaceView = imgV;
// test TODO
imgView.setWillNotCacheDrawing(true);
// imgView.setWillNotCacheDrawing(true);
}
public int[] getPixels() {
......@@ -203,17 +241,48 @@ public class GraphicsContext implements MessageConsumer {
// draw Canvas on current Bitmap
public void updateView() {
if (refreshEnabled) {
android.os.Message message = viewHandler.obtainMessage(0,
bitmapContainer.getBimap());
android.os.Message message = viewHandler.obtainMessage(0, pixels);
message.sendToTarget();
// Thread paintThread = new Thread(new Runnable() {
//
// @Override
// public void run() {
//
// paintCanvas();
//
// }
// });
// try {
// paintThread.start();
// } catch (OutOfMemoryError e) {
//
// }
//
// }
}
}
// set new Bitmap
public void updateView(final Bitmap bitmap) {
public void updateView(final int[] pixel) {
if (refreshEnabled) {
android.os.Message message = viewHandler.obtainMessage(0, bitmap);
android.os.Message message = viewHandler.obtainMessage(0, pixel);
message.sendToTarget();
// Thread paintThread = new Thread(new Runnable() {
//
// @Override
// public void run() {
//
// paintCanvas();
//
// }
// });
// try {
// paintThread.start();
// } catch (OutOfMemoryError e) {
//
// }
}
}
......@@ -266,11 +335,11 @@ 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.getBimap().setPixels(pixels,
x + y * prefs.framebufferWidth, prefs.framebufferWidth, x,
y, w, h);
// bitmapContainer.getBimap().setPixels(pixels,
// x + y * prefs.framebufferWidth, prefs.framebufferWidth, x,
// y, w, h);
updateView(bitmapContainer.getBimap());
updateView(pixels);
}
}
......@@ -336,7 +405,7 @@ public class GraphicsContext implements MessageConsumer {
}
// display all annotations
synchronized public void paintAnnotations() {
synchronized public void paintAnnotations(Canvas canvas) {
for (int i = 0; i < currentAnnotations.size(); i++) {
currentAnnotations.get(i).paint(canvas);
......@@ -404,17 +473,9 @@ public class GraphicsContext implements MessageConsumer {
return new WhiteboardMessage(0, whiteboardPage, prefs);
}
public void paintWhiteboard() {
int[] whitePixel = new int[prefs.framebufferHeight
* prefs.framebufferWidth];
for (int i = 0; i < whitePixel.length; i++) {
whitePixel[i] = Color.WHITE;
}
public void paintWhiteboard(Canvas canvas) {
bitmapContainer.getBimap().setPixels(whitePixel, 0,
prefs.framebufferWidth, 0, 0, prefs.framebufferWidth,
prefs.framebufferHeight);
canvas