截图android开发中常用的工具类整理

android开发工具  时间:2021-02-28  阅读:()

Android开发中常用的工具类整理privateL(){thrownewUnsupportedOperationExc eption(Lc annotinstantiated!}public staticvoidv(Stringtag,Stringmsg){if(LEVE L=5)Log.v(tag==null?DEFAULT_TAG:tag,ms g==null? :ms g);}public staticvoidd(Stringtag,Stringmsg){if(LEVE L=4)Log.d(tag==null?DEFAULT_TAG:tag,ms g==null? :ms g);}public staticvoidi(Stringtag,Stringms g){if(LEVE L=3)Log.i(tag==null?DEFAULT_TAG:tag,ms g==null? :ms g);}public staticvoidw(Stringtag,Stringmsg){if(LEVE L=2)Log.w(tag==null?DEFAULT_TAG:tag,ms g==null? :ms g);}public staticvoide(Stringtag,Stringmsg){if(LEVE L=1)Log.e(tag==null?D EFAULT_TAG:tag,ms g==null? :ms g);}

}

Toas tpac kagenet.wujingc hao.android.utilityimportandroid.c ontent.Context;

importandroid.w idget.Toast;publicclassT{privatefinalstaticbooleanis Show=true;privateT(){thrownewUnsupportedOperationExc eption(Tc annotbeinstantiated}public staticvoidshow Short(Contextc ontext,CharSequenc etext){if(is Show)Toast.makeText(c ontext,text,Toast.LENGTH_S HO RT).show();}public staticvoidshowLong(Contextc ontext,CharSequenc etext){if(is Show)Toast.makeText(c ontext,text,Toast.LENGTH_LONG).show();}

}pac kagenet.wujingc hao.android.utilityimportandroid.app.Activ ity;importandroid.c ontent.ComponentName;importandroid.c ontent.Context;importandroid.c ontent.Intent;importandroid.net.Connec tiv ityManag er;importandroid.net.Netw orkInfo;importjav ax.net.s sl.HttpsURLConnection;importjav ax.net.s sl.S SLContext;

importjav ax.net.s s l.TrustManager;importjav ax.net.s s l.X509Trus tManager;publicclassNetworkUtil{privateNetw orkUt il(){thrownewUnsupportedOperationExc eption(Netw orkUtilc annotbeinstantiated

}

/**

*判断网络是否连接

*

*/public staticbooleanisConnected(Contextc ontext){

Connec tivityManagerc onnec tivity=(Connectiv ityManager)c ontext.getSystemS ervic e(Context.CONNECT I VITY_S ERVI CE);if(null!=c onnec tivity){

Netw orkInfoinfo=c onnec tivity.getAc tiveNetw orkInfo();if(null!=info info.isConnected()){if(info.getState()==Netw orkInfo.State.CONNECTED){r eturntrue;

}

}

}

r eturnfals e;

}

/**

*判断是否是wifi连接

*/public staticbooleanisWifi(Contextc ontext){

ConnectivityManagerc onnectivity=(Connectiv ityManager)c ontext.getSystemS ervic e(Context.CONNECT I VITY_S ERVI CE);if(c onnec tivity==null)returnfals e;returnc onnec tivity.getAc tiv eNetw orkInfo().getType()==Connec tivityManager.TYP E_WIF I;

}

/**

*打开网络设置界面

*/public static voidopenS etting(Ac tiv ityactiv ity){

Intentintent=new Intent(/

ComponentNamec omponentName=newComponentName( c om.android.s ettings ,com.android.settings.Wireless Settingsintent.s etComponent(c omponentName);intent.s etAc tion(android.intent.ac tion.VIEWac tivity.s tartAc tiv ityF orResult(intent,0);

}

/**

*使用SSL不信任的证书

*/public staticvoidus eUntrustedCertific ate(){

//Createatrus tmanagerthatdoesnotvalidatec ertific atec hains

Trus tManager[]trus tAllCerts=new Trus tManager[]{new X509TrustManager(){publicjava.s ecurity.c ert.X509Certific ate[]getAc c eptedIssuers(){r eturnnull;

}publicvoidcheckClientTrusted(java.s ecurity.c ert.X509Certific ate[]c erts,StringauthType){

}publicvoidcheckServerTrusted(java.s ecurity.c ert.X509Certific ate[]c erts,StringauthType){

}

}

};

//Ins tallthea ll-trus tingtrus tmanagertry{

S SLContextsc=S SLContext.getInstanc e(SSLs c.init(null,trustAllCerts,newjava.s ec urity.S ecureRandom());

HttpsURLConnection.s etDefaultS SLSocketFactory(sc.getSocketFactory());

}catch(Exc eptione){e.printStackTrac e();

}

}

}

像素单位转换pac kagenet.wujingc hao.android.utilityimportandroid.c ontent.Context;importandroid.util.TypedValue;publicclassDensityUtil{privateDensityUtil(){thrownewUnsupportedOperationExc eption(DensityUtilc annotbeinstantiated}public intdip2px(Contextc ontext,intdip Value){finalfloats c ale=c ontext.getRes ourc es().getDisplayM etric s().dens ity;return(int)(dip Va lue*s c ale+0.5 f);

}public intpx2dip(Contextc ontext,floatpxValue){finalfloats c ale=c ontext.getRes ourc es().getDisplayM etric s().dens ity;return(int)(pxVa lue/s c ale+0.5 f);

}public static floatpx2sp(Contextc ontext,floatpxValue){

return(pxVa lue/c ontext.getRes ourc es().getDis playMetr ic s().sc aledDens ity);}public static intsp2px(Contextc ontext,intspValue){return(int)TypedVa lue.app lyD imens ion(TypedVa lu e.COMPLEX_UNIT_S P,spVa lue,c ontext.getRes ourc es().getDisplayMetr ic s());

}

}pac kagenet.wujingc hao.android.utilityimportandroid.app.Activ ity;importandroid.c ontent.Context;importandroid.graphic s.Bitmap;importandroid.graphic s.Rect;importandroid.util.D isplayMetric s;importandroid.view.View;importandroid.view.WindowManager;publicclassScreenUtil{privateScreenUtil()

{thrownewUnsupportedOperationExc eption(S creenUtilc annotbe instantiated}public static intgetScreenWidth(Contextc ontext)

{

.getSystemS ervic e(Context.WINDOW_SERVICE);

Dis play Metr ic s outMetric s=new Dis playMetr ic s();w m.getDefaultD is play().getMetric s(outMetric s);r eturnoutMetric s.w idthP ixels;

}public static intgetScreenHe ight(Contextc ontext){

WindowManag erwm=(WindowManager)c ontext

.getSystemS ervic e(Context.WINDOW_SERVICE);

Dis play Metr ic s outMetric s=new Dis playMetr ic s();w m.getDefaultD is play().getMetric s(outMetric s);returnoutMetric s.heightP ixels;

}public static intgetStatusHe ight(Contextc ontext){ints tatus He ight=-1;try{

Clas s ?c lazz=Clas s.forName(c om.android.internal.R$dimenObjectobject=clazz.newInstance();inthe ight=Integer.pars eInt(c lazz.getF ie ld( s tatus_bar_height ).get(object).toString());statusHeight=c ontext.getRes ourc es().getDimens ionPix elS iz e(height);}catch(Exc eptione){

e.printStackTrac e();

}r eturn s tatus Height;

}

/**

*获取当前屏幕截图包含状态栏

*/public static BitmapsnapShotWithStatusBar(Activity activity){Viewview=ac tivity.getWindow().getDec orView();view.s etDrawingCacheEnab led(true);view.buildDrawingCache();

Bitmapbmp=v iew.getDraw ingCache();intw idth=g et S c r e enWidth(ac tiv ity);inthe ight=getS c reenHe ight(ac tiv ity);

Bitmapbp=nu ll;bp=Bitmap.c reateBitmap(bmp,0,0,w idth,height);view.destroyDrawingCache();r eturnb p;

}

/**

*获取当前屏幕截图不包含状态栏

*

阿里云香港 16核32G 20M 999元/月

阿里云香港配置图提速啦是成立于2012年的十分老牌的一个商家这次给大家评测的是 阿里云香港 16核32G 20M 这款产品,单单说价格上就是十分的离谱原价8631元/月的现价只要 999元 而且还有个8折循环优惠。废话不多说直接进入正题。优惠时间 2021年8月20日-2021年9月20日 优惠码 wn789 8折优惠阿里云香港BGP专线 16核32G 10M带宽 优惠购买 399元购买链接阿里云...

MOACK:韩国服务器/双E5-2450L/8GB内存/1T硬盘/10M不限流量,$59.00/月

Moack怎么样?Moack(蘑菇主机)是一家成立于2016年的商家,据说是国人和韩国合资开办的主机商家,目前主要销售独立服务器,机房位于韩国MOACK机房,网络接入了kt/lg/kinx三条线路,目前到中国大陆的速度非常好,国内Ping值平均在45MS左右,而且商家的套餐比较便宜,针对国人有很多活动。不过目前如果购买机器如需现场处理,由于COVID-19越来越严重,MOACK办公楼里的人也被感染...

DiyVM:香港VPS五折月付50元起,2核/2G内存/50G硬盘/2M带宽/CN2线路

diyvm怎么样?diyvm这是一家低调国人VPS主机商,成立于2009年,提供的产品包括VPS主机和独立服务器租用等,数据中心包括香港沙田、美国洛杉矶、日本大阪等,VPS主机基于XEN架构,均为国内直连线路,主机支持异地备份与自定义镜像,可提供内网IP。最近,DiyVM商家对香港机房VPS提供5折优惠码,最低2GB内存起优惠后仅需50元/月。点击进入:diyvm官方网站地址DiyVM香港机房CN...

android开发工具为你推荐
微信如何建群微信怎么建立群直播加速手机上什么软件可以帮助直播加速,大神们推荐推荐网页打开很慢如何解决网速正常 网页打开很慢问题什么是云平台什么是云平台管理软件,一个云平台软件应该具有哪些基本功能网站优化方案几种常用的网站优化方法网站推广外链我是新手SEO,请问网站怎样做外链推广网站排名靠前全国B2B网站排名靠前的有哪些购买流量现在中国移动怎么买流量淘宝软文范例在淘宝上卖文案软文的一般都是什么人,指着这笔收入活不下去吧,收入一般怎么样啊?qq新闻弹窗QQ弹出新闻
美国主机空间 hostigation 免费cdn加速 godaddy支付宝 标准机柜尺寸 web服务器架设软件 北京双线 搜索引擎提交入口 实惠 域名转入 广东主机托管 如何登陆阿里云邮箱 国外免费云空间 网站加速 卡巴斯基试用版下载 好看的空间 数据湾 移动王卡 register.com 空间排行榜 更多