-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d8c23ba
Showing
44 changed files
with
1,056 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.sandeep.music_recognizer_app' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.sandeep.music_recognizer_app" | ||
minSdk 24 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.8.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/sandeep/music_recognizer_app/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.sandeep.music_recognizer_app | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.sandeep.music_recognizer_app", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> | ||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> | ||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Musicrecognizerapp" | ||
tools:targetApi="31"> | ||
|
||
<service | ||
android:name=".ForegroundService" | ||
android:enabled="true" | ||
android:exported="true" | ||
/> | ||
|
||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
130 changes: 130 additions & 0 deletions
130
app/src/main/java/com/sandeep/music_recognizer_app/ForegroundService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.sandeep.music_recognizer_app | ||
|
||
|
||
import android.app.Notification | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.Service | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.PixelFormat | ||
import android.os.Build | ||
import android.os.IBinder | ||
import android.view.* | ||
import androidx.annotation.RequiresApi | ||
import androidx.core.app.NotificationCompat | ||
|
||
|
||
class ForegroundService : Service() { | ||
|
||
private lateinit var mView: View | ||
private lateinit var mParams: WindowManager.LayoutParams | ||
private lateinit var mWindowManager: WindowManager | ||
private lateinit var layoutInflater: LayoutInflater | ||
|
||
override fun onBind(intent: Intent?): IBinder { | ||
throw UnsupportedOperationException("Not yet implemented") | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
// create the custom or default notification | ||
// based on the android version | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) startMyOwnForeground() else startForeground( | ||
1, | ||
Notification() | ||
) | ||
|
||
|
||
mParams = WindowManager.LayoutParams( | ||
WindowManager.LayoutParams.WRAP_CONTENT, | ||
WindowManager.LayoutParams.WRAP_CONTENT, | ||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, | ||
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | ||
or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | ||
or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, | ||
PixelFormat.TRANSLUCENT | ||
) | ||
|
||
mParams.gravity = Gravity.CENTER | ||
|
||
// getting a LayoutInflater | ||
layoutInflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater | ||
// inflating the view with the custom layout we created | ||
mView = layoutInflater.inflate(R.layout.popup_window, null) | ||
// set onClickListener on the remove button, which removes | ||
// the view from the window | ||
mView.findViewById<View>(R.id.window_close).setOnClickListener { onDestroy()} | ||
mWindowManager = getSystemService(WINDOW_SERVICE) as WindowManager | ||
mWindowManager.addView(mView, mParams) | ||
dragAndDrop() | ||
|
||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
stopForeground(STOP_FOREGROUND_REMOVE) | ||
mWindowManager.removeView(mView) | ||
System.exit(0) | ||
} | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
return super.onStartCommand(intent, flags, startId) | ||
} | ||
|
||
// for android version >=O we need to create | ||
// custom notification stating | ||
// foreground service is running | ||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun startMyOwnForeground() { | ||
val NOTIFICATION_CHANNEL_ID = "sandeep.permanence" | ||
val channelName = "Background Service" | ||
val chan = NotificationChannel( | ||
NOTIFICATION_CHANNEL_ID, | ||
channelName, | ||
NotificationManager.IMPORTANCE_MIN | ||
) | ||
val manager = | ||
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?)!! | ||
manager.createNotificationChannel(chan) | ||
val notificationBuilder: NotificationCompat.Builder = | ||
NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) | ||
val notification: Notification = notificationBuilder.setOngoing(true) | ||
.setContentTitle("Service running") | ||
.setContentText("Displaying over other apps") // this is important, otherwise the notification will show the way | ||
// you want i.e. it will show some default notification | ||
.setSmallIcon(R.drawable.ic_launcher_foreground) | ||
.setPriority(NotificationManager.IMPORTANCE_MIN) | ||
.setCategory(Notification.CATEGORY_SERVICE) | ||
.build() | ||
startForeground(2, notification) | ||
} | ||
|
||
|
||
fun dragAndDrop() { | ||
mView.setOnTouchListener { v, event -> | ||
if (event.action == MotionEvent.ACTION_MOVE || event.action == MotionEvent.ACTION_DOWN) { | ||
var xOffset = v.width / 2 | ||
var yOffset = v.height / 2 | ||
var x = event.rawX - xOffset | ||
var y = event.rawY - yOffset | ||
var params = WindowManager.LayoutParams( | ||
WindowManager.LayoutParams.WRAP_CONTENT, | ||
WindowManager.LayoutParams.WRAP_CONTENT, | ||
x.toInt(), y.toInt(), | ||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, | ||
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or | ||
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH or | ||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, | ||
PixelFormat.TRANSLUCENT | ||
) | ||
params.gravity = Gravity.TOP or Gravity.START | ||
mWindowManager.updateViewLayout(mView, params); | ||
return@setOnTouchListener true | ||
} | ||
return@setOnTouchListener false | ||
} | ||
} | ||
|
||
|
||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/sandeep/music_recognizer_app/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.sandeep.music_recognizer_app | ||
|
||
|
||
|
||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.provider.Settings | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
checkOverlayPermission() | ||
startService() | ||
} | ||
|
||
// method for starting the service | ||
private fun startService() { | ||
// check if the user has already granted | ||
// the Draw over other apps permission | ||
if (Settings.canDrawOverlays(this)) { | ||
// start the service based on the android version | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
startForegroundService(Intent(this, ForegroundService::class.java)) | ||
} else { | ||
startService(Intent(this, ForegroundService::class.java)) | ||
} | ||
} | ||
} | ||
|
||
private fun checkOverlayPermission() { | ||
if (!Settings.canDrawOverlays(this)) { | ||
// send user to the device settings | ||
val myIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION) | ||
startActivity(myIntent) | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
stopService(Intent(this, ForegroundService::class.java)) | ||
} | ||
|
||
|
||
override fun onResume() { | ||
super.onResume() | ||
startService() | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.