Android Open Source - msghandle Utils






From Project

Back to project page msghandle.

License

The source code is released under:

GNU General Public License

If you think the Android project msghandle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.anlong.msghandle.util;
/*from www . ja va2 s .com*/
import java.io.InputStream;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.Properties;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.anlong.msghandle.event.MessageEvent;
import com.anlong.msghandle.event.MessageEventSource;


/**
 * @Title: Utils.java 
 * @Package com.anlong.msghandle.util
 * @company ShenZhen AnLong Technology CO.,LTD.   
 * @author lixl   
 * @date 2014-3-12 ????3:56:43 
 * @version V1.0   
 * @Description: ???
 */
public class Utils {
  
  /**
   * ???????????
   * @return
   * @throws Exception
   */
  private static Properties getSource() throws Exception {
    ClassLoader classLoader = Utils.class.getClassLoader();
        URL resUrl = classLoader.getResource("/project.properties");
        InputStream input = resUrl.openStream();
        Properties property = new Properties();
        property.load(input);
        return property;
  }
  
  /**
   * ????????????
   * @param propertyName
   * @return
   */
  public static String getProperty(String propertyName){
    try {
      Properties property = getSource();
          return property.getProperty(propertyName);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
  
  /**
   * ??????????
   * SERVER_IP=""  , SERVER_PORT=""
   * @param name
   * @param value
   */
  public static void setProperty(String name,String value){
    try {
      Properties property = getSource();
          property.setProperty(name, value);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * TODO ?????????????1-????,2-?????,3-????Socket????,4-IP?????????????,
   *       5-?????,6-?????????,7-??Socket????,8-??????????
   * @author anlong 
   */
  public static void notifyMessage(Object obj,short bcode){
    try {
      Object object = obj;
      MessageEvent event = new MessageEvent(bcode, object);
      MessageEventSource eventSource=MessageEventSource.getSingleton();
      if(eventSource!=null){
        eventSource.notifyMessageEvent(event);
      }
      
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  
  /**
   * @Title: isNetworkConnected 
   * @Description: TODO ????????? 
   * @author anlong 
   * @param @param context
   * @param @return     
   * @return boolean     
   * @throws
   */
  public static boolean isNetworkConnected(Context context) {  
    if (context != null) {  
      ConnectivityManager mConnectivityManager = (ConnectivityManager) context  
          .getSystemService(Context.CONNECTIVITY_SERVICE);  
      NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();  
      if (mNetworkInfo != null) {  
        return mNetworkInfo.isAvailable();  
      }  
    }  
    return false;  
    /*State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();  
      if(State.CONNECTED==state){  
       Log.i("??", "GPRS?????");  
      }  
        
      state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();  
      if(State.CONNECTED==state){  
       Log.i("??", "WIFI?????");  
      }  */
  }  
  
  /**
   * ??????????????
   * 
   * @param fileSize
   * @return
   * @param
   */
  public static String getFileSizeString(Long fileS) {
    if (fileS == null) {
      fileS = 0L;
    }
    DecimalFormat df = new DecimalFormat("#.00");
    String fileSizeString = "";
    if (fileS < 1024) {
      fileSizeString = df.format((double) fileS) + "B";
    } else if (fileS < 1048576) {
      fileSizeString = df.format((double) fileS / 1024) + "K";
    } else if (fileS < 1073741824) {
      fileSizeString = df.format((double) fileS / 1048576) + "M";
    } else {
      fileSizeString = df.format((double) fileS / 1073741824) + "G";
    }
    return fileSizeString;
  }

  /** equals??? */
  public static boolean equals(String s1, String s2) {
    if (Utils.isNotNull(s1) && Utils.isNotNull(s2) && s1.equals(s2)) {
      return true;
    } else {
      return false;
    }
  }

  public static boolean equals(Object obj1, Object obj2) {
    if (Utils.isNotNull(obj1) && Utils.isNotNull(obj2)
        && obj1.toString().equals(obj2.toString())) {
      return true;
    } else {
      return false;
    }
  }

  /** ???????? */
  public static boolean isNull(Object obj1) {
    if (Utils.isNotNull(obj1)) {
      return false;
    } else {
      return true;
    }
  }

  /** ?????????? */
  public static boolean isNotNull(Object obj1) {
    if (null == obj1 || "".equals(obj1.toString())
        || "null".equals(obj1.toString())) {
      return false;
    } else {
      return true;
    }
  }

  /** int?????? */
  public static int getInt(String intValue, int defaultValue) {
    int value = defaultValue;
    try {
      value = Integer.parseInt(intValue);
    } catch (Exception e) {

    }
    return value;
  }

  /** long?????? */
  public static long getLong(String longValue, long defaultValue) {
    long value = defaultValue;
    try {
      Long.parseLong(longValue);
    } catch (Exception e) {
    }
    return value;
  }

}




Java Source Code List

com.anlong.msghandle.common.BaseMessage.java
com.anlong.msghandle.common.HandleStaticValue.java
com.anlong.msghandle.common.HandleTimer.java
com.anlong.msghandle.common.MessageTimer.java
com.anlong.msghandle.event.MessageEventListener.java
com.anlong.msghandle.event.MessageEventSource.java
com.anlong.msghandle.event.MessageEvent.java
com.anlong.msghandle.file.InitImageFileServer.java
com.anlong.msghandle.handle.ImageRequestHandle.java
com.anlong.msghandle.handle.ImageResponseHandle.java
com.anlong.msghandle.handle.MsgRequestHandle.java
com.anlong.msghandle.handle.MsgResponseHandle.java
com.anlong.msghandle.impl.AppParamImpl.java
com.anlong.msghandle.impl.AppSystemMessageReportImpl.java
com.anlong.msghandle.impl.AuthenticationImpl.java
com.anlong.msghandle.impl.BroadcastImpl.java
com.anlong.msghandle.impl.CommonContactImpl.java
com.anlong.msghandle.impl.DepImpl.java
com.anlong.msghandle.impl.DepInfoListImpl.java
com.anlong.msghandle.impl.EditGroupImpl.java
com.anlong.msghandle.impl.EditGroupUserImpl.java
com.anlong.msghandle.impl.EditUserInfoImpl.java
com.anlong.msghandle.impl.ExitPreventGroupImpl.java
com.anlong.msghandle.impl.GetGroupInfoImpl.java
com.anlong.msghandle.impl.GetHistoryMessageImpl.java
com.anlong.msghandle.impl.GetUserInfoImpl105.java
com.anlong.msghandle.impl.GroupInfoListImpl.java
com.anlong.msghandle.impl.GroupShareImpl.java
com.anlong.msghandle.impl.HeartImpl103.java
com.anlong.msghandle.impl.LocationImpl.java
com.anlong.msghandle.impl.LoginImpl101.java
com.anlong.msghandle.impl.MessageStateReportImpl.java
com.anlong.msghandle.impl.OnlineStateImpl102.java
com.anlong.msghandle.impl.OnlineUserListImpl110.java
com.anlong.msghandle.impl.SendImageFile.java
com.anlong.msghandle.impl.SendMessageImpl203.java
com.anlong.msghandle.impl.SystemParaImpl.java
com.anlong.msghandle.impl.UnreadMessageImpl.java
com.anlong.msghandle.impl.UpdatePasswordImpl.java
com.anlong.msghandle.impl.UserInfoListImpl.java
com.anlong.msghandle.interfac.AbstractMsgHandle.java
com.anlong.msghandle.interfac.BaseActivity.java
com.anlong.msghandle.interfac.MessageHandleActivity.java
com.anlong.msghandle.interfac.MsgHandle.java
com.anlong.msghandle.message.InitRequMessageServer.java
com.anlong.msghandle.message.InitRespMessageServer.java
com.anlong.msghandle.request.BaseRequest.java
com.anlong.msghandle.request.Request100.java
com.anlong.msghandle.request.Request101.java
com.anlong.msghandle.request.Request102.java
com.anlong.msghandle.request.Request103.java
com.anlong.msghandle.request.Request105.java
com.anlong.msghandle.request.Request110.java
com.anlong.msghandle.request.Request203.java
com.anlong.msghandle.request.Request301.java
com.anlong.msghandle.response.BaseResponse.java
com.anlong.msghandle.response.Response1000.java
com.anlong.msghandle.response.Response1010.java
com.anlong.msghandle.response.Response1020.java
com.anlong.msghandle.response.Response1030.java
com.anlong.msghandle.response.Response1050.java
com.anlong.msghandle.response.Response1100.java
com.anlong.msghandle.response.Response2030.java
com.anlong.msghandle.response.Response3010.java
com.anlong.msghandle.service.InitServerManager.java
com.anlong.msghandle.service.ServerManager.java
com.anlong.msghandle.socket.InitFileSocketServer.java
com.anlong.msghandle.socket.InitMsgSocketServer.java
com.anlong.msghandle.util.ByteAndInt.java
com.anlong.msghandle.util.FormatTransfer.java
com.anlong.msghandle.util.IMLog.java
com.anlong.msghandle.util.ReflectionUtil.java
com.anlong.msghandle.util.Utils.java
com.anlong.msghandle.vo.AppMessage.java
com.anlong.msghandle.vo.Application.java
com.anlong.msghandle.vo.BroadcastMessage.java
com.anlong.msghandle.vo.DepInfo.java
com.anlong.msghandle.vo.GroupInfo.java
com.anlong.msghandle.vo.GroupShare.java
com.anlong.msghandle.vo.OnlineUser.java
com.anlong.msghandle.vo.ReportState.java
com.anlong.msghandle.vo.SimpleUserInfo.java
com.anlong.msghandle.vo.UserInfo.java
com.anlong.msghandle.vo.UserMessage.java