Skip to content

Commit

Permalink
gradle update and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aykuttasil committed Nov 16, 2017
1 parent 8074216 commit d7fb02d
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 71 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion project.sdk
buildToolsVersion project.buildTools

defaultConfig {
applicationId "com.aykuttasil.callrecorder"
minSdkVersion project.minSdk
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/java/com/aykuttasil/callrecorder/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aykuttasil.callrecorder;

import android.media.MediaRecorder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
Expand All @@ -17,20 +18,18 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//callRecord = CallRecord.init(this);

callRecord = new CallRecord.Builder(this)
.setRecordFileName("CallRecorderFile")
.setRecordDirName("CallRecorderDir")
.setRecordFileName("CallRecorderTestFile")
.setRecordDirName("CallRecorderTest")
.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION)
.setShowSeed(true)
.build();

//callRecord.changeReceiver(new MyCallRecordReceiver(callRecord));

//callRecord.enableSaveFile();


/*
callRecord = new CallRecord.Builder(this)
.setRecordFileName("Record_" + new SimpleDateFormat("ddMMyyyyHHmmss", Locale.US).format(new Date()))
Expand All @@ -44,7 +43,6 @@ protected void onCreate(Bundle savedInstanceState) {
callRecord.startCallRecordService();
*/

}

