ErrorResUtils.java
上传用户:szyujian
上传日期:2016-09-20
资源大小:320k
文件大小:3k
源码类别:

android开发

开发平台:

C/C++

  1. /*
  2.  * Copyright (C) 2008 Esmertec AG.
  3.  * Copyright (C) 2008 The Android Open Source Project
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package com.android.im.app;
  18. import com.android.im.R;
  19. import com.android.im.engine.ImErrorInfo;
  20. import com.android.im.imps.ImpsErrorInfo;
  21. import android.content.res.Resources;
  22. public class ErrorResUtils {
  23.     public static String getErrorRes(Resources res, int code, Object... args) {
  24.         int resId = getErrorResId(code);
  25.         if (resId == 0) {
  26.             return res.getString(R.string.general_error, code);
  27.         } else {
  28.             return res.getString(resId, args);
  29.         }
  30.     }
  31.     private static int getErrorResId(int code) {
  32.         switch (code) {
  33.             case ImErrorInfo.ILLEGAL_CONTACT_LIST_MANAGER_STATE:
  34.                 return R.string.contact_not_loaded;
  35.             case ImErrorInfo.CONTACT_EXISTS_IN_LIST:
  36.                 return R.string.contact_already_exist;
  37.             case ImErrorInfo.CANT_ADD_BLOCKED_CONTACT:
  38.                 return R.string.contact_blocked;
  39.             case ImErrorInfo.CANT_CONNECT_TO_SERVER:
  40.                 return R.string.cant_connect_to_server;
  41.             case ImErrorInfo.NETWORK_ERROR:
  42.                 return R.string.network_error;
  43.             case ImpsErrorInfo.SERVICE_NOT_SUPPORTED:
  44.                 return R.string.service_not_support;
  45.             case ImpsErrorInfo.INVALID_PASSWORD:
  46.                 return R.string.invalid_password;
  47.             case ImpsErrorInfo.INTERNAL_SERVER_OR_NETWORK_ERROR:
  48.                 return R.string.internal_server_error;
  49.             case ImpsErrorInfo.NOT_IMPLMENTED:
  50.                 return R.string.not_implemented;
  51.             case ImpsErrorInfo.SERVER_UNAVAILABLE:
  52.                 return R.string.service_unavaiable;
  53.             case ImpsErrorInfo.TIMEOUT:
  54.                 return R.string.timeout;
  55.             case ImpsErrorInfo.VERSION_NOT_SUPPORTED:
  56.                 return R.string.version_not_supported;
  57.             case ImpsErrorInfo.MESSAGE_QUEUE_FULL:
  58.                 return R.string.message_queue_full;
  59.             case ImpsErrorInfo.DOMAIN_NOT_SUPPORTED:
  60.                 return R.string.domain_not_supported;
  61.             case ImpsErrorInfo.UNKNOWN_USER:
  62.                 return R.string.unknown_user;
  63.             case ImpsErrorInfo.RECIPIENT_BLOCKED_SENDER:
  64.                 return R.string.recipient_blocked_the_user;
  65.             case ImpsErrorInfo.SESSION_EXPIRED:
  66.                 return R.string.session_expired;
  67.             case ImpsErrorInfo.FORCED_LOGOUT:
  68.                 return R.string.forced_logout;
  69.             case ImpsErrorInfo.ALREADY_LOGGED:
  70.                 return R.string.already_logged_in;
  71.             case ImErrorInfo.NOT_LOGGED_IN:
  72.                 return R.string.not_signed_in;
  73.        
  74.             case ImpsErrorInfo.MSISDN_ERROR:
  75.                 return R.string.msisdn_error;
  76.             default:
  77.                 return 0;
  78.         }
  79.     }
  80. }