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

neue variante mit surfaceview

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