Toast 工具类:

SmartToastUtils.java
import android.content.Context;
import android.widget.Toast; /**
* Toast 弹出信息工具类,简化代码编写
* @author fairy
* */
public class SmartToastUtils {
public static void showLong(Context context, String info) {
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
public static void showShort(Context context,String info) {
Toast.makeText(context, info,Toast.LENGTH_SHORT).show();
}
}

打印日志工具类:

SmartLogUtils.java
import android.util.Log;

public class SmartLogUtils {

    private final static String DEBUG_TAG="xingyun";
/***
* 封装日志打印方法
* @param message 打印的消息
* @param showMessage 是否显示打印的消息
* **/
public static void showInfo(String message,Boolean showMessage){
if(showMessage){
int max_str_length = 2001 - DEBUG_TAG.length();
//大于4000时
while (message.length() > max_str_length) {
Log.i(DEBUG_TAG, message.substring(0, max_str_length));
message = message.substring(max_str_length);
}
//剩余部分
Log.i(DEBUG_TAG,message);
}
} /***
* 封装日志打印方法
* @param message 打印的消息
* @param showMessage 是否显示打印的消息
* **/
public static void showDebug(String message,Boolean showMessage){
if(showMessage){
int max_str_length = 2001 - DEBUG_TAG.length();
//大于4000时
while (message.length() > max_str_length) {
Log.d(DEBUG_TAG, message.substring(0, max_str_length));
message = message.substring(max_str_length);
}
//剩余部分
Log.d(DEBUG_TAG,message);
}
} public static void showError(String message,Boolean showMessage){
if(showMessage){
int max_str_length = 2001 - DEBUG_TAG.length();
//大于4000时
while (message.length() > max_str_length) {
Log.e(DEBUG_TAG, message.substring(0, max_str_length));
message = message.substring(max_str_length);
}
//剩余部分
Log.e(DEBUG_TAG,message);
}
}
}

Uri 转BitMap工具类:

