Code Monkey home page Code Monkey logo

appiconloader's Introduction

AppIconLoader

Android CI status GitHub release License

Android app icon loader from AOSP iconloaderlib, with optional Glide and Coil integration.

This is not an officially supported Google product.

Why AppIconLoader?

Because PackageManager.getApplicationIcon() (or PackageItemInfo.loadIcon()) just doesn't work well with adaptive icons. Non-adaptive icons usually have some shadow baked in (it's the recommended behavior), however adaptive icons never contain a shadow themselves, so we'll need to manually add the shadow or icons with a white background will just blend into our app's own background.

This library packaged the AOSP iconloaderlib for loading app icons, which has proper shadow and badging logic, and added easy integration with Glide and Coil.

Meanwhile, by passing true for the shrinkNonAdaptiveIcons parameter, this library can also synthesize adaptive icons for apps that don't have it.

Preview

Google Play

Sample APK

Integration

Gradle:

// For using with Glide.
implementation 'me.zhanghai.android.appiconloader:appiconloader-glide:1.5.0'
// For using with Coil.
implementation 'me.zhanghai.android.appiconloader:appiconloader-coil:1.5.0'
// For using AppIconLoader directly.
implementation 'me.zhanghai.android.appiconloader:appiconloader:1.5.0'
// For using iconloaderlib directly.
implementation 'me.zhanghai.android.appiconloader:appiconloader-iconloaderlib:1.5.0'

Usage

Glide integration

See Glide's documentation on registering a ModuleLoader.

Inside your implementation of AppGlideModule.registerComponents(), you can have something like the following code fragment:

int iconSize = context.getResources().getDimensionPixelSize(R.dimen.app_icon_size);
registry.prepend(PackageInfo.class, Bitmap.class, new AppIconModelLoader.Factory(iconSize,
        false, context));

See also the sample app's AppGlideModule implementation.

After the setup above, Glide will support loading app icons with the app's PackageInfo.

GlideApp.with(imageView)
        .load(packageInfo)
        .into(imageView);

Coil integration

val iconSize = context.resources.getDimensionPixelSize(R.dimen.app_icon_size)
Coil.setImageLoader(
    ImageLoader.Builder(context)
        .components {
            add(AppIconKeyer())
            add(AppIconFetcher.Factory(iconSize, false, context))
        }
        .build()
)

After the setup above, Coil will support loading app icons with the app's PackageInfo.

imageView.loadAny(packageInfo)

AppIconLoader

AppIconLoader is the API exposed by this library, and you can simply call AppIconLoader.loadIcon() to load an app icon. You can also use AppIconLoader.getIconKey() to generate a cache key for your loaded icon.

iconloaderlib

Please refer to its source code.

License

Copyright 2020 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

appiconloader's People

Contributors

rikkaw avatar shatyuka avatar zhanghai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.