Skip to content

Commit

Permalink
convert to kotlin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamsiree committed Mar 23, 2020
1 parent c1d7202 commit 1bb8d89
Show file tree
Hide file tree
Showing 29 changed files with 1,650 additions and 1,775 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ActivityCreateQRCode : ActivityBase(), View.OnClickListener {

override fun initView() {
rx_title.setLeftFinish(mContext)
rx_title.title = "动态生成码"
rx_title.setTitle("动态生成码")
ll_refresh.setOnClickListener(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ActivityRunTextView : ActivityBase() {
text.setText(26f, 5, -0x899eaa) //设置属性
text.setTextStillTime(3000) //设置停留时长间隔
text.setAnimTime(300) //设置进入和退出的时间间隔
text.setOnItemClickListener { position -> RxToast.success(mContext, "点击了 : " + titleList[position], Toast.LENGTH_SHORT, true).show() }
text.setOnItemClickListener { position -> RxToast.success(mContext, "点击了 : " + titleList[position], Toast.LENGTH_SHORT, true)?.show() }
val views: MutableList<View> = ArrayList()
setUPMarqueeView(views, 11)
upview1.setViews(views)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class ActivityRxCaptcha : ActivityBase() {
rx_title.setLeftFinish(mContext)
swipeCaptchaView.onCaptchaMatchCallback = object : OnCaptchaMatchCallback {
override fun matchSuccess(rxSwipeCaptcha: RxSwipeCaptcha) {
RxToast.success(mContext, "验证通过!", Toast.LENGTH_SHORT).show()
RxToast.success(mContext, "验证通过!", Toast.LENGTH_SHORT)?.show()
//swipeCaptcha.createCaptcha();
dragBar.isEnabled = false
}

override fun matchFailed(rxSwipeCaptcha: RxSwipeCaptcha) {
Log.d("zxt", "matchFailed() called with: rxSwipeCaptcha = [$rxSwipeCaptcha]")
RxToast.error(mContext, "验证失败:拖动滑块将悬浮头像正确拼合", Toast.LENGTH_SHORT).show()
RxToast.error(mContext, "验证失败:拖动滑块将悬浮头像正确拼合", Toast.LENGTH_SHORT)?.show()
rxSwipeCaptcha.resetCaptcha()
dragBar.progress = 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class ActivityRxToast : ActivityBase() {

override fun initView() {
rx_title.setOnClickListener { finish() }
button_error_toast.setOnClickListener { RxToast.error(mContext, "这是一个提示错误的Toast!", Toast.LENGTH_SHORT, true).show() }
button_success_toast.setOnClickListener { RxToast.success(mContext, "这是一个提示成功的Toast!", Toast.LENGTH_SHORT, true).show() }
button_info_toast.setOnClickListener { RxToast.info(mContext, "这是一个提示信息的Toast.", Toast.LENGTH_SHORT, true).show() }
button_warning_toast.setOnClickListener { RxToast.warning(mContext, "这是一个提示警告的Toast.", Toast.LENGTH_SHORT, true).show() }
button_normal_toast_wo_icon.setOnClickListener { RxToast.normal(mContext, "这是一个普通的没有ICON的Toast").show() }
button_error_toast.setOnClickListener { RxToast.error(mContext, "这是一个提示错误的Toast!", Toast.LENGTH_SHORT, true)?.show() }
button_success_toast.setOnClickListener { RxToast.success(mContext, "这是一个提示成功的Toast!", Toast.LENGTH_SHORT, true)?.show() }
button_info_toast.setOnClickListener { RxToast.info(mContext, "这是一个提示信息的Toast.", Toast.LENGTH_SHORT, true)?.show() }
button_warning_toast.setOnClickListener { RxToast.warning(mContext, "这是一个提示警告的Toast.", Toast.LENGTH_SHORT, true)?.show() }
button_normal_toast_wo_icon.setOnClickListener { RxToast.normal(mContext, "这是一个普通的没有ICON的Toast")?.show() }
button_normal_toast_w_icon.setOnClickListener {
val icon = resources.getDrawable(R.drawable.clover)
RxToast.normal(mContext, "这是一个普通的包含ICON的Toast", icon).show()
RxToast.normal(mContext, "这是一个普通的包含ICON的Toast", icon)?.show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ActivitySlidingDrawerSingle : ActivityBase() {
pb_web_base?.visibility = View.VISIBLE
}

override fun onReceivedTitle(title: String?) {
override fun onReceivedTitle(title: String) {
// rx_title.title = title
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,26 @@ package com.tamsiree.rxfeature.activity
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.widget.NestedScrollView
import com.tamsiree.rxfeature.R
import com.tamsiree.rxfeature.tool.RxBarCode
import com.tamsiree.rxfeature.tool.RxQRCode
import com.tamsiree.rxkit.*
import com.tamsiree.rxkit.view.RxToast
import com.tamsiree.rxui.activity.ActivityBase
import com.tamsiree.rxui.view.RxTitle
import com.tamsiree.rxui.view.ticker.RxTickerUtils
import com.tamsiree.rxui.view.ticker.RxTickerView
import kotlinx.android.synthetic.main.activity_code_tool.*

/**
* @author tamsiree
*/
class ActivityCodeTool : ActivityBase() {
private var mRxTitle: RxTitle? = null
private var mEtQrCode: EditText? = null
private var mIvCreateQrCode: ImageView? = null
private var mIvQrCode: ImageView? = null
private var mActivityCodeTool: LinearLayout? = null
private var mLlCode: LinearLayout? = null
private var mLlQrRoot: LinearLayout? = null
private var mEtBarCode: EditText? = null
private var mIvCreateBarCode: ImageView? = null
private var mIvBarCode: ImageView? = null
private var mLlBarCode: LinearLayout? = null
private var mLlBarRoot: LinearLayout? = null
private var mLlScaner: LinearLayout? = null
private var mLlQr: LinearLayout? = null
private var mLlBar: LinearLayout? = null
private var mRxTickerViewMade: RxTickerView? = null
private var mRxTickerViewScan: RxTickerView? = null
private var nestedScrollView: NestedScrollView? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
RxBarTool.noTitle(this)
RxBarTool.setTransparentStatusBar(this)
setContentView(R.layout.activity_code_tool)
RxDeviceTool.setPortrait(this)

}

override fun onResume() {
Expand All @@ -54,26 +31,8 @@ class ActivityCodeTool : ActivityBase() {
}

override fun initView() {
mRxTitle = findViewById(R.id.rx_title)
mEtQrCode = findViewById(R.id.et_qr_code)
mIvCreateQrCode = findViewById(R.id.iv_create_qr_code)
mIvQrCode = findViewById(R.id.iv_qr_code)
mActivityCodeTool = findViewById(R.id.activity_code_tool)
mLlCode = findViewById(R.id.ll_code)
mLlQrRoot = findViewById(R.id.ll_qr_root)
nestedScrollView = findViewById(R.id.nestedScrollView)
mEtBarCode = findViewById(R.id.et_bar_code)
mIvCreateBarCode = findViewById(R.id.iv_create_bar_code)
mIvBarCode = findViewById(R.id.iv_bar_code)
mLlBarCode = findViewById(R.id.ll_bar_code)
mLlBarRoot = findViewById(R.id.ll_bar_root)
mLlScaner = findViewById(R.id.ll_scaner)
mLlQr = findViewById(R.id.ll_qr)
mLlBar = findViewById(R.id.ll_bar)
mRxTickerViewScan = findViewById(R.id.ticker_scan_count)
mRxTickerViewScan?.setCharacterList(NUMBER_LIST)
mRxTickerViewMade = findViewById(R.id.ticker_made_count)
mRxTickerViewMade?.setCharacterList(NUMBER_LIST)
ticker_scan_count.setCharacterList(NUMBER_LIST)
ticker_made_count.setCharacterList(NUMBER_LIST)
updateMadeCodeCount()
}

Expand All @@ -82,64 +41,64 @@ class ActivityCodeTool : ActivityBase() {
}

private fun updateScanCodeCount() {
mRxTickerViewScan!!.setText(RxDataTool.stringToInt(RxSPTool.getContent(mContext.baseContext!!, RxConstants.SP_SCAN_CODE)).toString() + "", true)
ticker_scan_count!!.setText(RxDataTool.stringToInt(RxSPTool.getContent(mContext.baseContext!!, RxConstants.SP_SCAN_CODE)).toString() + "", true)
}

private fun updateMadeCodeCount() {
mRxTickerViewMade!!.setText(RxDataTool.stringToInt(RxSPTool.getContent(mContext.baseContext!!, RxConstants.SP_MADE_CODE)).toString() + "", true)
ticker_made_count.setText(RxDataTool.stringToInt(RxSPTool.getContent(mContext.baseContext!!, RxConstants.SP_MADE_CODE)).toString() + "", true)
}

private fun initEvent() {
mRxTitle!!.isLeftIconVisibility = true
mRxTitle!!.titleColor = Color.WHITE
mRxTitle!!.titleSize = RxImageTool.dp2px(20f)
mRxTitle!!.setLeftFinish(mContext)
mRxTickerViewScan!!.animationDuration = 500
mIvCreateQrCode!!.setOnClickListener {
val str = mEtQrCode!!.text.toString()
rx_title.setLeftIconVisibility(true)
rx_title.setTitleColor(Color.WHITE)
rx_title.setTitleSize(RxImageTool.dp2px(20f))
rx_title.setLeftFinish(mContext)
ticker_scan_count!!.animationDuration = 500
iv_create_qr_code.setOnClickListener {
val str = et_qr_code.text.toString()
if (RxDataTool.isNullString(str)) {
RxToast.error("二维码文字内容不能为空!")
} else {
mLlCode!!.visibility = View.VISIBLE
ll_code!!.visibility = View.VISIBLE

//二维码生成方式一 推荐此方法
RxQRCode.builder(str).backColor(-0x1).codeColor(-0x1000000).codeSide(600).codeLogo(resources.getDrawable(R.drawable.faviconhandsome)).codeBorder(1).into(mIvQrCode)
RxQRCode.builder(str).backColor(-0x1).codeColor(-0x1000000).codeSide(600).codeLogo(resources.getDrawable(R.drawable.faviconhandsome)).codeBorder(1).into(iv_qr_code)

//二维码生成方式二 默认宽和高都为800 背景为白色 二维码为黑色
// RxQRCode.createQRCode(str,mIvQrCode);
mIvQrCode!!.visibility = View.VISIBLE
// RxQRCode.createQRCode(str,iv_qr_code);
iv_qr_code!!.visibility = View.VISIBLE
RxToast.success("二维码已生成!")
RxSPTool.putContent(mContext.baseContext!!, RxConstants.SP_MADE_CODE, (RxDataTool.stringToInt(RxSPTool.getContent(mContext.baseContext!!, RxConstants.SP_MADE_CODE)) + 1).toString())
updateMadeCodeCount()
nestedScrollView!!.computeScroll()
}
}
mIvCreateBarCode!!.setOnClickListener {
val str1 = mEtBarCode!!.text.toString()
iv_create_bar_code!!.setOnClickListener {
val str1 = et_bar_code!!.text.toString()
if (RxDataTool.isNullString(str1)) {
RxToast.error("条形码文字内容不能为空!")
} else {
mLlBarCode!!.visibility = View.VISIBLE
ll_bar_code!!.visibility = View.VISIBLE

//条形码生成方式一 推荐此方法
RxBarCode.builder(str1).backColor(0x00000000).codeColor(-0x1000000).codeWidth(1000).codeHeight(300).into(mIvBarCode)
RxBarCode.builder(str1).backColor(0x00000000).codeColor(-0x1000000).codeWidth(1000).codeHeight(300).into(iv_bar_code)

//条形码生成方式二 默认宽为1000 高为300 背景为白色 二维码为黑色
//mIvBarCode.setImageBitmap(RxBarCode.createBarCode(str1, 1000, 300));
mIvBarCode!!.visibility = View.VISIBLE
//iv_bar_code.setImageBitmap(RxBarCode.createBarCode(str1, 1000, 300));
iv_bar_code!!.visibility = View.VISIBLE
RxToast.success("条形码已生成!")
RxSPTool.putContent(mContext.baseContext!!, RxConstants.SP_MADE_CODE, (RxDataTool.stringToInt(RxSPTool.getContent(mContext.baseContext!!, RxConstants.SP_MADE_CODE)) + 1).toString())
updateMadeCodeCount()
}
}
mLlScaner!!.setOnClickListener { RxActivityTool.skipActivity(mContext, ActivityScanerCode::class.java) }
mLlQr!!.setOnClickListener {
mLlQrRoot!!.visibility = View.VISIBLE
mLlBarRoot!!.visibility = View.GONE
ll_scaner!!.setOnClickListener { RxActivityTool.skipActivity(mContext, ActivityScanerCode::class.java) }
ll_qr!!.setOnClickListener {
ll_qr_root!!.visibility = View.VISIBLE
ll_bar_root!!.visibility = View.GONE
}
mLlBar!!.setOnClickListener {
mLlBarRoot!!.visibility = View.VISIBLE
mLlQrRoot!!.visibility = View.GONE
ll_bar!!.setOnClickListener {
ll_bar_root!!.visibility = View.VISIBLE
ll_qr_root!!.visibility = View.GONE
}
}

Expand Down
14 changes: 8 additions & 6 deletions RxKit/src/main/java/com/tamsiree/rxkit/RxDeviceTool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ object RxDeviceTool {
@JvmStatic
fun getScreenDensity(context: Context): Float {
return context.resources.displayMetrics.density
}//品牌类型 例如: Galaxy nexus
//品牌 例如:samsung
}

/**
* 获取手机唯一标识序列号
Expand Down Expand Up @@ -117,13 +116,11 @@ object RxDeviceTool {
*/
@JvmStatic
fun getIMEI(context: Context): String? {
val deviceId: String?
deviceId = if (isPhone(context)) {
return if (isPhone(context)) {
getDeviceIdIMEI(context)
} else {
getAndroidId(context)
}
return deviceId
}

/**
Expand Down Expand Up @@ -184,6 +181,7 @@ object RxDeviceTool {
* @param context
* @return
*/
@SuppressLint("HardwareIds")
@JvmStatic
fun getLine1Number(context: Context): String? {
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
Expand Down Expand Up @@ -296,6 +294,7 @@ object RxDeviceTool {
* @param context
* @return
*/
@SuppressLint("HardwareIds")
@JvmStatic
fun getSimSerialNumber(context: Context): String? {
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
Expand Down Expand Up @@ -324,6 +323,7 @@ object RxDeviceTool {
* @param context
* @return
*/
@SuppressLint("HardwareIds")
@JvmStatic
fun getSubscriberId(context: Context): String? {
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
Expand Down Expand Up @@ -356,6 +356,7 @@ object RxDeviceTool {
* @param context
* @return
*/
@SuppressLint("HardwareIds")
@JvmStatic
fun getAndroidId(context: Context): String {
return Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
Expand Down Expand Up @@ -392,6 +393,7 @@ object RxDeviceTool {
*/
@JvmStatic
val serialNumber: String?
@SuppressLint("PrivateApi", "HardwareIds")
get() {
var serial: String? = null
try {
Expand Down Expand Up @@ -455,7 +457,7 @@ object RxDeviceTool {
* @return
*/
@JvmStatic
fun checkPermission(context: Context, permission: String?): Boolean {
fun checkPermission(context: Context, permission: String): Boolean {
var result = false
if (Build.VERSION.SDK_INT >= 23) {
result = try {
Expand Down
10 changes: 2 additions & 8 deletions RxKit/src/main/java/com/tamsiree/rxkit/RxImageTool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import android.graphics.*
import android.graphics.Bitmap.CompressFormat
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.media.ExifInterface
import android.media.ThumbnailUtils
import android.util.DisplayMetrics
import android.util.Log
import android.view.WindowManager
import android.widget.ImageView
import androidx.exifinterface.media.ExifInterface
import com.tamsiree.rxkit.RxDataTool.Companion.isNullString
import com.tamsiree.rxkit.RxFileTool.Companion.closeIO
import com.tamsiree.rxkit.RxFileTool.Companion.createOrExistsFile
Expand Down Expand Up @@ -507,9 +507,6 @@ object RxImageTool {
*/
@JvmStatic
fun getBitmap(resId: Int): Bitmap? {
if (RxTool.getContext() == null) {
return null
}
val `is` = RxTool.getContext().resources.openRawResource(resId)
return BitmapFactory.decodeStream(`is`)
}
Expand All @@ -524,9 +521,6 @@ object RxImageTool {
*/
@JvmStatic
fun getBitmap(resId: Int, maxWidth: Int, maxHeight: Int): Bitmap? {
if (RxTool.getContext() == null) {
return null
}
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
val `is` = RxTool.getContext().resources.openRawResource(resId)
Expand Down Expand Up @@ -801,7 +795,7 @@ object RxImageTool {
* @return 旋转角度
*/
@JvmStatic
fun getRotateDegree(filePath: String?): Int {
fun getRotateDegree(filePath: String): Int {
var degree = 0
try {
val exifInterface = ExifInterface(filePath)
Expand Down
2 changes: 1 addition & 1 deletion RxKit/src/main/java/com/tamsiree/rxkit/RxNetTool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ object RxNetTool {
}
} else {
netType = NETWORK_NO
RxToast.error(context, "当前无网络连接").show()
RxToast.error(context, "当前无网络连接")?.show()
}
return netType
}
Expand Down
Loading

0 comments on commit 1bb8d89

Please sign in to comment.