<commit_before>// Copyright eeGeo Ltd (2012-2015), All Rights Reserved

package com.eegeo.menu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.json.JSONObject;

import com.eegeo.entrypointinfrastructure.MainActivity;
import com.eegeo.mobileexampleapp.R;

import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.RelativeLayout;

public abstract class MenuView implements View.OnClickListener, MenuAnimationStateCallback
{
	protected enum MenuState
	{
	    OFF_SCREEN,
	    CLOSED_ON_SCREEN,
	    OPEN_ON_SCREEN
	};
	
	protected MainActivity m_activity = null;
    protected long m_nativeCallerPointer;
    protected View m_view = null;
    protected MenuExpandableListView m_list = null;
    protected MenuExpandableListOnClickListener m_expandableListOnClickListener = null;
    
    protected Boolean m_loggingEnabled = true;
    
    protected MenuState m_menuState = MenuState.OFF_SCREEN;
    protected boolean m_animating = false;
    
    protected MenuAnimationHandler m_menuAnimationHandler = null;

    protected abstract void refreshListData(List<String> groups, HashMap<String, List<String>> groupToChildrenMap);
    
    protected abstract void onMenuChildItemClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id);

    public MenuView(MainActivity activity, long nativeCallerPointer)
    {
        m_activity = activity;
        m_nativeCallerPointer = nativeCallerPointer;
    }

    public void destroy()
    {
        final RelativeLayout uiRoot = (RelativeLayout)m_activity.findViewById(R.id.ui_container);
        uiRoot.removeView(m_view);
        m_view = null;
    }

    public boolean isAnimating()
    {
        return m_animating;
    }

    public boolean isDragging()
    {
        return false;
    }

    public void updateAnimation(final float deltaSeconds)
    {
    	// TODO: IR: animations are handled automatically via MenuAnimationHandler
    }
    
    @Override
    public void onOffScreenAnimationComplete()
    {
    	m_animating = false;
    }
    
    @Override
    public void onClosedOnScreenAnimationComplete()
    {
    	MenuViewJniMethods.ViewCloseCompleted(m_nativeCallerPointer);
    	
    	m_animating = false;
    	
        m_list.setVisibility(View.GONE);
    }
    
    @Override
	public void onOpenOnScreenAnimationComplete()
	{
    	MenuViewJniMethods.ViewOpenCompleted(m_nativeCallerPointer);
    	
    	m_animating = false;
    	
    	m_list.setEnabled(true);
	}

    public float normalisedAnimationProgress()
    {
    	return m_menuAnimationHandler.getOpenOnScreenState();
    }
    
    public void animateToClosedOnScreen()
    {
    	if(m_animating || m_menuAnimationHandler.isClosedOnScreen())
    	{
    		return;
    	}
    	
    	m_animating = true;
    	
    	m_menuAnimationHandler.playToClosedOnScreen();
    	
    	m_list.setEnabled(false);
    	
    	m_menuState = MenuState.CLOSED_ON_SCREEN;
    	
    	MenuViewJniMethods.ViewCloseCompleted(m_nativeCallerPointer);
    }

    public void animateToOpenOnScreen()
    {
    	if(m_animating || m_menuAnimationHandler.isOpenOnScreen())
    	{
    		return;
    	}
    	
    	m_animating = true;
    	
    	m_menuAnimationHandler.playToOpenOnScreen();
    	
    	m_menuState = MenuState.OPEN_ON_SCREEN;
    	
    	MenuViewJniMethods.ViewOpenCompleted(m_nativeCallerPointer);
    }

    public void animateOffScreen()
    {
    	if(m_animating) 
    	{
    		if(m_menuAnimationHandler.isOffScreen()) 
    		{
				m_menuAnimationHandler.cancelAnimation();<commit_msg>Fix for MPLY-7403 Cash occurring across all apps when selecting any option within the LHS and RHS menus on Android. Buddy: Michael<commit_after>// Copyright eeGeo Ltd (2012-2015), All Rights Reserved

package com.eegeo.menu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.json.JSONObject;

import com.eegeo.entrypointinfrastructure.MainActivity;
import com.eegeo.mobileexampleapp.R;

import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.RelativeLayout;

public abstract class MenuView implements View.OnClickListener, MenuAnimationStateCallback
{
	protected enum MenuState
	{
	    OFF_SCREEN,
	    CLOSED_ON_SCREEN,
	    OPEN_ON_SCREEN
	};
	
	protected MainActivity m_activity = null;
    protected long m_nativeCallerPointer;
    protected View m_view = null;
    protected MenuExpandableListView m_list = null;
    protected MenuExpandableListOnClickListener m_expandableListOnClickListener = null;
    
    protected Boolean m_loggingEnabled = true;
    
    protected MenuState m_menuState = MenuState.OFF_SCREEN;
    protected boolean m_animating = false;
    
    protected MenuAnimationHandler m_menuAnimationHandler = null;

    protected abstract void refreshListData(List<String> groups, HashMap<String, List<String>> groupToChildrenMap);
    
    protected abstract void onMenuChildItemClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id);

    public MenuView(MainActivity activity, long nativeCallerPointer)
    {
        m_activity = activity;
        m_nativeCallerPointer = nativeCallerPointer;
    }

    public void destroy()
    {
        final RelativeLayout uiRoot = (RelativeLayout)m_activity.findViewById(R.id.ui_container);
        uiRoot.removeView(m_view);
        m_view = null;
    }

    public boolean isAnimating()
    {
        return m_animating;
    }

    public boolean isDragging()
    {
        return false;
    }

    public void updateAnimation(final float deltaSeconds)
    {
    	// TODO: IR: animations are handled automatically via MenuAnimationHandler
    }
    
    @Override
    public void onOffScreenAnimationComplete()
    {
    	m_animating = false;
    }
    
    @Override
    public void onClosedOnScreenAnimationComplete()
    {
    	MenuViewJniMethods.ViewCloseCompleted(m_nativeCallerPointer);
    	
    	m_animating = false;
    	
        m_list.setVisibility(View.GONE);
    }
    
    @Override
	public void onOpenOnScreenAnimationComplete()
	{
    	MenuViewJniMethods.ViewOpenCompleted(m_nativeCallerPointer);
    	
    	m_animating = false;
    	
    	m_list.setEnabled(true);
	}

    public float normalisedAnimationProgress()
    {
    	return m_menuAnimationHandler.getOpenOnScreenState();
    }
    
    public void animateToClosedOnScreen()
    {
    	if(m_animating || m_menuAnimationHandler.isClosedOnScreen())
    	{
    		return;
    	}
    	
    	m_animating = true;
    	
    	m_menuAnimationHandler.playToClosedOnScreen();
    	
    	m_list.setEnabled(false);
    	
    	m_menuState = MenuState.CLOSED_ON_SCREEN;
    	
    	Handler closeHandler = new Handler();
    	closeHandler.postDelayed(new Runnable()
    	{
			@Override
			public void run()
			{
				MenuViewJniMethods.ViewCloseCompleted(m_nativeCallerPointer);
			}
		}, 1);
    }

    public void animateToOpenOnScreen()
    {
    	if(m_animating || m_menuAnimationHandler.isOpenOnScreen())
    	{
    		return;
    	}
    	
    	m_animating = true;
    	
    	m_menuAnimationHandler.playToOpenOnScreen();
    	
    	m_menuState = MenuState.OPEN_ON_SCREEN;
    	
    	Handler openHandler = new Handler();
    	openHandler.postDelayed(new Runnable()
    	{
			@Override
			public void run()
			{
				MenuViewJniMethods.ViewOpenCompleted(m_nativeCallerPointer);
			}
		}, 1);
    }

    public void animateOffScreen()
    {
    	if(m_animating) 
    	{
    		if(m_menuAnimationHandler.isOffScreen()) 
    		{
				m_menuAnimationHandler.cancelAnimation();
{'fraction_non_alphanumeric': 0.07196479420139788, 'fraction_numerical': 0.0028475278281128655, 'mean_word_length': 3.185807150595883, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5615470', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2333, 'n_words': 446}