0

first of all: I am a real noob to programming. I am confident that I can understand what code does, because I used to lern some code languages as a hobby and spent dozens of hours working with Rainmeter. Just so you are informed that I need some basic explanation where to start and how to get any possible code running. So thank you in advance for your patience with me.

What I want to do should actually be pretty easy: I want to create an overlay over the app icons I use on my screen and app drawer, which tints or colors the image dynamically depending on the AccentColor of the Album Art. It may sound weird, but you'll get the idea when you check out this screenshot or this one. As you can see: My icons are basically white lines and everything else is transparent. In case you are wondering: It is unsurprisingly called Lines. Now, I have read a bunch of threads on this forum and skimmed through some tutorials for similiar things on the net, but I couldn't really get the hang of it. So - even though I know this site is mainly used by programmers - I thought I would definetly find a solution here. I am running OxygenOS 4.0 (7.0.0 Nougat) on the OnePlus 3T, unlocked & rooted. Using the Nova Launcher.

I'd honestly appreciate if you took your time to clear things up for me.

EDIT: Meanwhile I have found this but I am not sure how to use it for me? I can't really make any sense of this. I still don't even understand how I can run this? Do I need to create an XML-file? How can I run that? From what I read on the net it seems like I'd have to create a whole new app just to run those few lines of code? Can't I just add those to some specific XML, which already exists?

Community
  • 1
  • 1
Kaiton
  • 33
  • 5

2 Answers2

1

You can use imageView.setColorFilter(Color.parseColor("#FF00000"));

This method works for all android devices all the way to API 1.

However, if you're targeting API 21 (Lollipop) or higher you can use ImageView#setImageTintList which takes a ColorStateList which has the added advantage that you can control the tinting based on various states like pressed, focused and so on.

Usage : imageView.setImageTintList(AppCompatResources.getColorStateList(context, R.color.color_selector));

where color_selector looks like:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:color="hex_color"
        android:state_pressed=["true" | "false"]
        android:state_focused=["true" | "false"]
        android:state_selected=["true" | "false"]
        android:state_checkable=["true" | "false"]
        android:state_checked=["true" | "false"]
        android:state_enabled=["true" | "false"]
        android:state_window_focused=["true" | "false"] />
</selector>
ashkhn
  • 1,642
  • 1
  • 13
  • 18
  • 1
    For most answers it is a good idea to add an explanation to show how the code works, this helps other people with less programming experience understand what the code does. – Rolf ツ Jan 06 '17 at 07:57
  • @Rolfツ I agree that answers should be as detailed as possible however, I'm not sure how I could elaborate on this further. It's pretty intuitive from the method name I think. If you could let me know what's missing I'll gladly edit my answer to add the relevant details – ashkhn Jan 06 '17 at 08:24
  • There are more ways to do this, not only by setting a color filter to an ImageView. Why should the questioner use this method? What are the alternatives? Your could also point him to the documentation for further reference. – Rolf ツ Jan 06 '17 at 08:26
  • Thank you for your answer akash, but does that mean I have to create an app just do to that? What I mean is: Where do I have to add the code to run it? Are there some relevant scritps / .xml-files where I can add such lines and have it run? Also: Is imageView able to actually grab the AccentColor of the AlbumArt like KUSTOM LWP does? Because what I think KLWP does is to save a dublicate of the current AlbumArt in the root directory and pick the "vibrant" color of it as the color for the elements/drawables: [Screenshot](https://puu.sh/td06H/e5c8b808f4.png). How can I do something _that_? – Kaiton Jan 06 '17 at 11:19
  • 1
    I think I may have misunderstood your question earlier then. Yes you will need to create an application. You can write code for using [Android Studio](https://developer.android.com/studio/index.html). Yes ImageView can grab the accent color of the AlbumArt using an API called [Palette](https://developer.android.com/reference/android/support/v7/graphics/Palette.html) – ashkhn Jan 06 '17 at 20:30
  • Thank you very much for your help but I found a workaround without real coding that worked for me, I will post it as an answer for any other users that might have that problem. – Kaiton Jan 07 '17 at 09:54
  • Yeah sure please post the answer so that others facing the same issue may refer to it – ashkhn Jan 07 '17 at 10:23
0

I found a workaround (without coding) using the Android App KLWP and the KLWP Icon Plugin. What I did was:

  1. Using the Icon Plugin and the IconPack you want to use (Lines in my case) to find the icons you want on your HomeScreen and tap them to get the formula.
  2. In KLWP, create a bitmap element and pick the box of the picture selector and tap the calculator icon in the top right to be able to insert the formula (which is actually just an directory to the icon) to the bitmap element. Screenshot.
  3. Next add an colourize filter and also tick it formula-ready and insert following formula. It will basically tint the bitmap according to the current Album Art.

    $if(tc(len,bp(lmuted,mi(cover)))=9,bp(lmuted,mi(cover)),bp(lvibrant,mi(cover)))$

  4. Next use the position tab to place it exactly over the original app icons and now you have two options:

  5. A) You just delete the original icons and add touch-elements to the bitmaps to have them run the corresponding application. This has the downside that opening apps takes longer and you cannot choose an opening animation (it is not even set to system default, so it's just the app being pulled up)

    B) (recomended) You download this icon pack and use it to change your homescreen icons to those empty bitmaps so that they basically are invisible via your launcher (it's pretty straightforward in Nova, don't know about other Launchers). This has the upside that the opening speed and animations stay the same as the changes are only of a cosmetic nature.

Here are some examples of how the finished product looks (depending on your screen's contrast & colour settings the differences might not be that visible).

I hope that helps someone. And thanks to akash93 who took his time to explain it to me programatically.

Kaiton
  • 33
  • 5