public void StartCallRecordClick(View view) {
Expand All @@ -62,4 +60,5 @@ public void StopCallRecordClick(View view) {
//callRecord.disableSaveFile();
//callRecord.changeRecordFileName("NewFileName");
}

}
22 changes: 14 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
Expand All @@ -14,6 +12,15 @@ buildscript {
allprojects {
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven { url "https://clojars.org/repo/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
maven { url "http://dl.bintray.com/android/android-tools" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jcenter.bintray.com" }
google()
}
}

Expand All @@ -22,10 +29,9 @@ task clean(type: Delete) {
}

ext {
sdk = 25
buildTools = "25.0.3"
sdk = 27
minSdk = 17
libraryVersion = "1.2.4"
libraryVersionCode = 16
supportVersion = "25.3.1"
libraryVersion = "1.2.5"
libraryVersionCode = 17
supportVersion = "27.0.1"
}
15 changes: 0 additions & 15 deletions callrecord/build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
allprojects {
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
maven { url "http://dl.bintray.com/android/android-tools" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jcenter.bintray.com" }
}
}

apply plugin: 'com.android.library'

android {

compileSdkVersion project.sdk
buildToolsVersion project.buildTools

defaultConfig {
minSdkVersion project.minSdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ public void changeReceiver(CallRecordReceiver receiver) {

public static class Builder {
private Context mContext;

public Builder(Context context) {
this.mContext = context;

PrefsHelper.writePrefString(mContext, PREF_FILE_NAME, "Record");
PrefsHelper.writePrefString(mContext, PREF_DIR_NAME, "CallRecord");
PrefsHelper.writePrefString(mContext, PREF_DIR_PATH, Environment.getExternalStorageDirectory().getPath());
Expand All @@ -162,6 +162,7 @@ public Builder(Context context) {
PrefsHelper.writePrefBool(mContext, PREF_SHOW_SEED, true);
PrefsHelper.writePrefBool(mContext, PREF_SHOW_PHONE_NUMBER, true);
}

public CallRecord build() {
CallRecord callRecord = new CallRecord(mContext);
callRecord.enableSaveFile();
Expand Down Expand Up @@ -190,6 +191,11 @@ public int getAudioSource() {
return PrefsHelper.readPrefInt(mContext, PREF_AUDIO_SOURCE);
}

/**
* @param audioSource
* @return
* @see MediaRecorder.AudioSource
*/
public Builder setAudioSource(int audioSource) {
PrefsHelper.writePrefInt(mContext, PREF_AUDIO_SOURCE, audioSource);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ protected void onRecordingFinished(Context context, CallRecord callRecord, File
}

private void startRecord(Context context, String seed, String phoneNumber) {

try {

boolean isSaveFile = PrefsHelper.readPrefBool(context, CallRecord.PREF_SAVE_FILE);
Log.i(TAG, "isSaveFile: " + isSaveFile);

Expand Down Expand Up @@ -140,38 +138,53 @@ private void startRecord(Context context, String seed, String phoneNumber) {

audiofile = File.createTempFile(file_name, suffix, sampleDir);

if (recorder != null) {
recorder.stop();
recorder.release();
recorder = null;
}

recorder = new MediaRecorder();
recorder.setAudioSource(audio_source);
recorder.setOutputFormat(output_format);
recorder.setAudioEncoder(audio_encoder);
recorder.setOutputFile(audiofile.getAbsolutePath());

recorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {
@Override
public void onError(MediaRecorder mediaRecorder, int i, int i1) {
Log.i("CallRecord", i + "");
Log.i("CallRecord", i1 + "");
}
});

recorder.prepare();
//Thread.sleep(2000);
recorder.start();

isRecordStarted = true;
onRecordingStarted(context, callRecord, audiofile);

Log.i(TAG, "record start");

} catch (IllegalStateException | IOException e) {
e.printStackTrace();
}
}

private void stopRecord(Context context) {
if (recorder != null && isRecordStarted) {

recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
try {
if (recorder != null && isRecordStarted) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;

isRecordStarted = false;
onRecordingFinished(context, callRecord, audiofile);
isRecordStarted = false;
onRecordingFinished(context, callRecord, audiofile);

Log.i(TAG, "record stop");
Log.i(TAG, "record stop");
}
} catch (Exception e) {
e.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,13 @@ public abstract class PhoneCallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

//We listen to two intents. The new outgoing call only tells us of an outgoing call. We use it to get the number.
if (intent.getAction().equals(CallRecordReceiver.ACTION_OUT)) {

savedNumber = intent.getExtras().getString(CallRecordReceiver.EXTRA_PHONE_NUMBER);

} else {

String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);

String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

savedNumber = number;

int state = 0;

if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
Expand All @@ -45,8 +38,6 @@ public void onReceive(Context context, Intent intent) {
} else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
state = TelephonyManager.CALL_STATE_RINGING;
}


onCallStateChanged(context, state, number);
}
}
Expand All @@ -69,61 +60,45 @@ public void onReceive(Context context, Intent intent) {
//Incoming call- goes from IDLE to RINGING when it rings, to OFFHOOK when it's answered, to IDLE when its hung up
//Outgoing call- goes from IDLE to OFFHOOK when it dials out, to IDLE when hung up
public void onCallStateChanged(Context context, int state, String number) {

if (lastState == state) {
//No change, debounce extras
return;
}

switch (state) {
case TelephonyManager.CALL_STATE_RINGING:

isIncoming = true;
callStartTime = new Date();
savedNumber = number;

onIncomingCallReceived(context, number, callStartTime);

break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if (lastState != TelephonyManager.CALL_STATE_RINGING) {

isIncoming = false;
callStartTime = new Date();

onOutgoingCallStarted(context, savedNumber, callStartTime);

} else {

isIncoming = true;
callStartTime = new Date();

onIncomingCallAnswered(context, savedNumber, callStartTime);

}

break;
case TelephonyManager.CALL_STATE_IDLE:

//Went to idle- this is the end of a call. What type depends on previous state(s)
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
//Ring but no pickup- a miss

onMissedCall(context, savedNumber, callStartTime);

} else if (isIncoming) {

onIncomingCallEnded(context, savedNumber, callStartTime, new Date());

} else {

onOutgoingCallEnded(context, savedNumber, callStartTime, new Date());

}
break;
}

lastState = state;
}
}
28 changes: 27 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,35 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true


# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true

# Improved incremental resource processing using AAPT2, which is now enabled by default. If you are experiencing issues while using AAPT2, please report a bug. You can also disable AAPT2 by setting android.enableAapt2=false in your gradle.properties file and restarting the Gradle daemon by running ./gradlew --stop from the command line.
# https://developer.android.com/studio/releases/gradle-plugin.html#updating-plugin
android.enableAapt2=false

org.gradle.caching=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 comments on commit d7fb02d

Please sign in to comment.