Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android front end #68

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Android/.DS_Store
Binary file not shown.
Binary file modified Android/.gradle/8.2/checksums/checksums.lock
Binary file not shown.
Binary file modified Android/.gradle/8.2/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified Android/.gradle/8.2/checksums/sha1-checksums.bin
Binary file not shown.
Binary file modified Android/.gradle/8.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified Android/.gradle/8.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified Android/.gradle/8.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified Android/.gradle/8.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified Android/.gradle/8.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified Android/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified Android/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Android/.gradle/file-system.probe
Binary file not shown.
2 changes: 1 addition & 1 deletion Android/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Android/app/.DS_Store
Binary file not shown.
10 changes: 8 additions & 2 deletions Android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.gms.google-services")
}

android {
Expand Down Expand Up @@ -49,15 +50,17 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.core:core-ktx:+")
implementation("androidx.core:core-ktx:1.13.1")
implementation("com.google.firebase:firebase-messaging:24.0.0")
implementation("androidx.work:work-runtime-ktx:2.9.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation ("com.squareup.retrofit2:retrofit:2.9.0")
implementation ("com.squareup.retrofit2:converter-gson:2.9.0")
implementation ("com.squareup.retrofit2:converter-scalars:2.9.0")
implementation ("com.android.volley:volley:1.2.1")
// https://mvnrepository.com/artifact/org.webrtc/google-webrtc
//https://mvnrepository.com/artifact/org.webrtc/google-webrtc
//implementation("org.webrtc:google-webrtc:1.0.32006")

implementation("com.mesibo.api:webrtc:1.0.5")
Expand All @@ -71,4 +74,7 @@ dependencies {
implementation ("io.grpc:grpc-stub:1.38.1")
implementation ("com.google.api:gax:1.58.0")

implementation (platform("com.google.firebase:firebase-bom:31.3.0"))
implementation ("com.google.firebase:firebase-analytics-ktx")
implementation ("com.google.firebase:firebase-messaging:23.0.3")
}
29 changes: 29 additions & 0 deletions Android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "278561057427",
"project_id": "ringo-4a945",
"storage_bucket": "ringo-4a945.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:278561057427:android:56c0f13373217851e07b66",
"android_client_info": {
"package_name": "com.example.front_end_android"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBDAxuh8PRCxuQxI2tUZ-qu15Uq1AJSStU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
26 changes: 22 additions & 4 deletions Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<application
android:name=".MyApplication"
Expand Down Expand Up @@ -35,8 +36,15 @@
android:name=".TestActivity"
android:exported="true" />
<activity
android:name=".Calling"
android:exported="true" />
android:name=".Login"
android:exported="true" >

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

</activity>
<activity
android:name=".AddFriend"
android:exported="true"
Expand All @@ -56,14 +64,24 @@
android:name=".MainActivity"
android:exported="true" />
<activity
android:name=".Login"
android:name=".Calling"
android:exported="true">
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<service
android:name=".firebase.MyFirebaseMessagingService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

</application>

</manifest>
68 changes: 38 additions & 30 deletions Android/app/src/main/java/com/example/front_end_android/Calling.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.example.front_end_android

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.content.Intent
import android.media.AudioManager
import android.os.Bundle
import android.speech.RecognitionListener
import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import android.speech.tts.TextToSpeech
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.front_end_android.databinding.ActivityCallingBinding
import com.example.front_end_android.models.IceCandidateModel
import com.example.front_end_android.models.MessageModel
Expand All @@ -15,25 +20,7 @@ import com.example.front_end_android.util.RTCAudioManager
import com.google.gson.Gson
import org.webrtc.IceCandidate
import org.webrtc.MediaStream
import org.webrtc.PeerConnection
import org.webrtc.SessionDescription
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.media.AudioManager
import android.os.Build
import android.speech.RecognitionListener
import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import android.speech.tts.TextToSpeech
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.google.gson.JsonObject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONObject
import java.util.Locale

class Calling : AppCompatActivity(), NewMessageInterface {
Expand Down Expand Up @@ -66,6 +53,14 @@ class Calling : AppCompatActivity(), NewMessageInterface {
init()
audioManager = getSystemService(AUDIO_SERVICE) as AudioManager

binding.linearLayout.visibility = View.GONE
val callingState = MyApplication.preferences.getString("callingState",".")
if(callingState == "receiver"){
binding.waitTxt.visibility = View.VISIBLE
binding.buttonTest.visibility = View.GONE
}
//binding.exitCallBackground.visibility = View.GONE

binding.nicknameInit.setOnClickListener {
binding.callingPeopleContainer.visibility = View.GONE
binding.linearLayout.visibility = View.GONE
Expand All @@ -87,7 +82,8 @@ class Calling : AppCompatActivity(), NewMessageInterface {
recognitionIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
recognitionIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName) // 여분의 키
// 실제로는 언어 설정에 내가 설정한 언어가 들어가야함
recognitionIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ko-KR") // 언어 설정
val sttLanguage = MyApplication.preferences.getString("SttLanguage","ko-KR")
recognitionIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, sttLanguage) // 언어 설정
// 새 SpeechRecognizer 를 만드는 팩토리 메서드
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this@Calling)
speechRecognizer.setRecognitionListener(recognitionListener) // 리스너 설정
Expand Down Expand Up @@ -121,13 +117,9 @@ class Calling : AppCompatActivity(), NewMessageInterface {
private fun init(){
userName = MyApplication.preferences.getString("email",".")
targetName = MyApplication.preferences.getString("targetName",".")

binding.nicknameInit.text = targetName
/*userName = intent.getStringExtra("username")//실제로는 intent로 유저 이름을 받아야함
if(userName == "[email protected]"){
targetName = "[email protected]"
}else{
targetName = "[email protected]"//실제로는 intentë¡œ 전화를 거는 상대방을 이름을 받아야함
}*/

socketRepository = SocketRepository(this)
userName?.let { socketRepository?.initSocket(it) }
rtcClient = RTCClient(application, userName!!, socketRepository!!, object : PeerConnectionObserver(){
Expand Down Expand Up @@ -155,11 +147,12 @@ class Calling : AppCompatActivity(), NewMessageInterface {

binding.apply {
binding.buttonTest.setOnClickListener {
//상대방이들어오면
socketRepository?.sendMessageToSocket(
MessageModel("start_call",userName,targetName,null
))
binding.buttonTest.visibility = View.GONE
}

switchCameraButton.setOnClickListener {
rtcClient?.switchCamera()
}
Expand Down Expand Up @@ -224,6 +217,10 @@ class Calling : AppCompatActivity(), NewMessageInterface {
runOnUiThread {

binding.apply {
binding.waitTxt.visibility = View.GONE
binding.buttonTest.visibility = View.GONE
binding.linearLayout.visibility = View.VISIBLE
binding.exitCallBackground.visibility = View.VISIBLE
rtcClient?.initializeSurfaceView(localView)
rtcClient?.initializeSurfaceView(remoteView)
rtcClient?.startLocalVideo(localView)
Expand Down Expand Up @@ -270,6 +267,9 @@ class Calling : AppCompatActivity(), NewMessageInterface {
binding.incomingNameTV.text = "${message.name.toString()} is calling you"
binding.acceptButton.setOnClickListener {
binding.buttonTest.visibility = View.GONE
binding.waitTxt.visibility = View.GONE
binding.linearLayout.visibility = View.VISIBLE
binding.exitCallBackground.visibility = View.VISIBLE
setIncomingCallLayoutGone()

binding.apply {
Expand Down Expand Up @@ -315,9 +315,17 @@ class Calling : AppCompatActivity(), NewMessageInterface {
if (status == TextToSpeech.SUCCESS) {
var result: Int? = null
if(message.target.toString().trim() == "ko"){
result = textToSpeech.setLanguage(Locale.KOREAN) // 언어를 미국 영어(en-US)로 설정
result = textToSpeech.setLanguage(Locale.KOREAN)
}else if(message.target.toString().trim() == "en"){
result = textToSpeech.setLanguage(Locale.US) // 언어를 미국 영어(en-US)로 설정
result = textToSpeech.setLanguage(Locale.US)
}else if(message.target.toString().trim() == "zh-CN"){
result = textToSpeech.setLanguage(Locale.SIMPLIFIED_CHINESE)
}else if(message.target.toString().trim() == "de"){
result = textToSpeech.setLanguage(Locale.GERMANY)
}else if(message.target.toString().trim() == "es"){
result = textToSpeech.setLanguage(Locale("es", "ES"))
}else if(message.target.toString().trim() == "fr"){
result = textToSpeech.setLanguage(Locale.FRANCE)
}
//val result = textToSpeech.setLanguage(Locale.US)
if (result == TextToSpeech.LANG_MISSING_DATA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import android.Manifest
import com.example.front_end_android.dataclass.CallFCMRequest
import com.example.front_end_android.dataclass.CallFCMResponse
import com.example.front_end_android.dataclass.ErrorResponse
import com.example.front_end_android.dataclass.FindMyFriendsRequest
import com.example.front_end_android.dataclass.FindMyFriendsResponse
import com.example.front_end_android.dataclass.FindResponse
import com.example.front_end_android.dataclass.FriendRequestListRequest
import com.example.front_end_android.util.AuthInterceptor
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import com.google.gson.Gson
import okhttp3.OkHttpClient
import retrofit2.converter.scalars.ScalarsConverterFactory

Expand Down Expand Up @@ -217,6 +224,9 @@ class FriendsFragment : Fragment() {
imageView.layoutParams = image_params
imageView.setOnClickListener {
MyApplication.preferences.setString("targetName",email)
val callingState = "sender"
MyApplication.preferences.setString("callingState",callingState)
sendCallFCM(email)

PermissionX.init(requireActivity())
.permissions(
Expand Down Expand Up @@ -314,4 +324,66 @@ class FriendsFragment : Fragment() {
return (this * scale + 0.5f).toInt()
}

private fun sendCallFCM(target: String){
val accessToken = MyApplication.preferences.getString("AccessToken",".")
val refreshToken = MyApplication.preferences.getString("RefreshToken",".")
val userEmail = MyApplication.preferences.getString("email",".")
val client = OkHttpClient.Builder()
.addInterceptor(AuthInterceptor(accessToken))
.build()

val gson = GsonBuilder().setLenient().create()
val retrofit = Retrofit.Builder()
.baseUrl("https://4kringo.shop:8080/")
.client(client)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
val service = retrofit.create(RetrofitService::class.java)

val callFCMRequest = CallFCMRequest(target,"Ringo", userEmail)
val callFCM = service.callFCMRetrofit(callFCMRequest)

callFCM.enqueue(object : Callback<CallFCMResponse> {
override fun onResponse(call: Call<CallFCMResponse>, response: Response<CallFCMResponse>) {
val jsonResponse = response.body()
val message = jsonResponse?.message
//val status = jsonResponse?.status
//val data = jsonResponse?.data

if (response.isSuccessful) {
Log.d("YMC", "onResponse 성공: $jsonResponse $response")
Log.d("YMC", "message: $message")
//Log.d("YMC", "data: $data")
//Log.d("YMC", "status: $status")

} else {
Log.d("YMC", "onResponse 실패")//*
Log.d("YMC", "onResponse 실패: $jsonResponse $response")
Log.d("YMC", "message: $message")
val errorBody = response.errorBody()
if (errorBody != null) {
val errorJson = errorBody.string()
Log.d("YMC", "onResponse 실패 errorJson: $errorJson")

val errorResponse = Gson().fromJson(errorJson, ErrorResponse::class.java)

val status = errorResponse.status
val message = errorResponse.message
val data = errorResponse.data
val code = errorResponse.code
Log.d("YMC", "onResponse 실패 : $status $message $data $code")
} else {
Log.d("YMC", "onResponse 실패 : errorBody is null")
}
}

}
override fun onFailure(call: Call<CallFCMResponse>, t: Throwable) {
Log.d("YMC", "onFailure 에러: ${t.message}")//*
}
})

}

}
Loading
Loading