Skip to content

Commit

Permalink
YUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
YeChao committed Dec 29, 2020
1 parent 07f4661 commit 983ce3c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 40 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![](https://img.shields.io/badge/language-Java%20&%20kotlin-orange.svg)
![](https://img.shields.io/hexpm/l/plug.svg)

最近更新 2020.12.26
最近更新 2020.12.29

### How to use

Expand All @@ -22,13 +22,13 @@ allprojects {
```
dependencies {
//kotlin 版本
implementation 'com.github.yechaoa.YUtils:yutilskt:3.1.4'
implementation 'com.github.yechaoa.YUtils:yutilskt:3.1.5'
//java 版本
implementation 'com.github.yechaoa.YUtils:yutils:3.1.4'
implementation 'com.github.yechaoa.YUtils:yutils:3.1.5'
//kotlin && java 版本
implementation 'com.github.yechaoa:YUtils:3.1.4'
implementation 'com.github.yechaoa:YUtils:3.1.5'
}
```

Expand All @@ -39,7 +39,8 @@ dependencies {
```
//初始化
YUtils.init(this);
//设置打印开关(可选,默认false)
//打印开关(可选,默认false不打印)
LogUtil.setIsLog(true);
```

Expand Down Expand Up @@ -75,6 +76,7 @@ LogUtil.setIsLog(true);

* void closeSoftKeyboard()<br>关闭软键盘

* Boolean hasSim()<br>是否有sim卡 即设备是否可以拨打电话等

> ## 2.ToastUtil(任意线程,不重复显示,可取消).
Expand Down Expand Up @@ -224,6 +226,10 @@ like this

## 更新记录

#### 3.1.5(2020-12-29)
- 初始化校验
- YUtils新增sim卡判断

#### 3.1.4(2020-12-26)
- SpUtil优化

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/ic_logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/yechaoa/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ class MainActivity : AppCompatActivity() {
// ActivityUtil.start(MainActivity::class.java)
// ActivityUtil.finish(this)

LogUtil.i("" + DisplayUtil.getStatusBarHeight() + "---" + DisplayUtil.getScreenHeight())
LogUtil.i("" + DisplayUtil.getActionBarHeight() + "---" + DisplayUtil.getNavBarHeight())
btn_display.setOnClickListener {
LogUtil.i("" + DisplayUtil.getStatusBarHeight() + "---" + DisplayUtil.getScreenHeight())
LogUtil.i("" + DisplayUtil.getActionBarHeight() + "---" + DisplayUtil.getNavBarHeight())
}

btn_sim.setOnClickListener {
ToastUtil.show(if (YUtils.hasSim()) "有sim卡" else "无sim卡")
}
}
}
49 changes: 22 additions & 27 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,64 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="Hello World!" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="存StringSet"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view" />
android:text="存StringSet" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="读StringSet"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
android:text="读StringSet" />

<Button
android:id="@+id/showLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="showLoading"
app:layout_constraintEnd_toEndOf="@+id/button2"
app:layout_constraintStart_toStartOf="@+id/button2"
app:layout_constraintTop_toBottomOf="@+id/button2" />
android:text="showLoading" />

<Button
android:id="@+id/hideLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="hideLoading"
app:layout_constraintEnd_toEndOf="@+id/showLoading"
app:layout_constraintStart_toStartOf="@+id/showLoading"
app:layout_constraintTop_toBottomOf="@+id/showLoading" />
android:text="hideLoading" />

<Button
android:id="@+id/btn_log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打印log"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="打印log" />

</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/btn_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打印屏幕宽高" />

<Button
android:id="@+id/btn_sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="是否有sim卡" />

</LinearLayout>
Binary file added app/src/main/res/mipmap-xxhdpi/ic_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">app</string>
<string name="app_name">YUtils</string>

<string name="large_text">
"Material is the metaphor.\n\n"
Expand Down
23 changes: 21 additions & 2 deletions yutils/src/main/java/com/yechaoa/yutils/YUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class YUtils {

private static Toast toast;
private static ProgressDialog progressDialog;
private static Application mApp;
private static Application mApp = null;

/**
* 使用init()即可
Expand All @@ -62,7 +63,11 @@ public static Application getApplication() {
}

public static Application getApp() {
return mApp;
if (null == mApp) {
throw new NullPointerException("YUtils未在Application中初始化");
} else {
return mApp;
}
}

/**
Expand Down Expand Up @@ -267,4 +272,18 @@ public static void closeSoftKeyboard() {
inputManger.hideSoftInputFromWindow(ActivityUtil.getCurrentActivity().getWindow().getDecorView().getWindowToken(), 0);
}

/**
* 是否有sim卡 即设备是否可以拨打电话等
*/
public static Boolean hasSim() {
TelephonyManager telephonyManager = (TelephonyManager) getApp().getSystemService(Context.TELEPHONY_SERVICE);
boolean result = true;
switch (telephonyManager.getSimState()) {
case TelephonyManager.SIM_STATE_ABSENT:
case TelephonyManager.SIM_STATE_UNKNOWN:
result = false;
break;
}
return result;
}
}
20 changes: 18 additions & 2 deletions yutilskt/src/main/java/com/yechaoa/yutilskt/YUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.pm.PackageManager
import android.telephony.TelephonyManager
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
Expand Down Expand Up @@ -50,7 +51,11 @@ object YUtils {
}

fun getApp(): Application {
return mApp
if (this::mApp.isInitialized) {
return mApp
} else {
throw UninitializedPropertyAccessException("YUtils未在Application中初始化")
}
}

/**
Expand Down Expand Up @@ -234,5 +239,16 @@ object YUtils {
inputManger.hideSoftInputFromWindow(ActivityUtil.currentActivity!!.window.decorView.windowToken, 0)
}


/**
* 是否有sim卡 即设备是否可以拨打电话等
*/
fun hasSim(): Boolean {
val telephonyManager = getApp().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
var result = true
when (telephonyManager.simState) {
TelephonyManager.SIM_STATE_ABSENT -> result = false
TelephonyManager.SIM_STATE_UNKNOWN -> result = false
}
return result
}
}

0 comments on commit 983ce3c

Please sign in to comment.