This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConfigurableWidgetConfigureActivity extends Activity { | |
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; | |
private EditText etUrl; | |
private Button btAdd; | |
private AppWidgetManager widgetManager; | |
private RemoteViews views; | |
@Override | |
public void onCreate(Bundle icicle) { | |
super.onCreate(icicle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest package="com.erenutku.simplewidgetexample" | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
<application...> | |
... | |
<receiver android:name=".SimpleAppWidget"> | |
<intent-filter> | |
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> | |
</intent-filter> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UpdatingWidget extends AppWidgetProvider { | |
private PendingIntent service; | |
@Override | |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | |
final AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | |
final Intent i = new Intent(context, UpdateService.class); | |
if (service == null) { | |
service = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UpdateService extends Service { | |
@Nullable | |
@Override | |
public IBinder onBind(Intent intent) { | |
return null; | |
} | |
@Override | |
public int onStartCommand(Intent intent, int flags, int startId) { | |
// generates random number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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="wrap_content" | |
android:orientation="vertical" | |
android:padding="16dp"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BroadcastWidget extends AppWidgetProvider { | |
private static final String ACTION_SIMPLEAPPWIDGET = "ACTION_BROADCASTWIDGETSAMPLE"; | |
private static int mCounter = 0; | |
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, | |
int appWidgetId) { | |
// Construct the RemoteViews object | |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.broadcast_widget); | |
// Construct an Intent which is pointing this class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SimpleAppWidget extends AppWidgetProvider { | |
@Override | |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | |
// There may be multiple widgets active, so update all of them | |
for (int appWidgetId : appWidgetIds) { | |
updateAppWidget(context, appWidgetManager, appWidgetId); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<appwidget-provider | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:initialKeyguardLayout="@layout/simple_app_widget" | |
android:initialLayout="@layout/simple_app_widget" | |
android:minHeight="60dp" | |
android:minWidth="60dp" | |
android:previewImage="@android:drawable/ic_menu_add" | |
android:resizeMode="horizontal|vertical" | |
android:updatePeriodMillis="0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView | |
android:id="@+id/tvWidget" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_margin="@dimen/widget_margin" | |
android:background="#ff6200" |
NewerOlder