• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 package com.android.im.app;
19 
20 import com.android.im.R;
21 import com.android.im.engine.ImErrorInfo;
22 import com.android.im.imps.ImpsErrorInfo;
23 
24 import android.content.res.Resources;
25 
26 public class ErrorResUtils {
27 
getErrorRes(Resources res, int code, Object... args)28     public static String getErrorRes(Resources res, int code, Object... args) {
29         int resId = getErrorResId(code);
30         if (resId == 0) {
31             return res.getString(R.string.general_error, code);
32         } else {
33             return res.getString(resId, args);
34         }
35     }
36 
getErrorResId(int code)37     private static int getErrorResId(int code) {
38         switch (code) {
39             case ImErrorInfo.ILLEGAL_CONTACT_LIST_MANAGER_STATE:
40                 return R.string.contact_not_loaded;
41 
42             case ImErrorInfo.CONTACT_EXISTS_IN_LIST:
43                 return R.string.contact_already_exist;
44 
45             case ImErrorInfo.CANT_ADD_BLOCKED_CONTACT:
46                 return R.string.contact_blocked;
47 
48             case ImErrorInfo.CANT_CONNECT_TO_SERVER:
49                 return R.string.cant_connect_to_server;
50 
51             case ImErrorInfo.NETWORK_ERROR:
52                 return R.string.network_error;
53 
54             case ImpsErrorInfo.SERVICE_NOT_SUPPORTED:
55                 return R.string.service_not_support;
56 
57             case ImpsErrorInfo.INVALID_PASSWORD:
58                 return R.string.invalid_password;
59 
60             case ImpsErrorInfo.INTERNAL_SERVER_OR_NETWORK_ERROR:
61                 return R.string.internal_server_error;
62 
63             case ImpsErrorInfo.NOT_IMPLMENTED:
64                 return R.string.not_implemented;
65 
66             case ImpsErrorInfo.SERVER_UNAVAILABLE:
67                 return R.string.service_unavaiable;
68 
69             case ImpsErrorInfo.TIMEOUT:
70                 return R.string.timeout;
71 
72             case ImpsErrorInfo.VERSION_NOT_SUPPORTED:
73                 return R.string.version_not_supported;
74 
75             case ImpsErrorInfo.MESSAGE_QUEUE_FULL:
76                 return R.string.message_queue_full;
77 
78             case ImpsErrorInfo.DOMAIN_NOT_SUPPORTED:
79                 return R.string.domain_not_supported;
80 
81             case ImpsErrorInfo.UNKNOWN_USER:
82                 return R.string.unknown_user;
83 
84             case ImpsErrorInfo.RECIPIENT_BLOCKED_SENDER:
85                 return R.string.recipient_blocked_the_user;
86 
87             case ImpsErrorInfo.SESSION_EXPIRED:
88                 return R.string.session_expired;
89 
90             case ImpsErrorInfo.FORCED_LOGOUT:
91                 return R.string.forced_logout;
92 
93             case ImpsErrorInfo.ALREADY_LOGGED:
94                 return R.string.already_logged_in;
95 
96             case ImErrorInfo.NOT_LOGGED_IN:
97                 return R.string.not_signed_in;
98 
99             case ImpsErrorInfo.MSISDN_ERROR:
100                 return R.string.msisdn_error;
101 
102             default:
103                 return 0;
104         }
105     }
106 }
107