Add an overlay to app icon with custom launcher - android

I took the following code to implement my own custom launcher:
https://github.com/fookwood/Launcher3
My goal is it to set an Bitmap or PNG file as an overlay above the normal app icon. But I can´t find the region where google is originally setting the app icon in the "All Apps View". Does somebody know where to look exactly?

Already found it by myself. For everyone who wants to know it. There´s a class called IconCache.Java.
/**
* Fill in "application" with the icon and label for "info."
*/
public synchronized void getTitleAndIcon(AppInfo application, LauncherActivityInfoCompat info,
HashMap<Object, CharSequence> labelCache) {
CacheEntry entry = cacheLocked(application.componentName, info, labelCache,
info.getUser(), false);
application.title = entry.title;
application.iconBitmap = overlay(entry.icon,BitmapFactory.decodeResource(mContext.getResources(), R.drawable.overlay_green));
//application.iconBitmap = entry.icon;
application.contentDescription = entry.contentDescription;
}

Related

Highlight the Menu Item found in Search Result of Android Settings App

Inside Android core Settings App, when we search anything in the search bar, then the result of that search is highlighted automatically.
For e.g. please see below image where I highlighted my application name in the Notification Access section.
I achieved this by following code:
val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS").apply {
val app = "${application.packageName}/${NotificationListener::class.java.name}" //Here NotificationListener is a service name
val fragmentKey = ":settings:fragment_args_key"
val showFragmentKey = ":settings:show_fragment_args"
putExtra(fragmentKey, app)
putExtra(showFragmentKey, Bundle().apply { putString(fragmentKey, app) })
}
I referred to the Solution on this LINK
However, I want to highlight my application name in the Usage Access Setting.
i.e. when I open the intent for Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) then inside the list of apps, my app name must be highlighted.
However the above logic/approach is not working for Usage Access Screen.
My application opens the intent but does not highlight my app name there.
I did a detailed research but I am still facing challenge.
Hence, I request you all to please assist.
For ACTION_USAGE_ACCESS_SETTINGS , I can't find one. Have you seen it anywhere? If so, please show me on which app. I've requested about this here:
https://issuetracker.google.com/issues/165311852
https://issuetracker.google.com/issues/160303945
And one in general, for all settings:
https://issuetracker.google.com/issues/163176781
As for notification-access, check here: stackoverflow.com/a/63914445/878126

Not Getting Thumb with Genres - Universal Music Player

I am using UMP example provided by Google, I have not made any change in my code, even I have not tried anything out of the box, I just imported your project into my work-space and checked it on my device, and found that I am not getting Thumb with Genres (Songs by genre) and List of Genres...
Whereas I supposed to get Thumb from our JSON, here is what I have tried (but no success) -
holder.mImageView.setImageBitmap(description.getIconBitmap());
UPDATE # 1 AS PER SUGGESTED BY #NageshSusarla here
holder.mTitleView.setText(description.getTitle());
holder.mDescriptionView.setText(description.getSubtitle());
AlbumArtCache cache = AlbumArtCache.getInstance();
Bitmap art = cache.getIconImage(url);
if (art == null) {
cache.fetch(url, new AlbumArtCache.FetchListener() {
#Override
public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
if (artUrl.equals(url)) {
holder.mImageView.setImageBitmap(icon);
}
}
});
} else {
holder.mImageView.setImageBitmap(bitmap);
}
holder.mImageView.setImageBitmap(description.getIconBitmap());
and getting Cannot resolve symbol 'url'
The icon bitmap may not have been set. It's best to use the AlbumartCache to fetch the icon and then set it on the imageView. The url to be passed to AlbumArtCache.getInstance().fetch(url,..) is description.getIconUri().toString()
The reason you may not be seeing it in uAmp is because of the tint being applied to it. You can remove the tint from media_list_item.xml to try out the changes.
Aside: This is indeed by design and the icon is only shown at the bottom when a user selects the item to be played.
This is by design. To keep the navigation cleaner, we decided to not
show the MediaItem icon on the local browsing UI. Other browsing UI's
may show it, like Android Auto and Android Wear.
I think you should check it in issues of android-UniversalMusicPlayer. Take a look at comment given by mangini here.
If you want to change uAmp to show the MediaDescription.getIconUri,
set the holder.mImageView at this.

Programmatically add icon to the home screen

