Commit 7b2de040 by Thomas Krex

thumbnails werden nicht runterskalier wegen zu schlechter qualität

heap füllt sich auf ca 17 mb
highlighting auf den thumbnails wird nun anders gehandhabt.
eine copy das thumnails wird mit einem canvas bearbeitet.
Es müssen alle index einträge überprüft werden.
z.b. leere suchanfrage: thumbnails mit früheren suchergebnissen müssen
durch orginal ersetzt werden.
parent 60096c4b
......@@ -6,5 +6,6 @@
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="lib" path="libs/commons-io-2.4.jar"/>
<classpathentry kind="lib" path="libs/commons-validator-1.4.0.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
......@@ -20,7 +20,8 @@
android:allowBackup="true"
android:icon="@drawable/ttt24"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
android:largeHeap="true"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar" >
<activity
android:name="tttclient.activities.MainActivity"
android:label="@string/app_name" >
......
......@@ -20,7 +20,8 @@
android:allowBackup="true"
android:icon="@drawable/ttt24"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
android:largeHeap="true"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar" >
<activity
android:name="tttclient.activities.MainActivity"
android:label="@string/app_name" >
......
......@@ -297,7 +297,7 @@ int id checkBox1 0x7f04003c
int id connect_btn 0x7f04003b
int id disableHome 0x7f040009
int id edit_query 0x7f040026
int id extend 0x7f040048
int id extend 0x7f040049
int id feedDetailsLv 0x7f040041
int id feed_list 0x7f040040
int id homeAsUp 0x7f040006
......@@ -305,6 +305,7 @@ int id indexScrollView 0x7f040034
int id itemTitle 0x7f040043
int id listMode 0x7f040002
int id liveChannel_button 0x7f040033
int id next 0x7f040048
int id normal 0x7f040001
int id playerView_extended 0x7f040035
int id playerView_fullscreen 0x7f040037
......
......@@ -8,9 +8,12 @@
android:showAsAction="always"
android:title="Search"/>
<item
android:id="@+id/next"
android:icon="@drawable/abs__ic_go"
android:showAsAction="always"/>
<item
android:id="@+id/extend"
android:icon="@drawable/ic_action_return_from_full_screen"
android:showAsAction="always">
</item>
android:showAsAction="always"/>
</menu>
\ No newline at end of file
......@@ -3,11 +3,13 @@ package tttclient.activities;
import tttclient.models.Feed;
import tttclient.models.FeedDbManager;
import tttclient.models.FeedItemDbManager;
import tttclient.utils.RssParser;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
......@@ -85,6 +87,8 @@ public class FeedActivity extends SherlockActivity implements
// TODO validate url
String url = urlTxt.getText().toString();
// using apache library to validate url
Feed feed = new Feed(name, url);
FeedDbManager fm = new FeedDbManager(getParent());
......@@ -161,4 +165,28 @@ public class FeedActivity extends SherlockActivity implements
builder.show();
return true;
}
public boolean checkUrl(final String url) {
final boolean status = true;
;
AsyncTask<Void, Void, Void> rssTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
RssParser parser = new RssParser(url);
try {
parser.parse();
} catch (Exception e) {
}
return null;
}
};
rssTask.execute();
return status;
}
}
......@@ -164,7 +164,7 @@ public class FeedDetailActivity extends SherlockActivity implements
intent.putExtra(Consts.SERVICE_ID, Consts.PARSE_SERVICE_ID);
intent.putExtra(ParseService.URL_STRING, feedUrl);
if (isNetworkAvailable())
if (isNetworkAvailable(getApplicationContext()))
startService(intent);
else
Toast.makeText(getApplicationContext(),
......@@ -240,7 +240,7 @@ public class FeedDetailActivity extends SherlockActivity implements
public void startDownloadService() {
// check if network connection is available
if (isNetworkAvailable()) {
if (isNetworkAvailable(getApplicationContext())) {
// ask user for confirmation
AlertDialog.Builder builder = new AlertDialog.Builder(
FeedDetailActivity.this);
......@@ -348,8 +348,9 @@ public class FeedDetailActivity extends SherlockActivity implements
return true;
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
private static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager
.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
......
......@@ -3,6 +3,7 @@ package tttclient.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
......@@ -13,7 +14,8 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
long heap = Runtime.getRuntime().maxMemory();
Log.d("Heap", "size: " + heap);
setContentView(R.layout.activity_main);
Button watchButton = (Button) findViewById(R.id.watch_button);
......
......@@ -228,15 +228,16 @@ public class PlayerActivity extends SherlockActivity implements
inflater.inflate(R.menu.player_menu, menu);
MenuItem item = menu.findItem(R.id.search);
searchView = (SearchView) item.getActionView();
//
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN
| EditorInfo.IME_ACTION_NEXT);
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
search(query);
recording.getIndex().highlightSearchResultsOnThumbnails();
searchView.clearFocus();
return true;
}
......@@ -244,9 +245,11 @@ public class PlayerActivity extends SherlockActivity implements
@Override
public boolean onQueryTextChange(String newText) {
search(newText);
recording.getIndex().highlightSearchResultsOnThumbnails();
return true;
}
});
return true;
}
......@@ -274,6 +277,11 @@ public class PlayerActivity extends SherlockActivity implements
}
return true;
case R.id.next:
if (!searchView.getQuery().toString().isEmpty())
Log.d("Player", "next invoked");
recording.getIndex().nextSearchResult();
default:
return super.onOptionsItemSelected(item);
}
......@@ -302,21 +310,11 @@ public class PlayerActivity extends SherlockActivity implements
}
// void switchSurface(int index) {
// if (index == 0) {
// surfaceView.setVisibility(View.INVISIBLE);
// surfaceView = (SurfaceView) findViewById(R.id.playerView_fullscreen);
// recording.graphicsContext().setSurfaceView(surfaceView);
// // recording.focusCurrentIndexEntry(recording.getLastIndexFired() -
// // 1);
// switcher.setDisplayedChild(0);
// }
// if (index == 1) {
// surfaceView.setVisibility(View.INVISIBLE);
// surfaceView = (SurfaceView) findViewById(R.id.playerView_extended);
// recording.graphicsContext().setSurfaceView(surfaceView);
// recording.graphicsContext().updateOverlay();
// }
// }
@Override
public void onBackPressed() {
super.onBackPressed();
recording.close();
}
}
......@@ -28,7 +28,7 @@ import java.io.DataInputStream;
import java.io.IOException;
import tttclient.ttt.Constants;
import tttclient.ttt.Index;
import tttclient.ttt.IndexEntry;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
......@@ -112,10 +112,10 @@ public class HighlightAnnotation extends SimpleAnnotation {
// scale Rect for thumbnail
RectF scaledBounds = new RectF(
(float) (rect.left * Index.THUMBNAIL_SCALE_FACTOR),
(float) (rect.top * Index.THUMBNAIL_SCALE_FACTOR),
(float) (rect.right * Index.THUMBNAIL_SCALE_FACTOR),
(float) (rect.left * Index.THUMBNAIL_SCALE_FACTOR));
(float) (rect.left * IndexEntry.THUMBNAIL_SCALE_FACTOR),
(float) (rect.top * IndexEntry.THUMBNAIL_SCALE_FACTOR),
(float) (rect.right * IndexEntry.THUMBNAIL_SCALE_FACTOR),
(float) (rect.left * IndexEntry.THUMBNAIL_SCALE_FACTOR));
canvas.drawRect(scaledBounds, highlightPaint);
......
......@@ -2,7 +2,6 @@ package tttclient.services;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
......@@ -34,6 +33,8 @@ public class ParseService extends IntentService {
static final String LENGTH = "length";
private URL feedUrl;
private boolean status = true;
private ArrayList<FeedItem> result;
public ParseService() {
super("ParseService");
......@@ -52,74 +53,74 @@ public class ParseService extends IntentService {
String urlString = intent.getStringExtra(URL_STRING);
try {
feedUrl = new URL(urlString);
} catch (MalformedURLException e) {
Log.e("ParseService", "malformed URL");
e.printStackTrace();
}
Log.d("Parser", "start parsing: " + feedUrl.toString());
final FeedItem feedItem = new FeedItem();
final ArrayList<FeedItem> result = new ArrayList<FeedItem>();
RootElement root = new RootElement(RSS);
Element itemlist = root.getChild(CHANNEL);
Element item = itemlist.getChild(ITEM);
item.setEndElementListener(new EndElementListener() {
@Override
public void end() {
result.add(feedItem.copy());
}
});
item.getChild(TITLE).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setTitle(body);
}
});
item.getChild(LINK).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setLink(body);
}
});
item.getChild(DESCRIPTION).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setDescription(body);
}
});
item.getChild(PUB_DATE).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setPupDate(body);
}
});
Element enclosure = item.getChild(ENCLOSURE);
enclosure.setStartElementListener(new StartElementListener() {
@Override
public void start(Attributes attributes) {
feedItem.setLength(attributes.getValue(LENGTH));
}
});
try {
Log.d("Parser", "start parsing: " + feedUrl.toString());
final FeedItem feedItem = new FeedItem();
result = new ArrayList<FeedItem>();
RootElement root = new RootElement(RSS);
Element itemlist = root.getChild(CHANNEL);
Element item = itemlist.getChild(ITEM);
item.setEndElementListener(new EndElementListener() {
@Override
public void end() {
result.add(feedItem.copy());
}
});
item.getChild(TITLE).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setTitle(body);
}
});
item.getChild(LINK).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setLink(body);
}
});
item.getChild(DESCRIPTION).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setDescription(body);
}
});
item.getChild(PUB_DATE).setEndTextElementListener(
new EndTextElementListener() {
@Override
public void end(String body) {
feedItem.setPupDate(body);
}
});
Element enclosure = item.getChild(ENCLOSURE);
enclosure.setStartElementListener(new StartElementListener() {
@Override
public void start(Attributes attributes) {
feedItem.setLength(attributes.getValue(LENGTH));
}
});
Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8,
root.getContentHandler());
} catch (Exception e) {
throw new RuntimeException(e);
status = false;
} finally {
sendResult(result);
}
sendResult(result);
}
public void sendResult(ArrayList<FeedItem> itemList) {
Intent intent = new Intent();
intent.setAction(BROADCAST_NAME);
intent.putExtra("status", status);
intent.putParcelableArrayListExtra("result", itemList);
Log.d("Parser", " sending Broadcast");
getApplicationContext().sendBroadcast(intent);
......
......@@ -349,8 +349,8 @@ public class GraphicsContext implements MessageConsumer {
// show blank page if whiteboard activated
if (isWhiteboardEnabled()) {
int[] whitePixels = new int[(int) (prefs.framebufferWidth * Index.THUMBNAIL_SCALE_FACTOR)
* (int) (prefs.framebufferWidth * Index.THUMBNAIL_SCALE_FACTOR)];
int[] whitePixels = new int[(int) (prefs.framebufferWidth * IndexEntry.THUMBNAIL_SCALE_FACTOR)
* (int) (prefs.framebufferWidth * IndexEntry.THUMBNAIL_SCALE_FACTOR)];
for (int i = 0; i < whitePixels.length; i++) {
whitePixels[i] = Color.WHITE;
......@@ -358,24 +358,27 @@ public class GraphicsContext implements MessageConsumer {
Bitmap whiteboard = Bitmap
.createBitmap(
whitePixels,
(int) (prefs.framebufferWidth * Index.THUMBNAIL_SCALE_FACTOR),
(int) (prefs.framebufferHeight * Index.THUMBNAIL_SCALE_FACTOR),
(int) (prefs.framebufferWidth * IndexEntry.THUMBNAIL_SCALE_FACTOR),
(int) (prefs.framebufferHeight * IndexEntry.THUMBNAIL_SCALE_FACTOR),
Config.ARGB_4444);
return whiteboard;
} else {
screenshot = Bitmap.createBitmap(pixels, prefs.framebufferWidth,
prefs.framebufferHeight, Config.ARGB_4444);
Bitmap scaledScreenshot = Bitmap
.createScaledBitmap(
screenshot,
(int) (prefs.framebufferWidth * Index.THUMBNAIL_SCALE_FACTOR),
(int) (prefs.framebufferHeight * Index.THUMBNAIL_SCALE_FACTOR),
true);
screenshot.recycle();
return scaledScreenshot;
// 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;
}
}
// ////////////////////////////////////////////////////////////////
......@@ -413,8 +416,10 @@ public class GraphicsContext implements MessageConsumer {
prefs.framebufferWidth, 0, 0, prefs.framebufferWidth,
prefs.framebufferHeight);
Paint p = new Paint(Color.BLACK);
p.setTextSize(20);
canvas.drawText("#" + whiteboardPage, prefs.framebufferWidth - 30, 20,
new Paint(Color.BLACK));
p);
}
......
......@@ -440,7 +440,6 @@ public class Index {
* @return
* @throws IOException
*/
final public static double THUMBNAIL_SCALE_FACTOR = 0.25;
public boolean createScreenshots() throws IOException {
......@@ -695,8 +694,6 @@ public class Index {
if (index.get(i).contains(searchword))
search_index.add(index.get(i));
highlightSearchResultsOnThumbnails();
}
public void nextSearchResult() {
......@@ -719,8 +716,8 @@ public class Index {
}
public void highlightSearchResultsOnThumbnails() {
for (int i = 0; i < search_index.size(); i++) {
search_index.get(i).highlightSearchResultsOnThumbail();
for (int i = 0; i < index.size(); i++) {
index.get(i).highlightSearchResultsOnThumbail();
}
}
......
......@@ -5,28 +5,28 @@ import java.io.IOException;
import java.util.ArrayList;
import tttclient.messages.annotations.Annotation;
import tttclient.messages.annotations.HighlightAnnotation;
import tttclient.shapes.ColoredShape;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class IndexEntry extends ImageButton {
private final int timestamp;
private final Index index;
private int[] pixel;
private Bitmap thumbnail;
private String title = "";
private String searchbase_of_page;
private ArrayList<SearchBaseEntry> words;
private ArrayList<Annotation> annotations;
public static double THUMBNAIL_SCALE_FACTOR = 0.3;
public static boolean SCALE_FACTOR_CALCULATED = false;
private boolean hasThumbnail = false;
......@@ -38,14 +38,30 @@ public class IndexEntry extends ImageButton {
this.title = title;
this.searchbase_of_page = searchableText;
this.thumbnail = thumbnail;
this.setBackgroundColor(Color.WHITE);
// this.setLayoutParams(new LinearLayout.LayoutParams(
// LinearLayout.LayoutParams.WRAP_CONTENT,
// LinearLayout.LayoutParams.WRAP_CONTENT));
this.setScaleType(ScaleType.CENTER_INSIDE);
this.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
setScaleType(ScaleType.CENTER_INSIDE);
// needed to get correct height
this.setAdjustViewBounds(true);
// ViewTreeObserver vto = this.getViewTreeObserver();
// vto.addOnPreDrawListener(new OnPreDrawListener() {
//
// @Override
// public boolean onPreDraw() {
// getMeasuredWidth();
//
// THUMBNAIL_SCALE_FACTOR = getMeasuredWidth()
// / index.getRecording().getProtocolPreferences().framebufferWidth;
// Log.d("Scale Factor", "" + THUMBNAIL_SCALE_FACTOR);
//
// return true;
// }
// });
this.setOnClickListener(new OnClickListener() {
@Override
......@@ -164,7 +180,7 @@ public class IndexEntry extends ImageButton {
}
// draw the search results on the canvas
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void highlightSearchResults(Canvas canvas) {
if (results != null)
for (int i = 0; i < results.size(); i++) {
......@@ -183,36 +199,13 @@ public class IndexEntry extends ImageButton {
}
// public void highlightSearchResults(int[] pixel) {
// if (results != null)
// for (int i = 0; i < results.size(); i++) {
// ColoredShape shape = results.get(i);
// Rect intRect = new Rect();
// shape.rectangle.roundOut(intRect);
//
// if (shape.filled) {
// GraphicsContext
// .fillRect(
// pixel,
// intRect,
// shape.color,
// index.getRecording()
// .getProtocolPreferences().framebufferWidth);
// } else
// GraphicsContext
// .borderRect(
// pixel,
// intRect,
// shape.color,
// index.getRecording()
// .getProtocolPreferences().framebufferWidth);
//
// }
//
// }
public void highlightSearchResultsOnThumbail() {
if (results != null)
if (!results.isEmpty()) {
// thumbail is inmutable --> create mutable one
Bitmap copy = thumbnail.copy(Config.ARGB_4444, true);
Canvas searchCanvas = new Canvas(copy);
for (int i = 0; i < results.size(); i++) {
ColoredShape shape = results.get(i);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
......@@ -223,39 +216,37 @@ public class IndexEntry extends ImageButton {
else
p.setStyle(Paint.Style.STROKE);
// scale shape for thumbnails
RectF scaledRect = new RectF(
(float) (shape.rectangle.left * Index.THUMBNAIL_SCALE_FACTOR),
(float) (shape.rectangle.top * Index.THUMBNAIL_SCALE_FACTOR),
(float) (shape.rectangle.right * Index.THUMBNAIL_SCALE_FACTOR),
(float) (shape.rectangle.bottom * Index.THUMBNAIL_SCALE_FACTOR));
// // scale shape for thumbnails
// RectF scaledRect = new RectF(
// (float) (shape.rectangle.left * THUMBNAIL_SCALE_FACTOR),
// (float) (shape.rectangle.top * THUMBNAIL_SCALE_FACTOR),
// (float) (shape.rectangle.right * THUMBNAIL_SCALE_FACTOR),
// (float) (shape.rectangle.bottom * THUMBNAIL_SCALE_FACTOR));
// thumbail is inmutable --> create mutable one
Bitmap copy = thumbnail.copy(Config.ARGB_8888, true);
Canvas searchCanvas = new Canvas(copy);
searchCanvas.drawRect(shape.rectangle,