截图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;

}

/**

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

*

Virmach$7.2/年,新款月抛vps上线,$3.23/半年,/1核640M内存/10 GB存储/ 1Gbps/1T流量

Virmach自上次推出了短租30天的VPS后,也就是月抛型vps,到期不能续费,直接终止服务。此次又推出为期6个月的月抛VPS,可选圣何塞和水牛城机房,适合短期有需求的用户,有兴趣的可以关注一下。VirMach是一家创办于2014年的美国商家,支持支付宝、PayPal等方式,是一家主营廉价便宜VPS服务器的品牌,隶属于Virtual Machine Solutions LLC旗下!在廉价便宜美国...

HostHatch(15美元)大硬盘VPS,香港NVMe,美国、英国、荷兰、印度、挪威、澳大利亚

HostHatch在当地时间7月30日发布了一系列的促销套餐,涉及亚洲和欧美的多个地区机房,最低年付15美元起,一次买2年还能免费升级双倍资源。商家成立于2011年,提供基于KVM架构的VPS主机,数据中心包括中国香港、美国、英国、荷兰、印度、挪威、澳大利亚等国家的十几个地区机房。官方网站:https://hosthatch.com/NVMe VPS(香港/悉尼)1 CPU core (12.5%...

racknerd:美国大硬盘服务器,$599/月,Ryzen7-3700X/32G内存/120gSSD+192T hdd

racknerd当前对美国犹他州数据中心的大硬盘服务器(存储服务器)进行低价促销,价格跌破眼镜啊。提供AMD和Intel两个选择,默认32G内存,120G SSD系统盘,12个16T HDD做数据盘,接入1Gbps带宽,每个月默认给100T流量,5个IPv4... 官方网站:https://www.racknerd.com 加密数字货币、信用卡、PayPal、支付宝、银联(卡),可以付款! ...

android开发工具为你推荐
郭吉军郭吉军和管鹏这两个站长怎么样?群里有人骂windows优化大师怎么用windows优化大师怎么用啊?人人时光机怎么查看人人网的注册时间?缓冲区溢出教程哪里可以下载黑客教程,详细网址,qq空间装扮QQ空间装扮godaddyGodaddy域名怎么接受保护气球什么气球可以骑?idc前线怎么知道我电脑是3兆的宽带?bluestackbluestacks安卓模拟器有什么用bluestack安卓模拟器bluestacks怎么用?
mach 优惠码 韩国电信 申请个人网页 免空 jsp空间 hkg cdn加速原理 南通服务器 linux服务器维护 双线机房 空间首页登陆 丽萨 西安主机 学生服务器 supercache 北京主机托管 中国电信宽带测速 wordpress空间 沈阳idc 更多