Commit bb8e546c authored by Thomas Krex's avatar Thomas Krex

download service sendet fortschritt an result receiver --> anzeigen in

activity
parent 6d90ee31
...@@ -76,6 +76,8 @@ public class FeedActivity extends Activity implements OnItemClickListener, ...@@ -76,6 +76,8 @@ public class FeedActivity extends Activity implements OnItemClickListener,
EditText urlTxt = (EditText) dialog EditText urlTxt = (EditText) dialog
.findViewById(R.id.tx_url); .findViewById(R.id.tx_url);
String name = nameTxt.getText().toString(); String name = nameTxt.getText().toString();
// TODO validate url
String url = urlTxt.getText().toString(); String url = urlTxt.getText().toString();
Feed feed = new Feed(name, url); Feed feed = new Feed(name, url);
......
...@@ -5,7 +5,6 @@ import java.util.ArrayList; ...@@ -5,7 +5,6 @@ import java.util.ArrayList;
import tttclient.models.FeedItem; import tttclient.models.FeedItem;
import tttclient.models.FeedItemDbManager; import tttclient.models.FeedItemDbManager;
import tttclient.services.DownloadReceiver;
import tttclient.services.DownloadService; import tttclient.services.DownloadService;
import tttclient.services.ParseService; import tttclient.services.ParseService;
import tttclient.utils.Consts; import tttclient.utils.Consts;
...@@ -20,6 +19,7 @@ import android.content.IntentFilter; ...@@ -20,6 +19,7 @@ import android.content.IntentFilter;
import android.database.Cursor; import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.ResultReceiver;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
...@@ -45,7 +45,7 @@ public class FeedDetailActivity extends Activity implements ...@@ -45,7 +45,7 @@ public class FeedDetailActivity extends Activity implements
ParseService feedParser; ParseService feedParser;
FeedItemDbManager manager; FeedItemDbManager manager;
SimpleCursorAdapter adapter; SimpleCursorAdapter adapter;
public ProgressDialog progressDialog; ProgressDialog progressDialog;
private final BroadcastReceiver receiver = new BroadcastReceiver() { private final BroadcastReceiver receiver = new BroadcastReceiver() {
...@@ -95,8 +95,8 @@ public class FeedDetailActivity extends Activity implements ...@@ -95,8 +95,8 @@ public class FeedDetailActivity extends Activity implements
setContentView(R.layout.feed_details_activity); setContentView(R.layout.feed_details_activity);
progressDialog = new ProgressDialog(FeedDetailActivity.this); progressDialog = new ProgressDialog(FeedDetailActivity.this);
progressDialog.setMessage("Downloading File"); progressDialog.setIndeterminate(false);
progressDialog.setIndeterminate(true); progressDialog.setTitle("Downloading File");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// progressDialog.setCancelable(true); // progressDialog.setCancelable(true);
...@@ -233,4 +233,29 @@ public class FeedDetailActivity extends Activity implements ...@@ -233,4 +233,29 @@ public class FeedDetailActivity extends Activity implements
return false; return false;
} }
public class DownloadReceiver extends ResultReceiver {
public DownloadReceiver(Handler handler) {
super(handler);
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
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.");
if (progress == 100) {
progressDialog.dismiss();
}
}
}
}
} }
...@@ -136,14 +136,6 @@ public class PlayerActivity extends Activity implements MediaPlayerControl { ...@@ -136,14 +136,6 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
}; };
initTask.execute(); initTask.execute();
// dialog.show();
// dialog.dismiss();
// android.os.Message message = recording.graphicsContext().sizeHandler
// .obtainMessage(0, imgVArray);
// message.sendToTarget();
} }
public void search(String word) { public void search(String word) {
......
package tttclient.services;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
public class DownloadReceiver extends ResultReceiver {
public DownloadReceiver(Handler handler) {
super(handler);
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
// if (resultCode == DownloadService.PROGRESS_UPDATE) {
// ProgressDialog pDialog = (ProgressDialog) progressDialog;
// int progress = resultData.getInt("progress");
//
// pDialog.setProgress(progress);
// if (progress == 100) {
// pDialog.dismiss();
// }
// }
}
}
...@@ -94,12 +94,12 @@ public class DownloadService extends IntentService { ...@@ -94,12 +94,12 @@ public class DownloadService extends IntentService {
total += count; total += count;
// publishing the progress.... // publishing the progress....
Bundle resultData = new Bundle(); Bundle resultData = new Bundle();
resultData.putInt("progress", (int) (total * 100 / fileLength)); if (fileLength > 0)
resultData.putInt("progress",
(int) (total * 100 / fileLength));
receiver.send(PROGRESS_UPDATE, resultData); receiver.send(PROGRESS_UPDATE, resultData);
if (fileLength > 0) // only if total length is known
// publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count); output.write(data, 0, count);
// Log.d("DownloadService", total + " bytes downloaded"); // Log.d("DownloadService", total + " bytes downloaded");
} }
......
...@@ -37,7 +37,6 @@ public class ParseService extends IntentService { ...@@ -37,7 +37,6 @@ public class ParseService extends IntentService {
public ParseService() { public ParseService() {
super("ParseService"); super("ParseService");
// TODO Auto-generated constructor stub
} }
protected InputStream getInputStream() { protected InputStream getInputStream() {
......
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