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.synox.android.utils.ErrorMessageAdapter.java

public static String getErrorCauseMessage(RemoteOperationResult result, RemoteOperation operation,
        Resources res) {

    String message = null;/*from  ww w .  j a va  2  s  .co m*/

    if (!result.isSuccess() && isNetworkError(result.getCode())) {
        message = getErrorMessage(result, res);

    } else if (operation instanceof UploadFileOperation) {

        if (result.isSuccess()) {
            message = String.format(res.getString(R.string.uploader_upload_succeeded_content_single),
                    ((UploadFileOperation) operation).getFileName());
        } else {
            if (result.getCode() == ResultCode.LOCAL_STORAGE_FULL
                    || result.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) {
                message = String.format(res.getString(R.string.error__upload__local_file_not_copied),
                        ((UploadFileOperation) operation).getFileName(), res.getString(R.string.app_name));
                /*
                } else if (result.getCode() == ResultCode.QUOTA_EXCEEDED) {
                    message = res.getString(R.string.failed_upload_quota_exceeded_text);
                    */

            } else if (result.getCode() == ResultCode.FORBIDDEN) {
                message = String.format(res.getString(R.string.forbidden_permissions),
                        res.getString(R.string.uploader_upload_forbidden_permissions));

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

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

    } else if (operation instanceof DownloadFileOperation) {

        if (result.isSuccess()) {
            message = String.format(res.getString(R.string.downloader_download_succeeded_content),
                    new File(((DownloadFileOperation) operation).getSavePath()).getName());

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

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

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

        } else {
            if (result.getCode().equals(ResultCode.FORBIDDEN)) {
                // Error --> No permissions
                message = String.format(res.getString(R.string.forbidden_permissions),
                        res.getString(R.string.forbidden_permissions_delete));
            } else {
                message = res.getString(R.string.remove_fail_msg);
            }
        }

    } else if (operation instanceof RenameFileOperation) {
        if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
            message = res.getString(R.string.rename_local_fail_msg);

        } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_rename));

        } else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
            message = res.getString(R.string.filename_forbidden_characters);

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

        } else {
            message = res.getString(R.string.rename_server_fail_msg);
        }

    } else if (operation instanceof SynchronizeFileOperation) {
        if (!((SynchronizeFileOperation) operation).transferWasRequested()) {
            message = res.getString(R.string.sync_file_nothing_to_do_msg);
        }

    } else if (operation instanceof CreateFolderOperation) {
        if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
            message = res.getString(R.string.filename_forbidden_characters);

        } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_create));

        } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
            message = res.getString(R.string.filename_forbidden_charaters_from_server);
        } else {
            message = res.getString(R.string.create_dir_fail_msg);
        }
    } else if (operation instanceof CreateShareViaLinkOperation
            || operation instanceof CreateShareWithShareeOperation) {

        if (result.getData() != null && result.getData().size() > 0) {
            message = (String) result.getData().get(0); // share API sends its own error messages

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

        } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.share_link_forbidden_permissions));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.share_link_file_error);
        }

    } else if (operation instanceof UnshareOperation) {

        if (result.getData() != null && result.getData().size() > 0) {
            message = (String) result.getData().get(0); // share API sends its own error messages

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

        } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.unshare_link_forbidden_permissions));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.unshare_link_file_error);
        }

    } else if (operation instanceof UpdateShareViaLinkOperation) {

        if (result.getData() != null && result.getData().size() > 0) {
            message = (String) result.getData().get(0); // share API sends its own error messages

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

        } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.update_link_forbidden_permissions));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.update_link_file_error);
        }

    } else if (operation instanceof MoveFileOperation) {

        if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
            message = res.getString(R.string.move_file_not_found);
        } else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) {
            message = res.getString(R.string.move_file_invalid_into_descendent);

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

        } else if (result.getCode() == ResultCode.FORBIDDEN) {
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_move));

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

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.move_file_error);
        }
    } else if (operation instanceof SynchronizeFolderOperation) {

        if (!result.isSuccess()) {
            String folderPathName = new File(((SynchronizeFolderOperation) operation).getFolderPath())
                    .getName();
            if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
                message = String.format(res.getString(R.string.sync_current_folder_was_removed),
                        folderPathName);

            } else { // Generic error
                // Show a Message, operation finished without success
                message = String.format(res.getString(R.string.sync_folder_failed_content), folderPathName);
            }
        }
    } else if (operation instanceof CopyFileOperation) {
        if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
            message = res.getString(R.string.copy_file_not_found);
        } else if (result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT) {
            message = res.getString(R.string.copy_file_invalid_into_descendent);

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

        } else if (result.getCode() == ResultCode.FORBIDDEN) {
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_copy));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.copy_file_error);
        }
    }

    return message;
}

