Alex,
The widget_info.xml file can only specify one particular minimum size,
and this is fixed at application build time.
Since widget_info.xml files are referenced from the app widget provider
declarations in the application manifest, there have to be separate
<receiver> blocks there declaring widgets.
Essentially, you're creating what looks to Android (and the users) as
two separate widgets.
You could maybe have one AppWidgetProvider for both widgets, but then
your widget class would have to know which widget size it's working with.
What I ended up doing for my application is this:
### The manifest
<receiver android:name=".WifiWidget_3x1"
android:label="@string/widget_name_3x1">
.... intent-filter snipped ....
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_info_3x1" />
</receiver>
<receiver android:name=".WifiWidget_2x1"
android:label="@string/widget_name_2x1">
.... intent-filter snipped ....
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_info_2x1" />
</receiver>
### widget_info_3x1
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="220dp"
android:minHeight="72dp"
android:initialLayout="@layout/appwidget_3x1"
android:configure="org.kman.WifiManager.WifiWidget_3x1"
>
</appwidget-provider>
### widget_info_2x1 is similar, but has different minWidth / minHeight
values
The widget providers, WifiWidget_3x1 and WifiWidget_2x1, are dervied
from a common base class that does most of the work. So are the config
activities, WifiWidget_3x1 and WifiWidget_2x1.
If you use a ComponentName to access your widgets from the base class,
you should be careful to call getClass() to get the actual Java class
known to Android (3x1 or 2x1) instead of using the common base class
(WifiWidgetBase.class).
-- Kostya
10.10.2010 17:58, Alex пишет:
If an app provides multiple widgets, e.g. 1x1, 3x1 etc., does each
widget need its own AppWidgetProvider or can they share one?
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en