提交 df1a07b5 编写于 作者: C cmj

see 10/31 log

上级 7ec066f3
*.iml
.gradle
/local.properties
.idea
.DS_Store
/build
/captures
.externalNativeBuild
\ No newline at end of file
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
applicationId "com.blankj.androidutilcode"
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':utilcode')
compile rootProject.ext.deps.design
compile rootProject.ext.deps.supportV4
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in G:\Android_IDE\ADT\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep class com.blankj.utilcode.** { *; }
-keep classmembers class com.blankj.utilcode.** { *; }
-dontwarn com.blankj.utilcode.**
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blankj.androidutilcode">
悲剧
<!--读写内存-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--network-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<!--phone-->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<!--拨打电话-->
<uses-permission android:name="android.permission.CALL_PHONE"/>
<!--发送短信-->
<uses-permission android:name="android.permission.SEND_SMS"/>
<!--获取手机联系人-->
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>-->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<!--获取短信-->
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>-->
<uses-permission android:name="android.permission.READ_SMS"/>
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/my_app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activities.ActivityActivity"/>
<activity android:name=".activities.AppActivity"/>
<activity android:name=".activities.CleanActivity"/>
<activity android:name=".activities.DeviceActivity"/>
<activity android:name=".activities.ImageActivity"/>
<activity
android:name=".activities.KeyboardActivity"
android:windowSoftInputMode="stateHidden|adjustPan"/>
<activity android:name=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activities.NetworkActivity"/>
<activity android:name=".activities.PhoneActivity"/>
<activity android:name=".activities.ProcessActivity"/>
<activity android:name=".activities.SDCardActivity"/>
<activity android:name=".activities.SnackbarActivity"/>
<activity android:name=".activities.ToastActivity"/>
</application>
</manifest>
\ No newline at end of file
package com.blankj.androidutilcode;
import android.app.Application;
import android.os.Handler;
import android.os.Message;
import com.blankj.utilcode.utils.CrashUtils;
import com.blankj.utilcode.utils.LogUtils;
import java.lang.ref.WeakReference;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/10/12
* desc :
* </pre>
*/
public class App extends Application {
private static App ourInstance;
public static App getInstance() {
return ourInstance;
}
@Override
public void onCreate() {
super.onCreate();
ourInstance = this;
CrashUtils.getInstance().init(this);
LogUtils.getBuilder(this).setTag("MyTag").setLog2FileSwitch(true).create();
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.ActivityUtils;
import com.blankj.utilcode.utils.DeviceUtils;
import com.blankj.utilcode.utils.IntentUtils;
import com.blankj.utilcode.utils.ShellUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/10/13
* desc : Activity工具类测试
* </pre>
*/
public class ActivityActivity extends Activity
implements View.OnClickListener {
private String packageName;
private String className;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity);
packageName = this.getPackageName();
className = packageName + ".activities.ImageActivity";
TextView tvAboutActivity = (TextView) findViewById(R.id.tv_about_activity);
findViewById(R.id.btn_launch_image_activity).setOnClickListener(this);
boolean isExists = ActivityUtils.isActivityExists(this, packageName, className);
tvAboutActivity.setText(String.format("Is ImageActivity Exists: %b", isExists));
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_launch_image_activity:
ActivityUtils.launchActivity(this, packageName, className);
break;
}
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.App;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.AppUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/10/13
* desc : App工具类测试
* </pre>
*/
public class AppActivity extends Activity
implements View.OnClickListener {
private String appPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app);
appPath = AppUtils.getAppPath(this);
TextView tvAboutApp = (TextView) findViewById(R.id.tv_about_app);
findViewById(R.id.btn_install_app).setOnClickListener(this);
findViewById(R.id.btn_install_app_silent).setOnClickListener(this);
findViewById(R.id.btn_uninstall_app).setOnClickListener(this);
findViewById(R.id.btn_uninstall_app_silent).setOnClickListener(this);
findViewById(R.id.btn_launch_app).setOnClickListener(this);
findViewById(R.id.btn_get_app_details_settings).setOnClickListener(this);
tvAboutApp.setText(AppUtils.getAppInfo(this).toString() +
"\nisInstallWeiXin: " + AppUtils.isInstallApp(this, "com.tencent.mm") +
"\nisAppRoot: " + AppUtils.isAppRoot() +
"\nisAppDebug: " + AppUtils.isAppDebug(this) +
"\nisWeiXinAppDebug: " + AppUtils.isAppDebug(this, "com.tencent.mm") +
"\nAppSignatureSHA1: " + AppUtils.getAppSignatureSHA1(this) +
"\nisAppForeground: " + AppUtils.isAppForeground(this) +
"\nisWeiXinForeground: " + AppUtils.isAppForeground(this, "com.tencent.mm")
);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_install_app:
AppUtils.installApp(this, appPath);
break;
case R.id.btn_install_app_silent:
new Thread(new Runnable() {
@Override
public void run() {
AppUtils.installAppSilent(App.getInstance(), appPath);
}
}).start();
break;
case R.id.btn_uninstall_app:
AppUtils.uninstallApp(this, this.getPackageName());
break;
case R.id.btn_uninstall_app_silent:
AppUtils.uninstallAppSilent(this, this.getPackageName(), false);
break;
case R.id.btn_launch_app:
AppUtils.launchApp(this, this.getPackageName());
break;
case R.id.btn_get_app_details_settings:
AppUtils.getAppDetailsSettings(this);
break;
}
}
}
package com.blankj.androidutilcode.activities;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.CleanUtils;
import java.io.File;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/29
* desc : Clean工具类测试
* </pre>
*/
public class CleanActivity extends Activity
implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clean);
Button btnCleanInternalCache = (Button) findViewById(R.id.btn_clean_internal_cache);
Button btnCleanInternalFiles = (Button) findViewById(R.id.btn_clean_internal_files);
Button btnCleanInternalDbs = (Button) findViewById(R.id.btn_clean_internal_databases);
Button btnCleanInternalSP = (Button) findViewById(R.id.btn_clean_internal_sp);
Button btnCleanExternalCache = (Button) findViewById(R.id.btn_clean_external_cache);
btnCleanInternalCache.setOnClickListener(this);
btnCleanInternalFiles.setOnClickListener(this);
btnCleanInternalDbs.setOnClickListener(this);
btnCleanInternalSP.setOnClickListener(this);
btnCleanExternalCache.setOnClickListener(this);
btnCleanInternalCache.setText(getCacheDir().getPath());
btnCleanInternalFiles.setText(getFilesDir().getPath());
btnCleanInternalDbs.setText(getFilesDir().getParent() + File.separator + "databases");
btnCleanInternalSP.setText(getFilesDir().getParent() + File.separator + "shared_prefs");
btnCleanExternalCache.setText(getExternalCacheDir().getPath());
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_clean_internal_cache:
Log.d("cleanInternalCache", "" + CleanUtils.cleanInternalCache(this));
break;
case R.id.btn_clean_internal_files:
Log.d("cleanInternalFiles", "" + CleanUtils.cleanInternalFiles(this));
break;
case R.id.btn_clean_internal_databases:
Log.d("cleanInternalDbs", "" + CleanUtils.cleanInternalDbs(this));
break;
case R.id.btn_clean_internal_sp:
Log.d("cleanInternalSP", "" + CleanUtils.cleanInternalSP(this));
break;
case R.id.btn_clean_external_cache:
Log.d("cleanExternalCache", "" + CleanUtils.cleanExternalCache(this));
break;
}
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.DeviceUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/27
* desc : Device工具类测试
* </pre>
*/
public class DeviceActivity extends Activity
implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_device);
TextView tvAboutDevice = (TextView) findViewById(R.id.tv_about_device);
findViewById(R.id.btn_shutdown).setOnClickListener(this);
findViewById(R.id.btn_reboot).setOnClickListener(this);
tvAboutDevice.setText("isRoot: " + DeviceUtils.isDeviceRoot() +
"\ngetSDKVersion: " + DeviceUtils.getSDKVersion() +
"\ngetAndroidID: " + DeviceUtils.getAndroidID(this) +
"\ngetMacAddress: " + DeviceUtils.getMacAddress(this)+
"\ngetManufacturer: " + DeviceUtils.getManufacturer() +
"\ngetModel: " + DeviceUtils.getModel()
);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_shutdown:
DeviceUtils.shutdown();
break;
case R.id.btn_reboot:
DeviceUtils.reboot();
break;
}
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.ImageUtils;
import com.blankj.utilcode.utils.SizeUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/26
* desc : 图片工具类测试
* </pre>
*/
public class ImageActivity extends Activity {
private ImageView ivSrc;
private ImageView ivView2Bitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
ivSrc = (ImageView) findViewById(R.id.iv_src);
ivView2Bitmap = (ImageView) findViewById(R.id.iv_view2Bitmap);
ImageView ivRound = (ImageView) findViewById(R.id.iv_round);
ImageView ivRoundCorner = (ImageView) findViewById(R.id.iv_round_corner);
ImageView ivFastBlur = (ImageView) findViewById(R.id.iv_fast_blur);
ImageView ivRenderScriptBlur = (ImageView) findViewById(R.id.iv_render_script_blur);
ImageView ivStackBlur = (ImageView) findViewById(R.id.iv_stack_blur);
ImageView ivAddFrame = (ImageView) findViewById(R.id.iv_add_frame);
ImageView ivAddReflection = (ImageView) findViewById(R.id.iv_add_reflection);
ImageView ivAddTextWatermark = (ImageView) findViewById(R.id.iv_add_text_watermark);
ImageView ivAddImageWatermark = (ImageView) findViewById(R.id.iv_add_image_watermark);
ImageView ivGray = (ImageView) findViewById(R.id.iv_gray);
Bitmap src = ImageUtils.getBitmap(getResources(), R.drawable.lena);
Bitmap watermark = ImageUtils.getBitmap(getResources(), R.mipmap.ic_launcher);
SizeUtils.forceGetViewSize(ivSrc, new SizeUtils.onGetSizeListener() {
@Override
public void onGetSize(View view) {
ivView2Bitmap.setImageBitmap(ImageUtils.view2Bitmap(ivSrc));
}
});
ivRound.setImageBitmap(ImageUtils.toRound(src));
ivRoundCorner.setImageBitmap(ImageUtils.toRoundCorner(src, 60));
ivFastBlur.setImageBitmap(ImageUtils.fastBlur(this, src, 0.1f, 5));
ivRenderScriptBlur.setImageBitmap(ImageUtils.renderScriptBlur(this, src, 10));
src = ImageUtils.getBitmap(getResources(), R.drawable.lena);
ivStackBlur.setImageBitmap(ImageUtils.stackBlur(src, 10, false));
ivAddFrame.setImageBitmap(ImageUtils.addFrame(src, 16, Color.GREEN));
ivAddReflection.setImageBitmap(ImageUtils.addReflection(src, 80));
ivAddTextWatermark.setImageBitmap(ImageUtils.addTextWatermark(src, "blankj", 40, 0x8800ff00, 0, 0));
ivAddImageWatermark.setImageBitmap(ImageUtils.addImageWatermark(src, watermark, 0, 0, 0x88));
ivGray.setImageBitmap(ImageUtils.toGray(src));
}
}
\ No newline at end of file
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.content.Context;
import android.inputmethodservice.Keyboard;
import android.os.Bundle;
import android.os.IBinder;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.KeyboardUtils;
import com.blankj.utilcode.utils.NetworkUtils;
public class KeyboardActivity extends Activity
implements View.OnClickListener {
TextView tvAboutKeyboard;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_keyboard);
findViewById(R.id.btn_hide_soft_input).setOnClickListener(this);
findViewById(R.id.btn_show_soft_input).setOnClickListener(this);
findViewById(R.id.btn_toggle_soft_input).setOnClickListener(this);
tvAboutKeyboard = (TextView) findViewById(R.id.tv_about_keyboard);
tvAboutKeyboard.setText("");
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_hide_soft_input:
KeyboardUtils.hideSoftInput(this);
break;
case R.id.btn_show_soft_input:
KeyboardUtils.showSoftInput(this, (EditText) findViewById(R.id.et));
break;
case R.id.btn_toggle_soft_input:
KeyboardUtils.toggleSoftInput(this);
break;
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (isShouldHideKeyboard(v, ev)) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
return super.dispatchTouchEvent(ev);
}
// 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘
private boolean isShouldHideKeyboard(View v, MotionEvent event) {
if (v != null && (v instanceof EditText)) {
int[] l = {0, 0};
v.getLocationInWindow(l);
int left = l[0],
top = l[1],
bottom = top + v.getHeight(),
right = left + v.getWidth();
return !(event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom);
}
return false;
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.blankj.androidutilcode.R;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/29
* desc : 吐司工具类测试
* </pre>
*/
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void activityClick(View view) {
startActivity(new Intent(this, ActivityActivity.class));
}
public void appClick(View view) {
startActivity(new Intent(this, AppActivity.class));
}
public void cleanClick(View view) {
startActivity(new Intent(this, CleanActivity.class));
}
public void crashClick(View view) {
int err = 1 / 0;
}
public void deviceClick(View view) {
startActivity(new Intent(this, DeviceActivity.class));
}
public void imageClick(View view) {
startActivity(new Intent(this, ImageActivity.class));
}
public void keyboardClick(View view) {
startActivity(new Intent(this, KeyboardActivity.class));
}
public void networkClick(View view) {
startActivity(new Intent(this, NetworkActivity.class));
}
public void phoneClick(View view) {
startActivity(new Intent(this, PhoneActivity.class));
}
public void processClick(View view) {
startActivity(new Intent(this, ProcessActivity.class));
}
public void sdcardClick(View view) {
startActivity(new Intent(this, SDCardActivity.class));
}
public void snackbarClick(View view) {
startActivity(new Intent(this, SnackbarActivity.class));
}
public void toastClick(View view) {
startActivity(new Intent(this, ToastActivity.class));
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.NetworkUtils;
public class NetworkActivity extends Activity
implements View.OnClickListener {
TextView tvAboutNetwork;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_network);
tvAboutNetwork = (TextView) findViewById(R.id.tv_about_network);
findViewById(R.id.btn_open_wireless_settings).setOnClickListener(this);
findViewById(R.id.btn_set_wifi_enabled).setOnClickListener(this);
setAboutNetwork();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_open_wireless_settings:
NetworkUtils.openWirelessSettings(this);
break;
case R.id.btn_set_data_enabled:
NetworkUtils.setDataEnabled(this, !NetworkUtils.getDataEnabled(this));
break;
case R.id.btn_set_wifi_enabled:
NetworkUtils.setWifiEnabled(this, !NetworkUtils.getWifiEnabled(this));
break;
}
setAboutNetwork();
}
private void setAboutNetwork() {
tvAboutNetwork.setText("isConnected: " + NetworkUtils.isConnected(this) +
"\nisAvailableByPing: " + NetworkUtils.isAvailableByPing(this) +
"\ngetDataEnabled: " + NetworkUtils.getDataEnabled(this) +
"\nis4G: " + NetworkUtils.is4G(this) +
"\ngetWifiEnabled: " + NetworkUtils.getWifiEnabled(this) +
"\nisWifiConnected: " + NetworkUtils.isWifiConnected(this) +
"\nisWifiAvailable: " + NetworkUtils.isWifiAvailable(this) +
"\ngetNetworkOperatorName: " + NetworkUtils.getNetworkOperatorName(this) +
"\ngetNetworkTypeName: " + NetworkUtils.getNetworkTypeName(this) +
"\ngetIPAddress: " + NetworkUtils.getIPAddress(true) +
"\ngetDomainAddress: " + NetworkUtils.getDomainAddress("baidu.com")
);
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.AppUtils;
import com.blankj.utilcode.utils.PhoneUtils;
public class PhoneActivity extends Activity implements
View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone);
TextView tvAboutPhone = (TextView) findViewById(R.id.tv_about_phone);
findViewById(R.id.btn_dial).setOnClickListener(this);
findViewById(R.id.btn_call).setOnClickListener(this);
findViewById(R.id.btn_send_sms).setOnClickListener(this);
findViewById(R.id.btn_send_sms_silent).setOnClickListener(this);
tvAboutPhone.setText("isPhone: " + PhoneUtils.isPhone(this) +
"\ngetIMEI: " + PhoneUtils.getIMEI(this) +
"\ngetIMSI: " + PhoneUtils.getIMSI(this) +
"\ngetPhoneType: " + PhoneUtils.getPhoneType(this) +
"\ngetSimOperatorName: " + PhoneUtils.getSimOperatorName(this) +
"\ngetSimOperatorByMnc: " + PhoneUtils.getSimOperatorByMnc(this) +
"\n获取手机状态信息: " + PhoneUtils.getPhoneStatus(this)
);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_dial:
PhoneUtils.dial(this, "10000");
break;
case R.id.btn_call:
PhoneUtils.call(this, "10000");
break;
case R.id.btn_send_sms:
PhoneUtils.sendSms(this, "10000", "test");
break;
case R.id.btn_send_sms_silent:
PhoneUtils.sendSmsSilent(this, "10000", "test");
break;
}
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.ProcessUtils;
import com.blankj.utilcode.utils.ToastUtils;
public class ProcessActivity extends Activity
implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_process);
findViewById(R.id.btn_kill_all_background_processes).setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_kill_all_background_processes:
ToastUtils.showShortToast(this, ProcessUtils.killAllBackgroundProcesses(this));
break;
}
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.SDCardUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/27
* desc : SD卡工具类测试
* </pre>
*/
public class SDCardActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sdcard);
TextView tvAboutSdcard = (TextView) findViewById(R.id.tv_about_sdcard);
tvAboutSdcard.setText("isSDCardEnable: " + SDCardUtils.isSDCardEnable() +
"\ngetDataPath: " + SDCardUtils.getDataPath() +
"\ngetSDCardPath: " + SDCardUtils.getSDCardPath() +
"\ngetFreeSpace: " + SDCardUtils.getFreeSpace() +
"\ngetSDCardInfo: " + SDCardUtils.getSDCardInfo()
);
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import com.blankj.androidutilcode.App;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.SnackbarUtils;
import com.blankj.utilcode.utils.ToastUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/10/17
* desc : Snackbar工具类测试
* </pre>
*/
public class SnackbarActivity extends Activity
implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_snackbar);
findViewById(R.id.btn_short_snackbar).setOnClickListener(this);
findViewById(R.id.btn_short_snackbar_with_action).setOnClickListener(this);
findViewById(R.id.btn_long_snackbar).setOnClickListener(this);
findViewById(R.id.btn_long_snackbar_with_action).setOnClickListener(this);
findViewById(R.id.btn_indefinite_snackbar).setOnClickListener(this);
findViewById(R.id.btn_indefinite_snackbar_with_action).setOnClickListener(this);
findViewById(R.id.btn_add_view).setOnClickListener(this);
findViewById(R.id.btn_add_view_with_action).setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_short_snackbar:
SnackbarUtils.showShortSnackbar(getWindow().getDecorView(), "short snackbar", Color.WHITE, Color.BLUE);
break;
case R.id.btn_short_snackbar_with_action:
SnackbarUtils.showLongSnackbar(getWindow().getDecorView(), "short snackbar", Color.WHITE, Color.BLUE,
"Short", Color.YELLOW, new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showShortToast(App.getInstance(), "Click Short");
}
});
break;
case R.id.btn_long_snackbar:
SnackbarUtils.showLongSnackbar(getWindow().getDecorView(), "long snackbar", Color.WHITE, Color.GREEN);
break;
case R.id.btn_long_snackbar_with_action:
SnackbarUtils.showLongSnackbar(getWindow().getDecorView(), "long snackbar", Color.WHITE, Color.GREEN,
"Long", Color.YELLOW, new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showLongToast(App.getInstance(), "Click Long");
}
});
break;
case R.id.btn_indefinite_snackbar:
SnackbarUtils.showIndefiniteSnackbar(getWindow().getDecorView(), "Indefinite snackbar", 5000, Color.WHITE, Color.RED);
break;
case R.id.btn_indefinite_snackbar_with_action:
SnackbarUtils.showIndefiniteSnackbar(getWindow().getDecorView(), "Indefinite snackbar", 5000, Color.WHITE, Color.RED,
"Indefinite", Color.YELLOW, new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showShortToast(App.getInstance(), "Click Indefinite");
}
});
break;
case R.id.btn_add_view:
SnackbarUtils.showShortSnackbar(getWindow().getDecorView(), "short snackbar", Color.WHITE, Color.BLUE);
SnackbarUtils.addView(R.layout.snackbar_add, 0);
break;
case R.id.btn_add_view_with_action:
SnackbarUtils.showLongSnackbar(getWindow().getDecorView(), "short snackbar", Color.WHITE, Color.BLUE,
"Short", Color.YELLOW, new View.OnClickListener() {
@Override
public void onClick(View v) {
ToastUtils.showShortToast(App.getInstance(), "Click Short");
}
});
SnackbarUtils.addView(R.layout.snackbar_add, 0);
break;
}
}
}
package com.blankj.androidutilcode.activities;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.ToastUtils;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/29
* desc : 吐司测试
* </pre>
*/
public class ToastActivity extends Activity
implements View.OnClickListener {
private Context mContext;
private boolean isJumpWhenMore;
private TextView tvAboutToast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toast);
mContext = this;
isJumpWhenMore = false;
tvAboutToast = (TextView) findViewById(R.id.tv_about_toast);
findViewById(R.id.btn_is_jump_when_more).setOnClickListener(this);
findViewById(R.id.btn_show_short_toast_safe).setOnClickListener(this);
findViewById(R.id.btn_show_long_toast_safe).setOnClickListener(this);
findViewById(R.id.btn_show_short_toast).setOnClickListener(this);
findViewById(R.id.btn_show_long_toast).setOnClickListener(this);
findViewById(R.id.btn_cancel_toast).setOnClickListener(this);
tvAboutToast.setText(String.format("Is Jump When More: %b", isJumpWhenMore));
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_is_jump_when_more:
ToastUtils.init(isJumpWhenMore = !isJumpWhenMore);
break;
case R.id.btn_show_short_toast_safe:
new Thread(new Runnable() {
@Override
public void run() {
ToastUtils.showShortToastSafe(mContext, "show_short_toast_safe");
}
}).start();
break;
case R.id.btn_show_long_toast_safe:
new Thread(new Runnable() {
@Override
public void run() {
ToastUtils.showLongToastSafe(mContext, "show_long_toast_safe");
}
}).start();
break;
case R.id.btn_show_short_toast:
ToastUtils.showShortToast(mContext, "show_short_toast");
break;
case R.id.btn_show_long_toast:
ToastUtils.showShortToast(mContext, "show_long_toast");
break;
case R.id.btn_cancel_toast:
ToastUtils.cancelToast();
break;
}
tvAboutToast.setText(String.format("Is Jump When More: %b", isJumpWhenMore));
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_launch_image_activity"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/activity.start_imageActivity"
/>
<TextView
android:id="@+id/tv_about_activity"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_install_app"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app.install"
/>
<Button
android:id="@+id/btn_install_app_silent"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app.install_silent"
/>
<Button
android:id="@+id/btn_uninstall_app"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app.uninstall"
/>
<Button
android:id="@+id/btn_uninstall_app_silent"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app.uninstall_silent"
/>
<Button
android:id="@+id/btn_launch_app"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app.launch"
/>
<Button
android:id="@+id/btn_get_app_details_settings"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app.get_details_settings"
/>
<TextView
android:id="@+id/tv_about_app"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_clean_internal_cache"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btn_clean_internal_files"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btn_clean_internal_databases"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btn_clean_internal_sp"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/btn_clean_external_cache"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_shutdown"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/device.shutdown"
/>
<Button
android:id="@+id/btn_reboot"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/device.reboot"
/>
<TextView
android:id="@+id/tv_about_device"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
tools:context="com.blankj.androidutilcode.activities.ImageActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<ImageView
android:id="@+id/iv_src"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lena"
/>
<ImageView
android:id="@+id/iv_view2Bitmap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_round"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_round_corner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_fast_blur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_render_script_blur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_stack_blur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_add_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_add_reflection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_add_text_watermark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_add_image_watermark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<EditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn_hide_soft_input"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/keyboard.hide_soft_input"
/>
<Button
android:id="@+id/btn_show_soft_input"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/keyboard.show_soft_input"
/>
<Button
android:id="@+id/btn_toggle_soft_input"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/keyboard.toggle_soft_input"
/>
<TextView
android:id="@+id/tv_about_keyboard"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="activityClick"
android:text="@string/test.activity"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="appClick"
android:text="@string/test.app"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="cleanClick"
android:text="@string/test.clean"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="crashClick"
android:text="@string/test.crash"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="deviceClick"
android:text="@string/test.device"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="imageClick"
android:text="@string/test.image"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="keyboardClick"
android:text="@string/test.keyboard"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="networkClick"
android:text="@string/test.network"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="phoneClick"
android:text="@string/test.phone"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="processClick"
android:text="@string/test.process"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sdcardClick"
android:text="@string/test.sdcard"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="snackbarClick"
android:text="@string/test.snackbar"
/>
<Button
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toastClick"
android:text="@string/test.toast"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_open_wireless_settings"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/network.open_wireless_settings"
/>
<Button
android:id="@+id/btn_set_data_enabled"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/network.set_data_enabled"
/>
<Button
android:id="@+id/btn_set_wifi_enabled"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/network.set_wifi_enabled"
/>
<TextView
android:id="@+id/tv_about_network"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_dial"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phone.dial"
/>
<Button
android:id="@+id/btn_call"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phone.call"
/>
<Button
android:id="@+id/btn_send_sms"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phone.send_sms"
/>
<Button
android:id="@+id/btn_send_sms_silent"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/phone.send_sms_silent"
/>
<TextView
android:id="@+id/tv_about_phone"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_kill_all_background_processes"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/process.kill_all_background"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<TextView
android:id="@+id/tv_about_sdcard"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_short_snackbar"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.show_short"
/>
<Button
android:id="@+id/btn_short_snackbar_with_action"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.show_short_with_action"
/>
<Button
android:id="@+id/btn_long_snackbar"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.show_long"
/>
<Button
android:id="@+id/btn_long_snackbar_with_action"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.show_long_with_action"
/>
<Button
android:id="@+id/btn_indefinite_snackbar"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.show_indefinite"
/>
<Button
android:id="@+id/btn_indefinite_snackbar_with_action"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.show_indefinite_with_action"
/>
<Button
android:id="@+id/btn_add_view"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.add_view"
/>
<Button
android:id="@+id/btn_add_view_with_action"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/snackbar.add_view_with_action"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/spacing_small">
<Button
android:id="@+id/btn_is_jump_when_more"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/toast.toggle_is_jump_when_more"
/>
<Button
android:id="@+id/btn_show_short_toast_safe"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/toast.show_short_safe"
/>
<Button
android:id="@+id/btn_show_long_toast_safe"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/toast.show_long_safe"/>
<Button
android:id="@+id/btn_show_short_toast"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/toast.show_short"/>
<Button
android:id="@+id/btn_show_long_toast"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/toast.show_long"
/>
<Button
android:id="@+id/btn_cancel_toast"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/toast.cancel"
/>
<TextView
android:id="@+id/tv_about_toast"
style="@style/Font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"/>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="red">#FF0000</color>
<color name="green">#00FF00</color>
<color name="blue">#0000FF</color>
<color name="black">#000000</color>
</resources>
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="spacing_huge">64dp</dimen>
<dimen name="spacing_large">32dp</dimen>
<dimen name="spacing_normal">16dp</dimen>
<dimen name="spacing_small">8dp</dimen>
<dimen name="spacing_tiny">4dp</dimen>
<dimen name="font_normal">12sp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_app_name">AndroidUtilCode</string>
<string name="test.activity">ActivityUtils Test</string>
<string name="test.app">AppUtils Test</string>
<string name="test.clean">CleanUtils Test</string>
<string name="test.crash">CrashUtils Test</string>
<string name="test.device">DeviceUtils Test</string>
<string name="test.image">ImageUtils Test</string>
<string name="test.keyboard">KeyboardUtils Test</string>
<string name="test.network">NetworkUtils Test</string>
<string name="test.phone">PhoneUtils Test</string>
<string name="test.process">ProcessUtils Test</string>
<string name="test.sdcard">SDCardUtils Test</string>
<string name="test.snackbar">SnackbarUtils Test</string>
<string name="test.toast">ToastUtils Test</string>
<!--Activity相关-->
<string name="activity.start_imageActivity">Start ImageActivity</string>
<!--App相关-->
<string name="app.install">Install App</string>
<string name="app.install_silent">Install App Silent</string>
<string name="app.uninstall">Uninstall App</string>
<string name="app.uninstall_silent">Uninstall App Silent</string>
<string name="app.launch">Launch App</string>
<string name="app.close">Close App</string>
<string name="app.isDebug">Is Debug</string>
<string name="app.get_details_settings">Get App Details Settings</string>
<!--Device相关-->
<string name="device.shutdown">Shutdown</string>
<string name="device.reboot">Reboot</string>
<!--Network相关-->
<string name="network.open_wireless_settings">Open Wireless Settings</string>
<string name="network.set_data_enabled">Set Data Enabled</string>
<string name="network.set_wifi_enabled">Set Wifi Enabled</string>
<!--Keyboard相关-->
<string name="keyboard.hide_soft_input">Hide Soft Input</string>
<string name="keyboard.show_soft_input">Show Soft Input</string>
<string name="keyboard.toggle_soft_input">Toggle Soft Input</string>
<!--Phone相关-->
<string name="phone.dial">Dial</string>
<string name="phone.call">Call</string>
<string name="phone.send_sms">Send SMS</string>
<string name="phone.send_sms_silent">Send SMS Silent</string>
<!--Process相关-->
<string name="process.kill_background">Kill Background Process</string>
<string name="process.kill_all_background">Kill All Background Processes</string>
<!--SnackBar相关工具类-->
<string name="snackbar.show_short">Show Short Snackbar</string>
<string name="snackbar.show_short_with_action">Show Short Snackbar With Action</string>
<string name="snackbar.show_long">Show Short Snackbar</string>
<string name="snackbar.show_long_with_action">Show Short Snackbar With Action</string>
<string name="snackbar.show_indefinite">Show Indefinite Snackbar</string>
<string name="snackbar.show_indefinite_with_action">Show Indefinite Snackbar With Action</string>
<string name="snackbar.add_view">Add View</string>
<string name="snackbar.add_view_with_action">Add View With Action</string>
<!--Toast相关-->
<string name="toast.toggle_is_jump_when_more">Toggle Is Jump When More</string>
<string name="toast.show_short_safe">Show Short Toast Safe</string>
<string name="toast.show_long_safe">Show Long Toast Safe</string>
<string name="toast.show_short">Show Short Toast</string>
<string name="toast.show_long">Show Long Toast</string>
<string name="toast.cancel">Cancel Toast</string>
</resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"/>
<style name="Font">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">@dimen/font_normal</item>
</style>
<style name="BtnFont" parent="Font">
<item name="android:textAllCaps" tools:targetApi="ice_cream_sandwich">false</item>
</style>
</resources>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: "config.gradle"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
signingConfig = [
storePassword : "xxx",
keyAlias : "xxx",
keyPassword : "xxx"
]
android = [
compileSdkVersion : 24,
buildToolsVersion : "24.0.3",
minSdkVersion : 11,
targetSdkVersion : 24,
versionCode : 10,
versionName : "1.3.1"
]
depsVersion = [
support : "24.0.0"
]
deps = [
// ------------- Android -------------
supportV4 : "com.android.support:support-v4:${depsVersion.support}",
design : "com.android.support:design:${depsVersion.support}",
// ------------- Test dependencies -------------
junit : "junit:junit:4.12",
truth : "com.google.truth:truth:0.29",
robolectric : "org.robolectric:robolectric:3.1.2"
]
}
\ No newline at end of file
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# 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
\ No newline at end of file
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
include ':app', ':utilcode'
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
compileSdkVersion 24
buildToolsVersion '24.0.3'
defaultConfig {
minSdkVersion 11
targetSdkVersion 25
targetSdkVersion 24
versionCode 10
versionName "1.3.1"
}
......@@ -22,8 +22,8 @@ dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.1.2'
testCompile 'com.google.truth:truth:0.29'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:design:25.0.0'
provided 'com.android.support:support-v4:24.0.0'
provided 'com.android.support:design:24.0.0'
}
//apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
//gradlew bintrayUpload
\ No newline at end of file
<manifest package="com.blankj.utilcode"
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>
<manifest package="com.blankj.utilcode"/>
\ No newline at end of file
......@@ -13,7 +13,9 @@ import android.graphics.drawable.Drawable;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* <pre>
......@@ -139,6 +141,22 @@ public class AppUtils {
return commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success");
}
/**
* 判断App是否有root权限
*
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isAppRoot() {
ShellUtils.CommandResult result = ShellUtils.execCmd("echo root", true);
if (result.result == 0) {
return true;
}
if (result.errorMsg != null) {
LogUtils.d("isAppRoot", result.errorMsg);
}
return false;
}
/**
* 打开App
*
......@@ -573,13 +591,13 @@ public class AppUtils {
@Override
public String toString() {
return "App包名:" + getPackageName() + "\n" +
"App名称:" + getName() + "\n" +
"App图标:" + getIcon() + "\n" +
"App路径:" + getPackagePath() + "\n" +
"App版本号:" + getVersionName() + "\n" +
"App版本码:" + getVersionCode() + "\n" +
"是否系统App:" + isSystem() + "\n";
return "App包名:" + getPackageName() +
"\nApp名称:" + getName() +
"\nApp图标:" + getIcon() +
"\nApp路径:" + getPackagePath() +
"\nApp版本号:" + getVersionName() +
"\nApp版本码:" + getVersionCode() +
"\n是否系统App:" + isSystem();
}
}
......
......@@ -31,20 +31,11 @@ public class DeviceUtils {
/**
* 判断设备是否root
*
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isRoot() {
return isRootByShell() || isRootByFile();
}
/**
* 根据文件判断设备是否root
*
* @return the boolean{@code true}: 是<br>{@code false}: 否
*/
private static boolean isRootByFile() {
public static boolean isDeviceRoot() {
String su = "su";
String[] locations = {"/sbin/", "/system/bin/", "/system/xbin/", "/system/sd/xbin/", "/system/bin/failsafe/",
String[] locations = {"/system/bin/", "/system/xbin/", "/sbin/", "/system/sd/xbin/", "/system/bin/failsafe/",
"/data/local/xbin/", "/data/local/bin/", "/data/local/"};
for (String location : locations) {
if (new File(location + su).exists()) {
......@@ -54,22 +45,6 @@ public class DeviceUtils {
return false;
}
/**
* 根据shell判断设备是否root
*
* @return {@code true}: 是<br>{@code false}: 否
*/
private static boolean isRootByShell() {
ShellUtils.CommandResult result = ShellUtils.execCmd("echo root", true);
if (result.result == 0) {
return true;
}
if (result.errorMsg != null) {
LogUtils.d("isRootByShell", result.errorMsg);
}
return false;
}
/**
* 获取设备系统版本号
*
......
......@@ -65,6 +65,39 @@ public class FileUtils {
return file != null && file.exists();
}
/**
* 重命名文件
*
* @param filePath 文件路径
* @param newName 新名称
* @return {@code true}: 重命名成功<br>{@code false}: 重命名失败
*/
public static boolean rename(String filePath, String newName) {
return rename(getFileByPath(filePath), newName);
}
/**
* 重命名文件
*
* @param file 文件
* @param newName 新名称
* @return {@code true}: 重命名成功<br>{@code false}: 重命名失败
*/
public static boolean rename(File file, String newName) {
// 文件为空返回false
if (file == null) return false;
// 文件不存在返回false
if (!file.exists()) return false;
// 新的文件名为空返回false
if (StringUtils.isSpace(newName)) return false;
// 如果文件名没有改变返回true
if (newName.equals(file.getName())) return true;
File newFile = new File(file.getParent() + File.separator + newName);
// 如果重命名的文件已存在返回false
return !newFile.exists()
&& file.renameTo(newFile);
}
/**
* 判断是否是目录
*
......
......@@ -24,7 +24,7 @@ public class KeyboardUtils {
/**
* 避免输入法面板遮挡
* <p>在manifest.xml中activity中设置</p>
* <p>android:windowSoftInputMode="adjustResize"</p>
* <p>android:windowSoftInputMode="adjustPan"</p>
*/
/**
......@@ -55,7 +55,8 @@ public class KeyboardUtils {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (isShouldHideKeyboard(v, ev)) {
hideKeyboard(v.getWindowToken());
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
return super.dispatchTouchEvent(ev);
......@@ -75,14 +76,6 @@ public class KeyboardUtils {
}
return false;
}
// 获取InputMethodManager,隐藏软键盘
private void hideKeyboard(IBinder token) {
if (token != null) {
InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
*/
}
......@@ -111,15 +104,4 @@ public class KeyboardUtils {
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
/**
* 判断键盘是否显示
*
* @param context 上下文
* @return {@code true}: 显示<br>{@code false}: 不显示
*/
public static boolean isShowSoftInput(Context context) {
return ((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE)).isActive();
}
}
\ No newline at end of file
......@@ -4,12 +4,14 @@ import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
......@@ -96,10 +98,10 @@ public class NetworkUtils {
ShellUtils.CommandResult result = ShellUtils.execCmd("ping -c 1 -w 1 123.125.114.144", false);
boolean ret = result.result == 0;
if (result.errorMsg != null) {
LogUtils.d("isAvailableByPing", result.errorMsg);
LogUtils.d("isAvailableByPing errorMsg", result.errorMsg);
}
if (result.successMsg != null) {
LogUtils.d("isAvailableByPing", result.successMsg);
LogUtils.d("isAvailableByPing successMsg", result.successMsg);
}
return ret;
}
......@@ -337,6 +339,8 @@ public class NetworkUtils {
try {
for (Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); nis.hasMoreElements(); ) {
NetworkInterface ni = nis.nextElement();
// 防止小米手机返回10.0.2.15
if (!ni.isUp()) continue;
for (Enumeration<InetAddress> addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) {
InetAddress inetAddress = addresses.nextElement();
if (!inetAddress.isLoopbackAddress()) {
......@@ -359,6 +363,24 @@ public class NetworkUtils {
return null;
}
public String getIpAdress(Context context) {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress();
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* 获取域名ip地址
* <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
......
......@@ -31,7 +31,7 @@ public class ProcessUtils {
}
/**
* 获取前台应用包名
* 获取前台线程包名
* <p>当不是查看当前App,且SDK >= 22时,
* 需添加权限 {@code <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>}</p>
*
......@@ -87,42 +87,45 @@ public class ProcessUtils {
}
/**
* 清除后台进程
* 杀死后台服务进程
* <p>需添加权限 {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>}</p>
*
* @param context 上下文
* @return 清除后台进程数
* @return 杀死后台进程数
*/
public static int cleanAllBackgroundProcesses(Context context) {
public static int killAllBackgroundProcesses(Context context) {
int count = 0;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> infos = am.getRunningAppProcesses();
if (infos == null || infos.size() == 0) return 0;
Set<ActivityManager.RunningAppProcessInfo> set = new HashSet<>();
Set<String> set = new HashSet<>();
for (ActivityManager.RunningAppProcessInfo info : infos) {
infos.remove(info);
set.add(info);
++count;
for (String pkg : info.pkgList) {
am.killBackgroundProcesses(pkg);
set.add(pkg);
++count;
}
}
infos = am.getRunningAppProcesses();
if (infos == null || infos.size() == 0) return count;
for (ActivityManager.RunningAppProcessInfo info : infos) {
set.remove(info);
--count;
for (String pkg : info.pkgList) {
set.remove(pkg);
--count;
}
}
System.out.println(set);
return count;
}
/**
* 清除后台进程
* 杀死后台服务进程
* <p>需添加权限 {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>}</p>
*
* @param context 上下文
* @param packageName 包名
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
* @return {@code true}: 杀死成功<br>{@code false}: 杀死失败
*/
public static boolean cleanBackgroundProcesses(Context context, String packageName) {
public static boolean killBackgroundProcesses(Context context, String packageName) {
if (StringUtils.isSpace(packageName)) return false;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> infos = am.getRunningAppProcesses();
......
......@@ -110,8 +110,8 @@ public class ShellUtils {
if (isNeedResultMsg) {
successMsg = new StringBuilder();
errorMsg = new StringBuilder();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
successResult = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8"));
String s;
while ((s = successResult.readLine()) != null) {
successMsg.append(s);
......
......@@ -17,9 +17,12 @@ import com.blankj.utilcode.R;
* desc : SnackBar相关工具类
* </pre>
*/
public class SnackbarUtils {
private SnackbarUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
private static Snackbar snackbar;
/**
......
......@@ -250,7 +250,6 @@ public class ToastUtils {
* @param duration 显示时长
*/
private static void showToast(Context context, CharSequence text, int duration) {
LogUtils.d(sToast == null);
if (isJumpWhenMore) cancelToast();
if (sToast == null) {
sToast = Toast.makeText(context, text, duration);
......
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/snackbar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="14dp"
android:paddingBottom="14dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:textSize="14sp"
android:textColor="?android:textColorPrimary"
android:maxLines="2"
android:layout_gravity="center_vertical|left|start"
android:ellipsize="end"
android:textAlignment="viewStart"/>
<Button
android:id="@+id/snackbar_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:layout_gravity="center_vertical|right|end"
android:paddingTop="14dp"
android:paddingBottom="14dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:visibility="gone"
android:textColor="?attr/colorAccent"
style="?attr/borderlessButtonStyle"/>
</merge>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--snackbar-->
<attr name="colorAccent" format="color"/>
<attr name="borderlessButtonStyle" format="reference"/>
<attr name="textColorPrimary" format="reference|color"/>
</resources>
\ No newline at end of file
......@@ -37,6 +37,11 @@ public class FileUtilsTest {
assertThat(isFileExists(path + "UTF8")).isFalse();
}
@Test
public void testRename() throws Exception {
assertThat(rename(path + "GBK.txt", "GBK1.txt")).isTrue();
}
@Test
public void testIsDir() throws Exception {
assertThat(isDir(path + "UTF8.txt")).isFalse();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册