Commit ca859d19 by Thomas Krex

eintrag in datenbank ob file gedownloadad wurde /status

icon ändert sich dementsrpechend via viewbinder
parent bb8e546c
......@@ -5,5 +5,6 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<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="output" path="bin/classes"/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
......@@ -21,28 +21,32 @@ public final class R {
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
public static final int my_border=0x7f020001;
public static final int selected_index_border=0x7f020002;
public static final int checked_icon=0x7f020000;
public static final int ic_launcher=0x7f020001;
public static final int my_border=0x7f020002;
public static final int selected_index_border=0x7f020003;
public static final int unchecked_icon=0x7f020004;
}
public static final class id {
public static final int action_settings=0x7f080013;
public static final int add=0x7f080012;
public static final int action_settings=0x7f080015;
public static final int add=0x7f080014;
public static final int button_save=0x7f08000e;
public static final int checkBox1=0x7f08000b;
public static final int connect_btn=0x7f08000a;
public static final int extend=0x7f080015;
public static final int extend=0x7f080017;
public static final int feedDetailsLv=0x7f080010;
public static final int feed_list=0x7f08000f;
public static final int indexScrollView=0x7f080003;
public static final int itemTitle=0x7f080012;
public static final int liveChannel_button=0x7f080002;
public static final int playerView_extended=0x7f080004;
public static final int playerView_fullscreen=0x7f080006;
public static final int port_tx=0x7f080009;
public static final int progressBar=0x7f080011;
public static final int scrollView1=0x7f080005;
public static final int search=0x7f080014;
public static final int search=0x7f080016;
public static final int server_tx=0x7f080008;
public static final int statusIcon=0x7f080013;
public static final int test_button=0x7f080000;
public static final int tx_name=0x7f08000d;
public static final int tx_url=0x7f08000c;
......@@ -58,6 +62,7 @@ public final class R {
public static final int dialog_feeds=0x7f030005;
public static final int feed_activity=0x7f030006;
public static final int feed_details_activity=0x7f030007;
public static final int list_feeditems=0x7f030008;
}
public static final class menu {
public static final int feed_menu=0x7f070000;
......
Apache Commons IO
Copyright 2002-2012 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>
\ No newline at end of file
......@@ -12,3 +12,4 @@
# Project target.
target=android-19
android.library=false
......@@ -4,7 +4,7 @@
<stroke
android:width="10dip"
android:color="@android:color/darker_gray" >
android:color="@android:color/background_dark" >
</stroke>
</shape>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="5" >
<TextView
android:id="@+id/itemTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/statusIcon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="?android:attr/textCheckMark" />
</LinearLayout>
\ No newline at end of file
package tttclient.activities;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.commons.io.FileUtils;
import tttclient.models.FeedItem;
import tttclient.models.FeedItemDbManager;
import tttclient.services.DownloadService;
......@@ -25,8 +28,11 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import com.example.test.R;
......@@ -46,6 +52,7 @@ public class FeedDetailActivity extends Activity implements
FeedItemDbManager manager;
SimpleCursorAdapter adapter;
ProgressDialog progressDialog;
ListView lv;
private final BroadcastReceiver receiver = new BroadcastReceiver() {
......@@ -63,12 +70,13 @@ public class FeedDetailActivity extends Activity implements
if (result == RESULT_OK) {
Log.d("Download", "complete " + path);
manager.updatePath(title, path);
manager.updatePath(title, path, true);
adapter.changeCursor(manager.getAllFromDB());
startPlayer();
}
lv.setClickable(true);
} else if (action.equals(ParseService.BROADCAST_NAME)) {
itemList = bundle.getParcelableArrayList("result");
......@@ -95,25 +103,58 @@ public class FeedDetailActivity extends Activity implements
setContentView(R.layout.feed_details_activity);
progressDialog = new ProgressDialog(FeedDetailActivity.this);
progressDialog.setIndeterminate(false);
progressDialog.setIndeterminate(true);
progressDialog.setTitle("Downloading File");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// progressDialog.setCancelable(true);
progressDialog.setMessage("0% downloaded");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
feedId = getIntent().getStringExtra("id");
feedName = getIntent().getStringExtra("name");
feedUrl = getIntent().getStringExtra("feedUrl");
this.setTitle(feedName);
ListView lv = (ListView) findViewById(R.id.feedDetailsLv);
lv = (ListView) findViewById(R.id.feedDetailsLv);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
manager = new FeedItemDbManager(this);
Cursor cursor = manager.getAllFromDB();
adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, cursor,
new String[] { FeedItemDbManager.COLUMN_TITLE },
new int[] { android.R.id.text1 });
adapter = new SimpleCursorAdapter(this, R.layout.list_feeditems,
cursor, new String[] { FeedItemDbManager.COLUMN_TITLE,
FeedItemDbManager.COLUMN_STATUS }, new int[] {
R.id.itemTitle, R.id.statusIcon });
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor,
int columnIndex) {
if (view.getId() == R.id.statusIcon) {
ImageView icon = (ImageView) view;
int status = cursor.getInt(cursor
.getColumnIndex(FeedItemDbManager.COLUMN_STATUS));
if (status == 1) {
icon.setImageDrawable(getResources().getDrawable(
(R.drawable.checked_icon)));
} else if (status == 0) {
icon.setImageDrawable(getResources().getDrawable(
(R.drawable.unchecked_icon)));
}
return true;
}
return false;
}
});
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
lv.setOnItemLongClickListener(this);
Intent intent = new Intent(this, ParseService.class);
intent.putExtra(Consts.SERVICE_ID, Consts.PARSE_SERVICE_ID);
......@@ -151,12 +192,18 @@ public class FeedDetailActivity extends Activity implements
link = c.getString(c.getColumnIndex(FeedItemDbManager.COLUMN_LINK));
title = c.getString(c
.getColumnIndex(FeedItemDbManager.COLUMN_TITLE));
int status = c.getInt(c
.getColumnIndex(FeedItemDbManager.COLUMN_STATUS));
Log.d("FeedItem", "status: " + status);
if (path != null) {
if (checkPath(path)) {
startPlayer();
} else {
manager.updatePath(title, "");
manager.updatePath(title, "", false);
Toast.makeText(FeedDetailActivity.this,
"invalide path, start downloading",
Toast.LENGTH_LONG).show();
startDownloadService();
}
}
......@@ -193,6 +240,19 @@ public class FeedDetailActivity extends Activity implements
}
public void isDownloaded() {
int count = lv.getChildCount();
for (int i = 0; i < count; i++) {
CheckedTextView child = (CheckedTextView) lv.getChildAt(i);
String title = child.getText().toString();
Log.d("isDownloaded", "title: " + title);
String path = manager.getPath(title);
child.setChecked(checkPath(path));
}
}
public boolean checkPath(String path) {
Log.d("FILE", "checking path " + path);
......@@ -217,15 +277,33 @@ public class FeedDetailActivity extends Activity implements
// delete feed from list, refresh feed list
Cursor c = (Cursor) av.getAdapter().getItem(position);
int _id = c.getInt(c
.getColumnIndex(FeedItemDbManager.COLUMN_ID));
// int _id = c.getInt(c
// .getColumnIndex(FeedItemDbManager.COLUMN_ID));
String path = c.getString(c
.getColumnIndex(FeedItemDbManager.COLUMN_PATH));
String title = c.getString(c
.getColumnIndex(FeedItemDbManager.COLUMN_TITLE));
File dir = new File(path);
try {
FileUtils.deleteDirectory(dir);
Toast.makeText(FeedDetailActivity.this, "File was deleted",
Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(FeedDetailActivity.this, "File not found",
Toast.LENGTH_LONG).show();
}
FeedItemDbManager fm = new FeedItemDbManager(av.getContext());
fm.deleteFromDb(_id);
// fm.deleteFromDb(_id);
fm.updatePath(title, path, false);
adapter.changeCursor(fm.getAllFromDB());
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog.Builder builder = new AlertDialog.Builder(
FeedDetailActivity.this);
builder.setMessage("delete?");
builder.setPositiveButton("delete", listener);
builder.setNegativeButton("cancel", null);
......@@ -245,11 +323,8 @@ public class FeedDetailActivity extends Activity implements
if (resultCode == DownloadService.PROGRESS_UPDATE) {
int progress = resultData.getInt("progress");
Log.d("ResultReceiver", "progress: " + progress);
progressDialog.setProgress(progress);
progressDialog.setMessage(String.valueOf(progress)
+ "% downloaded sucessfully.");
progressDialog.setMessage(progress + "% donwloaded");
if (progress == 100) {
progressDialog.dismiss();
......
......@@ -17,13 +17,15 @@ public class FeedItemDbManager {
public static final String COLUMN_DESCRIPTION = "description";
public static final String COLUMN_PUBDATE = "pubDate";
public static final String COLUMN_PATH = "path";
public static final String COLUMN_STATUS = "status";
private static final String TABLE_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TABLE_FEEDITEMS + " ( " + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_FEEDID
+ " INTEGER, " + COLUMN_TITLE + " VARCHAR, " + COLUMN_LINK
+ " VARCHAR, " + COLUMN_DESCRIPTION + " VARCHAR, " + COLUMN_PUBDATE
+ " VARCHAR, " + COLUMN_PATH + " VARCHAR );";
+ " VARCHAR, " + COLUMN_PATH + " VARCHAR, " + COLUMN_STATUS
+ " INTEGER );";
private final SQLiteDatabase db;
public FeedItemDbManager(Context context) {
......@@ -41,17 +43,22 @@ public class FeedItemDbManager {
// + " FROM " + TABLE_FEEDITEMS + " ORDER BY " + COLUMN_PUBDATE);
return db
.rawQuery(
"SELECT title, id as _id , feedId, link, description, pubDate, path FROM feedItems ORDER BY pubDate",
"SELECT title, id as _id , feedId, link, description, pubDate, path, status FROM feedItems ORDER BY pubDate",
null);
}
public void updatePath(String title, String path) {
public void updatePath(String title, String path, boolean isDownloaded) {
Cursor cursor = db.rawQuery("SELECT id FROM feedItems WHERE title = ?",
new String[] { title });
if (cursor.moveToNext()) {
db.execSQL("UPDATE feedItems SET path = ? WHERE id=?",
new String[] { path, cursor.getString(0) });
String status;
if (isDownloaded) {
status = "1";
} else
status = "0";
db.execSQL("UPDATE feedItems SET path = ?, status=? WHERE id=?",
new String[] { path, status, cursor.getString(0) });
} else {
Log.e("SQL", "FeedItem with title " + title + " not found ");
......@@ -59,6 +66,21 @@ public class FeedItemDbManager {
}
public String getPath(String title) {
Cursor cursor = db.rawQuery(
"SELECT id, path FROM feedItems WHERE title = ? ",
new String[] { title });
if (cursor.moveToNext()) {
return cursor.getString(1);
} else {
Log.d("Database", "No entry found");
return null;
}
}
public void insertintoDB(ArrayList<FeedItem> itemList, String feedId)
throws Exception {
......@@ -75,7 +97,8 @@ public class FeedItemDbManager {
db.execSQL("INSERT INTO " + TABLE_FEEDITEMS + " ("
+ COLUMN_TITLE + ", " + COLUMN_FEEDID + ", "
+ COLUMN_LINK + ", " + COLUMN_DESCRIPTION + ", "
+ COLUMN_PUBDATE + ") VALUES ( ? , ? , ? , ? , ? )",
+ COLUMN_PUBDATE + ", " + COLUMN_STATUS
+ ") VALUES ( ? , ? , ? , ? , ?," + 0 + " )",
new String[] { item.getTitle(), feedId, item.getLink(),
item.getDescription(), item.getPupDate() });
......
......@@ -18,6 +18,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.ResultReceiver;
import android.util.Log;
import android.widget.Toast;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class DownloadService extends IntentService {
......@@ -88,6 +89,8 @@ public class DownloadService extends IntentService {
+ fileName + ".zip");
byte data[] = new byte[512000];
long total = 0;
int lastProgress = 0;
int progress = 0;
int count;
while ((count = input.read(data)) != -1) {
// allow canceling with back button
......@@ -95,9 +98,13 @@ public class DownloadService extends IntentService {
// publishing the progress....
Bundle resultData = new Bundle();
if (fileLength > 0)
resultData.putInt("progress",
(int) (total * 100 / fileLength));
receiver.send(PROGRESS_UPDATE, resultData);
progress = (int) (total * 100 / fileLength);
resultData.putInt("progress", progress);
if (progress > lastProgress) {
receiver.send(PROGRESS_UPDATE, resultData);
lastProgress = progress;
}
output.write(data, 0, count);
// Log.d("DownloadService", total + " bytes downloaded");
......@@ -109,9 +116,12 @@ public class DownloadService extends IntentService {
if (zipFile.exists()) {
result = Activity.RESULT_OK;
Log.d("DownloadService", " sucessful");
Toast.makeText(getApplicationContext(), "unzipping file ...",
Toast.LENGTH_LONG);
UnzipManager unzip = new UnzipManager(
zipFile.getAbsolutePath(), lectureDir.getAbsolutePath());
unzip.unzip();
zipFile.delete();
}
} catch (Exception e) {
// TODO Auto-generated catch block
......
......@@ -370,20 +370,23 @@ public class GraphicsContext implements MessageConsumer {
public Bitmap getScreenshotWithoutAnnotations() {
Bitmap screenshot;
// Create a buffered image using the default color model
screenshot = Bitmap.createBitmap(pixels, prefs.framebufferWidth,
prefs.framebufferHeight, Config.ARGB_8888);
Bitmap scaledScreenshot = Bitmap.createScaledBitmap(screenshot,
prefs.framebufferWidth / 3, prefs.framebufferHeight / 3, true);
screenshot.recycle();
// show blank page if whiteboard activated
if (isWhiteboardEnabled()) {
int[] whitePixels = new int[prefs.framebufferWidth
* prefs.framebufferWidth];
int[] whitePixels = new int[prefs.framebufferWidth / 3
* prefs.framebufferWidth / 3];
for (int i = 0; i < whitePixels.length; i++) {
whitePixels[i] = Color.WHITE;
}
Bitmap whiteboard = Bitmap.createBitmap(whitePixels,
prefs.framebufferWidth, prefs.framebufferHeight,
prefs.framebufferWidth / 3, prefs.framebufferHeight / 3,
Config.ARGB_8888);
return whiteboard;
......@@ -391,7 +394,7 @@ public class GraphicsContext implements MessageConsumer {
// show desktop
return screenshot;
return scaledScreenshot;
}
// ////////////////////////////////////////////////////////////////
......
......@@ -44,7 +44,6 @@ public class Index {
final public static int NO_SEARCHBASE = 0;
final public static int ASCII_SEARCHBASE = 1;
final public static int XML_SEARCHBASE = 2;
final public static double THUMBNAIL_SCALE_FACTOR = 0.25;
public ArrayList<IndexEntry> index = new ArrayList<IndexEntry>();
ArrayList<IndexEntry> search_index = new ArrayList<IndexEntry>();
......@@ -441,6 +440,8 @@ public class Index {
* @return
* @throws IOException
*/
final public static double THUMBNAIL_SCALE_FACTOR = 0.3;
public boolean createScreenshots() throws IOException {
// measure time
......@@ -458,10 +459,13 @@ public class Index {
// create screenshot
Bitmap screenshot = recording.graphicsContext()
.getScreenshotWithoutAnnotations();
int scaledWidth = (int) (screenshot.getWidth() * THUMBNAIL_SCALE_FACTOR);
int scaledHeight = (int) (screenshot.getHeight() * THUMBNAIL_SCALE_FACTOR);
Bitmap scaled = Bitmap.createScaledBitmap(screenshot, scaledWidth,
scaledHeight, true);
// int scaledWidth = (int) (screenshot.getWidth() *
// THUMBNAIL_SCALE_FACTOR);
// int scaledHeight = (int) (screenshot.getHeight() *
// THUMBNAIL_SCALE_FACTOR);
// Bitmap scaled = Bitmap.createScaledBitmap(screenshot,
// scaledWidth,
// scaledHeight, true);
indexEntry.setThumbnail(screenshot);
......
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 sign in to comment