Create a control for Android AppWidget? - android

You can see a list of views that are capable of remote views:
absolutelayout-framelayout-linearlayout-relativelayout-analogclock-button-imagebutton-iamgeview-textview
and other controls.
My question is:
Is there any way to create a custom view that be capable of remoteviews?

Is there any way to create a custom view that be capable of remoteviews?
If, by this, you mean "is there any way to create a custom View that a RemoteViews can use?", at best the only way that is possible is if both apps have that class. So, for example, if you wrote the home screen, and you wrote the app that is publishing an app widget, so you can arrange for your custom View to be in both apps, then maybe you can include that custom View in the layout used as the starting point for the RemoteViews. It's possible that the way RemoteViews inflates the layout that even this approach will not work, though.

Related

Android How to use gauge package in appwidget

Actually I was seeking for a solution to display gauge widget in Android AppWidget.
Inorder to display Gauge package in Home screen widgets like weather widgets in our mobile home screens.
I recommend you to take a look at this documentation.
It explains how to achieve what you were looking for.
After you make the skeleton then you can use the custom gauge widgets.
An app widget uses RemoteViews for describing its UI, and RemoteViews supports a limited number of built-in widgets. You cannot use a custom View subclass directly. After all, your app is not rendering the UI — whatever app has the home screen implementation is rendering the UI, and that app does not have your custom View subclass.
The closest thing that you can do is to put an ImageView in your app widget's layout, then populate that ImageView with bitmaps that depict what you want to show in terms of a gauge UI.

A view for a game without a layout

I'm at the beginning of my development for my game and I have a basic question.
Is the layout necessary for displaying a view?
I have the method which allows me to make the toolbar disappear and set the view screen wide, but it seems a bit useless to do so.
Besides in the snake sample provided in the sdk, the views are merged without a layout.
So, which one is the best practice.
And if it's the layout-less solution, how to do for a unique view to display?
Thanks.
Well, I am as new as you are too, but as far as I have searched and learned online and with a few examples, all I can say is, NO. Game programming does not need any xml layouts. For developing a game, you need to first create a good basic framework. All the views, sprites, actions, audio, etc... is created at background.
This is a very nice tutorial to start with.
It depends on lots of things, but yes you don't need to create an XML layout. Pay attention to the word XML. You can create a custom class which extends SurfaceView and work in cooperate with Thread to do the update. So in this case you just need to set your Activity's Content View to this subclass of SurfaceView. But by using SurfaceView you have a raw of context which means you should do everything from stratch, e.g you should implement your own button.
Beside this it depends on the engine/framework you use too. But for SurfaceView/Canvas API the lines I mentioned above is valid.

Is it possible to make a home-screen widget that contains a SeekBar?

A bit new to Android. I am trying to create a home-screen widget that lets you change ringtone or music volume, using the SeekBar View. I was reading on widgets in http://developer.android.com/guide/topics/appwidgets/index.html, and was surprised to come across a section, "Creating the App Widget Layout," that says only certain classes can be handled by a RemoteViews object, and thus only these can be used in a home-screen widget. The ProgressBar class is supported, but the documentation explicitly says descendant classes are not supported. Since I am trying to create a SeekBar in my widget, which is a descendant of ProgressBar, is this impossible via RemoteViews? If so, is there another method to create widgets which does not rely on RemoteViews? Thanks in advance for any help.
Since I am trying to create a SeekBar in my widget, which is a descendant of ProgressBar, is this impossible via RemoteViews?
Correct.
If so, is there another method to create widgets which does not rely on RemoteViews?
No. You can write your own home screen app, though, and there you can use whatever you want on the home screen, since it is your own app.

how to create a shared view in android

I am having one app where i created a view. And i want to use the same view in another application. Is there any way to pass the second apps context as parameter to the view. So that the view is created second application's context.
Or is there any way to create a view library so that many applications use that view library to create views.
Ron
You can create a class and call it CustomView wich extends View and customize the view. Then, you can use it in both apps.
However, since you already created your view, my suggestion is to copy-paste the code into your new app unless you are planning to use the same view in future apps.
I see two ways to interpret your question. 1) You have a custom View (like a custom control) and want to share it. The earlier answers address that interpretation of the question -- how to share the code that implements the View.
Another interpretation is you want Application "A" to bring up a screen defined by Application "B". That is you want not only the View, but the behavior behind the view.
For this use I would suggest sharing Activities or Fragments rather than Views. You can have application A use Application B's Activity (if Application B is willing) by sending an appropriate Intent.
I would suggest you follow iturki's method or just copying the same layout into each application xml layout file..I dont think that is to difficult. It is practically easier.
In Android source build system you can usually create a jar and export that jar to multiple apps to share the common functionality. Never tried doing it independently. You can check Phone app on Gingerbread. Some functionality is shared between Phone app and Contacts app. Though these are not sharing Views, Ideally you could take this idea forward and implement Views

Is it possible to create a custom notification with controls such as buttons in Android? How?

According to the Android Developers' Guide, it is possible to create a custom notification view. However, is it possible to create one with controls such as buttons and text views? If yes, how?
Note that I think it has something to do with PendingIntent.
Create a RemoteViews object -- like you would for an app widget -- and put it in the contentView public data member of the Notification.

Categories

Resources