List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId, Object... formatArgs)
From source file:com.android.fastlibrary.AppException.java
/** * ????//from w ww . ja v a 2 s. c o m * * @param ctx */ public void makeToast(Context ctx) { switch (this.getType()) { case TYPE_HTTP_CODE: String err = ctx.getString(R.string.http_status_code_error, this.getCode()); Toast.makeText(ctx, err, Toast.LENGTH_SHORT).show(); break; case TYPE_HTTP_ERROR: Toast.makeText(ctx, R.string.http_exception_error, Toast.LENGTH_SHORT).show(); break; case TYPE_SOCKET: Toast.makeText(ctx, R.string.socket_exception_error, Toast.LENGTH_SHORT).show(); break; case TYPE_NETWORK: Toast.makeText(ctx, R.string.network_not_connected, Toast.LENGTH_SHORT).show(); break; case TYPE_XML: Toast.makeText(ctx, R.string.xml_parser_failed, Toast.LENGTH_SHORT).show(); break; case TYPE_JSON: Toast.makeText(ctx, R.string.xml_parser_failed, Toast.LENGTH_SHORT).show(); break; case TYPE_IO: Toast.makeText(ctx, R.string.io_exception_error, Toast.LENGTH_SHORT).show(); break; case TYPE_RUN: Toast.makeText(ctx, R.string.app_run_code_error, Toast.LENGTH_SHORT).show(); break; } }
From source file:com.tcl.lzhang1.mymusic.AppException.java
/** * Make toast.//from w w w . j ava2 s.c o m * * @param ctx the ctx */ public void makeToast(Context ctx) { switch (this.getType()) { case TYPE_HTTP_CODE: String err = ctx.getString(R.string.http_status_code_error, this.getCode()); Toast.makeText(ctx, err, Toast.LENGTH_SHORT).show(); break; case TYPE_HTTP_ERROR: Toast.makeText(ctx, R.string.http_exception_error, Toast.LENGTH_SHORT).show(); break; case TYPE_SOCKET: Toast.makeText(ctx, R.string.socket_exception_error, Toast.LENGTH_SHORT).show(); break; case TYPE_NETWORK: Toast.makeText(ctx, R.string.network_not_connected, Toast.LENGTH_SHORT).show(); break; case TYPE_XML: Toast.makeText(ctx, R.string.xml_parser_failed, Toast.LENGTH_SHORT).show(); break; case TYPE_IO: Toast.makeText(ctx, R.string.io_exception_error, Toast.LENGTH_SHORT).show(); break; case TYPE_RUN: Toast.makeText(ctx, R.string.app_run_code_error, Toast.LENGTH_SHORT).show(); break; } }
From source file:android_network.hetnet.vpn_service.AdapterAccess.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final long id = cursor.getLong(colID); final int version = cursor.getInt(colVersion); final int protocol = cursor.getInt(colProtocol); final String daddr = cursor.getString(colDaddr); final int dport = cursor.getInt(colDPort); long time = cursor.getLong(colTime); int allowed = cursor.getInt(colAllowed); int block = cursor.getInt(colBlock); long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent); long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived); int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections); // Get views/*from www . j av a2 s. c om*/ TextView tvTime = (TextView) view.findViewById(R.id.tvTime); ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock); final TextView tvDest = (TextView) view.findViewById(R.id.tvDest); LinearLayout llTraffic = (LinearLayout) view.findViewById(R.id.llTraffic); TextView tvConnections = (TextView) view.findViewById(R.id.tvConnections); TextView tvTraffic = (TextView) view.findViewById(R.id.tvTraffic); // Set values tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time)); if (block < 0) ivBlock.setImageDrawable(null); else { ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable()); DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn); } } tvDest.setText( Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "")); if (Util.isNumericAddress(daddr)) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { ViewCompat.setHasTransientState(tvDest, true); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String addr) { tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr + (dport > 0 ? "/" + dport : "")); ViewCompat.setHasTransientState(tvDest, false); } }.execute(daddr); if (allowed < 0) tvDest.setTextColor(colorText); else if (allowed > 0) tvDest.setTextColor(colorOn); else tvDest.setTextColor(colorOff); llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE); if (connections > 0) tvConnections.setText(context.getString(R.string.msg_count, connections)); if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024 * 1024f) : 0))); else if (sent > 1204 * 1024L || received > 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024f) : 0))); else tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0), (received > 0 ? received / 1024f : 0))); }