Home screen widget with dynamic size - android

Is it possible to create a Home Screen widget dynamically (that is without defining a fixed layout in project resources)?
Currently I have 4 layouts - but to cover all options I'll need at least 15 different layouts with different width / height which fills up the widget selector for user.
I'd prefer to offer the widget design in App preferences then create layout as required.

You can't change the widget size, unless you are on a tablet which is running Android 3.1 (Honeycomb). Otherwise you have to specify all the sizes you need as a single widget.
Regarding all the different layouts and the filled widget selector. You only have to add one entry there for every size. After the user clicks on one of these entries,
you can implement a configuration/select-activity (e.g. like you can see in sense, or the News&Weather app from google where you pick a layout with weather, news or both).
The user can pick a layout there for the widget. You just have to remember that choice and
set the correct layout when the widget is updating. You can change the widgets layout
inside the RemoveViews constructor that you have inside a widget update function anyway:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

Related

How to make Preference widget appear below title in Android?

I'm new to Android development and wonder if there is an easy way to have a Preference (androidx.preference.Preference) with the widget appearing below the title? I am aware that layoutResource can be set to a custom layout, but I actually only need to change the widget (so I can set widgetLayoutResource instead of layoutResource) and I want it to appear below the title. If I change the whole layout to a custom one, I have to make it look like the other Preference layouts manually, which seems like an overkill given that I only want to change the title position.

Android Form Widget Size

How do I take into account form widgets eg Editbox, checkbox being different sizes in different android themes when designing my forms?
I am using proper relative layouts, but when I have several widgets in the table layout for example, and change the theme, some drop off the bottom!
Thanks
Well, for the "dropping off the bottom", all you need to do is add a ScrollView.
If you don't know how to use it, you can look it up here.
If your aim is to change the sizes of your widgets based on the phone, all that you will need to do is give a different layout file for your activity for each ldpi,mdpi,hdpi,xhdpi. with those specifications.
Look up "Providing different layout for different screen sizes" here

Android: multiple AppWidgets - one manifest entry

In my app I have a 4x2 Widget and now I wanted a second 4x1 Widget displayig almost the same content, so I created a secondary appwidget-provider xml. When I then wanted to use the same Widgetprovider Android only showed one widget in the list. :-(
As I found out, you have to use for each Widget defined in the Manifest another widgetprovider... why?
how to add multiple widgets in one app?
Furthermore I would liek to have only one widget entry in the List...
Can I change the appwidget-provider xml in the AppWidgetConfig Activity so that I don't have to use the initial size? how?
you have to use for each Widget defined in the Manifest another widgetprovider... why?
Because that is the way they wrote it.
Furthermore I would liek to have only one widget entry in the List
Then only define one AppWidgetProvider for only one size of app widget.
Can I change the appwidget-provider xml in the AppWidgetConfig Activity so that I don't have to use the initial size?
No.

Android widget select type/size like in HTC Sense

Is it possible to change android:minWidth and android:minHeight in widget configuration activity.
I want to be able to give user a selection of different sizes/types like in htc sense widgets, how did they succeed?
Different sizes in one menu entry are not possible. Thats a sense/custom launcher specific feature. The only exception is Honeycomb, you can have resizable widgets there.
What you can do is multiple types of widgets from one menu entry, as long as they are the same size. Use a configuration activity to select the type, remember it (e.g. in the SharedPreferences) and then set the layout in your RemoteViews when updating the widgets accordingly. You can use the appWidgetId as an identifier to remember which instance has which layout.
I don't think vanilla Android can do what your after.
I suspect sense has a custom Launcher
However you could try using the AppWidgetProviderInfo class, something like the following:
AppWidgetProviderInfo widget_info = appWidgetManager.getAppWidgetInfo(appWidgetId);
widget_info.minWidth = 72;
widget_info.minHeight = 72;
Obviously you'd set values as per your the users choice in the widget configuration activity ((number of cols or rows * 74) - 2)
I'm also not entirely sure if changes to those fields persist.
Sorry for the uncertainty, hopefully this will at least give you something to try.

Why should I use RemoteViews for Android home screen widgets?

I'm trying to realize an Android home screen widget. I am interested to know why I should use RemoteViews in implementing widgets?
Refer this link site.
Creating the App Widget layout is simple if you're familiar with Declaring Layout in XML. However, you must be aware that App Widget layouts are based on RemoteViews, which do not support every kind of layout or view widget.
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
And the following widget classes:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
Descendants of these classes are not supported.
Most of the time Widget is hosted within another application, like Launcher, which is run within that parent application's process.
RemoteViews describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.
The main reason behind this choice is related to security and performance.
RemoteViews is used for the app widgets. They are part of separate process but bind to the main process i.e. why when we click over widgets it redirects to the associated application with more detailed information.

Categories

Resources