From source file:com.cerema.cloud2.utils.ErrorMessageAdapter.java

public static String getErrorCauseMessage(RemoteOperationResult result, RemoteOperation operation,
        Resources res) {

    String message = null;/*  ww  w  .  ja  va 2  s .com*/

    if (!result.isSuccess() && isNetworkError(result.getCode())) {
        message = getErrorMessage(result, res);

    } else if (operation instanceof UploadFileOperation) {

        if (result.isSuccess()) {
            message = String.format(res.getString(R.string.uploader_upload_succeeded_content_single),
                    ((UploadFileOperation) operation).getFileName());
        } else {
            if (result.getCode() == ResultCode.LOCAL_STORAGE_FULL
                    || result.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) {
                message = String.format(res.getString(R.string.error__upload__local_file_not_copied),
                        ((UploadFileOperation) operation).getFileName(), res.getString(R.string.app_name));
                /*
                } else if (result.getCode() == ResultCode.QUOTA_EXCEEDED) {
                    message = res.getString(R.string.failed_upload_quota_exceeded_text);
                    */

            } else if (result.getCode() == ResultCode.FORBIDDEN) {
                message = String.format(res.getString(R.string.forbidden_permissions),
                        res.getString(R.string.uploader_upload_forbidden_permissions));

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

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

    } else if (operation instanceof DownloadFileOperation) {

        if (result.isSuccess()) {
            message = String.format(res.getString(R.string.downloader_download_succeeded_content),
                    new File(((DownloadFileOperation) operation).getSavePath()).getName());

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

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

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

        } else {
            if (result.getCode().equals(ResultCode.FORBIDDEN)) {
                // Error --> No permissions
                message = String.format(res.getString(R.string.forbidden_permissions),
                        res.getString(R.string.forbidden_permissions_delete));
            } else {
                message = res.getString(R.string.remove_fail_msg);
            }
        }

    } else if (operation instanceof RenameFileOperation) {
        if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
            message = res.getString(R.string.rename_local_fail_msg);

        } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_rename));

        } else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
            message = res.getString(R.string.filename_forbidden_characters);

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

        } else {
            message = res.getString(R.string.rename_server_fail_msg);
        }

    } else if (operation instanceof SynchronizeFileOperation) {
        if (!((SynchronizeFileOperation) operation).transferWasRequested()) {
            message = res.getString(R.string.sync_file_nothing_to_do_msg);
        }

    } else if (operation instanceof CreateFolderOperation) {
        if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
            message = res.getString(R.string.filename_forbidden_characters);

        } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_create));

        } else if (result.getCode() == ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER) {
            message = res.getString(R.string.filename_forbidden_charaters_from_server);
        } else {
            message = res.getString(R.string.create_dir_fail_msg);
        }
    } else if (operation instanceof CreateShareViaLinkOperation
            || operation instanceof CreateShareWithShareeOperation) {

        if (result.getData() != null && result.getData().size() > 0) {
            message = (String) result.getData().get(0); // share API sends its own error messages

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

        } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.share_link_forbidden_permissions));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.share_link_file_error);
        }

    } else if (operation instanceof UnshareOperation) {

        if (result.getData() != null && result.getData().size() > 0) {
            message = (String) result.getData().get(0); // share API sends its own error messages

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

        } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.unshare_link_forbidden_permissions));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.unshare_link_file_error);
        }

    } else if (operation instanceof UpdateShareViaLinkOperation
            || operation instanceof UpdateSharePermissionsOperation) {

        if (result.getData() != null && result.getData().size() > 0) {
            message = (String) result.getData().get(0); // share API sends its own error messages

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

        } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
            // Error --> No permissions
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.update_link_forbidden_permissions));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.update_link_file_error);
        }

    } else if (operation instanceof MoveFileOperation) {

        if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
            message = res.getString(R.string.move_file_not_found);
        } else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) {
            message = res.getString(R.string.move_file_invalid_into_descendent);

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

        } else if (result.getCode() == ResultCode.FORBIDDEN) {
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_move));

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

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.move_file_error);
        }
    } else if (operation instanceof SynchronizeFolderOperation) {

        if (!result.isSuccess()) {
            String folderPathName = new File(((SynchronizeFolderOperation) operation).getFolderPath())
                    .getName();
            if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
                message = String.format(res.getString(R.string.sync_current_folder_was_removed),
                        folderPathName);

            } else { // Generic error
                // Show a Message, operation finished without success
                message = String.format(res.getString(R.string.sync_folder_failed_content), folderPathName);
            }
        }
    } else if (operation instanceof CopyFileOperation) {
        if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
            message = res.getString(R.string.copy_file_not_found);
        } else if (result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT) {
            message = res.getString(R.string.copy_file_invalid_into_descendent);

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

        } else if (result.getCode() == ResultCode.FORBIDDEN) {
            message = String.format(res.getString(R.string.forbidden_permissions),
                    res.getString(R.string.forbidden_permissions_copy));

        } else { // Generic error
            // Show a Message, operation finished without success
            message = res.getString(R.string.copy_file_error);
        }
    }

    return message;
}

From source file:com.mobile.natal.natalchart.NetworkUtilities.java

/**
 * Get a default message for an HTTP code.
 *
 * @param context          the context to use.
 * @param responseCode     the http code.
 * @param defaultOkMessage an optional message for the ok code.
 * @return the message./* w  w w  .j  av a  2 s.c  om*/
 */
public static String getMessageForCode(Context context, int responseCode, String defaultOkMessage) {
    Resources resources = context.getResources();
    switch (responseCode) {
    case HttpURLConnection.HTTP_OK:
        if (defaultOkMessage != null) {
            return defaultOkMessage;
        } else {
            return resources.getString(R.string.http_ok_msg);
        }
    case HttpURLConnection.HTTP_FORBIDDEN:
        return resources.getString(R.string.http_forbidden_msg);
    case HttpURLConnection.HTTP_UNAUTHORIZED:
        return resources.getString(R.string.http_forbidden_msg);
    case HttpURLConnection.HTTP_NOT_FOUND:
        return resources.getString(R.string.http_not_found_msg);
    default:
        return resources.getString(R.string.http_not_implemented_code_msg) + " " + responseCode;
    }
}

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

/**
 * Return an internationalized user message corresponding to an operation result
 * and the operation performed.//from   w w w.j a  v a 2  s . c  om
 *
 * @param result        Result of a {@link RemoteOperation} performed.
 * @param operation     Operation performed.
 * @param res           Reference to app resources, for i18n.
 * @return User message corresponding to 'result' and 'operation'.
 */
@NonNull
public static String getErrorCauseMessage(RemoteOperationResult result, RemoteOperation operation,
        Resources res) {
    String message = getSpecificMessageForResultAndOperation(result, operation, res);

    if (message == null || message.length() <= 0) {
        message = getCommonMessageForResult(result, res);
    }

    if (message == null || message.length() <= 0) {
        message = getGenericErrorMessageForOperation(operation, res);
    }

    if (message == null) {
        if (result.isSuccess()) {
            message = res.getString(R.string.common_ok);

        } else {
            message = res.getString(R.string.common_error_unknown);
        }
    }

    return message;
}

From source file:com.google.android.apps.santatracker.notification.SantaNotificationBuilder.java

/**
 * Construct a generic Santa notification with a headline title.
 *//*  w w w  .j  ava 2s.  c  o m*/
private static Notification GetNotification(Context c, int headline) {
    Resources r = c.getResources();

    // Add the wearable extender with a different notification background
    Bitmap largeIcon = BitmapFactory.decodeResource(r, R.drawable.santa_notification_background);
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
            .setHintHideIcon(false).setBackground(largeIcon);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
            .setSmallIcon(R.drawable.notification_small)
            .setColor(c.getResources().getColor(R.color.brandSantaTracker)).setAutoCancel(true)
            .setContentTitle(r.getString(headline)).setContentText(r.getString(R.string.track_santa))
            .extend(wearableExtender);

    // Add the type of notification for wearable to app tracking of clicks
    Intent i = new Intent(c, StartupActivity.class);
    i.putExtra(NotificationConstants.KEY_NOTIFICATION_TYPE, NotificationConstants.TAKEOFF_PATH);

    // Add the intent to open the main startup activity when clicked
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(c);
    stackBuilder.addParentStack(StartupActivity.class);
    stackBuilder.addNextIntent(i);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    return mBuilder.build();
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java

static CharSequence dumpIntentFilter(IntentFilter filter, Resources res, boolean isBroadcast) {
    FormattedTextBuilder ftb = new FormattedTextBuilder();
    int tagColor = res.getColor(R.color.xml_tag);
    int attributeNameColor = res.getColor(R.color.xml_attr_name);
    int attributeValueColor = res.getColor(R.color.xml_attr_value);
    int commentColor = res.getColor(R.color.xml_comment);
    final String protectedComment = " <!-- " + res.getString(R.string.broadcast_action_protected_comment)
            + " -->";

    ftb.appendColoured("\n<intent-filter>", tagColor);

    for (int i = 0, j = filter.countActions(); i < j; i++) {
        final String action = filter.getAction(i);
        ftb.appendColoured("\n  <action", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + action + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);

        if (isBroadcast && Utils.isProtectedBroadcast(action)) {
            ftb.appendColoured(protectedComment, commentColor);
        }/*from  w ww  . ja  va  2 s. co  m*/
    }

    for (int i = 0, j = filter.countCategories(); i < j; i++) {
        ftb.appendColoured("\n  <category", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getCategory(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataSchemes(); i < j; i++) {
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:scheme=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getDataScheme(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataAuthorities(); i < j; i++) {
        IntentFilter.AuthorityEntry authority = filter.getDataAuthority(i);
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:host=", attributeNameColor);
        ftb.appendColoured("\"" + authority.getHost() + "\"", attributeValueColor);
        if (authority.getPort() != -1) {
            ftb.appendColoured(" a:port=", attributeNameColor);
            ftb.appendColoured("\"" + authority.getPort() + "\"", attributeValueColor);
        }
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataPaths(); i < j; i++) {
        PatternMatcher pathMatcher = filter.getDataPath(i);
        int type = pathMatcher.getType();
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(
                " a:path"
                        + (type == PatternMatcher.PATTERN_LITERAL ? ""
                                : type == PatternMatcher.PATTERN_PREFIX ? "Prefix"
                                        : type == PatternMatcher.PATTERN_SIMPLE_GLOB ? "Pattern" : "[unknown]")
                        + "=",
                attributeNameColor);
        ftb.appendColoured("\"" + pathMatcher.getPath() + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataTypes(); i < j; i++) {
        String dataType = filter.getDataType(i);
        if (!dataType.contains("/")) {
            // IntentFilter for partial types don't store "/*" at end
            // e.g. "image" instead of "image/*".
            // We display it in full form here
            dataType += "/*";
        }
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:mimeType=", attributeNameColor);
        ftb.appendColoured("\"" + dataType + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    ftb.appendColoured("\n</intent-filter>", tagColor);
    return ftb.getText();
}

From source file:com.nttec.everychan.chans.makaba.MakabaJsonMapper.java

static BoardModel defaultBoardModel(String boardName, Resources resources) {
    BoardModel model = new BoardModel();
    model.chan = CHAN_NAME;/*from  w w  w.j  a  v  a  2  s.  c  o  m*/
    model.uniqueAttachmentNames = true;
    model.timeZoneId = "GMT+3";
    model.readonlyBoard = false;
    model.allowDeletePosts = false;
    model.allowDeleteFiles = false;
    model.allowReport = BoardModel.REPORT_WITH_COMMENT;
    model.allowSage = true;
    model.allowEmails = true;
    model.ignoreEmailIfSage = true;
    model.allowCustomMark = true;
    model.allowRandomHash = true;
    model.searchAllowed = true;
    model.catalogAllowed = true;
    model.catalogTypeDescriptions = new String[] { resources.getString(R.string.makaba_catalog_standart),
            resources.getString(R.string.makaba_catalog_last_reply),
            resources.getString(R.string.makaba_catalog_num),
            resources.getString(R.string.makaba_catalog_image_size) };
    model.firstPage = 0;
    model.attachmentsFormatFilters = ATTACHMENT_FORMATS;
    model.markType = BoardModel.MARK_BBCODE;

    model.boardName = boardName;
    model.boardDescription = boardName;
    model.boardCategory = "";

    model.defaultUserName = "?";
    model.bumpLimit = 500;
    model.lastPage = 9;

    model.nsfw = SFW_BOARDS.indexOf(model.boardName) == -1;
    model.requiredFileForNewThread = NO_IMAGES_BOARDS.indexOf(model.boardName) == -1;
    model.attachmentsMaxCount = NO_IMAGES_BOARDS.indexOf(model.boardName) == -1 ? 4 : 0;
    model.allowSubjects = NO_SUBJECTS_BOARDS.indexOf(model.boardName) == -1;
    model.allowNames = NO_USERNAMES_BOARDS.indexOf(model.boardName) == -1;

    return model;
}

From source file:cm.confide.ex.chips.BaseRecipientAdapter.java

public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor,
        Account account) {/*from   w w  w. j  a  v  a2 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            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:com.deepak.myclock.alarms.AlarmNotifications.java

public static void showAlarmNotification(Context context, AlarmInstance instance) {
    Log.v("Displaying alarm notification for alarm instance: " + instance.mId);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    // Close dialogs and window shade, so this will display
    context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    Resources resources = context.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(instance.getLabelOrDefault(context))
            .setContentText(AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false).setWhen(0);

    // Setup Snooze Action
    Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(context, "SNOOZE_TAG", instance,
            AlarmInstance.SNOOZE_STATE);
    PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), snoozeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.addAction(R.drawable.stat_notify_alarm, resources.getString(R.string.alarm_alert_snooze_text),
            snoozePendingIntent);//from   w w w  .  j  av  a2  s . co m

    // Setup Dismiss Action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance,
            AlarmInstance.DISMISSED_STATE);
    PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(context, instance.hashCode(), dismissIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.addAction(android.R.drawable.ic_menu_close_clear_cancel,
            resources.getString(R.string.alarm_alert_dismiss_text), dismissPendingIntent);

    // Setup Content Action
    Intent contentIntent = AlarmInstance.createIntent(context, AlarmActivity.class, instance.mId);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), contentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup fullscreen intent
    /*Intent fullScreenIntent = AlarmInstance.createIntent(context, AlarmActivity.class,
       instance.mId);
    // set action, so we can be different then content pending intent
    fullScreenIntent.setAction("fullscreen_activity");
    fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
       Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    notification.setFullScreenIntent(PendingIntent.getActivity(context,
       instance.hashCode(), fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT), true);*/
    notification.setPriority(NotificationCompat.PRIORITY_MAX);

    nm.cancel(instance.hashCode());
    nm.notify(instance.hashCode(), notification.build());
}

From source file:gmc.hotplate.logic.ServerDataManager.java

public ServerDataManager(Context context) {
    this.context = context;
    Resources r = context.getResources();
    urlString = r.getString(R.string.default_url);
    recipes = new ArrayList<Recipe>();
    connection = new Connection(context);
}