package com.kitty.poclient.common; import android.os.Handler; import android.os.Message; import android.widget.Toast; import com.kitty.poclient.fragment.usb.ExternalDeviceFragment; import com.kitty.poclient.widget.CustomToast; public class MainHandler extends Handler { public static final int SHOW_INFO = 0; public static final int USB_INSERT = 1; public static final int USB_REMOVE = 2; public static final int SHOW_ALERT = 10; @Override public void handleMessage(Message msg) { String croutonText = (String) (msg.obj); if(UpnpApp.mainActivity != null){ switch (msg.what) { case SHOW_INFO: CroutonHelper.showSystemInfoCrouton(croutonText); break; case USB_INSERT: if(ExternalDeviceFragment.IS_ALIVE){ ExternalDeviceFragment.hasExternalDevice = true; ExternalDeviceFragment.getCurrentInstance().openFirstDir(); } /* CroutonHelper.showSystemInfoCrouton(croutonText);*/ break; case USB_REMOVE: if(ExternalDeviceFragment.IS_ALIVE){ ExternalDeviceFragment.hasExternalDevice = false; ExternalDeviceFragment.getCurrentInstance().showNoUsbdeviceDialog(); } /* CroutonHelper.showSystemInfoCrouton(croutonText);*/ break; case SHOW_ALERT: CroutonHelper.showSystemAlertCrouton(croutonText); break; } } else { CustomToast.makeText(UpnpApp.context, croutonText, Toast.LENGTH_SHORT).show(); } } public void showCommonMsg(int msgType, String msgText){ Message msg = obtainMessage(msgType, msgText); //(int what, Object obj) sendMessage(msg); } // public void showInfo(String msgText){ // showCommonMsg(SHOW_INFO, msgText); // } public void showInfo(int resourceId){ String infoText = getString(resourceId); showCommonMsg(SHOW_INFO, infoText); } public void showInfo(String croutonText){ showCommonMsg(SHOW_INFO, croutonText); } public void showAlert(int resourceId){ String alertText = getString(resourceId); showCommonMsg(SHOW_ALERT, alertText); } public void showAlert(String croutonText){ showCommonMsg(SHOW_ALERT, croutonText); } /** * 从资源文件获取文本信息。 * @param resourceId The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. * @return the string value associated with a particular resource ID. It will be stripped of any styled text information. */ public String getString(int resourceId){ String msgText = UpnpApp.context.getResources().getString(resourceId); return msgText; } }