Commit bb8e546c by 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,
EditText urlTxt = (EditText) dialog
.findViewById(R.id.tx_url);
String name = nameTxt.getText().toString();
// TODO validate url
String url = urlTxt.getText().toString();
Feed feed = new Feed(name, url);
......
......@@ -5,7 +5,6 @@ import java.util.ArrayList;
import tttclient.models.FeedItem;
import tttclient.models.FeedItemDbManager;
import tttclient.services.DownloadReceiver;
import tttclient.services.DownloadService;
import tttclient.services.ParseService;
import tttclient.utils.Consts;
......@@ -20,6 +19,7 @@ import android.content.IntentFilter;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
......@@ -45,7 +45,7 @@ public class FeedDetailActivity extends Activity implements
ParseService feedParser;
FeedItemDbManager manager;
SimpleCursorAdapter adapter;
public ProgressDialog progressDialog;
ProgressDialog progressDialog;
private final BroadcastReceiver receiver = new BroadcastReceiver() {
......@@ -95,8 +95,8 @@ public class FeedDetailActivity extends Activity implements
setContentView(R.layout.feed_details_activity);
progressDialog = new ProgressDialog(FeedDetailActivity.this);
progressDialog.setMessage("Downloading File");
progressDialog.setIndeterminate(true);
progressDialog.setIndeterminate(false);
progressDialog.setTitle("Downloading File");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// progressDialog.setCancelable(true);
......@@ -233,4 +233,29 @@ public class FeedDetailActivity extends Activity implements
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 {
};
initTask.execute();
// dialog.show();
// dialog.dismiss();
// android.os.Message message = recording.graphicsContext().sizeHandler
// .obtainMessage(0, imgVArray);
// message.sendToTarget();
}
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 {
total += count;
// publishing the progress....
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);
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");
}
......
......@@ -37,7 +37,6 @@ public class ParseService extends IntentService {
public ParseService() {
super("ParseService");
// TODO Auto-generated constructor stub
}
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 sign in to comment