use of android.widget.RemoteViews in project FileDownloaderManager by arlyxiao.
the class NotificationServiceBar method pause_notification.
public void pause_notification(ArrayList<FileDownloader> download_store_list, FileDownloader file_downloader, int notice_id) {
int length = download_store_list.size();
if (length > 0) {
return;
}
String downloaded_size = download_service.show_human_size(file_downloader.downloaded_size);
String file_size = download_service.show_human_size(file_downloader.file_size);
android.support.v4.app.NotificationCompat.Builder mBuilder = new android.support.v4.app.NotificationCompat.Builder(context);
mBuilder.setContentTitle("Download").setContentText(Integer.toString(file_downloader.downloaded_size)).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setWhen(System.currentTimeMillis());
Notification notification = mBuilder.getNotification();
RemoteViews content_view = new RemoteViews(context.getPackageName(), R.layout.single_pause_notification);
content_view.setImageViewResource(R.id.progress_pause_image, R.drawable.ic_launcher);
content_view.setTextViewText(R.id.progress_title_text, Tool.regenerate_filename(file_downloader.get_file_name()));
content_view.setTextViewText(R.id.progress_percentage, downloaded_size + " / " + file_size);
content_view.setTextViewText(R.id.wait_text, "下载暂停");
final ComponentName receiver = new ComponentName(file_downloader.context, file_downloader.activity_class);
Intent notice_intent = new Intent(file_downloader.context.getClass().getName() + System.currentTimeMillis());
notice_intent.setComponent(receiver);
String param_name1 = file_downloader.intent_extras.getString("param_name1");
Log.i("notification bar 测试值 ", param_name1);
if (file_downloader.intent_extras != null) {
notice_intent.putExtras(file_downloader.intent_extras);
}
PendingIntent p_intent = PendingIntent.getActivity(file_downloader.context, 0, notice_intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.contentIntent = p_intent;
content_view.setOnClickPendingIntent(R.id.progress_content_pause, p_intent);
notification.contentView = content_view;
download_service.startForeground(notice_id, notification);
}
use of android.widget.RemoteViews in project AndroidSDK-RecipeBook by gabu.
the class MyActivity method onCreate.
@Override
public void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.activity);
// EditText
EditText editText = (EditText) findViewById(R.id.EditText01);
// Widget の id を受け取る
final Uri uri = getIntent().getData();
// 過去のデータを表示
if (uri != null) {
int id = (int) ContentUris.parseId(uri);
editText.setText(loadText(id));
}
// Button
Button button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = MyActivity.this;
AppWidgetManager manager = AppWidgetManager.getInstance(context);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
EditText editText = (EditText) findViewById(R.id.EditText01);
CharSequence text = editText.getText();
if (uri != null) {
int id = (int) ContentUris.parseId(uri);
Log.d("MyActivity", "id:" + id);
// 入力された値を保存
saveText(id, text);
// Widget 表示を更新
remoteViews.setTextViewText(R.id.TextView01, text);
manager.updateAppWidget(id, remoteViews);
}
finish();
}
});
}
use of android.widget.RemoteViews in project FBReaderJ by geometer.
the class BookDownloaderService method createDownloadProgressNotification.
private Notification createDownloadProgressNotification(String title) {
final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
contentView.setTextViewText(R.id.download_notification_title, title);
contentView.setTextViewText(R.id.download_notification_progress_text, "");
contentView.setProgressBar(R.id.download_notification_progress_bar, 100, 0, true);
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
final Notification notification = new Notification();
notification.icon = android.R.drawable.stat_sys_download;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.contentView = contentView;
notification.contentIntent = contentIntent;
return notification;
}
use of android.widget.RemoteViews in project FBReaderJ by geometer.
the class BookDownloaderService method startFileDownload.
private void startFileDownload(final String urlString, final File file, final String title) {
myDownloadingURLs.add(urlString);
sendDownloaderCallback();
final int notificationId = NotificationUtil.getDownloadId(file.getPath());
final Notification progressNotification = createDownloadProgressNotification(title);
final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
myOngoingNotifications.add(Integer.valueOf(notificationId));
notificationManager.notify(notificationId, progressNotification);
final int MESSAGE_PROGRESS = 0;
final int MESSAGE_FINISH = 1;
final Handler handler = new Handler() {
public void handleMessage(Message message) {
switch(message.what) {
case MESSAGE_PROGRESS:
{
final int progress = message.arg1;
final RemoteViews contentView = (RemoteViews) progressNotification.contentView;
final boolean showPercent = progress >= 0;
contentView.setTextViewText(R.id.download_notification_progress_text, showPercent ? progress + "%" : "");
contentView.setProgressBar(R.id.download_notification_progress_bar, 100, showPercent ? progress : 0, !showPercent);
notificationManager.notify(notificationId, progressNotification);
break;
}
case MESSAGE_FINISH:
myDownloadingURLs.remove(urlString);
NotificationUtil.drop(BookDownloaderService.this, notificationId);
myOngoingNotifications.remove(Integer.valueOf(notificationId));
notificationManager.notify(notificationId, createDownloadFinishNotification(file, title, message.arg1 != 0));
sendDownloaderCallback();
doStop();
break;
}
}
};
final ZLNetworkRequest request = new ZLNetworkRequest.Get(urlString) {
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
// FIXME: remove hardcoded time constant
final int updateIntervalMillis = 1000;
int downloadedPart = 0;
long progressTime = System.currentTimeMillis() + updateIntervalMillis;
if (length <= 0) {
handler.sendMessage(handler.obtainMessage(MESSAGE_PROGRESS, -1, 0, null));
}
final OutputStream outStream;
try {
outStream = new FileOutputStream(file);
} catch (FileNotFoundException ex) {
throw ZLNetworkException.forCode(ZLNetworkException.ERROR_CREATE_FILE, file.getPath());
}
try {
final byte[] buffer = new byte[8192];
while (true) {
final int size = inputStream.read(buffer);
if (size <= 0) {
break;
}
downloadedPart += size;
if (length > 0) {
final long currentTime = System.currentTimeMillis();
if (currentTime > progressTime) {
progressTime = currentTime + updateIntervalMillis;
handler.sendMessage(handler.obtainMessage(MESSAGE_PROGRESS, downloadedPart * 100 / length, 0, null));
}
}
outStream.write(buffer, 0, size);
}
final BookCollectionShadow collection = new BookCollectionShadow();
collection.bindToService(BookDownloaderService.this, new Runnable() {
@Override
public void run() {
collection.rescan(file.getPath());
collection.unbind();
}
});
} finally {
outStream.close();
}
}
};
final Thread downloader = new Thread(new Runnable() {
public void run() {
boolean success = false;
try {
SQLiteCookieDatabase.init(BookDownloaderService.this);
myNetworkContext.perform(request);
success = true;
} catch (final ZLNetworkException e) {
e.printStackTrace();
final String title = getResource().getResource("downloadFailed").getValue();
handler.post(new Runnable() {
public void run() {
showMessageText(title + ": " + e.getMessage());
}
});
file.delete();
} finally {
handler.sendMessage(handler.obtainMessage(MESSAGE_FINISH, success ? 1 : 0, 0, null));
}
}
});
downloader.setPriority(Thread.MIN_PRIORITY);
downloader.start();
}
use of android.widget.RemoteViews in project XobotOS by xamarin.
the class AppWidgetHost method createView.
/**
* Create the AppWidgetHostView for the given widget.
* The AppWidgetHost retains a pointer to the newly-created View.
*/
public final AppWidgetHostView createView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget);
view.setAppWidget(appWidgetId, appWidget);
synchronized (mViews) {
mViews.put(appWidgetId, view);
}
RemoteViews views;
try {
views = sService.getAppWidgetViews(appWidgetId);
} catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
}
view.updateAppWidget(views);
return view;
}
Aggregations