Skip to content

Commit

Permalink
[superCall] 系统拨号界面 日常提交3
Browse files Browse the repository at this point in the history
  • Loading branch information
yangmingchuan committed Nov 30, 2020
1 parent b955639 commit 660b0b1
Show file tree
Hide file tree
Showing 24 changed files with 395 additions and 130 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dependencies {
implementation 'com.googlecode.libphonenumber:geocoder:2.99'
implementation 'com.googlecode.libphonenumber:prefixmapper:2.109'

implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34'
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
testImplementation 'org.testng:testng:6.9.6'
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</activity>
<activity android:name="com.maiya.call.view.SplashActivity" />
<activity android:name="com.maiya.call.view.MainActivity" />
<activity android:name=".phone.view.phonecall.PhoneCallActivity" />

<!-- 电话service -->
<service
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/maiya/call/phone/PhoneListActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.provider.ContactsContract
import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import com.maiya.call.R
import com.maiya.call.phone.utils.MobileNumberUtils
import com.maiya.call.util.LogUtils


Expand All @@ -27,8 +26,6 @@ class PhoneListActivity : AppCompatActivity() {
setContentView(R.layout.activity_phone_list)
getConName()
getContentCallLog()
LogUtils.e("运营商 : ${MobileNumberUtils.getCarrier(this,"17621066329",86)}")
LogUtils.e("归属地:${MobileNumberUtils.getGeo("17621066329")}")
}

private val projection = arrayOf(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER)
Expand Down Expand Up @@ -77,6 +74,4 @@ class PhoneListActivity : AppCompatActivity() {
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.maiya.call.phone.adapter

import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.maiya.call.R

/**
* @ClassName: [CallerKeyboardAdapter]
* @Description:
*
* Created by admin at 2020-07-06
* @Email [email protected]
*/
class CallerKeyboardAdapter
: BaseQuickAdapter<CallerKeyboardAdapter.CallerKeyboard, CallerKeyboardAdapter.KeyboardHolder>(
R.layout.item_caller_keyboard, mutableListOf<CallerKeyboard>().also {
it.add(CallerKeyboard('1', ""))
it.add(CallerKeyboard('2', "ABC"))
it.add(CallerKeyboard('3', "DEF"))
it.add(CallerKeyboard('4', "GHI"))
it.add(CallerKeyboard('5', "JKL"))
it.add(CallerKeyboard('6', "MNO"))
it.add(CallerKeyboard('7', "PQRS"))
it.add(CallerKeyboard('8', "TUV"))
it.add(CallerKeyboard('9', "WXYZ"))
it.add(CallerKeyboard('*', ""))
it.add(CallerKeyboard('0', "+"))
it.add(CallerKeyboard('#', ""))
}
) {

override fun convert(helper: KeyboardHolder, item: CallerKeyboard) {
helper.tvDigit.text = item.digit.toString()
helper.tvLetter.text = item.desc
}

inner class KeyboardHolder(view: View) : BaseViewHolder(view) {
val tvDigit: TextView = view.findViewById(R.id.tv_digit)
val tvLetter: TextView = view.findViewById(R.id.tv_letter)
}

class CallerKeyboard(val digit: Char, val desc: String)

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.maiya.call.phone.utils;
package com.maiya.call.phone.manager;

import android.content.Context;
import android.os.Looper;

public class ContactUtils {
import com.maiya.call.phone.utils.ContactUtil;
import com.maiya.call.phone.utils.ThreadManager;
import com.ymc.ijkplay.utils.AppHandlerUtil;

public class ContactManager {

public static void getContentCallLog(Context mContext, String number, Callback callBack) {
ThreadManager.execute(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.maiya.call.phone.interfaces.ICanAddCallChangedListener
import com.maiya.call.phone.interfaces.IPhoneCallInterface
import com.maiya.call.phone.service.PhoneCallService
import com.maiya.call.phone.utils.GlobalActivityLifecycleMonitor
import com.maiya.call.phone.view.PhoneCallActivity
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArraySet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import com.maiya.call.phone.mode.PhoneModel
*/

object PhoneNumberManager {
private var phoneMsg :PhoneMsg? = null
private var phoneMsg: PhoneMsg? = null

/**
* 根据电话号码 获取电话归属地和 运行商信息
*/
@JvmStatic
@JvmOverloads
fun getStageTaskList(number: String, listener: OnPhoneListener? = null) {
PhoneModel.seachMsgByPhoneNumber(number, object : Callback<PhoneMsg> {
PhoneModel.searchMsgByPhoneNumber(number, object : Callback<PhoneMsg> {
override fun onSuccess(response: PhoneMsg?) {
if (null == response) {
return
Expand Down
22 changes: 8 additions & 14 deletions app/src/main/java/com/maiya/call/phone/mode/PhoneModel.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.maiya.call.phone.mode

import com.maiya.call.MApplication
import com.maiya.call.phone.bean.PhoneMsg
import com.maiya.call.phone.utils.MobileNumberUtils

/**
* Author : ymc
Expand All @@ -10,20 +12,12 @@ import com.maiya.call.phone.bean.PhoneMsg

object PhoneModel : BaseModel() {

fun seachMsgByPhoneNumber(content: String, callBack: Callback<PhoneMsg>?) {
// TODO 根据电话号码获取信息
// val params = mutableMapOf<String, String>().also {
// it["phone"] = content
// }
// HttpUtils.postWithPhpEncrypt(UrlConstants.PHONE_ATTRIBUTION, params, object : RequestDataCallback<ServerPhoneMsg>() {
// override fun onSuccess(serverData: ServerPhoneMsg?) {
// safeCallSuccess(callBack, BeanTransformUtils.toPhoneMsg(serverData))
// }
//
// override fun onFailure(errorMsg: String?) {
// safeCallFailed(callBack, errorMsg)
// }
// })
fun searchMsgByPhoneNumber(content: String, callBack: Callback<PhoneMsg>?) {
var pm = PhoneMsg()
pm.city = MobileNumberUtils.getGeo(content)
pm.type = MobileNumberUtils.getCarrier(MApplication(), content, 86)
safeCallSuccess(callBack, pm)

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.os.Handler
import android.os.Looper
import com.maiya.call.base.BasePresenter
import com.maiya.call.phone.bean.PhoneMsg
import com.maiya.call.phone.utils.ContactUtils
import com.maiya.call.phone.manager.ContactManager
import com.maiya.call.phone.view.callheader.CallHeaderContract
import com.maiya.call.phone.manager.PhoneNumberManager
import java.util.concurrent.ConcurrentHashMap
Expand All @@ -31,7 +31,7 @@ class CallHeaderPresenter(view: CallHeaderContract.View) : BasePresenter<CallHea
private var mCallId: String? = null

override fun queryLocalContactInfo(context: Context, phoneNum: String) {
ContactUtils.getContentCallLog(context, phoneNum) {
ContactManager.getContentCallLog(context, phoneNum) {
if (mView == null) {
return@getContentCallLog
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/maiya/call/phone/utils/ContactUtil.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.maiya.call.phone.utils

import android.annotation.SuppressLint
import android.content.Context
import android.database.Cursor
import android.provider.ContactsContract
import com.maiya.call.util.LogUtils

Expand All @@ -13,7 +11,7 @@ import com.maiya.call.util.LogUtils
*/

object ContactUtil {
/**
/**¬
* 根据电话号码获取联系人
*/
@JvmStatic
Expand Down

This file was deleted.

58 changes: 58 additions & 0 deletions app/src/main/java/com/maiya/call/phone/utils/MobileNumberUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.maiya.call.phone.utils

import android.content.Context
import com.google.i18n.phonenumbers.NumberParseException
import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper
import com.google.i18n.phonenumbers.PhoneNumberUtil
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber
import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder
import java.util.*

/**
* Author : ymc
* Date : 2020/5/25 14:05
* Class : MobileNumberUtils
*/
object MobileNumberUtils {
private val phoneNumberUtil = PhoneNumberUtil.getInstance()
private val carrierMapper = PhoneNumberToCarrierMapper.getInstance()
private val geocoder = PhoneNumberOfflineGeocoder.getInstance()
private const val LANGUAGE = "CN"

//获取手机号码运营商
fun getCarrier(context: Context?, phoneNumber: String?, countryCode: Int): String {
var referencePhonenumber: PhoneNumber? = PhoneNumber()
try {
referencePhonenumber = phoneNumberUtil.parse(phoneNumber, LANGUAGE)
} catch (e: NumberParseException) {
e.printStackTrace()
}
//返回结果只有英文,自己转成成中文
val carrierEn = carrierMapper.getNameForNumber(referencePhonenumber, Locale.ENGLISH)
var carrierZh = ""
return if (countryCode == 86 && Locale.CHINA.country == Locale.getDefault().country) {
when (carrierEn) {
"China Mobile" -> carrierZh += "中国移动"
"China Unicom" -> carrierZh += "中国联通"
"China Telecom" -> carrierZh += "中国电信"
else -> {
}
}
carrierZh
} else {
carrierEn
}
}

//获取手机号码归属地
fun getGeo(phoneNumber: String?): String {
var referencePhonenumber: PhoneNumber? = null
try {
referencePhonenumber = phoneNumberUtil.parse(phoneNumber, LANGUAGE)
} catch (e: NumberParseException) {
e.printStackTrace()
}
//手机号码归属城市 referenceRegion
return geocoder.getDescriptionForNumber(referencePhonenumber, Locale.CHINA)
}
}
Loading

0 comments on commit 660b0b1

Please sign in to comment.