I have a website and a mobile web-app for the same service.
I want to when users access the mobile site, to have a button saying "install app" that when pressed, will add the icon to the phone homescreen linking to the mobile web app.
I hope I'm clear, I don't want to make users feel like they are using a native app, from then on, avoiding making them manually add the site to the homescreen.
Thank you
Here's the basic code to create tiles on start:
// check if secondary tile is already made and pinned
ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Title=SecondaryTile"));
if (Tile == null) {
// create a new secondary tile
StandardTileData data = new StandardTileData();
// tile foreground data
data.Title = "Secondary tile";
data.BackgroundImage = new Uri("/Images/Blue.jpg", UriKind.Relative);
data.Count = 2;
// create a new tile for this Second Page
ShellTile.Create(new Uri("/SecondPage.xaml?Title=SecondaryTile", UriKind.Relative), data);
You'll need to navigate it to your desired page, then use the WebBrowserTask to go to the desired web page.
Hope that helps.

Android: access "system"-drawables

I'm currently working on an app to display the battery status and I'd like to use Android-drawables instead of own images to reduce the app size.
I've found this page which lists available images and the availability for each SDK-version:http://www.fixedd.com/projects/android_drawables_display
My question: How can I access the "system"-drawables? If you click on the link and choose the tab "Status", there are some battery-drawables like "stat_sys_battery_0", but I can't access it, Eclipse doesn't offer intellisense for it and won't compile the app if I use one of those drawables.
As those drawables are part of all SDK-versions, I'd think I should be able to use them, or are those "special" drawables protected in a way so they can only be used by system-functions (and not apps)?
Any idea is appreciated.
Select0r
Hope this is what you were looking for:
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
#Override
public void onReceive(Context arg0, Intent intent) {
int level = intent.getIntExtra("level", 0);
int batteryIconId = intent.getIntExtra("icon-small", 0);
Button toolBarBattery = (Button) findViewById(R.id.toolBarButton);
LevelListDrawable batteryLevel = (LevelListDrawable) getResources().getDrawable(batteryIconId);
batteryLevel.setLevel(level);
toolBarBattery.setBackgroundDrawable(batteryLevel);
}
};
I've found another link with information that not all drawables are public. It doesn't say why some drawables would be private, but I guess I'll have to live with the fact and copy the needed images to my app.http://androiddrawableexplorer.appspot.com/
NOTE: Some of the images in the Android jar are not public and therefore cannot be directly used (you can copy them to you own application, but can't reference them via the "android" package namespace).
There actually seems to be a way to access the system icons, but it's not really working as stated in the documentation, but I'll add it in case somebody is interested:
intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, -1)
Will get you the resource-ID of the icon that matches the current battery-status:http://developer.android.com/reference/android/os/BatteryManager.html#EXTRA_ICON_SMALL
Extra for ACTION_BATTERY_CHANGED:
integer containing the resource ID of
a small status bar icon indicating the
current battery state.
However, it always returns the same icon, no matter what the actual battery level is. Finding the icon by just trying random numbers may work, but I don't know if the IDs are consistent throughout the SKD-levels as well as different machines, so I'd rather not rely in that.

Android: Any idea why cannot load drawable object?

There are several custom-made graphic objects (.png files) included in the project inside res/drawable map.
All elements are normally loaded and displayed in the user interface except two icons and so far haven't figured out what causes the problem.
The code which doesn't affect the user interface as it should is the following:
if (settings.isMute()) {
muteIcon.setIconImage(R.drawable.ic_volume_off_small);
} else {
muteIcon.setIconImage(R.drawable.ic_volume_small);
}
In both cases there is only ic_volume_small displayed on the screen and the Variables window in the IDE displays the following:
R.drawable.ic_volume_small = Class not
loaded : net.client.android.R$drawable
R.drawable.ic_volume_of_small = Class
not loaded :
net.client.android.R$drawable
The method (member of IconImage class) which should change the icon image is the following:
public void setIconImage(int imageFromResources) {
iconImage = BitmapFactory.decodeResource(getResources(), imageFromResources);
iconWidth = iconImage.getWidth();
iconHeight = iconImage.getHeight();
invalidate();
}
Does anyone know what could cause the described problem?
Thanks!
Assuming what you want is the drawable from the Android framework and not your own, you'd want to use:
android.R.drawable.ic_volumne_off_small
rather than
R.drawable.ic_volume_off_small
(notice the android prefix).
If you recently added file, please refresh (press F5) the drawable directory and R is going to be generated again. Once R is regenerated, you can use the newly added resource.

Categories

Resources