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.chen.mail.browse.SendersView.java

private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) {
    if (sConfigurationChangedReceiver == null && resourceCachingRequired) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override//from w w w.  j av a2  s  . c om
            public void onReceive(Context context, Intent intent) {
                sDraftSingularString = null;
                getSenderResources(context, true);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (sDraftSingularString == null) {
        Resources res = context.getResources();
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedString = res.getString(R.string.senders_elided);
        sDraftSingularString = res.getQuantityText(R.plurals.draft, 1);
        sDraftPluralString = res.getQuantityText(R.plurals.draft, 2);
        sDraftCountFormatString = res.getString(R.string.draft_count_format);
        sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance);
        sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance);
        sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance);
        sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersUnreadTextAppearance);
        sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance);
        sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersReadTextAppearance);
        sMessageCountSpacerString = res.getString(R.string.message_count_spacer);
        sSendingString = res.getString(R.string.sending);
        sBidiFormatter = BidiFormatter.getInstance();
    }
}

From source file:com.android.mail.browse.SendersView.java

private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) {
    if (sConfigurationChangedReceiver == null && resourceCachingRequired) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override//from   ww w  .  j a  va 2s  .com
            public void onReceive(Context context, Intent intent) {
                sDraftSingularString = null;
                getSenderResources(context, true);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (sDraftSingularString == null) {
        Resources res = context.getResources();
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedString = res.getString(R.string.senders_elided);
        sDraftSingularString = res.getQuantityText(R.plurals.draft, 1);
        sDraftPluralString = res.getQuantityText(R.plurals.draft, 2);
        sDraftCountFormatString = res.getString(R.string.draft_count_format);
        sMeSubjectString = res.getString(R.string.me_subject_pronoun);
        sMeObjectString = res.getString(R.string.me_object_pronoun);
        sToHeaderString = res.getString(R.string.to_heading);
        sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance);
        sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance);
        sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance);
        sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceUnreadStyle);
        sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance);
        sRetryingStyleSpan = new TextAppearanceSpan(context, R.style.RetryingTextAppearance);
        sFailedStyleSpan = new TextAppearanceSpan(context, R.style.FailedTextAppearance);
        sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceReadStyle);
        sMessageCountSpacerString = res.getString(R.string.message_count_spacer);
        sSendingString = res.getString(R.string.sending);
        sRetryingString = res.getString(R.string.message_retrying);
        sFailedString = res.getString(R.string.message_failed);
        sBidiFormatter = BidiFormatter.getInstance();
    }
}

From source file:com.aegiswallet.utils.BasicUtils.java

public static String getNFCErrorMessage(Context context, String writeMessage) {
    String result = null;//from   www  . ja  v  a 2 s .  c o m

    Resources resources = context.getResources();

    if (writeMessage.equals(Constants.NFC_TAG_TOO_SMALL)) {
        result = resources.getString(R.string.nfc_error_tag_too_small);
    } else if (writeMessage.equals(Constants.NFC_READ_ONLY)) {
        result = resources.getString(R.string.nfc_error_tag_read_only);
    } else if (writeMessage.equals(Constants.NFC_CANT_CONNECT)) {
        result = resources.getString(R.string.nfc_error_tag_cant_connect);
    } else if (writeMessage.equals(Constants.NFC_CANT_FORMAT)) {
        result = resources.getString(R.string.nfc_error_tag_cant_format);
    } else if (writeMessage.equals(Constants.NFC_TAG_NOT_SUPPORTED)) {
        result = resources.getString(R.string.nfc_error_tag_not_supported);
    } else if (writeMessage.equals(Constants.NFC_WRITE_EXCEPTION)) {
        result = resources.getString(R.string.nfc_error_tag_write_exception);
    }

    return result;
}

From source file:com.owncloud.android.ui.errorhandling.ErrorMessageAdapter.java

/**
 * Return a user message corresponding to a generic error for a given operation.
 *
 * @param operation     Operation performed.
 * @param res           Reference to app resources, for i18n.
 * @return User message corresponding to a generic error of 'operation'.
 *//*ww w .  j  a  va 2  s .  c  o  m*/
