My App must have a widget that can show cards and user can turn over cards. StackWidget sample (in Android's resources) has a good widget:
But there is a StackView in layout of widget and it is available since API Level 11 and I have to implement my App for API level 5.
Also I saw this widget that works API level 7 and upper, and I guess uses OpenGL ES:
Finally how we can simulate stack view in Android 2 (API 5)? Or how we can implement a widget like second image (above)?
It is absolutely impossible to use custom views in widgets because of security. You can only use system ones marked with a #RemoteView annotation.
Those fancy animated scrollable 3D widgets OEMs used to put in their firmwares only work with their custom launchers because they are aware of those custom views and allow them to be inflated. Alternatively, these widgets can as well be a part of said custom launchers.
Related
Android Wear Watches are a lot smaller then Android phones, but when looking over the Android API pages and training guides, I didn't see any restrictions on layout elements. Some layouts, however, wouldn't make sense on some watches. For example, a large custom layout ListView wouldn't fit very well on round watches. Are all layout elements really available on Android Wear?
Not all layouts are available (WebView for example). You can see the unsupported libraries here.
And some layouts are meant to be used in Android Wear only.
There is no restriction as far as I know. There are some adjustments that one need to pay attention to in order to have a pleasant UI on both square and round displays, by adjusting the location of items and taking advantage of what the platform adds for handling round vs square, etc but outside of that, all the layouts are, as far as I know, available there too.
Many of the Material Design UIs if not all are dependent on drop shadows. But sadly the elevation attribute is only present on Lollipop devices. So how to create a single consistent UI for your application if something as simple as drop shadows is not available on pre lollipop build versions?
There are of course some workarounds such as creating two versions of each layout, using nine patch drawables, using CardView, etc. But they all have certain problems:
They require creating two versions of every layout, if you wan't to use the lollipop APIs as well for supported devices.
Hard to implement for custom views with different shapes.
Require separate drawables for every view, cluttering up the drawables folder.
The shadows are considered a part of the view itself, so side by side placed views with the same elevation require use of negative margins.
So what is the solution to creating Material Design UIs that work on both Lollipop as well as pre Lollipop devices?
It might not be the ideal solution, but for me using compatibility libraries for all Android versions works pretty well. I own a Galaxy S with Android Gingerbread, so it's really old and certainly doesn't support shadows and ripples. So I wrote a library backporting all things I needed. Rendering realtime shadows for arbitrary shapes is possible since Cupcake (or Froyo - I'm not sure). Ripples are very easy to implement. So it's like this:
One version of each layout
Supports any shape
No additional drawables
Shadows are drawn by layouts, not by shadow casters.
One of the problems is that there's no that new rendering thread, so for example the ripple animation lags when an Activity changes.
If you'd like to know more about my approach, check out my blog and github.
https://androidreclib.wordpress.com/ https://github.com/ZieIony/Carbon
Make use of android support libraries
http://developer.android.com/tools/support-library/features.html#v4-appcompat
My supported OS versions are >= 2.2
Now i want to use some >= 4.0 views in my application, So whats the best way to load different layouts according to different os? say I want to use default time picker in android os < 4.0 and holo theme time picker in android >= 4.0
Is it possible? whats the best way?
See this article.
Basically you can define different layouts per API level (and many other qualifiers). In your case, you would have:
res/layout/my_layout.xml (with the "old" controls).
res/layout-v15/my_layout.xml (with the "new" controls).
A device with API level 15 (i.e. ICS) or greater will use the "new" layout, while those with a lower API level will use the other one.
To simplify your code (e.g. usage of findViewById()) make sure that corresponding views in both layouts have the same ids.
I'm trying to figure out how to enable vertical scroll for an Android widget.
From what I read in the documentation and this post it's possible to do that only from Android version 3.0 and up.
However, I saw a phone (Motorola Razr) with Android version 2.3.6 that had a Gmail widget with a vertical scroll.
So I can't understand if it's possible or not? And if it is possible, how to implement it?
Manufacturers generally build out Android from a custom version of AOSP. Since the entire source for Android 2.3.x is available, it is quite possible that Motorola simply added support for scrolling widgets by modifying the source for their own devices (potentially using the same techniques that AOSP 3.0 does). And if this is indeed the case, that will require changes in the underlying operating system and hence will likely not be available to you if you are building the widgets using the SDK.
If by widgets you are talking about ? extends widget.View, you can always build you own View that does vertical scrolling.
This envolves parsing onTouchEvent (and probably onDispatchTouchEvent) and a lot of math.
I did it myself at work.
I'm working a personal project that's going to include a home-screen widget updated with information from a service - I'm developing using a Android 3.1 tablet (physical) as well as an Android 2.3 emulated phone.
For the Honeycomb version, I'd like to use the StackView, building up 3-4 pages which the user can swipe through, whereas this isn't supported on pre-Honeycomb devices, so is there an easy way to
have Honeycomb devices use a StackView but have Gingerbread/earlier use a TextView (I think this can be done by using res/layouts-v1{1,2,3,4}
Have the RemoteView detect which it is and clear/create the StackView items or set the text on the TextView
You can indicate different layout for pre and post Honeycomb by using the v11 qualifier in your layout names. You can also use the Build class to detect what Build version you're running on and then load the appropriate layout.