All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.solovyev.android.LabeledFormatter Maven / Gradle / Ivy

There is a newer version: 1.1.18
Show newest version
package org.solovyev.android;

import android.content.Context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.text.Formatter;

import java.lang.ref.WeakReference;

/**
 * User: serso
 * Date: 8/10/12
 * Time: 1:01 PM
 */
public class LabeledFormatter implements Formatter {

    @NotNull
    private WeakReference contextRef;

    public LabeledFormatter(@NotNull Context context) {
        this.contextRef = new WeakReference(context);
    }

    @Override
    public String formatValue(@Nullable T value) throws IllegalArgumentException {
        final Context context = contextRef.get();
        if (context != null) {
            return context.getString(value.getCaptionResId());
        } else {
            return String.valueOf(value);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy