[Xiaomi Redmi 1S] thewisenerd:
I think I'll take this one post to explain what MusicMode (or MusiqMod) really is, afterall, it's long overdue.

There once was a concept of Sweep2Wake (hereby known as S2W), where you swipe left/right on the screen of a phone, and the phone's screen turns on. Though there is much speculation of when this originally surfaced, and on which device it originally did; it doesn't really matter, does it?

Then, someone clearly got tired of writing the same code again, and again, and again for every device that one developed for, that someone went ahead and put all of that into a separate file, and that became 'modular'.

Then came the concept of DoubleTap2Wake (hereby known as DT2W), LG popularizing it as "KnockKnock", and then eventually figuring out "Knock Code" (which would 'revolutionize' security (for the time being)). Then again, this was modularized (i.e. all code put into another file).

One doesn't really know who came up with the idea, but the basic framework for S2W, and DT2W, is pretty much the same for every possible friggin' device.

S2W: take the initial x co-ordinate; keep tracking the x co-ordinate; once that crosses a particular val; turn on the screen; reset variables at finger release event.

DT2W: take x coordinate, y coordinate (if ! init). track second tap x coordinate, y coordinate. if abs(x2 - x1) < a && abs(y2 - y1) < a (where a is the side length of the little square permissible for dt2w (since obviously you can't tap the exact same pixel on the screen, can you?)

I really have no intention of starting another 'kernel war' here, so I'll just skip to...

today.

So, The Redmi 1S got S2W, DT2W, thanks to some quick porting of showp1984's implementation of S2W and DT2W on the Nexus 5 (the porting part was pretty simple actually, I just had to add the Redmi 1S config and track the ft5x06 touch panel). But then, it wasn't on the keypad exactly. The reason? Well, I myself wasn't very clear at the beginning, and never really looked into the matter.

Then, I just added a small tiny config that tracks the 'earpiece' (the one that is to the right of the camera, and is used during phone calls), and checked its 'status' before actually calling the s2w/dt2w detect functions.

Then, because I felt like it, I went ahead and added a fullscreen option for S2W.

Then, one day, when I was going through some random Xperia Z1 kernel thread (a CTS(close to stock) kernel), someone was discussing about DT2W, and someone suggested to check out alin.p's implementation of it, on a *pretty old* device, which I did. To my amazement, it was awesome. You know good code, when you look at it (when you can understand it, that is). So, I decided to take 'one' of its features, and build upon it.

What it originally did:

DoubleTap2[Wake/Play/Pause]

* This gesture wakes the phone with a double tap on the screen if the lock timeout of 5 seconds hasn't passed yet. If the timeout has passed, double tapping the screen will Play/Pause the music.

* The Media Control feature (Play/Pause) can be disabled, making DoubleTap2Wake work even after the lock timeout has passed.

Now, a quick look at my release notes:

So, if I were to make that for the first post ( i hate big OPs), that've be something like this:

DoubleTap2[Wake/Play/Pause]

* double tapping the screen will Play/Pause the music if headset is plugged in and headset in use. (why? because headset plugged in is a pretty good reason for the screen to act as a media control (like the lockscreen), and moreover, who has time to turn on the phone, and change the song?

* in case you pause playback, and headset is plugged in, you can resume playback regardless of headset in use or not (obviously not, since you paused playback, duh.)

* in case the screen is turned on, then, poof. everything's reset.

Sweep2[Next/Previous]Song

* sweep right to go to next song

* sweep left to go to previous song

There, you have my reason for hating big OPs.

Then, users started complaining that 'it' wasn't working. S2W, DT2W, nothing. The 'problem'? Xiaomi had chose not to use one, but three different types of touch panels around the world for its production of this device (why else would they have three different touch panels enabled in the 'stock' kernel in the first place huh?) So, I went ahead and quickly added support for those touchpanels too.

at some point I remember hackishly fixing up in call touches, but Kra1o5 figured out a better (working fix) (which was improved upon by zeroblade)

Then, I got fed up. I couldn't power on the device if music was on. and that annoyed me. So, I went ahead and disabled s2w controlling music on the navbar area (referring to the bottom most part of the screen which had s2w in the first place) and disabled it.

so, now:

Sweep2[Wake/Next song/Previous song]

and then, at some point; the fact that the keypad wasn't being used for s2w bugged me enough to look into the matter. What I found was that the firmware implementation of touches in the keypad area was such that only button presses were being reported back. So, generic S2W won't work. Also, since finger release event is sent as soon as the finger leaves a button, this would only mean one thing. a *small* scale hack, involving around a 100 lines of code. thus, we finally had s2w with the keypad on S2W.

that didn't do for me. Diagonal swipes were working (with S2W previous/next song). It shouldn't. Swipes should be more or less 'straight'. Fixed that up.

Cleaned up code indentation, and split the screen into three regions. swipes in the top most region would control the volume (because they could, and it was similar to those video player apps, where one side controlled volume, and the other brightness (original motivation behind the new layout for musiqmod)), swipes in the bottom most region would control previous/next song playback. the center region would do nothing.

wait, nothing? yes. I typed that right. I didn't want swipes working over the entire screen. Instead, I figured that it could work out something like a 'remote', with a play/pause button, and next/previous buttons.

thus, I finally stumbled upon this layout, which I've been using for the past 'one' day, so probably, I'm going to stick to it.

-------------------------------------

| volume zone |

| swipe right: vol up |

| swipe left: vol down |

| |

|----------------------------------- | // _Y_B1 (300)

| | | |

| | | |

| | | |

| prev | pause/ | next |

| song | play | song |

| | | |

| | | |

| | | |

| | | |

|-------------------------------------| // _Y_B2 ( _Y_LIMIT - 300 )

| track zone |

| swipe right: next song |

| swipe left: prev song |

| |

-------------------------------------

| |

_X_B1 (200) _X_B2 (_X_MAX - 200)

there, guess that won't be much messed up while rendering.

*never mind; it got messed up. read the commit message here, ain't messed up.

https://github.com/thewisenerd/android_kernel_xiaomi_armani/commit/7674cd32ed22d8a1f3e4924c25bc739ec39f772e