Commit 672017b9 authored by Thomas Krex's avatar Thomas Krex

-initilisierung von recording in thread gelegt--> progress muss noch

angezeigt werden
-searchview in actionbar getan --> suchlogik komplett
parent 0323ee3d
# cache for current jar dependency. DO NOT EDIT.
# format is <lastModified> <length> <SHA-1> <path>
# Encoding is UTF-8
......@@ -28,7 +28,7 @@ public final class R {
public static final int action_settings=0x7f08000f;
public static final int add=0x7f08000e;
public static final int button_save=0x7f08000a;
public static final int extend=0x7f080010;
public static final int extend=0x7f080011;
public static final int feedDetailsLv=0x7f08000c;
public static final int feed_list=0x7f08000b;
public static final int feedback_button=0x7f080002;
......@@ -37,6 +37,7 @@ public final class R {
public static final int playerView_fullscreen=0x7f080006;
public static final int progressBar=0x7f08000d;
public static final int scrollView1=0x7f080005;
public static final int search=0x7f080010;
public static final int test_button=0x7f080000;
public static final int tx_name=0x7f080009;
public static final int tx_url=0x7f080008;
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/search"
android:actionViewClass="android.widget.SearchView"
android:showAsAction="always"
android:title="Search"/>
<item
android:id="@+id/extend"
android:icon="@android:drawable/ic_input_add"
......
......@@ -5,9 +5,11 @@ import java.io.IOException;
import tttclient.services.DownloadService;
import tttclient.ttt.Recording;
import android.annotation.TargetApi;
import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
......@@ -21,6 +23,8 @@ import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.MediaController.MediaPlayerControl;
import android.widget.ScrollView;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.ViewSwitcher;
import com.example.test.R;
......@@ -37,7 +41,9 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
private MediaController audioController;
private int imgVHeight;
private int imgVWidth;
private SearchView searchView;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -53,49 +59,75 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
setTitle(fileName);
filePath = getIntent().getStringExtra(DownloadService.FILE_PATH);
File tttFile = new File(filePath + "/" + fileName + ".ttt");
final File tttFile = new File(filePath + "/" + fileName + ".ttt");
File audioFile = new File(filePath + "/" + fileName + ".mp3");
audioPlayer = MediaPlayer.create(this, Uri.fromFile(audioFile));
try {
Log.d("Player", " width: " + imgVWidth + " , height: " + imgVHeight);
Log.d("Player", " width: " + imgVWidth + " , height: " + imgVHeight);
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth(); // deprecated
int screenHeight = display.getHeight(); // deprecated
recording = new Recording(getApplicationContext(), tttFile,
audioPlayer, imgV, scrollView, screenWidth, screenHeight);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// create audio player & control
Display display = getWindowManager().getDefaultDisplay();
final int screenWidth = display.getWidth(); // deprecated
final int screenHeight = display.getHeight(); // deprecated
audioController = new MediaController(this);
audioController.setMediaPlayer(this);
// final ProgressDialog dialog = new ProgressDialog(
// getApplicationContext());
// dialog.setMessage("Reading File");
// dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
OnClickListener prevListener = new OnClickListener() {
// TODO ProgressDialog anzeigen lassen
Thread t = new Thread(new Runnable() {
@Override
public void onClick(View v) {
recording.previous();
public void run() {
}
};
OnClickListener nextListener = new OnClickListener() {
// dialog.show();
try {
recording = new Recording(getApplicationContext(), tttFile,
audioPlayer, imgV, scrollView, screenWidth,
screenHeight);
@Override
public void onClick(View v) {
recording.next();
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);
// dialog.dismiss();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
audioController.setPrevNextListeners(nextListener, prevListener);
});
t.start();
audioController.setAnchorView(imgV);
// init SearchView in ActionBar
// erst ab API 11
// create audio player & control
}
public void search(String word) {
if (recording.getIndex() != null)
recording.getIndex().search(word);
}
@Override
......@@ -180,10 +212,28 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
audioPlayer.release();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.player_menu, menu);
MenuItem item = menu.findItem(R.id.search);
searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
search(query);
searchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
return false;
}
});
return true;
}
......@@ -193,6 +243,7 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.extend:
if (!isExtendend) {
switchLayout(1);
......
......@@ -312,15 +312,17 @@ public class HextileMessage extends FramebufferUpdateMessage {
int w, int h, byte[] colorField, boolean updateFlag) {
int color = graphicsContext.decodeColor(colorField);
// Paint paint = new Paint(color);
// Rect rect = new Rect(x, y, x + w, y + h);
// graphicsContext.getCanvas().drawRect(rect, paint);
for (int i = y; i < y + h; i++) {
int offset = i * graphicsContext.getPrefs().framebufferWidth + x;
for (int j = 0; j < w; j++) {
// TODO: add 8bit support
graphicsContext.getPixels()[offset + j] = color;
}
}
// graphicsContext.handleUpdatedPixels(x, y, w, h);
}
......
......@@ -24,16 +24,16 @@
*/
package tttclient.ttt;
import android.graphics.drawable.shapes.Shape;
import android.graphics.RectF;
public class ColoredShape {
int color;
Shape shape;
RectF rectangle;
boolean filled;
public ColoredShape(int color, Shape shape, boolean filled) {
public ColoredShape(int color, RectF rectangle, boolean filled) {
this.color = color;
this.shape = shape;
this.rectangle = rectangle;
this.filled = filled;
}
}
......@@ -33,6 +33,7 @@ import tttclient.messages.Message;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.Log;
public class Index {
......@@ -736,23 +737,25 @@ public class Index {
return searchbaseFormatStored;
}
// // search for given keyword
// public void search(String searchword) {
// // clear old results
// search_index.clear();
//
// // perform search
// for (int i = 0; i < index.size(); i++)
// // add to search results
// if (index.get(i).contains(searchword))
// search_index.add(index.get(i));
//
// // force repaint to highlight results
// recording.graphicsContext().refresh();
// }
// search for given keyword
public void search(String searchword) {
Log.d("search", "Searching after: " + searchword);
// clear old results
search_index.clear();
// public void highlightSearchResultsOfCurrentIndex() {
// getCurrentIndex().highlightSearchResults();
// }
// perform search
for (int i = 0; i < index.size(); i++)
// add to search results
if (index.get(i).contains(searchword))
search_index.add(index.get(i));
Log.d("search", "number of hits: " + search_index.size());
// force repaint to highlight results
recording.graphicsContext().refresh();
}
public void highlightSearchResultsOfCurrentIndex() {
getCurrentIndex().highlightSearchResults();
}
}
......@@ -115,48 +115,48 @@ public class IndexEntry extends ImageButton {
}
// perform search
// public boolean contains(String searchword) {
// // empty search
// if (searchword == null || searchword.equals("")) {
// results.clear();
// return false;
// }
//
// // ASCII searchbase
// if (words == null)
// return searchbase_of_page.toLowerCase().indexOf(
// searchword.toLowerCase()) >= 0;
//
// // XML searchbase
// else
// return getSearchResults(searchword);
// }
public boolean contains(String searchword) {
// empty search
if (searchword == null || searchword.equals("")) {
results.clear();
return false;
}
// ASCII searchbase
if (words == null)
return searchbase_of_page.toLowerCase().indexOf(
searchword.toLowerCase()) >= 0;
// XML searchbase
else
return getSearchResults(searchword);
}
private final ArrayList<ColoredShape> results = new ArrayList<ColoredShape>();
// // perform advanced search (XML searchbase with coordinates)
// private boolean getSearchResults(String searchword) {
// results.clear();
//
// if (words != null) {
// for (int i = 0; i < words.size(); i++)
// words.get(i).contains(searchword, results);
// }
//
// // any result found?
// return results.size() > 0;
// }
// public void highlightSearchResults() {
// if (results != null)
// for (int i = 0; i < results.size(); i++) {
// ColoredShape shape = results.get(i);
// g.setColor(shape.color);
// if (shape.filled)
// g.fill(shape.shape);
// else
// g.draw(shape.shape);
// }
// }
// perform advanced search (XML searchbase with coordinates)
private boolean getSearchResults(String searchword) {
results.clear();
if (words != null) {
for (int i = 0; i < words.size(); i++)
words.get(i).contains(searchword, results);
}
// any result found?
return results.size() > 0;
}
public void highlightSearchResults() {
// if (results != null)
// for (int i = 0; i < results.size(); i++) {
// ColoredShape shape = results.get(i);
// g.setColor(shape.color);
// if (shape.filled)
// g.fill(shape.shape);
// else
// g.draw(shape.shape);
// }
}
}
......@@ -25,10 +25,11 @@
package tttclient.ttt;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import android.graphics.Color;
import android.graphics.RectF;
/**
* @author ziewer
......@@ -39,7 +40,7 @@ import android.graphics.Color;
public class SearchBaseEntry {
// character widths for dynamic underlining
static int[] widths = new int[256];
// static int[] widths = new int[256];
// static {
// // choose standard font (proportions will be similar for other fonts)
// Font f = new Font("Serif", Font.PLAIN, 16);
......@@ -87,117 +88,97 @@ public class SearchBaseEntry {
// TODO: return value not used / think about naming of method
// adds words from searchbase containing searchword to resultss
// public boolean contains(String searchword, ArrayList<ColoredShape>
// results) {
// // System.out.println(searchText);
// if (searchText.indexOf(Constants.reduce(searchword)) >= 0) {
//
// // highlight search results
// if (results != null) {
// // NOTE: explicit round to avoid java drawing bug (different
// // rounding if color is transparent)
// Rect rectangle = new Rect((int) (getX() - borderSize),
// (int) (getY() - borderSize),
// (int) (getWidth() + 2 * borderSize),
// (int) (getHeight() + 2 * borderSize));
//
// // highlight
// results.add(new ColoredShape(highlighColor, rectangle, true));
//
// // border
// results.add(new ColoredShape(borderColor, rectangle, false));
//
// // underline results
// boolean fixedSize = false;
// if (fixedSize) {
// // using fixed sized font
// // TODO: use character specific letter size - variable sized
// // font
// double sizeOfLetter = (getWidth()) / searchText.length();
// int indexOf = -1;
// // System.out.println("\"" + result.searchText + "\"");
// while (-1 != (indexOf = searchText.indexOf(searchword,
// indexOf + 1))) {
// // System.out.println(indexOf + "\t" + sizeOfLetter +
// // "\t" + (result.right - result.left));
// results.add(new ColoredShape(underlineColor, new Rect(
// getX() + sizeOfLetter * indexOf, getY()
// + getHeight() + borderSize - 2,
// sizeOfLetter * (searchword.length()), 4), true));
// }
//
// // TODO: only for testing - remove
// // letter ticks
// if (!false)
// for (int j = 0; j <= searchText.length(); j++) {
// results.add(new ColoredShape(underlineColor,
// new Line2D.Double(
// getX() + j * sizeOfLetter, getY()
// + getHeight() - 3, getX()
// + j * sizeOfLetter, getY()
// + getHeight() + 3), false));
// }
// } else {
// // proportional size
// int charWidths[] = new int[searchTextOriginal.length()];
// int overall = 0;
// for (int i = 0; i < charWidths.length; i++) {
// // determine character widths
// try {
// charWidths[i] = widths[searchTextOriginal.charAt(i)];
// overall += charWidths[i];
// } catch (IndexOutOfBoundsException e) {
// }
// }
// double ratio = getWidth() / overall;
//
// // determine occurrences
// int indexOf = -1;
// // System.out.println("\"" + result.searchText + "\"");
// while (-1 != (indexOf = searchTextOriginal.toLowerCase()
// .indexOf(searchword.toLowerCase(), indexOf + 1))) {
// int start = 0;
// for (int i = 0; i < indexOf; i++)
// start += charWidths[i];
// int end = 0;
// for (int i = indexOf; i < indexOf + searchword.length(); i++)
// end += charWidths[i];
//
// // System.out.println(indexOf + "\t" + sizeOfLetter +
// // "\t" + (result.right - result.left));
// results.add(new ColoredShape(underlineColor,
// new Rectangle2D.Double(getX() + start * ratio,
// getY() + getHeight() + borderSize - 3,
// end * ratio, 5), true));
//
// // TODO: only for testing - remove
// // letter ticks
// if (false) {
// int sum = 0;
// results.add(new ColoredShape(underlineColor,
// new Line2D.Double(getX(), getY()
// + getHeight() - 3, getX(), getY()
// + getHeight() + 3), false));
// for (int j = 0; j < searchTextOriginal.length(); j++) {
// sum += charWidths[j];
// results.add(new ColoredShape(underlineColor,
// new Line2D.Double(getX() + sum * ratio,
// getY() + getHeight() - 3,
// getX() + sum * ratio, getY()
// + getHeight() + 3),
// false));
// }
// }
// }
//
// }
//
// }
// return true;
//
// } else
// return false;
// }
public boolean contains(String searchword, ArrayList<ColoredShape> results) {
// System.out.println(searchText);
if (searchText.indexOf(Constants.reduce(searchword)) >= 0) {
// highlight search results
if (results != null) {
// NOTE: explicit round to avoid java drawing bug (different
// rounding if color is transparent)
RectF rectangle = new RectF(
(int) (getX() - borderSize),
(int) (getY() - borderSize),
(int) ((getX() - borderSize) + (getWidth() + 2 * borderSize)),
(int) ((getY() - borderSize) + (getHeight() + 2 * borderSize)));
// highlight
results.add(new ColoredShape(highlighColor, rectangle, true));
// border
results.add(new ColoredShape(borderColor, rectangle, false));
// underline results
boolean fixedSize = false;
if (fixedSize) {
// using fixed sized font
// TODO: use character specific letter size - variable sized
// font
double sizeOfLetter = (getWidth()) / searchText.length();
int indexOf = -1;
// System.out.println("\"" + result.searchText + "\"");
while (-1 != (indexOf = searchText.indexOf(searchword,
indexOf + 1))) {
// System.out.println(indexOf + "\t" + sizeOfLetter +
// "\t" + (result.right - result.left));
// from rectangle2d(x,y,width,height) to rect(left ,top,
// right bottom)
float left = (float) (getX() + sizeOfLetter * indexOf);
float top = (float) (getY() + getHeight() + borderSize - 2);
float right = left
+ (float) (sizeOfLetter * (searchword.length()));
float bottom = top + 4;
results.add(new ColoredShape(underlineColor, new RectF(
left, top, right, bottom), true));
}
} else {
// proportional size
int charWidths[] = new int[searchTextOriginal.length()];
int overall = 0;
for (int i = 0; i < charWidths.length; i++) {
// determine character widths
try {
// charWidths[i] =
// widths[searchTextOriginal.charAt(i)];
overall += charWidths[i];
} catch (IndexOutOfBoundsException e) {
}
}
double ratio = getWidth() / overall;
// determine occurrences
int indexOf = -1;
// System.out.println("\"" + result.searchText + "\"");
while (-1 != (indexOf = searchTextOriginal.toLowerCase()
.indexOf(searchword.toLowerCase(), indexOf + 1))) {
int start = 0;
for (int i = 0; i < indexOf; i++)
start += charWidths[i];
int end = 0;
for (int i = indexOf; i < indexOf + searchword.length(); i++)
end += charWidths[i];
// System.out.println(indexOf + "\t" + sizeOfLetter +
// "\t" + (result.right - result.left));
float left = (float) (getX() + start * ratio);
float top = (float) (getY() + getHeight() + borderSize - 3);
float right = left + (float) (end * ratio);
float bottom = top + 5;
results.add(new ColoredShape(underlineColor, new RectF(
left, top, right, bottom), true));
}
}
}
return true;
} else
return false;
}
@Override
public String toString() {
......@@ -227,22 +208,6 @@ public class SearchBaseEntry {
// I/O used for searchbase extension
// ////////////////////////////////////////////////////
// write as part of searchbase extension
public void write(DataOutputStream out) throws IOException {
// search string
// NOTE: String.length() not always equals String.getBytes().length
// depending on the system's character encoding (Umlauts may fail)
// out.writeShort(searchTextOriginal.length());
out.writeShort(searchTextOriginal.getBytes().length);
out.write(searchTextOriginal.getBytes());
// coordinates (without ratio)
out.writeShort(x);
out.writeShort(y);
out.writeShort(width);
out.writeShort(height);
}
// read as part of searchbase extension
static public SearchBaseEntry read(DataInputStream in, double ratio)
throws IOException {
......
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