Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dg76 committed Nov 18, 2018
1 parent a4a0acf commit b927b5d
Show file tree
Hide file tree
Showing 49 changed files with 1,070 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This is an Android app to let the user pick an entry from his call log.

When it is started directly you can tap on an entry to either

1. create an event from it
1. create an event from it (using one of your installed calendar apps)
2. or to call that number.

When it is started by another app using a
Expand Down
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
48 changes: 48 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.dgunia.calllogpicker"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
configDefault {
keyAlias 'key0'
keyPassword 'calllogpicker'
storeFile file('../../calllog-picker.keystore')
storePassword 'calllogpicker'
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.configDefault
}
debug {
signingConfig signingConfigs.configDefault
}
}
}

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 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
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'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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
51 changes: 51 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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.dgunia.calllogpicker">

<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/CallLogPickerTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:label="@string/maintitle">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK"/>

<category android:name="android.intent.category.DEFAULT"/>

<data
android:host="call_log"
android:scheme="content"/>
</intent-filter>
</activity>

<receiver android:name=".IncomingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>

<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>

<activity
android:name=".SettingsActivity"
android:label="@string/settings">
</activity>
</application>

</manifest>
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.dgunia.calllogpicker

import android.content.res.Configuration
import android.os.Bundle
import android.preference.PreferenceActivity
import android.support.annotation.LayoutRes
import android.support.v7.app.ActionBar
import android.support.v7.app.AppCompatDelegate
import android.support.v7.widget.Toolbar
import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup

/**
* A [android.preference.PreferenceActivity] which implements and proxies the necessary calls
* to be used with AppCompat.
*/
abstract class AppCompatPreferenceActivity : PreferenceActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
delegate.installViewFactory()
delegate.onCreate(savedInstanceState)
super.onCreate(savedInstanceState)
}

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
delegate.onPostCreate(savedInstanceState)
}

val supportActionBar: ActionBar?
get() = delegate.supportActionBar

fun setSupportActionBar(toolbar: Toolbar?) {
delegate.setSupportActionBar(toolbar)
}

override fun getMenuInflater(): MenuInflater {
return delegate.menuInflater
}

override fun setContentView(@LayoutRes layoutResID: Int) {
delegate.setContentView(layoutResID)
}

override fun setContentView(view: View) {
delegate.setContentView(view)
}

override fun setContentView(view: View, params: ViewGroup.LayoutParams) {
delegate.setContentView(view, params)
}

override fun addContentView(view: View, params: ViewGroup.LayoutParams) {
delegate.addContentView(view, params)
}

override fun onPostResume() {
super.onPostResume()
delegate.onPostResume()
}

override fun onTitleChanged(title: CharSequence, color: Int) {
super.onTitleChanged(title, color)
delegate.setTitle(title)
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
delegate.onConfigurationChanged(newConfig)
}

override fun onStop() {
super.onStop()
delegate.onStop()
}

override fun onDestroy() {
super.onDestroy()
delegate.onDestroy()
}

override fun invalidateOptionsMenu() {
delegate.invalidateOptionsMenu()
}

private val delegate: AppCompatDelegate by lazy {
AppCompatDelegate.create(this, null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dgunia.calllogpicker

object BroadcastActions {
val REFRESH = BuildConfig.APPLICATION_ID + ".REFRESH"
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/dgunia/calllogpicker/Contact.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dgunia.calllogpicker

class Contact {
var contactId: String
var displayName: String
var givenName: String? = null
var middleName: String? = null
var familyName: String? = null

constructor(contactId: String, displayName: String) {
this.contactId = contactId
this.displayName = displayName
}

constructor(contactId: String, displayName: String, givenName: String, middleName: String, familyName: String) {
this.contactId = contactId
this.displayName = displayName
this.givenName = givenName
this.middleName = middleName
this.familyName = familyName
}
}
56 changes: 56 additions & 0 deletions app/src/main/java/com/dgunia/calllogpicker/IncomingCallReceiver.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.dgunia.calllogpicker

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.telephony.TelephonyManager

/**
* Gets the number of the currently active call.
*/
class IncomingCallReceiver : BroadcastReceiver() {
companion object {
var currentlyActiveCallNumber: String? = null
}

override fun onReceive(context: Context?, intent: Intent?) {
context?.let { context ->
when (intent?.action) {
TelephonyManager.ACTION_PHONE_STATE_CHANGED -> {
val state = intent.getStringExtra(TelephonyManager.EXTRA_STATE)

when (state) {
TelephonyManager.EXTRA_STATE_RINGING -> {
context.getSharedPreferences("incomingcallreceiver", Context.MODE_PRIVATE).edit()
.putBoolean("ringing", true)
.putBoolean("offhook", false)
.apply()
}
TelephonyManager.EXTRA_STATE_OFFHOOK -> {
context.getSharedPreferences("incomingcallreceiver", Context.MODE_PRIVATE).edit()
.putBoolean("offhook", true)
.apply()
currentlyActiveCallNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)
}
TelephonyManager.EXTRA_STATE_IDLE -> {
val prefs = context.getSharedPreferences("incomingcallreceiver", Context.MODE_PRIVATE)
val ringing = prefs.getBoolean("ringing", false)
val offhook = prefs.getBoolean("offhook", false)
currentlyActiveCallNumber = null

val phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)
if (ringing && !offhook && phoneNumber != null && phoneNumber.isNotBlank()) {
onMissedCall(context, phoneNumber)
}
}
}

context.sendBroadcast(Intent(BroadcastActions.REFRESH).apply { setPackage(BuildConfig.APPLICATION_ID) })
}
}
}
}

private fun onMissedCall(context: Context, phoneNumber: String) {
}
}
Loading

0 comments on commit b927b5d

Please sign in to comment.