Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

completed WidgetAlarmManagerExample project.

commit a66f19a9bafe4ae0f0d3bf6e294f0cfe651a47dd 1 parent bb60663
@rakeshcusat authored
Showing with 114 additions and 91 deletions.
  1. BIN  AndroidProjects/AlarmManagerExample/bin/AlamarManagerExample.apk
  2. BIN  AndroidProjects/AlarmManagerExample/bin/AlarmManagerExample.apk
  3. +0 −3  AndroidProjects/AlarmManagerExample/bin/jarlist.cache
  4. BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-hdpi/ic_launcher.png
  5. BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-ldpi/ic_launcher.png
  6. BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-mdpi/ic_launcher.png
  7. BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-xhdpi/ic_launcher.png
  8. +13 −1 AndroidProjects/WidgetAlarmManagerExample/AndroidManifest.xml
  9. +13 −1 AndroidProjects/WidgetAlarmManagerExample/bin/AndroidManifest.xml
  10. BIN  AndroidProjects/WidgetAlarmManagerExample/bin/WidgetAlarmManagerExample.apk
  11. +0 −3  AndroidProjects/WidgetAlarmManagerExample/bin/jarlist.cache
  12. 0  ...dProjects/{AlarmManagerExample → WidgetAlarmManagerExample}/bin/res/drawable-hdpi/ic_action_search.png
  13. BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-hdpi/ic_launcher.png
  14. BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-ldpi/ic_launcher.png
  15. 0  ...dProjects/{AlarmManagerExample → WidgetAlarmManagerExample}/bin/res/drawable-mdpi/ic_action_search.png
  16. BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-mdpi/ic_launcher.png
  17. 0  ...Projects/{AlarmManagerExample → WidgetAlarmManagerExample}/bin/res/drawable-xhdpi/ic_action_search.png
  18. BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-xhdpi/ic_launcher.png
  19. +3 −4 AndroidProjects/WidgetAlarmManagerExample/gen/com/rakesh/widgetalarmmanagerexample/R.java
  20. +18 −0 AndroidProjects/WidgetAlarmManagerExample/res/layout/time_widget_layout.xml
  21. +0 −17 AndroidProjects/WidgetAlarmManagerExample/res/layout/widget_layout.xml
  22. +0 −1  AndroidProjects/WidgetAlarmManagerExample/res/values/strings.xml
  23. +1 −1  AndroidProjects/WidgetAlarmManagerExample/res/xml/widget_metadata.xml
  24. +27 −46 ...jects/WidgetAlarmManagerExample/src/com/rakesh/widgetalarmmanagerexample/AlarmManagerBroadcastReceiver.java
  25. +27 −12 AndroidProjects/WidgetAlarmManagerExample/src/com/rakesh/widgetalarmmanagerexample/TimeWidgetProvider.java
  26. +12 −0 AndroidProjects/WidgetAlarmManagerExample/src/com/rakesh/widgetalarmmanagerexample/Utility.java
  27. +0 −2  ...Projects/WidgetAlarmManagerExample/src/com/rakesh/widgetalarmmanagerexample/WidgetAlarmManagerActivity.java
