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

}

/**

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

*

华纳云E5处理器16G内存100Mbps688元/月

近日华纳云商家正式上线了美国服务器产品,这次美国机房上线的产品包括美国云服务器、美国独立服务器、美国高防御服务器以及美国高防云服务器等产品,新产品上线华纳云推出了史上优惠力度最高的特价优惠活动,美国云服务器低至3折,1核心1G内存5Mbps带宽低至24元/月,20G ddos高防御服务器低至688元/月,年付周期再送2个月、两年送4个月、三年送6个月,终身续费同价,有需要的朋友可以关注一下。华纳云...

SugarHosts糖果主机,(67元/年)云服务器/虚拟主机低至半价

SugarHosts 糖果主机商也算是比较老牌的主机商,从2009年开始推出虚拟主机以来,目前当然还是以虚拟主机为主,也有新增云服务器和独立服务器。早年很多网友也比较争议他们家是不是国人商家,其实这些不是特别重要,我们很多国人商家或者国外商家主要还是看重的是品质和服务。一晃十二年过去,有看到SugarHosts糖果主机商12周年的促销活动。如果我们有需要香港、美国、德国虚拟主机的可以选择,他们家的...

RAKsmart 黑色星期五云服务器七折优惠 站群服务器首月半价

一年一度的黑色星期五和网络星期一活动陆续到来,看到各大服务商都有发布促销活动。同时RAKsmart商家我们也是比较熟悉的,这次是继双十一活动之后的促销活动。在活动产品中基本上沿袭双11的活动策略,比如有提供云服务器七折优惠,站群服务器首月半价、还有新人赠送红包等活动。如果我们有需要RAKsmart商家VPS、云服务器、独立服务器等产品的可以看看他们家的活动。这次活动截止到11月30日。第一、限时限...

android开发工具为你推荐
回收站在哪回收站在系统的哪文件夹支付宝查询余额支付宝里如何查询银行卡里面的余额?spgnux怎么安装思普操作系统网站运营我想成为网站运营的人我该学什么??数码资源网哪个网站可以直接在线做照片?功能要齐全的`9flash在“属性”对话框中的“Move”后面的框中输入Flash动画文件的绝对路径及文件名,这句话怎么操作?童之磊湖北中文在线数字出版有限公司怎么样?免费免费建站我想建一个自己的免费网站,但不知道那里有..bt封杀现在是全面封杀BT下载了吗?现在都找不到BT下载影片了系统分析员如何成为系统分析师?
备案域名出售 omnis paypal认证 宕机监控 最好的空间 泉州电信 彩虹云 ebay注册 主机管理系统 网络速度 汤博乐 cdn加速 美国服务器 傲盾代理 回程 neobux 瓦工工资 电脑主机打不开 台式机主机 sockscap下载 更多