@Nullable
private static String getGenericErrorMessageForOperation(RemoteOperation operation, Resources res) {
    String message = null;

    if (operation instanceof UploadFileOperation) {
        message = String.format(res.getString(R.string.uploader_upload_failed_content_single),
                ((UploadFileOperation) operation).getFileName());

    } else if (operation instanceof DownloadFileOperation) {
        message = String.format(res.getString(R.string.downloader_download_failed_content),
                new File(((DownloadFileOperation) operation).getSavePath()).getName());

    } else if (operation instanceof RemoveFileOperation) {
        message = res.getString(R.string.remove_fail_msg);

    } else if (operation instanceof RenameFileOperation) {
        message = res.getString(R.string.rename_server_fail_msg);

    } else if (operation instanceof CreateFolderOperation) {
        message = res.getString(R.string.create_dir_fail_msg);

    } else if (operation instanceof CreateShareViaLinkOperation
            || operation instanceof CreateShareWithShareeOperation) {
        message = res.getString(R.string.share_link_file_error);

    } else if (operation instanceof UnshareOperation) {
        message = res.getString(R.string.unshare_link_file_error);

    } else if (operation instanceof UpdateShareViaLinkOperation
            || operation instanceof UpdateSharePermissionsOperation) {
        message = res.getString(R.string.update_link_file_error);

    } else if (operation instanceof MoveFileOperation) {
        message = res.getString(R.string.move_file_error);

    } else if (operation instanceof SynchronizeFolderOperation) {
        String folderPathName = new File(((SynchronizeFolderOperation) operation).getFolderPath()).getName();
        message = String.format(res.getString(R.string.sync_folder_failed_content), folderPathName);

    } else if (operation instanceof CopyFileOperation) {
        message = res.getString(R.string.copy_file_error);
    }

    return message;
}

From source file:com.bt.download.android.gui.util.UIUtils.java

public static String getFileTypeAsString(Resources resources, byte fileType) {
    switch (fileType) {
    case Constants.FILE_TYPE_APPLICATIONS:
        return resources.getString(R.string.applications);
    case Constants.FILE_TYPE_AUDIO:
        return resources.getString(R.string.audio);
    case Constants.FILE_TYPE_DOCUMENTS:
        return resources.getString(R.string.documents);
    case Constants.FILE_TYPE_PICTURES:
        return resources.getString(R.string.pictures);
    case Constants.FILE_TYPE_RINGTONES:
        return resources.getString(R.string.ringtones);
    case Constants.FILE_TYPE_VIDEOS:
        return resources.getString(R.string.video);
    case Constants.FILE_TYPE_TORRENTS:
        return resources.getString(R.string.media_type_torrents);
    default://from ww w  . j  av a 2 s  .c  o m
        return resources.getString(R.string.unknown);
    }
}

From source file:com.achep.acdisplay.notifications.NotificationHelper.java