View
BIN  AndroidProjects/AlarmManagerExample/bin/AlamarManagerExample.apk
Binary file not shown
View
BIN  AndroidProjects/AlarmManagerExample/bin/AlarmManagerExample.apk
Binary file not shown
View
3  AndroidProjects/AlarmManagerExample/bin/jarlist.cache
@@ -1,3 +0,0 @@
-# cache for current jar dependecy. DO NOT EDIT.
-# format is <lastModified> <length> <SHA-1> <path>
-# Encoding is UTF-8
View
BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-hdpi/ic_launcher.png
Deleted file not rendered
View
BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-ldpi/ic_launcher.png
Deleted file not rendered
View
BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-mdpi/ic_launcher.png
Deleted file not rendered
View
BIN  AndroidProjects/AlarmManagerExample/bin/res/drawable-xhdpi/ic_launcher.png
Deleted file not rendered
View
14 AndroidProjects/WidgetAlarmManagerExample/AndroidManifest.xml
@@ -11,7 +11,7 @@
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
- android:theme="@style/AppTheme" >
+ >
<activity
android:name=".WidgetAlarmManagerActivity"
android:label="@string/title_activity_widget_alarm_manager" >
@@ -21,6 +21,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <!-- Widget Broadcast receiver -->
+ <receiver
+ android:name=".TimeWidgetProvider"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data
+ android:name="android.appwidget.provider"
+ android:resource="@xml/widget_metadata" />
+ </receiver>
<!-- Broadcast receiver -->
<receiver android:name=".AlarmManagerBroadcastReceiver"></receiver>
</application>
View
14 AndroidProjects/WidgetAlarmManagerExample/bin/AndroidManifest.xml
@@ -11,7 +11,7 @@
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
- android:theme="@style/AppTheme" >
+ >
<activity
android:name=".WidgetAlarmManagerActivity"
android:label="@string/title_activity_widget_alarm_manager" >
@@ -21,6 +21,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <!-- Widget Broadcast receiver -->
+ <receiver
+ android:name=".TimeWidgetProvider"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data
+ android:name="android.appwidget.provider"
+ android:resource="@xml/widget_metadata" />
+ </receiver>
<!-- Broadcast receiver -->
<receiver android:name=".AlarmManagerBroadcastReceiver"></receiver>
</application>
View
BIN  AndroidProjects/WidgetAlarmManagerExample/bin/WidgetAlarmManagerExample.apk
Binary file not shown
View
3  AndroidProjects/WidgetAlarmManagerExample/bin/jarlist.cache
@@ -1,3 +0,0 @@
-# cache for current jar dependecy. DO NOT EDIT.
-# format is <lastModified> <length> <SHA-1> <path>
-# Encoding is UTF-8
View
0  ...in/res/drawable-hdpi/ic_action_search.png → ...in/res/drawable-hdpi/ic_action_search.png
File renamed without changes
View
BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0  ...in/res/drawable-mdpi/ic_action_search.png → ...in/res/drawable-mdpi/ic_action_search.png
File renamed without changes
View
BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0  ...n/res/drawable-xhdpi/ic_action_search.png → ...n/res/drawable-xhdpi/ic_action_search.png
File renamed without changes
View
BIN  AndroidProjects/WidgetAlarmManagerExample/bin/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 AndroidProjects/WidgetAlarmManagerExample/gen/com/rakesh/widgetalarmmanagerexample/R.java
@@ -27,16 +27,15 @@
}
public static final class layout {
public static final int activity_widget_alarm_manager=0x7f030000;
- public static final int widget_layout=0x7f030001;
+ public static final int time_widget_layout=0x7f030001;
}
public static final class menu {
public static final int activity_widget_alarm_manager=0x7f080000;
}
public static final class string {
public static final int app_name=0x7f060000;
- public static final int hello_world=0x7f060001;
- public static final int menu_settings=0x7f060002;
- public static final int title_activity_widget_alarm_manager=0x7f060003;
+ public static final int menu_settings=0x7f060001;
+ public static final int title_activity_widget_alarm_manager=0x7f060002;
}
public static final class style {
public static final int AppTheme=0x7f070000;
View
18 AndroidProjects/WidgetAlarmManagerExample/res/layout/time_widget_layout.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:background="@drawable/widget_background" >
+
+ <TextView
+ android:id="@+id/tvTime"
+ style="@android:style/TextAppearance.Medium"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:layout_margin="4dip"
+ android:gravity="center_horizontal|center_vertical"
+ android:textColor="#000000" />
+
+</LinearLayout>
View
17 AndroidProjects/WidgetAlarmManagerExample/res/layout/widget_layout.xml
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="@drawable/widget_background" >
- <TextView
- android:id="@+id/tvTime"
- style="@android:style/TextAppearance.Medium"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center"
- android:gravity="center_horizontal|center_vertical"
- android:layout_margin="4dip"
- />
-
-</LinearLayout>
View
1  AndroidProjects/WidgetAlarmManagerExample/res/values/strings.xml
@@ -1,7 +1,6 @@
<resources>
<string name="app_name">WidgetAlarmManagerExample</string>
- <string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_widget_alarm_manager">WidgetAlarmManagerActivity</string>
View
2  AndroidProjects/WidgetAlarmManagerExample/res/xml/widget_metadata.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
- android:initialLayout="@layout/widget_layout"
+ android:initialLayout="@layout/time_widget_layout"
android:minHeight="40dp"
android:minWidth="130dp"
android:updatePeriodMillis="1800000" >
View
73 ...anagerExample/src/com/rakesh/widgetalarmmanagerexample/AlarmManagerBroadcastReceiver.java
@@ -1,16 +1,14 @@
package com.rakesh.widgetalarmmanagerexample;
-import java.text.Format;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
import android.app.AlarmManager;
import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.os.Bundle;
import android.os.PowerManager;
+import android.widget.RemoteViews;
import android.widget.Toast;
public class AlarmManagerBroadcastReceiver extends BroadcastReceiver {
@@ -18,46 +16,29 @@
final public static String ONE_TIME = "onetime";
@Override
public void onReceive(Context context, Intent intent) {
- PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "YOUR TAG");
- //Acquire the lock
- wl.acquire();
+ PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+ PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "YOUR TAG");
+ //Acquire the lock
+ wl.acquire();
- //You can do the processing here update the widget/remote views.
-
- Toast.makeText(context, getCurrentTime(), Toast.LENGTH_LONG).show();
-
- //Release the lock
- wl.release();
-
- }
- public void SetAlarm(Context context)
- {
- AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
- intent.putExtra(ONE_TIME, Boolean.FALSE);
- PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
- //After after 30 seconds
- am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 5 , pi);
- }
+ //You can do the processing here update the widget/remote views.
+ RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
+ R.layout.time_widget_layout);
+ String time = Utility.getCurrentTime("hh:mm:ss a");
+ remoteViews.setTextViewText(R.id.tvTime, time);
+ //Toast.makeText(context, time, Toast.LENGTH_LONG).show();
+ ComponentName thiswidget = new ComponentName(context, TimeWidgetProvider.class);
+ AppWidgetManager manager = AppWidgetManager.getInstance(context);
+ manager.updateAppWidget(thiswidget, remoteViews);
+ //Release the lock
+ wl.release();
- public void CancelAlarm(Context context)
- {
- Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
- PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
- AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- alarmManager.cancel(sender);
- }
- public void setOnetimeTimer(Context context){
- AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
- intent.putExtra(ONE_TIME, Boolean.TRUE);
- PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
- am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pi);
- }
-
- public static String getCurrentTime(){
- Format formatter = new SimpleDateFormat("hh:mm a");
- return formatter.format(new Date());
- }
-}
+ }
+ public void setOnetimeTimer(Context context){
+ AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
+ Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
+ intent.putExtra(ONE_TIME, Boolean.TRUE);
+ PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
+ am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pi);
+ }
+}
View
39 ...idgetAlarmManagerExample/src/com/rakesh/widgetalarmmanagerexample/TimeWidgetProvider.java
@@ -4,49 +4,64 @@
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.widget.RemoteViews;
+import android.widget.Toast;
public class TimeWidgetProvider extends AppWidgetProvider {
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
- // TODO Auto-generated method stub
+ Toast.makeText(context, "TimeWidgetRemoved id(s):"+appWidgetIds, Toast.LENGTH_SHORT).show();
super.onDeleted(context, appWidgetIds);
}
@Override
public void onDisabled(Context context) {
- super.onDisabled(context);
+ Toast.makeText(context, "onDisabled():last widget instance removed", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
- PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
- AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- alarmManager.cancel(sender);
+ PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
+ AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ alarmManager.cancel(sender);
+ super.onDisabled(context);
}
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
- PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
- //After after 5 seconds
- am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ 100 * 3, 1000 * 5 , pi);
+ Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
+ PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
+ //After after 3 seconds
+ am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ 100 * 3, 1000 , pi);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
- super.onUpdate(context, appWidgetManager, appWidgetIds);
-
+ ComponentName thisWidget = new ComponentName(context,
+ TimeWidgetProvider.class);
+
+ for (int widgetId : appWidgetManager.getAppWidgetIds(thisWidget)) {
+
+ //Get the remote views
+ RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
+ R.layout.time_widget_layout);
+ // Set the text with the current time.
+ remoteViews.setTextViewText(R.id.tvTime, Utility.getCurrentTime("hh:mm:ss a"));
+
+ appWidgetManager.updateAppWidget(widgetId, remoteViews);
+ }
}
@Override
public void onAppWidgetOptionsChanged(Context context,
AppWidgetManager appWidgetManager, int appWidgetId,
Bundle newOptions) {
- // TODO Auto-generated method stub
+ Toast.makeText(context, "onAppWidgetOptionsChanged() called", Toast.LENGTH_SHORT).show();
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId,
newOptions);
}
View
12 ...dProjects/WidgetAlarmManagerExample/src/com/rakesh/widgetalarmmanagerexample/Utility.java
@@ -0,0 +1,12 @@
+package com.rakesh.widgetalarmmanagerexample;
+
+import java.text.Format;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class Utility {
+ public static String getCurrentTime(String timeformat){
+ Format formatter = new SimpleDateFormat(timeformat);
+ return formatter.format(new Date());
+ }
+}
View
2  ...rmManagerExample/src/com/rakesh/widgetalarmmanagerexample/WidgetAlarmManagerActivity.java
@@ -3,8 +3,6 @@
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
-import android.view.MenuItem;
-import android.support.v4.app.NavUtils;
public class WidgetAlarmManagerActivity extends Activity {
Please sign in to comment.
Something went wrong with that request. Please try again.