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

org.ioc.commons.impl.android.ui.HasTextWrapper Maven / Gradle / Ivy

package org.ioc.commons.impl.android.ui;

import org.ioc.commons.ui.HasStorage;
import org.ioc.commons.ui.HasText;

import android.widget.TextView;

public class HasTextWrapper {

	private HasTextWrapper() {
		/* No const */
	}

	/**
	 * Get a new wrapper from a {@link TextView} instance.
	 * 
	 * @param widget
	 *            The instance to wrap
	 * @return A new wrapper
	 */
	public static HasText from(final TextView widget) {
		return new HasText() {

			@Override
			public void setText(String value) {
				widget.setText(value);
			}

			@Override
			public String getText() {
				return widget.getText().toString();
			}

		};
	}

	/**
	 * Get a new wrapper from a {@link TextView} instance.
	 * 
	 * @param widget
	 *            The instance to wrap
	 * @param cache
	 *            Wrappers cache
	 * @return A new wrapper
	 */
	public static HasText from(final TextView widget, HasStorage cache) {
		Object cached = cache.retrieve(widget);
		HasText hasText = (cached instanceof HasText ? (HasText) cached : null);
		if (hasText == null) {
			hasText = from(widget);
			cache.store(widget, hasText);
		}
		return hasText;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy