Why should I use RemoteViews for Android home screen widgets? - android

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.

Related

Android : Difference between Component and Widget?

what is the difference between Component and Widget? in the Android UI Design Level. Difference between Java Class Creative UI and using .xml layout file design?
"widget" for subclasses of View that have a visual representation to the user by default -- things like TextView, Button, ListView, etc.
I tend to use the term "view" for something that could be any subclass of View, including pure containers like LinearLayout.
But, again, there is no particular harm in referring to them by either term.

How to create your own widget and reuse it in other activities android

Right now I am in the process of creating a custom date picker on screen in a test app, but I wish to use it in multiple activities in my app, and it is complex enough that I just don't want to copy and past the code. I was wondering whether there is a way to nicely package it so I can reuse it easily.
Thanks for any help and info!
Create whatever widget u intend to in a separate layout resource say "my_widget. xml"
And then use it another activity's xml (say activity_1.xml) by calling your widget in it, using
<include layout=#layout/my_widget />
Create a custom view (aka widget) following this "Guide" implementing all your customizations you currently have to the view in your activity (as I understood) and then you can reuse your widget anywhere in this application or even on other applications (this is if you export this view into separate lib, and is subject for another discussion)

Map in android widget

I m trying to show map in android widget . But as far as i see there is no mapview in android widget. Anybody please tell me is there any possible way to display a map in android widget?
a Mapview is NOT a view that is supported in a widget. As can be noted here:
http://developer.android.com/guide/topics/appwidgets/index.html
Creating the App Widget layout is simple if you're familiar with XML
Layouts. 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
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper
Descendants of these classes are not supported.
You can use simple ImageView with Static Maps API and draw over returned image from Google Maps. It's not exactly Google Maps, but it's extremely light weight (which is perfect for app widgets).
If you are app developer, there is no way.
If you can modify the framework, you can.

Home screen widget with dynamic size

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);

Tips on making custom, reuesable components in Android

I want to create a component that will appear as a navigation menu for an Android application. Basically, the custom component is a rectangular "Div" (to use HTML terms) that contains six buttons. Each button provides a link to another part of the application. I want to use this on every "page", so I want to make it easy to maintain.
What is the recommended class to extend for creating custom components like this? (I've seen the "Widget" class, but not sure If this should only be used for widget that appear outside the app (like Google search))
And
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
The class to extend is View, the Widget class is for widgets in the homescreen. This is a nice doc to read: Building Custom Components, I suggest to look at the Compound Controls section, that seems suitable for your problem.
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
Yes, once you have written your own view, you just have to add it to your layouts in the XML (just like you do with the android views), something like this:
<com.your.package.YourNiceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

Categories

Resources