@NonNull
public static Notification buildNotification(@NonNull Context context, final int id,
        @NonNull Object... objects) {
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.stat_acdisplay).setColor(App.ACCENT_COLOR).setAutoCancel(true);

    PendingIntent pi = null;//from  ww  w  . java 2  s.co m
    switch (id) {
    case App.ID_NOTIFY_TEST: {
        NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
                .bigText(res.getString(R.string.notification_test_message_large));
        builder.setStyle(bts).setContentTitle(res.getString(R.string.app_name))
                .setContentText(res.getString(R.string.notification_test_message))
                .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        break;
    }
    case App.ID_NOTIFY_BATH: {
        CharSequence contentText = (CharSequence) objects[0];
        Intent contentIntent = (Intent) objects[1];
        // Build notification
        pi = PendingIntent.getActivity(context, id, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentTitle(res.getString(R.string.service_bath)).setContentText(contentText)
                .setPriority(Notification.PRIORITY_MIN);
        break;
    }
    case App.ID_NOTIFY_INIT: {
        builder.setSmallIcon(R.drawable.stat_notify).setContentTitle(res.getString(R.string.app_name))
                .setContentText(res.getString(R.string.notification_init_text))
                .setPriority(Notification.PRIORITY_MIN);
        break;
    }
    case App.ID_NOTIFY_APP_AUTO_DISABLED: {
        CharSequence summary = (CharSequence) objects[0];
        NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
                .bigText(res.getString(R.string.permissions_auto_disabled)).setSummaryText(summary);
        builder.setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
                .setContentTitle(res.getString(R.string.app_name))
                .setContentText(res.getString(R.string.permissions_auto_disabled))
                .setPriority(Notification.PRIORITY_HIGH).setStyle(bts);
        break;
    }
    default:
        throw new IllegalArgumentException();
    }
    if (pi == null) {
        pi = PendingIntent.getActivity(context, id, new Intent(context, MainActivity.class),
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
    return builder.setContentIntent(pi).build();
}

From source file:com.owncloud.android.ui.errorhandling.ErrorMessageAdapter.java

/**
 * Return a user message corresponding to an operation result with no knowledge about the operation
 * performed./*  w  ww . j a  va  2  s.  c  o m*/
 *
 * @param result        Result of a {@link RemoteOperation} performed.
 * @param res           Reference to app resources, for i18n.
 * @return User message corresponding to 'result'.
 */
@Nullable
private static String getCommonMessageForResult(RemoteOperationResult result, Resources res) {

    String message = null;

    if (!result.isSuccess()) {
        if (result.getCode() == ResultCode.WRONG_CONNECTION) {
            message = res.getString(R.string.network_error_socket_exception);

        } else if (result.getCode() == ResultCode.TIMEOUT) {
            message = res.getString(R.string.network_error_socket_exception);

            if (result.getException() instanceof SocketTimeoutException) {
                message = res.getString(R.string.network_error_socket_timeout_exception);

            } else if (result.getException() instanceof ConnectTimeoutException) {
                message = res.getString(R.string.network_error_connect_timeout_exception);
            }

        } else if (result.getCode() == ResultCode.HOST_NOT_AVAILABLE) {
            message = res.getString(R.string.network_host_not_available);

        } else if (result.getCode() == ResultCode.MAINTENANCE_MODE) {
            message = res.getString(R.string.maintenance_mode);

        } else if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {
            message = res.getString(R.string.uploads_view_upload_status_failed_ssl_certificate_not_trusted);

        } else if (result.getHttpPhrase() != null && result.getHttpPhrase().length() > 0) {
            // last chance: error message from server
            message = result.getHttpPhrase();
        }
    }

    return message;
}

From source file:com.achep.acdisplay.ui.activities.MainActivity.java

private static void sendTestNotification(@NonNull Context context) {
    final int id = App.ID_NOTIFY_TEST;
    final Resources res = context.getResources();

    PendingIntent pendingIntent = PendingIntent.getActivity(context, id,
            new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
            .bigText(res.getString(R.string.notification_test_message_large));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(res.getString(R.string.app_name))
            .setContentText(res.getString(R.string.notification_test_message)).setContentIntent(pendingIntent)
            .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
            .setSmallIcon(R.drawable.stat_acdisplay).setAutoCancel(true).setStyle(bts)
            .setColor(App.ACCENT_COLOR)//from  w w w . j  a  va  2s.co m
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(id, builder.build());
}

From source file:com.bullmobi.message.ui.activities.MainActivity.java

private static void sendTestNotification(@NonNull Context context) {
    final int id = App.ID_NOTIFY_TEST;
    final Resources res = context.getResources();

    PendingIntent pendingIntent = PendingIntent.getActivity(context, id,
            new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle()
            .bigText(res.getString(R.string.notification_test_message_large));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(res.getString(R.string.app_name))
            .setContentText(res.getString(R.string.notification_test_message)).setContentIntent(pendingIntent)
            .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))
            .setSmallIcon(R.drawable.stat_easynotification).setAutoCancel(true).setStyle(bts)
            .setColor(App.ACCENT_COLOR)/* w  ww  . j  av a 2s .c  om*/
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(id, builder.build());
}

From source file:com.silentcircle.silenttext.util.DeviceUtils.java

public static boolean isPartnerDevice(Resources resources) {
    return resources != null && isPartnerDevice(resources.getString(R.string.build_partners).split(","));
}