Skip to content

Commit

Permalink
Merge pull request #4 from OriKerer/triple-tap-functionality
Browse files Browse the repository at this point in the history
Triple tap functionality
  • Loading branch information
kerero committed Mar 19, 2021
2 parents 4f25f62 + 49ba916 commit 24ab57d
Show file tree
Hide file tree
Showing 46 changed files with 160 additions and 107 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
.DS_Store
/build
/captures
.externalNativeBuild


# Built application files
*.apk
Expand Down Expand Up @@ -51,7 +49,6 @@ proguard/
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
## Airdots Double-Tap
##### Adds the functionality to skip songs on double-tap with the "Xiaomi Airdots" (Will work with other earphones that activate personal assitant)
##### Adds the functionality to skip songs on double-tap with the "Xiaomi Airdots" (Will work with other earphones that activate personal assistant)
There are other apps with the same functionality (like MacroDroid) But they will keep running in the background.
I personally didn't liked this. Therefore AirdotsDoubleTap app will only run while skipping the song.
#
### You can download the APK from the release sectione [here](https://github.com/OriKerer/AirdotsDoubleTap/releases)
### You can download the APK from the release section [here](https://github.com/OriKerer/AirdotsDoubleTap/releases)
#
### How to use
* Install the app
* Double tap the airdots
* The device will ask you with which app to complete the action
* Select always with AirdotsDoubleTap

### Play Previous song
- Pouse the media with one tap
- Once the media is poused double tap
#
#### Tested on:
- Android 8.1 (Nexus 5x)
- Android 9
- Android 10 (Galaxy s10e)
- Android 11

20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
compileSdkVersion 30
buildToolsVersion '30.0.3'
defaultConfig {
applicationId "com.orik.airdotsdoubletap"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
targetSdkVersion 30
versionCode 3
versionName "1.2"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
Expand All @@ -26,9 +26,9 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.orik.airdotsdoubletap

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -18,7 +18,7 @@ class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.orik.airdotsdoubletap", appContext.packageName)
}
}
41 changes: 25 additions & 16 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.orik.airdotsdoubletap">
xmlns:tools="http://schemas.android.com/tools"
package="com.orik.airdotsdoubletap">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:ignore="GoogleAppIndexingWarning"
android:theme="@android:style/Theme.NoDisplay">

<activity
android:name="com.orik.airdotsdoubletap.MainActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:showOnLockScreen="true">
<intent-filter >
<action android:name="android.intent.action.VOICE_COMMAND" />
android:allowBackup="true"
android:icon="@mipmap/new_ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/new_ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".Settings">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:theme="@android:style/Theme.NoDisplay"
android:showOnLockScreen="true">

<intent-filter>
<action android:name="android.intent.action.VOICE_COMMAND" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>

</manifest>
25 changes: 20 additions & 5 deletions app/src/main/java/com/orik/airdotsdoubletap/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.orik.airdotsdoubletap

import android.content.Context
import android.support.v7.app.AppCompatActivity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlin.system.exitProcess
import android.view.KeyEvent
Expand All @@ -22,11 +22,26 @@ class MainActivity : AppCompatActivity() {
private fun skipTrack(appContext: Context) {
val mAudioManager = appContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
val eventTime = SystemClock.uptimeMillis()
var keyCode = KeyEvent.KEYCODE_MEDIA_NEXT

if(!mAudioManager.isMusicActive) {
keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS
val prefs = getSharedPreferences(
this.applicationContext.packageName, MODE_PRIVATE
)
// Skip to previous song instead of rewinding current one if not at song start
if(prefs.getBoolean(getString(R.string.PREF_NO_REWIND), false)) {
pressKey(keyCode, mAudioManager, eventTime)
}
}
pressKey(keyCode, mAudioManager, eventTime)
}

val downEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT, 0)
mAudioManager.dispatchMediaKeyEvent(downEvent)
private fun pressKey(keyCode: Int, audioManager: AudioManager, eventTime: Long) {
val downEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0)
audioManager.dispatchMediaKeyEvent(downEvent)

val upEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT, 0)
mAudioManager.dispatchMediaKeyEvent(upEvent)
val upEvent = KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0)
audioManager.dispatchMediaKeyEvent(upEvent)
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/orik/airdotsdoubletap/Settings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.orik.airdotsdoubletap

import android.app.Activity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_settings.*

class Settings : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
val prefs = getSharedPreferences(
this.applicationContext.packageName, MODE_PRIVATE
)
val editor = prefs.edit()
R.id.swtchNoRewind
swtchNoRewind.isChecked = prefs.getBoolean(getString(R.string.PREF_NO_REWIND), false)
swtchNoRewind.setOnCheckedChangeListener { _, isChecked ->
editor.putBoolean(getString(R.string.PREF_NO_REWIND), isChecked)
editor.apply()
}
}
}
Binary file added app/src/main/new_ic_launcher-playstore.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 0 additions & 34 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

19 changes: 0 additions & 19 deletions app/src/main/res/layout/activity_main.xml

This file was deleted.

43 changes: 43 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/txtNoRewind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="60dp"
android:text="@string/settings_no_rewind"
android:textColor="#FFFFFF"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="251dp"
android:layout_height="62dp"
android:layout_marginStart="40dp"
android:layout_marginTop="12dp"
android:text="@string/settings_no_rewind_desc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtNoRewind" />

<Switch
android:id="@+id/swtchNoRewind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="96dp"
android:layout_marginEnd="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.191"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 0 additions & 5 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

This file was deleted.

5 changes: 0 additions & 5 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/main/res/mipmap-anydpi-v26/new_ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/new_ic_launcher_background"/>
<foreground android:drawable="@mipmap/new_ic_launcher_foreground"/>
</adaptive-icon>
5 changes: 5 additions & 0 deletions app/src/main/res/mipmap-anydpi-v26/new_ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/new_ic_launcher_background"/>
<foreground android:drawable="@mipmap/new_ic_launcher_foreground"/>
</adaptive-icon>
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file added app/src/main/res/mipmap-hdpi/new_ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file added app/src/main/res/mipmap-mdpi/new_ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file added app/src/main/res/mipmap-xhdpi/new_ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/main/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#3DDC84</color>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/new_ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="new_ic_launcher_background">#3DDC84</color>
</resources>
7 changes: 6 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<resources>
<string name="app_name">AirdotsDoubleTap</string>
<string name="app_name">Double-Tap</string>
<string name="settings_no_rewind">No Rewind</string>
<string name="settings_no_rewind_desc">
When \'triple\' tapping do not rewind and just skip to previous song (May help with some media players)
</string>
<string name="PREF_NO_REWIND">NO_REWIND</string>
</resources>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.41'
ext.kotlin_version = '1.4.31'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ org.gradle.jvmargs=-Xmx1536m
# org.gradle.parallel=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.useAndroidX=true
android.enableJetifier=true

0 comments on commit 24ab57d

Please sign in to comment.