inital commit of a working example of a widget
This commit is contained in:
7
HelloWidget/.classpath
Normal file
7
HelloWidget/.classpath
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="gen"/>
|
||||||
|
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
33
HelloWidget/.project
Normal file
33
HelloWidget/.project
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>HelloWidget</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
18
HelloWidget/AndroidManifest.xml
Normal file
18
HelloWidget/AndroidManifest.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="de.thesmile.android.widget"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0">
|
||||||
|
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||||
|
|
||||||
|
<!-- Broadcast Receiver that will process AppWidget updates -->
|
||||||
|
<receiver android:name=".HelloWidget" 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/hello_widget_provider" />
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
</application>
|
||||||
|
<uses-sdk android:minSdkVersion="3" />
|
||||||
|
</manifest>
|
||||||
BIN
HelloWidget/bin/HelloWidget.apk
Normal file
BIN
HelloWidget/bin/HelloWidget.apk
Normal file
Binary file not shown.
BIN
HelloWidget/bin/classes.dex
Normal file
BIN
HelloWidget/bin/classes.dex
Normal file
Binary file not shown.
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/HelloWidget.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/HelloWidget.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/R$attr.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/R$attr.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/R$drawable.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/R$drawable.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/R$id.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/R$id.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/R$layout.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/R$layout.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/R$string.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/R$string.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/R$xml.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/R$xml.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/de/thesmile/android/widget/R.class
Normal file
BIN
HelloWidget/bin/de/thesmile/android/widget/R.class
Normal file
Binary file not shown.
BIN
HelloWidget/bin/resources.ap_
Normal file
BIN
HelloWidget/bin/resources.ap_
Normal file
Binary file not shown.
11
HelloWidget/default.properties
Normal file
11
HelloWidget/default.properties
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# This file is automatically generated by Android Tools.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file must be checked in Version Control Systems.
|
||||||
|
#
|
||||||
|
# To customize properties used by the Ant build system use,
|
||||||
|
# "build.properties", and override values to adapt the script to your
|
||||||
|
# project structure.
|
||||||
|
|
||||||
|
# Project target.
|
||||||
|
target=android-3
|
||||||
BIN
HelloWidget/res/drawable/icon.png
Normal file
BIN
HelloWidget/res/drawable/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
BIN
HelloWidget/res/drawable/widget_bg_normal.9.png
Normal file
BIN
HelloWidget/res/drawable/widget_bg_normal.9.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 268 B |
17
HelloWidget/res/layout/main.xml
Normal file
17
HelloWidget/res/layout/main.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="@drawable/widget_bg_normal"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView android:id="@+id/widget_textview"
|
||||||
|
android:text="@string/widget_text"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal|center"
|
||||||
|
android:layout_marginTop="5dip"
|
||||||
|
android:padding="10dip"
|
||||||
|
android:textColor="@android:color/black" android:clickable="true"/>
|
||||||
|
</LinearLayout>
|
||||||
5
HelloWidget/res/values/strings.xml
Normal file
5
HelloWidget/res/values/strings.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="widget_text">Hello Widget!</string>
|
||||||
|
<string name="app_name">Hello Widget</string>
|
||||||
|
</resources>
|
||||||
14
HelloWidget/res/xml/hello_widget_provider.xml
Normal file
14
HelloWidget/res/xml/hello_widget_provider.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
AppWidget default settings:
|
||||||
|
- setting width and hight
|
||||||
|
- setting update periode to 1 second
|
||||||
|
- setting the initialLayout to layout/widget_text.xml
|
||||||
|
-->
|
||||||
|
|
||||||
|
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:minWidth="146dip"
|
||||||
|
android:minHeight="72dip"
|
||||||
|
android:updatePeriodMillis="10000"
|
||||||
|
android:initialLayout="@layout/main"
|
||||||
|
/>
|
||||||
78
HelloWidget/src/de/thesmile/android/widget/HelloWidget.java
Normal file
78
HelloWidget/src/de/thesmile/android/widget/HelloWidget.java
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package de.thesmile.android.widget;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetManager;
|
||||||
|
import android.appwidget.AppWidgetProvider;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.widget.RemoteViews;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class HelloWidget extends AppWidgetProvider {
|
||||||
|
|
||||||
|
private Date currentTime;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
|
||||||
|
int[] appWidgetIds) {
|
||||||
|
Toast.makeText(context, "onUpdate", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
|
||||||
|
|
||||||
|
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MyTime extends TimerTask {
|
||||||
|
|
||||||
|
RemoteViews remoteViews;
|
||||||
|
AppWidgetManager appWidgetManager;
|
||||||
|
ComponentName thisWidget;
|
||||||
|
DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());
|
||||||
|
|
||||||
|
public MyTime(Context context, AppWidgetManager appWidgetManager) {
|
||||||
|
this.appWidgetManager = appWidgetManager;
|
||||||
|
remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
|
||||||
|
thisWidget = new ComponentName(context, HelloWidget.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
currentTime = new Date();
|
||||||
|
|
||||||
|
remoteViews.setTextViewText(R.id.widget_textview, "Time = " + format.format(currentTime));
|
||||||
|
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
||||||
|
// v1.5 fix that doesn't call onDelete Action
|
||||||
|
final String action = intent.getAction();
|
||||||
|
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
|
||||||
|
final int appWidgetId = intent.getExtras().getInt(
|
||||||
|
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||||
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||||
|
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||||
|
this.onDeleted(context, new int[] { appWidgetId });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.onReceive(context, intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDeleted(Context context, int[] appWidgetIds) {
|
||||||
|
Toast.makeText(context, "onDelete", Toast.LENGTH_SHORT).show();
|
||||||
|
super.onDeleted(context, appWidgetIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user