 private Bitmap getBitmapFromUri(Uri uri) throws IOException {
ParcelFileDescriptor parcelFileDescriptor =
getContentResolver().openFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
return image;
}

打开系统内容提供器获取所有图片:

//打开搜索到的所有设备图片页面
private static final int READ_REQUEST_CODE = 42;
public void performFileSearch() { // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
// browser.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); // Filter to only show results that can be "opened", such as a
// file (as opposed to a list of contacts or timezones)
intent.addCategory(Intent.CATEGORY_OPENABLE); // Filter to show only images, using the image MIME data type.
// If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
// To search for all documents available via installed storage providers,
// it would be "*/*".
intent.setType("image/*");
startActivityForResult(intent, READ_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent resultData) { // The ACTION_OPEN_DOCUMENT intent was sent with the request code
// READ_REQUEST_CODE. If the request code seen here doesn't match, it's the
// response to some other intent, and the code below shouldn't run at all. if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
// The document selected by the user won't be returned in the intent.
// Instead, a URI to that document will be contained in the return intent
// provided to this method as a parameter.
// Pull that URI using resultData.getData().
Uri uri = null;
if (resultData != null) {
uri = resultData.getData();
SmartToastUtils.showShort(MainActivity.this, "URI=" + uri.toString());
showURITextView.setText(uri.toString());
dumpImageMetaData(uri);
try {
saveBitMapToPhoneDevice(getBitmapFromUri(uri));
checkedPicFileImageView.setImageURI(uri);
} catch (IOException e) {
SmartToastUtils.showShort(MainActivity.this, "图片解析失败" + e.toString());
}
}
}
} //将BitMap保存到手机上
private void saveBitMapToPhoneDevice(Bitmap bitmap) {
//将保存到SDCard /xingyun_test_create 文件夹下
File appDir = new File(Environment.getExternalStorageDirectory(), "xingyun_test_create");
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = System.currentTimeMillis() + "AAA.jpg";
File file = new File(appDir, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
SmartToastUtils.showShort(MainActivity.this,"save success");
}

Uri 解析图片信息

 //解析URI 读取图片信息 实际大小和实际名称
public void dumpImageMetaData(Uri uri) { // The query, since it only applies to a single document, will only return
// one row. There's no need to filter, sort, or select fields, since we want
// all fields for one document.
Cursor cursor = MainActivity.this.getContentResolver()
.query(uri, null, null, null, null, null); try {
// moveToFirst() returns false if the cursor has 0 rows. Very handy for
// "if there's anything to look at, look at it" conditionals.
if (cursor != null && cursor.moveToFirst()) { // Note it's called "Display Name". This is
// provider-specific, and might not necessarily be the file name.
String displayName = cursor.getString(
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
SmartToastUtils.showShort(MainActivity.this, "Display Name: " + displayName); int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
// If the size is unknown, the value stored is null. But since an
// int can't be null in Java, the behavior is implementation-specific,
// which is just a fancy term for "unpredictable". So as
// a rule, check if it's null before assigning to an int. This will
// happen often: The storage API allows for remote files, whose
// size might not be locally known.
String size = null;
if (!cursor.isNull(sizeIndex)) {
// Technically the column stores an int, but cursor.getString()
// will do the conversion automatically.
size = cursor.getString(sizeIndex);
} else {
size = "Unknown";
}
// Log.i(TAG, "Size: " + size);
SmartToastUtils.showShort(MainActivity.this, "Size=" + size);
}
} finally {
cursor.close();
}
}
网络状态监听广播类:
public final static String LISTENING_NETWORK_STATUS="android.net.conn.CONNECTIVITY_CHANGE";
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo; import com.xingyun.smartusbdeviceapp.util.SmartToastUtils; /*******
* 网络状态监听改变需要这个权限
* <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
* */
public class NetworkChangeReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
//根据系统服务类 获取管理网络连接
ConnectivityManager connectivityManager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//获取网络连接信息
NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo();
//检查网络是否连接成功
if(networkInfo!=null && networkInfo.isConnected()){
SmartToastUtils.showShort(context,"network is connected");
}else{
SmartToastUtils.showShort(context,"network is disconnected");
}
//拦截掉广播
//abortBroadcast();
}
}
文件工具类:
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList; /**
* Created by apple on 2018/7/13.
*/ public class FileUtils {
/**
* 把字节数组保存为一个文件
* @param
*/
public static File bytes2File(byte[] b, String outputFile) {
BufferedOutputStream stream = null;
File file = null;
try {
file = new File(outputFile);
if(!file.getParentFile().exists()){
boolean mkdirs = file.getParentFile().mkdirs();
}
boolean newFile = file.createNewFile();
FileOutputStream fstream = new FileOutputStream(file);
stream = new BufferedOutputStream(fstream);
stream.write(b);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return file;
} // 用于遍历sdcard卡上所有文件的类
public static void DirAll(File dirFile) throws Exception {
// 用于存放sdcard卡上的所有图片路径
ArrayList<String> dirAllStrArr = new ArrayList<String>();
if (dirFile.exists()) {
File files[] = dirFile.listFiles();
for (File file : files) {
if (file.isDirectory()) {
String fileName = file.getName();
// 除sdcard上Android这个文件夹以外。
if (!fileName.endsWith("Android")) {
// 如果遇到文件夹则递归调用。
DirAll(file);
}
} else {
// 如果是图片文件压入数组
String fileName = file.getName();
if (fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")
|| fileName.endsWith(".bmp")
|| fileName.endsWith(".gif")
|| fileName.endsWith(".png")) {
// 如果遇到文件则放入数组
if (dirFile.getPath().endsWith(File.separator)) {
dirAllStrArr
.add(dirFile.getPath() + file.getName());
} else {
dirAllStrArr.add(dirFile.getPath() + File.separator + file.getName());
}
}
}
}
}
}
}

public class NetworkReceiverConstant {
public final static String LISTENING_NETWORK_STATUS="android.net.conn.CONNECTIVITY_CHANGE"; }

星云 Android 开发工具箱的更多相关文章

  1. Python 帮你玩微信跳一跳 GitHub Python脚本

    前言想自己搞游戏小程序的 在github 有人已经利用 python程序, 通过adb 获取不同型号安卓手机的系统截图,然后通过计算小人与目标位置距离之后得到准确的触摸时间,再通过 开发者模式里的 a ...

  2. 星云測试- Android应用深度体检专业平台

    星云測试-给你的Android应用做个深度体检   星云測试- Android应用深度体检专业平台 星云在线云測试(简称星云測试www.teststars.cc)是全球第一个公布并商用的数字化精准软件 ...

  3. Android Studio 星云常用配置工具箱

    1. 安装插件 1.1 Android View绑定框架 开源地址:https://github.com/JakeWharton/butterknife 插件地址: https://github.co ...

  4. 五步搞定Android开发环境部署

    引言   在windows安装Android的开发环境不简单也说不上算复杂,本文写给第一次想在自己Windows上建立Android开发环境投入 Android浪潮的朋友们,为了确保大家能顺利完成开发 ...

  5. 安卓学习进程(2)Android开发环境的搭建

        本节将分为五个步骤来完成Android开发环境的部署. 第一步:安装JDK. 第二步:配置Windows上JDK的变量环境 . 第三步:下载安装Eclipse . 第四步:下载安装Androi ...

  6. android开发环境搭建日记和嵌入式Android开发环境初探

    非常感谢博客园的各位,按照你们的博文,还有利用百度和谷歌逐渐建立了android的开发环境,只是给自己备份参考查看,看过的人可以忽略这篇文章. 本文章大部分参考了:http://www.cnblogs ...

  7. Android开发环境部署

    引言   在windows系统中安装Android的开发环境,将分为五个步骤来完成: 第一步:安装JDK 第二步:配置Windows上JDK的变量环境 第三步: 下载安装Eclipse 第四步:下载安 ...

  8. 五步搞定Android开发环境部署——非常详细的Android开发环境搭建教程

      在windows安装Android的开发环境不简单也说不上算复杂,本文写给第一次想在自己Windows上建立Android开发环境投入Android浪潮的朋友们,为了确保大家能顺利完成开发环境的搭 ...

  9. Android开发新手学习总结(一)——使用Android Studio搭建Android集成开发环境

    [新手连载]一:使用Android Studio搭建Android集成开发环境http://bbs.itcast.cn/forum.php?mod=viewthread&tid=87055&a ...

随机推荐

  1. Atitit.Guibutton与面板---项目规模的评估----文件数统计,结构,代码行数,每类型文件行数.

    Atitit.Guibutton与面板---项目规模的评估----文件数统计,结构,代码行数,每类型文件行数. 1. Kpi:::  代码行数(凝视行数,空白的行数), 方法数,class数 1 2. ...

  2. Jquery的html方法里包含特殊字符的处理

    jqueryhtml()特殊字符 在使用jquery的html()方法时,有时候里面添加的html代码含有一些特殊字符,需要进行转义. 如下例子: inst_html = "<a st ...

  3. MSVC下使用Boost的自动链接

    简述 好久没有用过boost库了,以前用也是在linux下,需要哪个部分就添加哪个部分到Makefile中. 最近要在Windows下使用,主要是mongocxx库依赖它,不想自己去编译它了,就直接在 ...

  4. java第八节 GUI/图形用户界面

    /* *第8讲 GUI/图形用户界面 * AWT的基础知识 * GUI全称是Graphical User Interface,即图形用户界面 * JDK中提供了AWT和Swing两个包,用于GUI程序 ...

  5. 高效编写微信小程序

    原文:https://isux.tencent.com/high-performance-wechat-app-development.html 前言 微信小程序是一个工程,就和盖房子一样,打好了地基 ...

  6. ASP.NET之通过JS向服务端(后台)发出请求(__doPostBack is undefined)

    ASP.NET回发数据是通过函数__doPostBack来实现的.该函数在加入了服务端控件,并将AutoPostBack设置为true之后,将自己主动生成,详细能够參看以下的图. watermark/ ...

  7. 导入数据库备份报错1067 – Invalid default value for ‘create_time’

    通过navicat工具导入psc数据库备份文件,报错如下,mysql版本5.7 执行如下语句不通过 DROP TABLE IF EXISTS `guard_user`; CREATE TABLE `g ...

  8. [转]expect实现ssh自动交互

    shell脚本实现ssh自动登录远程服务器示例: #!/usr/bin/expect spawn ssh root@192.168.22.194 expect "*password:&quo ...

  9. google开发新人入职100天,聊聊自己的经验&教训 个人对编程和开发的理解 技术发展路线

    新人入职100天,聊聊自己的经验&教训 这篇文章讲了什么? 如题,本屌入职100天之后的经验和教训,具体包含: 对开发的一点感悟. 对如何提问的一点见解. 对Google开发流程的吐槽. 如果 ...

  10. 【svn】解析subversion的使用

    目录结构: contents structure [-] 安装客户端 安装服务端 创建仓库 启动仓库 创建客户端与仓库取得联系 使用svn服务 SVN密码管理 SVN的仓库布局和常规命令 分支.合并和 ...