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

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

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

import java.util.HashMap;
import java.util.Map;

import org.ioc.commons.flowcontrol.actioncontroller.ActionController;
import org.ioc.commons.flowcontrol.actioncontroller.ActionControllerBinder;
import org.ioc.commons.flowcontrol.actioncontroller.IsExternalAction;
import org.ioc.commons.flowcontrol.eventbus.EventBus;
import org.ioc.commons.flowcontrol.eventbus.EventBusBinder;
import org.ioc.commons.flowcontrol.eventbus.IsEvent;
import org.ioc.commons.flowcontrol.operationmanager.IsOperation;
import org.ioc.commons.flowcontrol.operationmanager.OperationManager;
import org.ioc.commons.flowcontrol.operationmanager.OperationManagerBinder;
import org.ioc.commons.impl.android.flowcontrol.AndroidFlowController;
import org.ioc.commons.ui.HasPrecisePosition;
import org.ioc.commons.ui.HasStorage;
import org.ioc.commons.ui.IsDisplay;
import org.ioc.commons.ui.IsPresenter;
import org.ioc.commons.ui.IsResizable;
import org.ioc.commons.ui.IsWidget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.HasContext;
import android.view.View;
import android.view.ViewParent;
import android.widget.LinearLayout;

public abstract class LinearLayoutDisplay, O extends Enum, A extends Enum, P extends IsPresenter>
		extends LinearLayout implements IsDisplay, IsResizable, HasPrecisePosition, HasStorage, HasContext {

	protected final AndroidFlowController flowController;
	protected final EventBus eventbus;
	protected final OperationManager operationManager;
	protected final ActionController actionController;
	private final Map storage = new HashMap();

	protected P presenter;

	private boolean initialized;

	public LinearLayoutDisplay(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		this.flowController = new AndroidFlowController(this.getContext(), false);
		this.eventbus = flowController.eventBus();
		this.operationManager = flowController.operationManager();
		this.actionController = flowController.actionController();
	}

	public LinearLayoutDisplay(Context context, AttributeSet attrs) {
		this(context, attrs,0);
	}

	public LinearLayoutDisplay(Context context) {
		this(context, null);
	}
	
	@Override
	protected void onAttachedToWindow() {
		super.onAttachedToWindow();
		if (this.presenter != null && !this.initialized) {
			this.initialized = true;
			this.presenter.onInitDisplay();
		}
	}

	final public EventBusBinder eventBus() {
		return this.eventbus;
	}

	final public OperationManagerBinder operationManager() {
		return this.operationManager;
	}

	final public ActionControllerBinder actionController() {
		return this.actionController;
	}

	@Override
	public void store(Object key, Object data) {
		storage.put(key, data);
	}

	@Override
	public Object retrieve(Object key) {
		return storage.get(key);
	}

	@Override
	public IsWidget getWidgetParent() {
		return LinearLayoutDisplay.getWidgetParent(this);
	}

	/**
	 * A helpful method for other widgets which need to implements
	 * {@link IsWidget#getWidgetParent()} and cannot or do not want to extend
	 * from {@link LinearLayoutDisplay}
	 * 
	 * @param w
	 *            Widget which we want to get its parent.
	 * @return Parent widget if exists or null otherwise.
	 */
	public static IsWidget getWidgetParent(View w) {
		ViewParent parent = w.getParent();
		return parent != null ? (parent instanceof IsWidget ? ((IsWidget) parent) : new IsWidgetImpl(parent)) : null;
	}

	@Override
	public boolean isInitialized() {
		return initialized;
	}

	@Override
	public Object asWidget() {
		return this;
	}

	@Override
	public void setWidth(int width) {
		DisplayComposite.setWidth(this, width);
	}

	@Override
	public void setHeight(int height) {
		DisplayComposite.setHeight(this, height);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy