Commit 0323ee3d authored by Thomas Krex's avatar Thomas Krex
Browse files

-wechsel zwischen fullscreen und extended view impelemntiert mit View

Switcher, entsprechendes Menü item hinzugefügt
parent 04a303bd
<?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="vertical" >
<ViewSwitcher
android:id="@+id/viewSwitcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/playerView_fullscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<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_height="match_parent"
android:layout_toRightOf="@+id/scrollView1"
android:layout_weight="5"
android:background="@drawable/my_border"
android:padding="10dip"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</ViewSwitcher>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/extend"
android:icon="@android:drawable/ic_input_add"
android:showAsAction="always">
</item>
</menu>
\ No newline at end of file
......@@ -4,5 +4,6 @@
<string name="app_name">test</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="wait">Please Wait. Reading File</string>
</resources>
......@@ -4,23 +4,24 @@ import java.io.File;
import java.io.IOException;
import tttclient.services.DownloadService;
import tttclient.ttt.IndexEntry;
import tttclient.ttt.Recording;
import android.app.Activity;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.MediaController.MediaPlayerControl;
import android.widget.ScrollView;
import android.widget.ViewSwitcher;
import com.example.test.R;
......@@ -29,6 +30,7 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
public String fileName;
public String filePath;
public ImageView imgV;
private ViewSwitcher switcher;
private ScrollView scrollView;
private Recording recording;
private MediaPlayer audioPlayer;
......@@ -39,11 +41,16 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player_extended);
imgV = (ImageView) findViewById(R.id.playerView_extended);
setContentView(R.layout.activity_player_main);
scrollView = (ScrollView) findViewById(R.id.indexScrollView);
switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
// desfault fullscreen
imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
// switchLayout(0);
fileName = getIntent().getStringExtra(DownloadService.FILE_NAME);
setTitle(fileName);
filePath = getIntent().getStringExtra(DownloadService.FILE_PATH);
File tttFile = new File(filePath + "/" + fileName + ".ttt");
......@@ -57,7 +64,7 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
int screenWidth = display.getWidth(); // deprecated
int screenHeight = display.getHeight(); // deprecated
recording = new Recording(getApplicationContext(), tttFile,
audioPlayer, imgV, screenWidth, screenHeight);
audioPlayer, imgV, scrollView, screenWidth, screenHeight);
} catch (IOException e) {
// TODO Auto-generated catch block
......@@ -89,8 +96,6 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
audioController.setAnchorView(imgV);
initScrollView();
}
@Override
......@@ -175,20 +180,57 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
audioPlayer.release();
}
public void initScrollView() {
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setBackgroundColor(Color.MAGENTA);
//
int length = recording.getIndex().size();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.player_menu, menu);
return true;
}
boolean isExtendend = false;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.extend:
if (!isExtendend) {
switchLayout(1);
item.setIcon(getResources().getDrawable(
android.R.drawable.ic_input_delete));
isExtendend = true;
} else if (isExtendend) {
switchLayout(0);
item.setIcon(getResources().getDrawable(
android.R.drawable.ic_input_add));
isExtendend = false;
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
void switchLayout(int index) {
// fullscreen
if (index == 0) {
imgV = (ImageView) findViewById(R.id.playerView_fullscreen);
recording.graphicsContext().setImageView(imgV);
switcher.setDisplayedChild(0);
for (int i = 0; i < length; i++) {
IndexEntry entry = recording.getIndex().get(i);
layout.addView(entry);
System.out.println("Index " + i + " has thumbnail "
+ entry.hasThumbnail());
}
// extended View
if (index == 1) {
imgV = (ImageView) findViewById(R.id.playerView_extended);
// recording.graphicsContext().refresh();
recording.graphicsContext().setImageView(imgV);
switcher.setDisplayedChild(1);
scrollView.addView(layout);
}
}
}
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universit?t M?nchen
//
// This file is part of TeleTeachingTool.
//
// TeleTeachingTool is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TeleTeachingTool is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TeleTeachingTool. If not, see <http://www.gnu.org/licenses/>.
/*
* Created on 23.02.2006
*
* Author: Peter Ziewer, TU Munich, Germany - ziewer@in.tum.de
*/
package tttclient.ttt;
import android.graphics.drawable.shapes.Shape;
public class ColoredShape {
int color;
Shape shape;
boolean filled;
public ColoredShape(int color, Shape shape, boolean filled) {
this.color = color;
this.shape = shape;
this.filled = filled;
}
}
......@@ -26,7 +26,7 @@ public class GraphicsContext implements MessageConsumer {
private Canvas scaledCanvas;
private final BitmapContainer bitmapContainer;
private Bitmap scaledBitmap;
private final ImageView imgView;
private ImageView imgView;
private boolean refreshEnabled = true;
private final MessageProducer producer;
private final ProtocolPreferences prefs;
......@@ -90,10 +90,10 @@ 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);
// Bitmap.createScaledBitmap(bitmap, screenWidth, screenHeight,
// true);
imgView.setImageBitmap(bitmap);
imgView.invalidate();
// imgView.invalidate();
}
};
......@@ -107,6 +107,10 @@ public class GraphicsContext implements MessageConsumer {
return refreshEnabled;
}
public void setImageView(ImageView imgV) {
this.imgView = imgV;
}
public int[] getPixels() {
return this.pixels;
}
......@@ -142,7 +146,6 @@ public class GraphicsContext implements MessageConsumer {
// }
public void updateView(final Bitmap bitmap) {
android.os.Message message = bitmapHandler.obtainMessage(0, bitmap);
message.sendToTarget();
}
......@@ -228,7 +231,8 @@ public class GraphicsContext implements MessageConsumer {
bitmapContainer.getBimap().setPixels(pixels,
x + y * prefs.framebufferWidth, prefs.framebufferWidth, x,
y, w, h);
updateView(bitmapContainer.getBimap());
if (refreshEnabled)
updateView(bitmapContainer.getBimap());
}
}
......
......@@ -45,9 +45,6 @@ public class Index {
public ArrayList<IndexEntry> index = new ArrayList<IndexEntry>();
ArrayList<IndexEntry> search_index = new ArrayList<IndexEntry>();
public int searchbaseFormatStored = NO_SEARCHBASE;
public int searchbaseFormat = NO_SEARCHBASE;
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
// constructors
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -59,6 +56,10 @@ public class Index {
return recording.getProtocolPreferences().framebufferWidth;
}
public Recording getRecording() {
return recording;
}
public Index(Recording recording, Context context) {
this.recording = recording;
this.context = context;
......@@ -290,43 +291,6 @@ public class Index {
index.add(new IndexEntry(context, this));
}
// // write index entries as extension
// public void writeIndexExtension(DataOutputStream out) throws IOException
// {
// if (index != null) {
// // buffer output to determine its length
// ByteArrayOutputStream byteArrayOutputStream = new
// ByteArrayOutputStream();
// DataOutputStream buffer = new DataOutputStream(
// byteArrayOutputStream);
//
// // header
// buffer.writeByte(Constants.EXTENSION_INDEX_TABLE);
// buffer.writeShort(index.size());
// // index table
// for (int i = 0; i < index.size(); i++) {
// IndexEntry indexEntry = index.get(i);
// // timestamp
// buffer.writeInt(indexEntry.getTimestamp());
// // title
// buffer.writeByte(indexEntry.getTitle().length());
// buffer.writeBytes(indexEntry.getTitle());
//
// // write searchbase text (if exist)
// String searchableText = indexEntry.getSearchbase();
// if (searchableText == null || searchableText.length() == 0)
// buffer.writeInt(0);
// else {
// searchbaseFormatStored = Index.XML_SEARCHBASE;
// // NOTE: String.length() not always equals
// // String.getBytes().length
// // depending on the system's character encoding (Umlauts may
// // fail)
// buffer.writeInt(searchableText.getBytes().length);
// buffer.write(searchableText.getBytes());
// }
//
// TODO bufferedImage in Bitmap transformieren
// read one image representing thumbnail
private void readThumbnail(DataInputStream in) throws IOException {
......@@ -346,31 +310,6 @@ public class Index {
}
}
// private void writeThumbnail(IndexEntry indexEntry, DataOutputStream out)
// throws IOException {
// // TODO: write annotated thumbnail for HTML script
//
// // write thumbnail image
// ImageIcon thumbnail = indexEntry.getThumbnail();
// if (thumbnail == null)
// // no thumbnail available
// out.writeInt(0);
// else {
// // buffer to determine size of image
// BufferedImage bufferedImage = new BufferedImage(
// thumbnail.getIconWidth(), thumbnail.getIconHeight(),
// BufferedImage.TYPE_INT_RGB);
// Graphics g = bufferedImage.createGraphics();
// g.drawImage(thumbnail.getImage(), 0, 0, null);
// ByteArrayOutputStream imageOut = new ByteArrayOutputStream();
// ImageIO.write(bufferedImage, "png", imageOut);
// imageOut.flush();
// // write size + image
// out.writeInt(imageOut.size());
// out.write(imageOut.toByteArray());
// }
// }
// ///////////////////////////////////////////
// thumbnail defaults
// ///////////////////////////////////////////
......@@ -548,22 +487,21 @@ public class Index {
// set time of index
IndexEntry indexEntry = index.get(i);
int timestamp = indexEntry.getTimestamp();
// for screenshots Bitmap hast to set but not the display
// for screenshots Bitmap has to set but not the display/audio
recording.setTime(timestamp, false);
// create screenshot
Bitmap screenshot = recording.graphicsContext()
.getScreenshotWithoutAnnotations();
Bitmap scaled = Bitmap
.createScaledBitmap(screenshot, screenshot.getWidth() / 5,
screenshot.getHeight() / 5, true);
// set thumbnail
// faster image scaling
// Image thumbnail = ScriptCreator.getScaledInstance(
// screenshot, recording.prefs.framebufferWidth
// / thumbnail_scale_factor,
// recording.prefs.framebufferHeight
// / thumbnail_scale_factor);
indexEntry.setThumbnail(screenshot);
indexEntry.setThumbnail(scaled);
}
......@@ -730,7 +668,7 @@ public class Index {
// set index
nowPlayingIndex_startingAtZero = i;
// recording.fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
recording.fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
}
public IndexEntry get(int i) {
......@@ -765,10 +703,12 @@ public class Index {
for (int i = 0; i < index.size(); i++)
if (index.get(i).getTimestamp() == timestamp) {
nowPlayingIndex_startingAtZero = i;
// index.get(i).setBackgroundColor(Color.RED);
// index.get
// fire event (index event starting at one)
// recording
// .fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
recording
.fireIndexChangedEvent(nowPlayingIndex_startingAtZero + 1);
// update search result highligting
// recording.graphicsContext().refresh();
......@@ -784,18 +724,18 @@ public class Index {
// final public static int ASCII_SEARCHBASE = 1;
// final public static int XML_SEARCHBASE = 2;
//
// // TOD:; visibility
// public int searchbaseFormatStored = NO_SEARCHBASE;
// public int searchbaseFormat = NO_SEARCHBASE;
//
// public int getSearchbaseFormat() {
// return searchbaseFormat;
// }
//
// public int getSearchbaseFormatStored() {
// return searchbaseFormatStored;
// }
//
// TOD:; visibility
public int searchbaseFormatStored = NO_SEARCHBASE;
public int searchbaseFormat = NO_SEARCHBASE;
public int getSearchbaseFormat() {
return searchbaseFormat;
}
public int getSearchbaseFormatStored() {
return searchbaseFormatStored;
}
// // search for given keyword
// public void search(String searchword) {
// // clear old results
......@@ -808,269 +748,11 @@ public class Index {
// search_index.add(index.get(i));
//
// // force repaint to highlight results
// recording.graphicsContext.refresh();
// recording.graphicsContext().refresh();
// }
// public void highlightSearchResultsOfCurrentIndex(Graphics2D g) {
// getCurrentIndex().highlightSearchResults(g);
// }
/*******************************************************************************************************************
* reading search base
******************************************************************************************************************/
/***
* read hOCR/xhtml generated by tesseract-OCR
*
* @param fileName
* @return
*/
// public boolean readSearchBaseFromHOCRFile(String fileName, int pageindex)
// {
// File file = new File(fileName);
// if (TTT.verbose)
// System.out.print("Reading search base: " + fileName);
// if (file.exists()) {
// // Use an instance of ourselves as the SAX event handler
//
// hOCRHandler handler = new hOCRHandler();
// try {
// XMLReader xmlReader = XMLReaderFactory.createXMLReader();
// xmlReader
// .setFeature(
// "http://apache.org/xml/features/nonvalidating/load-external-dtd",
// false);
// xmlReader.setContentHandler(handler);
// xmlReader.parse(new InputSource(new FileReader(file)));
// ArrayList<ArrayList<SearchBaseEntry>> pages = handler
// .getResult();
//
// // check size
// if (pages.size() != 1 && pageindex >= this.index.size()) {
// // TODO: modify dialog
// TTT.showMessage("Missmatch in OCR/index",
// "expected pages: " + index.size()
// + " requested page: " + pageindex
// + " paket size: " + pages.size(),
// JOptionPane.WARNING_MESSAGE);
//
// } else {
// // set searchbase
// index.get(pageindex).setSearchbase(pages.get(0));
// searchbaseFormat = XML_SEARCHBASE;
// return true;
// }
//
// } catch (Throwable t) {
// t.printStackTrace();
// TTT.showMessage("XML file '" + file
// + "' contains errors.\nError: " + t,
// "TTT: Reading hOCR Searchbase File",
// JOptionPane.ERROR_MESSAGE);
// }
// } else if (TTT.verbose)
// System.out.println("not found.");
// return false;
// public void highlightSearchResultsOfCurrentIndex() {
// getCurrentIndex().highlightSearchResults();
// }
// public// read XML generated by OCR
// // double ratioXMLSearchBase;
// // Dimension resolutionXMLSearchBase;
// boolean readSearchBaseFromFileXML(String fileName) {
// if (TTT.verbose)
// System.out.print("Reading search base: ");
//
// File file = new File(fileName);
// if (TTT.verbose)
// System.out.print(fileName + " ");
//
// if (file.exists()) {
// // Use an instance of ourselves as the SAX event handler
// XMLHandler handler = new XMLHandler();
// // set desktop resolution
// // NOTE: desktop resolution is not stored within OmniPage 14 XML
// // file but within OmniPage 15 XML files
// handler.setDesktopResolution(recording.prefs.framebufferWidth,
// recording.prefs.framebufferHeight);
// // Use the default (non-validating) parser
// SAXParserFactory factory = SAXParserFactory.newInstance();
// try {
// // Parse the input
// SAXParser saxParser = factory.newSAXParser();
// saxParser.parse(file, handler);
//
// // TODO: maybe ratio should be index-dependent and not
// // word-dependent
// // resolutionXMLSearchBase = handler.getResolution();
// // ratioXMLSearchBase = recording.prefs.framebufferWidth /
// // resolutionXMLSearchBase.getWidth();
// // System.out.println("RATIO: "+ratio);
//
// ArrayList<ArrayList<SearchBaseEntry>> pages = handler
// .getResult();
//
// // check size
// if (pages.size() != this.index.size()) {
// // TODO: modify dialog
// TTT.showMessage(
// "Searchbase "
// + (pages.size() < this.index.size() ? "incomplete"
// : "not suitable") + "\nFound "
// + pages.size() + " entries (expected "
// + +this.index.size() + ")",
// "Searchbase incomplete",
// JOptionPane.WARNING_MESSAGE);
//
// } else {
// if (TTT.verbose)
// System.out.println(" ok");
//
// // set searchbase
// for (int i = 0; i < pages.size(); i++) {
// index.get(i).setSearchbase(pages.get(i));
// }
// searchbaseFormat = XML_SEARCHBASE;
// return true;
// }
//
// } catch (Throwable t) {
// t.printStackTrace();
// TTT.showMessage("XML file '" + file
// + "' contains errors.\nError: " + t,
// "TTT: Reading XML Searchbase File",
// JOptionPane.ERROR_MESSAGE);
// }
// } else if (TTT.verbose)
// System.out.println("not found.");
// return false;
// }