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

org.ioc.commons.impl.android.ui.FragmentDisplay 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.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.HasContext;
import android.view.View;
import android.view.ViewParent;

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

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

	protected P presenter;

	private boolean initialized;

	public FragmentDisplay() {
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		this.initialized = false;
		this.flowController = new AndroidFlowController(this.getContext(), false);
		this.eventbus = flowController.eventBus();
		this.operationManager = flowController.operationManager();
		this.actionController = flowController.actionController();
		
		this.flowController.onActivityCreated(savedInstanceState);
	}

	@Override
	public void onStart() {
		super.onStart();
		if (this.presenter != null && !this.initialized) {
			this.initialized = true;
			this.presenter.onInitDisplay();
		}

		this.flowController.onStart();
	}

	@Override
	public void onResume() {
		super.onResume();

		this.flowController.onResume();
	}

	@Override
	public void onPause() {
		super.onPause();

		this.flowController.onPause();
	}

	@Override
	public void onStop() {
		super.onStop();
		
		this.flowController.onStop();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();

		this.flowController.onDestroy();
	}

	@Override
	public Context getContext() {
		return this.getActivity();
	}

	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 FragmentDisplay.getWidgetParent(this.getView());
	}

	/**
	 * A helpful method for other widgets which need to implements
	 * {@link IsWidget#getWidgetParent()} and cannot or do not want to extend
	 * from {@link FragmentDisplay}
	 * 
	 * @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.getView(), width);
	}

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

	@Override
	public int getWidth() {
		return this.getView().getWidth();
	}

	@Override
	public int getHeight() {
		return this.getView().getHeight();
	}

	@Override
	public float getX() {
		return this.getView().getX();
	}

	@Override
	public float getY() {
		return this.getView().getY();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy