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;
}
/**
*获取当前屏幕截图不包含状态栏
*
BlueHost 主机商在以前做外贸网站的时候还是经常会用到的,想必那时候有做外贸网站或者是选择海外主机的时候还是较多会用BlueHost主机商的。只不过这些年云服务器流行且性价比较高,于是大家可选择商家变多,但是BlueHost在外贸主机用户群中可选的还是比较多的。这次年中618活动大促来袭,毕竟BLUEHOST商家目前中文公司设立在上海,等后面有机会也过去看看。他们也会根据我们的国内年中促销发...
Pia云商家在前面有介绍过一次,根据市面上的信息是2018的开办的国人商家,原名叫哔哔云,目前整合到了魔方云平台。这个云服务商家主要销售云服务器VPS主机业务和服务,云服务器采用KVM虚拟架构 。目前涉及的机房有美国洛杉矶、中国香港和深圳地区。洛杉矶为crea机房,三网回程CN2 GIA,自带20G防御。中国香港机房的线路也是CN2直连大陆,比较适合建站或者有游戏业务需求的用户群。在这篇文章中,简...
RAKsmart 虽然是美国主机商,但是商家的主要客户群还是在我们国内,于是我们可以看到每次的国内节日促销活动期间商家也会发布促销。包括这次年中大促活动,RAKsmart商家也有发布为期两个月的年终活动,其中有商家擅长的独立服务器和便宜VPS主机。服务器包括站群服务器、特价服务器、高达10G带宽不限制流量的美国服务器。商家优惠活动,可以看到对应商品的优惠,同时也可以使用 优惠码 RAKBL9 同时...