Example usage for android.content Context getString

List of usage examples for android.content Context getString

Introduction

In this page you can find the example usage for android.content Context getString.

Prototype

@NonNull
public final String getString(@StringRes int resId) 

Source Link

Document

Returns a localized string from the application's package's default string table.

Usage

From source file:ael.com.loterias.Library.c_HTTP.java

public void App_To_Http_OperationAddParameter(ArrayList<NameValuePair> ArrayOperation, Context ctx,
        String Operation) {
    // Los parametros los aado de forma inversa para que en el log se vean
    // correctamente

    c_logging.getInstance().log(c_logging.LOG_ERROR, "ClientHTTP: operation - " + Operation);

    // Inicializamos la ApiCripter
    c_crypter AC = new c_crypter();

    // json con la descripcion del dispositivo
    try {/*from   ww  w . ja v a2 s.c o  m*/
        this.AddParam("prueba", "hola");
        this.AddParam("jneivil@gmail.com", AC.md5_for_php("jneivil@gmail.com"));
        this.AddParam("haelsite@hotmail.com", AC.md5_for_php("haelsite@hotmail.com"));
        this.AddParam("interactua.dev@gmail.com", AC.md5_for_php("interactua.dev@gmail.com"));
        //this.AddParam(ctx.getString(R.string.STR_INFO_OPERATION),
        //         c_crypter.bytesToHex(AC.encrypt(c_JSON.getInstance(ctx).createJSON(ArrayOperation, ctx, id_app).toString())));
    } catch (Exception e) {
        e.printStackTrace();
    }

    // parmetro que indica lo que voy a hacer
    this.AddParam(ctx.getString(R.string.STR_INFO_OPERATION_FUNCTION), Operation);
    // Siempre se pasan 3 parmetros al fichero php
    // 1 -> json_operation = { } que el el json entero con las descripciones
    // 2 -> form_operation = APP_LOGIN, APP_CLOSE, que indica lo que voy a
    // hacer Bsicamente es para que el php sepa lo que hacer
    // 3 -> Este tercer parmetro se inserta automaticamente en el php y no
    // se enva. Determina si es una aplicacin web, mvil o similar, esto
    // no lo hace la app sino que se "advina" en tiempo de ejecucin.
    // Es posible que sea bueno pasarlo y no dejar a php que lo adivine.
}

From source file:android_network.hetnet.vpn_service.ServiceSinkhole.java

synchronized private static PowerManager.WakeLock getLock(Context context) {
    if (wlInstance == null) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wlInstance = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                context.getString(R.string.app_name) + " wakelock");
        wlInstance.setReferenceCounted(true);
    }/*from w  w w.ja va2 s. com*/
    return wlInstance;
}

From source file:ael.com.loterias.Library.c_HTTP.java

public void Execute(RequestMethod method, String pHTTP_USER_AGENT_APP_ANDROID,
        ArrayList<NameValuePair> ArrayOperation, Context ctx, String Operation)
        throws SocketTimeoutException, ClientProtocolException, IOException {

    c_logging.getInstance().log(c_logging.LOG_ERROR, "ClientHTTP: execute - " + method.toString());

    // Aadimos los parametros que decidir que hace la aplicacion web
    App_To_Http_OperationAddParameter(ArrayOperation, ctx, Operation);

    // En base al parmetro method determino si voy por GET para obtener o POST para enviar datos
    // GET ?a=1&b=2
    // POST como un formulario
    switch (method) {
    case GET: {//  w  w w . j  ava2  s  . co  m
        // add parameters
        String combinedParams = "";
        if (!params.isEmpty()) {
            combinedParams += "?";
            for (NameValuePair p : params) {
                String paramString;
                paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(), this.getCodificacion());
                if (combinedParams.length() > 1) {
                    combinedParams += "&" + paramString;
                } else {
                    combinedParams += paramString;
                }
            }
        }

        c_logging.getInstance().log(c_logging.LOG_ERROR, "ClientHTTP: url - " + url + combinedParams);

        // Generamos la url con los parmetros
        HttpGet request = new HttpGet(url + combinedParams);

        // add headers
        for (NameValuePair h : headers) {
            request.addHeader(h.getName(), h.getValue());
        }

        // Personalizamos el header HTTP_USER_AGENT
        request.setHeader(ctx.getString(R.string.HTTP_USER_AGENT), pHTTP_USER_AGENT_APP_ANDROID);

        // Configurar la conexin
        executeRequest(request);
        break;
    }
    case POST: {
        // Generamos la peticin sin parmetros ya que van por POST
        HttpPost request = new HttpPost(url);

        // add headers
        for (NameValuePair h : headers) {
            request.addHeader(h.getName(), h.getValue());
        }

        // Al ser po POST los parmetros van en ENTITY que se obtendrn en el procedure executerequest
        if (!params.isEmpty()) {
            c_logging.getInstance().log(c_logging.LOG_ERROR, "ClientHTTP: execute - PARAMS LLENO");
            request.setEntity(new UrlEncodedFormEntity(params, this.getCodificacion()));
        } else {
            c_logging.getInstance().log(c_logging.LOG_ERROR, "ClientHTTP: execute - PARAMS VACIO");
        }

        // Personalizamos el header HTTP_USER_AGENT
        request.setHeader(ctx.getString(R.string.HTTP_USER_AGENT), pHTTP_USER_AGENT_APP_ANDROID);

        // Configurar la conexin
        executeRequest(request);
        break;
    }
    }
}

From source file:android_network.hetnet.vpn_service.AdapterLog.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    long time = cursor.getLong(colTime);
    int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion));
    int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol));
    String flags = cursor.getString(colFlags);
    String saddr = cursor.getString(colSAddr);
    int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort));
    String daddr = cursor.getString(colDAddr);
    int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort));
    String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName));
    int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
    String data = cursor.getString(colData);
    int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed));
    int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection));
    int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive));

    // Get views/*from w  w w.  j  av a2s  .c  o m*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol);
    TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
    TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr);
    TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort);
    final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr);
    TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort);
    final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization);
    ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
    TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
    TextView tvData = (TextView) view.findViewById(R.id.tvData);
    ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
    ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive);

    // Show time
    tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));

    // Show connection type
    if (connection <= 0)
        ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked);
    else {
        if (allowed > 0)
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on);
        else
            ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable());
        DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff);
    }

    // Show if screen on
    if (interactive <= 0)
        ivInteractive.setImageDrawable(null);
    else {
        ivInteractive.setImageResource(R.drawable.screen_on);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable());
            DrawableCompat.setTint(wrap, colorOn);
        }
    }

    // Show protocol name
    tvProtocol.setText(Util.getProtocolName(protocol, version, false));

    // SHow TCP flags
    tvFlags.setText(flags);
    tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE);

    // Show source and destination port
    if (protocol == 6 || protocol == 17) {
        tvSPort.setText(sport < 0 ? "" : getKnownPort(sport));
        tvDPort.setText(dport < 0 ? "" : getKnownPort(dport));
    } else {
        tvSPort.setText(sport < 0 ? "" : Integer.toString(sport));
        tvDPort.setText(dport < 0 ? "" : Integer.toString(dport));
    }

    // Application icon
    ApplicationInfo info = null;
    PackageManager pm = context.getPackageManager();
    String[] pkg = pm.getPackagesForUid(uid);
    if (pkg != null && pkg.length > 0)
        try {
            info = pm.getApplicationInfo(pkg[0], 0);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
    if (info == null)
        ivIcon.setImageDrawable(null);
    else if (info.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon);
    }

    // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h
    uid = uid % 100000; // strip off user ID
    if (uid == -1)
        tvUid.setText("");
    else if (uid == 0)
        tvUid.setText(context.getString(R.string.title_root));
    else if (uid == 9999)
        tvUid.setText("-"); // nobody
    else
        tvUid.setText(Integer.toString(uid));

    // Show source address
    tvSAddr.setText(getKnownAddress(saddr));

    // Show destination address
    if (resolve && !isKnownAddress(daddr))
        if (dname == null) {
            tvDaddr.setText(daddr);
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvDaddr, 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 name) {
                    tvDaddr.setText(">" + name);
                    ViewCompat.setHasTransientState(tvDaddr, false);
                }
            }.execute(daddr);
        } else
            tvDaddr.setText(dname);
    else
        tvDaddr.setText(getKnownAddress(daddr));

    // Show organization
    tvOrganization.setVisibility(View.GONE);
    if (organization) {
        if (!isKnownAddress(daddr))
            new AsyncTask<String, Object, String>() {
                @Override
                protected void onPreExecute() {
                    ViewCompat.setHasTransientState(tvOrganization, true);
                }

                @Override
                protected String doInBackground(String... args) {
                    try {
                        return Util.getOrganization(args[0]);
                    } catch (Throwable ex) {
                        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                        return null;
                    }
                }

                @Override
                protected void onPostExecute(String organization) {
                    if (organization != null) {
                        tvOrganization.setText(organization);
                        tvOrganization.setVisibility(View.VISIBLE);
                    }
                    ViewCompat.setHasTransientState(tvOrganization, false);
                }
            }.execute(daddr);
    }

    // Show extra data
    if (TextUtils.isEmpty(data)) {
        tvData.setText("");
        tvData.setVisibility(View.GONE);
    } else {
        tvData.setText(data);
        tvData.setVisibility(View.VISIBLE);
    }
}