I am trying to figure out some way to determine the current background on a phone and then set that background as my own in my application to create a seamless transition between my application and the phone. However I haven't been able to find any functions for this at Androids SDK site.
Setting android:theme="#style/Theme.NoBackground" inside my Manifest almost does what I want, but it still has the icons in the background.
Thanks in advance
Yeah the WallpaperManager was the answer, a little searching revealed this in one of the API Demos for anyone who needs this.
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
Obviously add the variable wallpaperDrawable to setBackgroundDrawable();
You should also be able to declare in your manifest that your activity should use the 'wallpaper' theme, like so:
<activity android:theme="#android:style/Theme.Wallpaper">
Try to use the following code in your program, so that you can overcome your problem:
activity android:theme="#android:style/Theme.Wallpaper"
this will help for you.
You can do call this.getWallpaper() in your Activity in prior 2.0.
Related
I am making an app and the Google Maps API is a very depending part for me and I want to get a kind of light like this one: http://findicons.com/files/icons/1933/symbols/128/green_light.png
And when the Google maps API is down it changes to a red version of that picture.
greetings
First of all, I think it's safe to assume the Google Maps API won't ever be down. But, to answer your question:
Find the pictures you want to use
Add them as drawables to your app project (java/res/drawable)
Add ImageView to your layout
Add the android:src attribute to your ImageView (in the layout's .xml)
Example:
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/service_online" />
You can also change the ImageView's image source programmatically, more information on that here.
As others said, the Maps API should be present always, but anyway..
You can try to use any method from the API inside a try/catch block inside your app. A simple example:
mApiAvailable = true;
try {
mMapsApi.checkVersion(); // I made up the method name
} catch (Exception ignored) {
mApiAvailable = false;
}
Then for your ImageView (image names are also made up) set the appropriate icon:
mIndicator.setImageResource(mApiAvailable ? R.drawable.api_on : R.drawable.api_off);
You could listen for some location event if such event exists to check the availability again and update the ImageView.
I need to do animation like it is there in Recent App section in Android 5.0.
Like shown in the image below. Any hint or link or even the Animation type used here would be helpful.
Take a look here: https://github.com/vikramkakkar/DeckView
There is also an example here. You can also find about RecentsView here:
https://github.com/android/platform_frameworks_base/blob/59701b9ba5c453e327bc0e6873a9f6ff87a10391/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
I have never done this, but I can point you in the right direction to use StackView. It was added in API level 11 (Android 3.0)
I have found some examples
http://www.broculos.net/2011/12/android-101-how-to-create-stackview.html
http://www.informit.com/articles/article.aspx?p=2078060&seqNum=3
http://www.thaicreate.com/mobile/android-stackview.html
Also this library looks decent
https://github.com/blipinsk/FlippableStackView
Take a look here: https://github.com/ZieIony/MaterialRecents I personally tried it and it looks promising.
You can always look at the official Android source code.
Check the method startRecentsActivity() under packages/SystemUI from the official Android source code.
It's not a very easy-to-read code, but it's definitely the best and most reliable source if you really want to mimic the official Android Lollipop animations.
i have created a github repo with my class i hope it helps,
it's is the start i hope it helps
Stack Cards Android
it makes the same as your image
you can set the difference between cards, scale from card to card,
animation duration, number of cards of course
usage easy just include the class &
// **Paramters definitions** :
// Activity owningActivity, RelativeLayout container, int cardHeightDP, int cardDiffDP,float cardScale, int animationDuration)
StackCards stackCards = new StackCards(yourActivity.this, cardsContainer, 100, 50, (float) 0.2, 500);
//(Number of Cards, The Layout of the Card)
stackCards.initCards(7, R.layout.stack_card);
I'm using following function to enable and disable drawables...
public static void setDrawableState(Drawable d, boolean enabled)
{
if (d == null)
return;
d.mutate(); // so drawables don't share state anymore
if (enabled)
d.setAlpha(255);
else
d.setAlpha(100);
}
This worked on all phones I've tried yet, now I see it does not seem to work on android 4.4.2 (maybe it's not even version specific).
Is there another (better) way to set the alpha of a drawable? Or am I'm missing something?
Because drawables might share the same state, changing the drawable state will not have any effect. You need to mutate the drawable, for example in your code, try something like:
d.mutate().setAlpha(100);
Android developer Blogs has a great blog post explaining more on drawable state and mutations.
in case you wanna be really sure:
Drawable d2 = d.getConstantState().newDrawable().mutate();
d2.setAlpha(100)
I have written a program that can create shortcut of my application in android emulator homescreen.But the problem is when i created the shortcut then it has the default android icon.
My question is how can i change the icon of the shortcut ?
I have used the following line to set the icon
Intent j=new Intent();
j.putExtra(Intent.EXTRA_SHORTCUT_INTENT,i);
j.putExtra(Intent.EXTRA_SHORTCUT_NAME,n);
j.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,R.drawable.icon);
j.putExtra ("duplicate", false);
j.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(j);
The system is not in your context. You therefore need to give more details to send you icon.
see https://github.com/ldo/ShortcutCircus_Android/blob/master/src/Activity2.java
The icon is given by :
Intent.ShortcutIconResource.fromContext(Activity2.this, R.drawable.icon)
Or you could decode the bitmap and use EXTRA_SHORTCUT_ICON instead.
You can do this in two way.
putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,resId);
putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
I have a problem that I want to create an Android App which captures the current wallpaper of Device Desktop, in the background. Which is already done in an App which is shown below in images. as:
Desktop of Device:
And Background of an Clock App:
So, My problem is the same as above, how we set the background of an Activity as the current Desktop WallPaper. Please suggest me the right solution about the same.
Thanks in advance.
set for your activity in the manifest file :
android:theme="#android:style/Theme.Wallpaper"
it will work even if the wallpaper is a live one
To see if current system has wallpaper, you use peekDrawable():
WallpaperManager wallpaperManager1 = WallpaperManager
.getInstance(getApplicationContext());
final Drawable wallpaperDrawable1 = wallpaperManager1.peekDrawable();
And Implement it like this:
if (wallpaperDrawable1==null)
{
Resources res = getResources();
Drawable drawable1=res.getDrawable(R.drawable.bg1);
getWindow().setBackgroundDrawable(drawable1);
}
else
{
getWindow().setBackgroundDrawable(wallpaperDrawable1);
}