Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2015 AChep@xda <artemchep@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */

import android.content.Context;
import android.content.res.Resources;

import android.support.annotation.NonNull;

import android.support.annotation.StringRes;
import java.util.IllegalFormatException;
import java.util.Locale;

public class Main {
    /**
     * @see #getString(android.content.res.Resources, int, Object...)
     */
    @NonNull
    public static String getString(@NonNull Context context, @StringRes int id, Object... formatArgs) {
        return getString(context.getResources(), id, formatArgs);
    }

    /**
     * Return the string value associated with a particular resource ID,
     * substituting the format arguments as defined in {@link java.util.Formatter}
     * and {@link java.lang.String#format}. It will be stripped of any styled text
     * information.
     *
     * @param id         The desired resource identifier, as generated by the aapt
     *                   tool. This integer encodes the package, type, and resource
     *                   entry. The value 0 is an invalid identifier.
     * @param formatArgs The format arguments that will be used for substitution.
     * @return String The string data associated with the resource,
     * stripped of styled text information.
     * @throws Resources.NotFoundException Throws NotFoundException if the given ID does not exist.
     */
    @NonNull
    public static String getString(@NonNull Resources resources, @StringRes int id, Object... formatArgs) {
        try {
            return resources.getString(id, formatArgs);
        } catch (IllegalFormatException e) {
            final String message = "Failed to format the string resource! The user locale is:"
                    + Locale.getDefault().toString();
            throw new IllegalArgumentException(message, e);
        }
    }
}