Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

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

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.github.shareme.gwschips.library.BaseRecipientAdapter.java

public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor,
        Account account) {/*from   w  w  w  . j a  v a 2 s  . c o m*/
    final PackageManager packageManager = context.getPackageManager();
    final List<DirectorySearchParams> paramsList = new ArrayList<>();
    DirectorySearchParams preferredDirectory = null;
    while (directoryCursor.moveToNext()) {
        final long id = directoryCursor.getLong(DirectoryListQuery.ID);

        // Skip the local invisible directory, because the default directory already includes
        // all local results.
        if (id == Directory.LOCAL_INVISIBLE) {
            continue;
        }

        final DirectorySearchParams params = new DirectorySearchParams();
        final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME);
        final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID);
        params.directoryId = id;
        params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME);
        params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME);
        params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE);
        if (packageName != null && resourceId != 0) {
            try {
                final Resources resources = packageManager.getResourcesForApplication(packageName);
                params.directoryType = resources.getString(resourceId);
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e);
            }
        }

        // If an account has been provided and we found a directory that
        // corresponds to that account, place that directory second, directly
        // underneath the local contacts.
        if (account != null && account.name.equals(params.accountName)
                && account.type.equals(params.accountType)) {
            preferredDirectory = params;
        } else {
            paramsList.add(params);
        }
    }

    if (preferredDirectory != null) {
        paramsList.add(1, preferredDirectory);
    }

    return paramsList;
}

From source file:com.google.android.apps.forscience.whistlepunk.review.GraphExploringSeekBar.java

private void init() {
    // Use an AccessibilityDelegate to add custom text to Accessibility events.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        @Override/*www . ja v  a 2 s. c o  m*/
        public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onPopulateAccessibilityEvent(host, event);
            event.getText().clear();
            event.getText().add(generateEventText());
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setText(generateEventText());
        }
    });

    Resources res = getContext().getResources();
    mFormat = res.getString(R.string.graph_exploring_seekbar_content_description);

    // Always use LTR layout, since graphs are always LTR.
    setLayoutDirection(LAYOUT_DIRECTION_LTR);
}

From source file:com.mk4droid.IMC_Services.Security.java

/**
 * Authenticate user using username and password. Password is encrypted and then sent. 
 * //  w w w  . j ava 2s .co  m
 * @param Username   latin characters
 * @param Password   actual password up to 16 chars (latin characters)
 * @param resources  for UI
 * @param ctx        for current Android activity
 * @return
 */
public static void AuthFun(String Username_in, String Password_in, Resources resources, Context ctx_in,
        boolean updVotes_in) {

    ctx = ctx_in;
    Username = Username_in;
    Password = Password_in;
    updVotes = updVotes_in;

    if (Username.equals(""))
        ctx.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("Authenticated", "failed"));

    if (InternetConnCheck.getInstance(ctx).isOnline(ctx)) {
        new AsyncAuth(Constants_API.COM_Protocol + Constants_API.ServerSTR + Constants_API.phpExec, "GET",
                new String[] { "option", "com_improvemycity", "task", Phptasks.TASK_AUTH_USER, "format", "json",
                        "username", Username_in, "password", EncWrapper(Password_in) },
                "UTF-8", "CalledBySecurity").execute();

    } else {
        Toast.makeText(ctx, resources.getString(R.string.NoInternet), tlv).show();
        ctx.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("Authenticated", "failed"));
    }
}

From source file:com.vrem.wifianalyzer.wifi.channelavailable.ChannelAvailableAdapterTest.java

@Test
public void testGetView() throws Exception {
    // setup/*from w  ww  .ja va  2  s . c  om*/
    Resources resources = mainActivity.getResources();
    String wiFiBand2 = resources.getString(WiFiBand.GHZ2.getTextResource());
    String wiFiBand5 = resources.getString(WiFiBand.GHZ5.getTextResource());
    String expected = wiFiChannelCountry.getCountryCode() + " - " + wiFiChannelCountry.getCountryName();
    String expected_GHZ_2 = StringUtils.join(wiFiChannelCountry.getChannelsGHZ2().toArray(), ",");
    String expected_GHZ_5 = StringUtils.join(wiFiChannelCountry.getChannelsGHZ5().toArray(), ",");
    // execute
    View actual = fixture.getView(0, null, null);
    // validate
    assertNotNull(actual);

    assertEquals(expected, ((TextView) actual.findViewById(R.id.channel_available_country)).getText());
    assertEquals(wiFiBand2 + " : ",
            ((TextView) actual.findViewById(R.id.channel_available_title_ghz_2)).getText());
    assertEquals(expected_GHZ_2, ((TextView) actual.findViewById(R.id.channel_available_ghz_2)).getText());
    assertEquals(wiFiBand5 + " : ",
            ((TextView) actual.findViewById(R.id.channel_available_title_ghz_5)).getText());
    assertEquals(expected_GHZ_5, ((TextView) actual.findViewById(R.id.channel_available_ghz_5)).getText());
}

From source file:com.glanznig.beepme.MainSectionsPagerAdapter.java

@Override
public CharSequence getPageTitle(int position) {
    Resources res = context.getResources();
    switch (position) {
    case 0:/*from w w  w.  ja v  a2s.  co  m*/
        return res.getString(R.string.samples);
    case 1:
        return res.getString(R.string.history);
    }

    return "";
}

From source file:com.android.ex.chips.BaseRecipientAdapter.java

public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor,
        Account account) {// w  w w. ja v a 2 s.  co m
    final PackageManager packageManager = context.getPackageManager();
    final List<DirectorySearchParams> paramsList = new ArrayList<DirectorySearchParams>();
    DirectorySearchParams preferredDirectory = null;
    while (directoryCursor.moveToNext()) {
        final long id = directoryCursor.getLong(DirectoryListQuery.ID);

        // Skip the local invisible directory, because the default directory already includes
        // all local results.
        if (id == Directory.LOCAL_INVISIBLE) {
            continue;
        }

        final DirectorySearchParams params = new DirectorySearchParams();
        final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME);
        final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID);
        params.directoryId = id;
        params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME);
        params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME);
        params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE);
        if (packageName != null && resourceId != 0) {
            try {
                final Resources resources = packageManager.getResourcesForApplication(packageName);
                params.directoryType = resources.getString(resourceId);
                if (params.directoryType == null) {
                    Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e);
            }
        }

        // If an account has been provided and we found a directory that
        // corresponds to that account, place that directory second, directly
        // underneath the local contacts.
        if (account != null && account.name.equals(params.accountName)
                && account.type.equals(params.accountType)) {
            preferredDirectory = params;
        } else {
            paramsList.add(params);
        }
    }

    if (preferredDirectory != null) {
        paramsList.add(1, preferredDirectory);
    }

    return paramsList;
}

From source file:net.naonedbus.rest.controller.NodRestController.java

/**
 * Rcuprer tous les lments sous forme de liste d'object dfinie.
 * /*from ww w. j a v a2 s.  c o m*/
 * @param apiSection
 * @return La liste des lments.
 * @throws IOException
 * @throws JSONException
 */
protected List<T> getAll(final Resources res, final String apiSection) throws IOException, JSONException {
    final URL url = new URL(String.format(PATH, apiSection, res.getString(R.string.nod_key)));
    return parseJson(url);
}

From source file:com.vrem.wifianalyzer.navigation.items.ExportItem.java

@NonNull
private String getTitle(@NonNull MainActivity mainActivity) {
    Resources resources = mainActivity.getResources();
    return resources.getString(R.string.action_access_points);
}

From source file:be.uhasselt.privacypolice.NotificationHandler.java

/**
 * Asks the user whether it is certain that a network should be currently available
 * @param SSID The name of the network//from  www  . j  av  a  2 s  .c  om
 * @param BSSID The MAC address of the access point that triggered this (only used when we will block the AP)
 */
public void askNetworkPermission(String SSID, String BSSID) {
    Log.d("PrivacyPolice", "Asking permission for " + SSID + " (" + BSSID + ")");
    // Intent that will be used when the user allows the network
    Intent addIntent = new Intent(ctx, PermissionChangeReceiver.class);
    addIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID).putExtra("enable", true);
    PendingIntent addPendingIntent = PendingIntent.getBroadcast(ctx, 0, addIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Intent that will be used when the user blocks the network
    Intent disableIntent = new Intent(ctx, PermissionChangeReceiver.class);
    disableIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID).putExtra("enable", false);
    PendingIntent disablePendingIntent = PendingIntent.getBroadcast(ctx, 1, disableIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Intent that will be used when the user's OS does not support notification actions
    Intent activityIntent = new Intent(ctx, AskPermissionActivity.class);
    activityIntent.putExtra("SSID", SSID).putExtra("BSSID", BSSID);
    PendingIntent activityPendingIntent = PendingIntent.getActivity(ctx, 2, activityIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    // Build the notification dynamically, based on the network name
    Resources res = ctx.getResources();
    String headerString = String.format(res.getString(R.string.permission_header), SSID);
    String permissionString = String.format(res.getString(R.string.ask_permission), SSID);
    String yes = res.getString(R.string.yes);
    String no = res.getString(R.string.no);

    // NotificationCompat makes sure that the notification will also work on Android <4.0
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_notification).setPriority(Notification.PRIORITY_MAX) // To force it to be first in list (and thus, expand)
            .setContentTitle(headerString).setContentText(permissionString)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(permissionString))
            .setContentIntent(activityPendingIntent)
            .addAction(android.R.drawable.ic_delete, no, disablePendingIntent)
            .addAction(android.R.drawable.ic_input_add, yes, addPendingIntent);
    notificationManager.notify(0, mBuilder.build());
}

From source file:com.androzic.route.RouteStart.java

public void updateRouteInfo(View view) {
    if (route.length() < 2) {
        Toast.makeText(getActivity(), R.string.err_shortroute, Toast.LENGTH_LONG).show();
        // "Close" fragment
        getFragmentManager().popBackStack();
        return;/* w w  w  . java  2 s .c  o m*/
    }

    TextView name = (TextView) view.findViewById(R.id.name);
    name.setText(route.name);

    Waypoint start = route.getWaypoint(0);
    Waypoint end = route.getWaypoint(route.length() - 1);

    RadioButton forward = (RadioButton) view.findViewById(R.id.forward);
    RadioButton reverse = (RadioButton) view.findViewById(R.id.reverse);

    Resources resources = getResources();
    String from = resources.getString(R.string.from_start);
    String to = resources.getString(R.string.start_to_end);
    forward.setText(from + " " + start.name + " " + to + " " + end.name);
    reverse.setText(from + " " + end.name + " " + to + " " + start.name);

    forward.setChecked(true);
}