Commit be157c0e authored by Thomas Krex's avatar Thomas Krex

haptisches feedback bei longclick

bei löschen eines feeds werden alle feeditems+folder gelöscht
parent 18f4ba66
......@@ -9,6 +9,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" >
</uses-permission>
<uses-sdk
android:minSdkVersion="9"
......
......@@ -9,6 +9,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" >
</uses-permission>
<uses-sdk
android:minSdkVersion="9"
......
......@@ -18,6 +18,7 @@
android:id="@+id/playerView_fullscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:scaleType="centerInside" />
</LinearLayout>
......
......@@ -9,13 +9,14 @@
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="@+id/statusIcon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="?android:attr/textCheckMark" />
android:src="@drawable/ic_action_download" >
</ImageView>
</LinearLayout>
\ No newline at end of file
......@@ -8,7 +8,7 @@
android:title="Search"/>
<item
android:id="@+id/extend"
android:icon="@android:drawable/ic_input_add"
android:icon="@drawable/ic_action_return_from_full_screen"
android:showAsAction="always">
</item>
......
......@@ -10,5 +10,11 @@
<string name="port">Port</string>
<string name="prompt_title">Connect to a Lecture</string>
<string name="multicast">Enabling Multicast</string>
<string name="confirm_download">Do you want to download this Lecture?\nThis could take some time and can\'t be canceled</string>
<string name="yes">Yes</string>
<string name="cancel">Cancel</string>
<string name="inet_needed">Internet Connection needed</string>
<string name="not_found">File was not found</string>
<string name="deleted">File was deleted</string>
</resources>
\ No newline at end of file
......@@ -2,6 +2,7 @@ package tttclient.activities;
import tttclient.models.Feed;
import tttclient.models.FeedDbManager;
import tttclient.models.FeedItemDbManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
......@@ -9,6 +10,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
......@@ -29,13 +31,14 @@ public class FeedActivity extends Activity implements OnItemClickListener,
private SimpleCursorAdapter adapter;
private String feedUrl;
private String feedName;
private String feedId;
private int feedId;
private Vibrator myVib;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.feed_activity);
myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
ListView feedList = (ListView) findViewById(R.id.feed_list);
FeedDbManager fManager = new FeedDbManager(this);
......@@ -43,11 +46,12 @@ public class FeedActivity extends Activity implements OnItemClickListener,
adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, cursor,
new String[] { FeedDbManager.COLUMN_NAME,
FeedDbManager.COLUMN_FEEDURL },
new int[] { android.R.id.text1 });
FeedDbManager.COLUMN_FEEDURL }, new int[] {
android.R.id.text1, android.R.id.text2 });
feedList.setAdapter(adapter);
feedList.setOnItemClickListener(this);
feedList.setOnItemLongClickListener(this);
}
......@@ -109,9 +113,10 @@ public class FeedActivity extends Activity implements OnItemClickListener,
// click on feed in list
if (position != -1) {
Cursor c = (Cursor) av.getAdapter().getItem(position);
feedUrl = c.getString(c.getColumnIndex("feedUrl"));
feedName = c.getString(c.getColumnIndex("name"));
feedId = c.getString(c.getColumnIndex("_id"));
feedUrl = c.getString(c
.getColumnIndex(FeedDbManager.COLUMN_FEEDURL));
feedName = c.getString(c.getColumnIndex(FeedDbManager.COLUMN_NAME));
feedId = c.getInt(c.getColumnIndex("_id"));
}
Intent intent = new Intent(this, FeedDetailActivity.class);
......@@ -127,6 +132,7 @@ public class FeedActivity extends Activity implements OnItemClickListener,
if (id == -1) {
return false;
}
myVib.vibrate(50);
// confirm delete
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
......@@ -136,19 +142,21 @@ public class FeedActivity extends Activity implements OnItemClickListener,
// delete feed from list, refresh feed list
Cursor c = (Cursor) av.getAdapter().getItem(position);
int _id = c.getInt(c.getColumnIndex(FeedDbManager.COLUMN_ID));
feedId = c.getInt(c.getColumnIndex("_id"));
FeedDbManager fm = new FeedDbManager(av.getContext());
fm.deleteFromDb(_id);
FeedItemDbManager fim = new FeedItemDbManager(av.getContext());
// delete all childs and their folders
fim.deleteFromDb(feedId);
fm.deleteFromDb(feedId);
adapter.changeCursor(fm.getAllFromDB());
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Do you want to delete this feed?");
builder.setMessage("Do you want to delete this feed? All Lectures saved on this devices will be deleted");
builder.setPositiveButton("delete", listener);
builder.setNegativeButton("cancel", null);
builder.show();
return false;
return true;
}
}
......@@ -25,12 +25,12 @@ import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.os.Vibrator;
import android.util.Log;
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;
......@@ -42,11 +42,10 @@ public class FeedDetailActivity extends Activity implements
private static String feedUrl;
private static String feedName;
private static String feedId;
private static int feedId;
private static String path;
private static String link;
private static String title;
private static String length;
ArrayList<FeedItem> itemList;
ParseService feedParser;
......@@ -54,6 +53,7 @@ public class FeedDetailActivity extends Activity implements
SimpleCursorAdapter adapter;
ProgressDialog progressDialog;
ListView lv;
Vibrator myVib;
private final BroadcastReceiver receiver = new BroadcastReceiver() {
......@@ -72,7 +72,7 @@ public class FeedDetailActivity extends Activity implements
if (result == RESULT_OK) {
Log.d("Download", "complete " + path);
manager.updatePath(title, path, true);
adapter.changeCursor(manager.getAllFromDB());
adapter.changeCursor(manager.getAllFromDB(feedId));
startPlayer();
......@@ -83,7 +83,7 @@ public class FeedDetailActivity extends Activity implements
try {
manager.insertintoDB(itemList, feedId);
adapter.changeCursor(manager.getAllFromDB());
adapter.changeCursor(manager.getAllFromDB(feedId));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -102,7 +102,9 @@ public class FeedDetailActivity extends Activity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.feed_details_activity);
myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
// init progress dialog for showing downloading/unzipping progress
progressDialog = new ProgressDialog(FeedDetailActivity.this);
progressDialog.setIndeterminate(true);
progressDialog.setTitle("Downloading File");
......@@ -111,7 +113,7 @@ public class FeedDetailActivity extends Activity implements
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
feedId = getIntent().getStringExtra("id");
feedId = getIntent().getIntExtra("id", 0);
feedName = getIntent().getStringExtra("name");
feedUrl = getIntent().getStringExtra("feedUrl");
this.setTitle(feedName);
......@@ -119,7 +121,7 @@ public class FeedDetailActivity extends Activity implements
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
manager = new FeedItemDbManager(this);
Cursor cursor = manager.getAllFromDB();
Cursor cursor = manager.getAllFromDB(feedId);
adapter = new SimpleCursorAdapter(this, R.layout.list_feeditems,
cursor, new String[] { FeedItemDbManager.COLUMN_TITLE,
FeedItemDbManager.COLUMN_STATUS }, new int[] {
......@@ -138,11 +140,11 @@ public class FeedDetailActivity extends Activity implements
if (status == 1) {
icon.setImageDrawable(getResources().getDrawable(
(R.drawable.checked_icon)));
(R.drawable.ic_action_play)));
} else if (status == 0) {
icon.setImageDrawable(getResources().getDrawable(
(R.drawable.unchecked_icon)));
(R.drawable.ic_action_download)));
}
......@@ -199,27 +201,30 @@ public class FeedDetailActivity extends Activity implements
.getColumnIndex(FeedItemDbManager.COLUMN_TITLE));
int status = c.getInt(c
.getColumnIndex(FeedItemDbManager.COLUMN_STATUS));
Log.d("FeedItem", "status: " + status);
if (path != null) {
if (checkPath(path)) {
// checks whether file has to be downloaded or can be played
if (status == 0)
startDownloadService();
// checks if saved path is correct
else if (status == 1) {
if (checkPath(path, title))
startPlayer();
} else {
manager.updatePath(title, "", false);
Toast.makeText(FeedDetailActivity.this,
"invalide path, start downloading",
else {
// if ttt file was not found , the whole directory is
// deleted and downloaded again
Toast.makeText(getApplicationContext(), R.string.not_found,
Toast.LENGTH_LONG).show();
try {
FileUtils.deleteDirectory(new File(path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startDownloadService();
}
}
// download file if it not exists
// checks if file exists at path --> No => delete path out of
// database and download file
else {
startDownloadService();
}
}
}
......@@ -233,39 +238,48 @@ public class FeedDetailActivity extends Activity implements
public void startDownloadService() {
// check if network connection is available
if (isNetworkAvailable()) {
progressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra(DownloadService.FILE_NAME, title);
intent.putExtra(DownloadService.FILE_URL, link);
intent.putExtra(DownloadService.PROGRESS_RECEIVER,
new DownloadReceiver(new Handler()));
// Start download service
startService(intent);
} else
Toast.makeText(getApplicationContext(),
"Internet Connection needed", Toast.LENGTH_LONG).show();
}
// ask user for confirmation
AlertDialog.Builder builder = new AlertDialog.Builder(
FeedDetailActivity.this);
builder.setMessage(R.string.confirm_download);
builder.setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
// if confirmed, start DownloadService and show progress
// dialog
@Override
public void onClick(DialogInterface dialog, int which) {
progressDialog.show();
// define intent for service
Intent intent = new Intent(getApplicationContext(),
DownloadService.class);
intent.putExtra(DownloadService.FILE_NAME, title);
intent.putExtra(DownloadService.FILE_URL, link);
intent.putExtra(DownloadService.PROGRESS_RECEIVER,
new DownloadReceiver(new Handler()));
// Start download service
startService(intent);
}
});
builder.setNegativeButton(R.string.cancel, null);
builder.show();
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));
}
} else
Toast.makeText(getApplicationContext(), R.string.inet_needed,
Toast.LENGTH_LONG).show();
}
public boolean checkPath(String path) {
Log.d("FILE", "checking path " + path);
// checks if the ttt file (title.ttt) is in the correspondig directory
public boolean checkPath(String path, String title) {
File file = new File(path);
File file = new File(path + "/" + title + ".ttt");
Log.d("Path check", path + "/" + title + ".ttt");
return file.exists();
......@@ -278,37 +292,51 @@ public class FeedDetailActivity extends Activity implements
return false;
}
myVib.vibrate(50);
// confirm delete
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// delete feed from list, refresh feed list
Toast deletedToast = Toast.makeText(FeedDetailActivity.this,
R.string.deleted, Toast.LENGTH_SHORT);
Toast foundToast = Toast.makeText(FeedDetailActivity.this,
R.string.not_found, Toast.LENGTH_SHORT);
Cursor c = (Cursor) av.getAdapter().getItem(position);
// 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);
// delete File from devices
File dir = null;
if (path != null)
dir = new File(path);
else {
foundToast.show();
return;
}
try {
FileUtils.deleteDirectory(dir);
Toast.makeText(FeedDetailActivity.this, "File was deleted",
Toast.LENGTH_LONG).show();
if (dir.exists()) {
FileUtils.deleteDirectory(dir);
deletedToast.show();
} else {
foundToast.show();
return;
}
} catch (IOException e) {
Toast.makeText(FeedDetailActivity.this, "File not found",
Toast.LENGTH_LONG).show();
foundToast.show();
}
FeedItemDbManager fm = new FeedItemDbManager(av.getContext());
// fm.deleteFromDb(_id);
// refresh feed item list
fm.updatePath(title, path, false);
adapter.changeCursor(fm.getAllFromDB());
adapter.changeCursor(fm.getAllFromDB(feedId));
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(
......@@ -317,7 +345,7 @@ public class FeedDetailActivity extends Activity implements
builder.setPositiveButton("delete", listener);
builder.setNegativeButton("cancel", null);
builder.show();
return false;
return true;
}
private boolean isNetworkAvailable() {
......@@ -342,9 +370,14 @@ public class FeedDetailActivity extends Activity implements
progressDialog.setMessage(progress + "% donwloaded");
if (progress == 100) {
}
else if (resultCode == DownloadService.UNZIPPING) {
boolean unzipping = resultData.getBoolean("progress");
if (unzipping)
progressDialog.setMessage("unzipping file");
else
progressDialog.dismiss();
}
}
}
}
......
......@@ -116,7 +116,7 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
protected void onPostExecute(Void result) {
dialog.dismiss();
audioController.show();
audioController.show(5000);
}
};
......@@ -130,7 +130,7 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
// update display if recording is not playing
// if (!recording.isPlaying())
recording.graphicsContext().updateCanvas();
recording.graphicsContext().updateView();
}
......@@ -254,13 +254,13 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
switchLayout(1);
// switchSurface(1);
item.setIcon(getResources().getDrawable(
android.R.drawable.ic_input_delete));
R.drawable.ic_action_full_screen));
isExtendend = true;
} else if (isExtendend) {
switchLayout(0);
// switchSurface(0);
item.setIcon(getResources().getDrawable(
android.R.drawable.ic_input_add));
R.drawable.ic_action_return_from_full_screen));
isExtendend = false;
}
......@@ -286,7 +286,8 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
if (index == 1) {
imgV = (ImageView) findViewById(R.id.playerView_extended);
recording.graphicsContext().setImageView(imgV);
recording.graphicsContext().refresh();
recording.graphicsContext().updateView();
switcher.setDisplayedChild(1);
}
......
......@@ -78,48 +78,6 @@ public abstract class Message {
// /////////////////////////////////////////////////
abstract public void paint(GraphicsContext graphicsContext);
// /////////////////////////////////////////////////
// write message
// /////////////////////////////////////////////////
static final public int NO_TIMESTAMP = -1;
static final public int TIMESTAMP_OF_MESSAGE = -2;
// write message to TTT output stream
// abstract public void write(DataOutputStream out, int writeTimestamp)
// throws IOException;
//
// // helper method to write message header, because it's the same for all
// // messages
// final void writeHeader(DataOutputStream out, int writeTimestamp)
// throws IOException {
// switch (writeTimestamp) {
// case NO_TIMESTAMP:
// // size of message
// out.writeInt(getSize());
// // encoding without timestamp
// out.writeByte(getEncoding());
// break;
//
// case TIMESTAMP_OF_MESSAGE:
// // size of message
// out.writeInt(getSize() + 4);
// // encoding and timestamp
// out.writeByte(getEncoding() | Constants.EncodingFlagTimestamp);
// out.writeInt(getTimestamp());
// break;
//
// default:
// // size of message
// out.writeInt(getSize() + 4);
// // encoding and timestamp
// out.writeByte(getEncoding() | Constants.EncodingFlagTimestamp);
// out.writeInt(writeTimestamp);
//
// break;
// }
// }
// return size of message in bytes (if written to stream)
abstract public int getSize();
......
......@@ -51,6 +51,7 @@ public class WhiteboardMessage extends FramebufferUpdateMessage {
@Override
public void paint(GraphicsContext graphicsContext) {
graphicsContext.setWhiteboardPage(pageNumber);
}
public boolean isWhiteboardEnabled() {
......@@ -70,14 +71,4 @@ public class WhiteboardMessage extends FramebufferUpdateMessage {
+ " at (" + x + "," + y + ")";
}
/*******************************************************************************************************************
* write message
******************************************************************************************************************/
// return size of message in bytes (if written to stream)
@Override
public int getSize() {
return 2;
}
}
......@@ -52,7 +52,7 @@ public class DeleteAnnotation extends Annotation {
@Override
public void paint(GraphicsContext graphicsContext) {
graphicsContext.removeAnnotationsAt(x, y);
graphicsContext.refresh();
graphicsContext.updateView();
}
@Override
......
package tttclient.models;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.commons.io.FileUtils;
import tttclient.utils.DBManager;
import android.content.Context;
import android.database.Cursor;
......@@ -34,7 +38,7 @@ public class FeedItemDbManager {
db.execSQL(TABLE_CREATE);
}
public Cursor getAllFromDB() {
public Cursor getAllFromDB(int feedid) {
// Log.d("SQL", "SELECT " + COLUMN_TITLE + ", " + COLUMN_ID +
// " as _id , "
......@@ -43,8 +47,8 @@ public class FeedItemDbManager {
// + " FROM " + TABLE_FEEDITEMS + " ORDER BY " + COLUMN_PUBDATE);
return db
.rawQuery(
"SELECT title, id as _id , feedId, link, description, pubDate, path, status FROM feedItems ORDER BY pubDate",
null);
"SELECT title, id as _id , feedId, link, description, pubDate, path, status FROM feedItems WHERE feedId = ? ORDER BY title DESC",
new String[] { String.valueOf(feedid) });
}
......@@ -81,7 +85,7 @@ public class FeedItemDbManager {
}
public void insertintoDB(ArrayList<FeedItem> itemList, String feedId)
public void insertintoDB(ArrayList<FeedItem> itemList, int feedId)
throws Exception {
for (FeedItem item : itemList) {
......@@ -94,13 +98,15 @@ public class FeedItemDbManager {
// if
// so
if (!c.moveToNext()) {
db.execSQL("INSERT INTO " + TABLE_FEEDITEMS + " ("
+ COLUMN_TITLE + ", " + COLUMN_FEEDID + ", "
+ COLUMN_LINK + ", " + COLUMN_DESCRIPTION + ", "
+ COLUMN_PUBDATE + ", " + COLUMN_STATUS
+ ") VALUES ( ? , ? , ? , ? , ?," + 0 + " )",
new String[] { item.getTitle(), feedId, item.getLink(),
item.getDescription(), item.getPupDate() });
db.execSQL(
"INSERT INTO " + TABLE_FEEDITEMS + " (" + COLUMN_TITLE
+ ", " + COLUMN_FEEDID + ", " + COLUMN_LINK
+ ", " + COLUMN_DESCRIPTION + ", "
+ COLUMN_PUBDATE + ", " + COLUMN_STATUS
+ ") VALUES ( ? , ? , ? , ? , ?," + 0 + " )",
new String[] { item.getTitle(), String.valueOf(feedId),
item.getLink(), item.getDescription(),
item.getPupDate() });
}
......@@ -117,6 +123,26 @@ public class FeedItemDbManager {
}
public void deleteFromDb(int feedId) {
// delete all folders belonging to a certain lecture
Cursor cursor = db.rawQuery(
"Select path from feedItems WHERE feedid = ?",
new String[] { String.valueOf(feedId) });
while (cursor.moveToNext()) {
String path = cursor.getString(cursor.getColumnIndex(COLUMN_PATH));
if (path != null) {
File dir = new File(path);
if (dir.exists())
try {
FileUtils.deleteDirectory(dir);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// delete the entries from the feedItems table
db.execSQL("DELETE FROM feedItems WHERE feedId = ?",
new String[] { String.valueOf(feedId) });
}
......