<commit_before>/**
 * 
 */
package org.commcare.view;

import java.util.Vector;

import org.commcare.util.CommCareSense;
import org.commcare.util.MultimediaListener;
import org.javarosa.formmanager.view.CustomChoiceGroup;
import org.javarosa.utilities.media.MediaUtils;

import de.enough.polish.ui.ChoiceGroup;
import de.enough.polish.ui.Command;
import de.enough.polish.ui.CommandListener;
import de.enough.polish.ui.Displayable;
import de.enough.polish.ui.List;

/**
 * @author ctsims
 *
 */
public class CommCareListView extends List implements MultimediaListener {	
	
	private Vector<String> audioLocations = new Vector<String>();
	
	public CommCareListView(String title) {
		this(title, CommCareSense.formEntryQuick(), !CommCareSense.formEntryQuick());
	}
	
	public CommCareListView(String title, boolean autoSelect, boolean numericNavigation) {
		super(title, List.IMPLICIT);
		this.choiceGroup = new CustomChoiceGroup(null, ChoiceGroup.IMPLICIT, autoSelect, numericNavigation) {
			public void playAudio(int index) {
				if(audioLocations.size() > index && audioLocations.elementAt(index) != null) {
					MediaUtils.playAudio(audioLocations.elementAt(index));
				}
			}
		};
		this.choiceGroup.isFocused = true;
		this.container = this.choiceGroup;
	}

	public void registerAudioTrigger(int index, String audioURI) {
		if(audioLocations.size() < index+1) {
			audioLocations.setSize(index+1);
		}
		audioLocations.setElementAt(audioURI, index);
	}
	
	protected CommandListener wrapped;
	public void setCommandListener(CommandListener cl) {
		wrapped = cl;
		super.setCommandListener(new CommandListener(){
			public void commandAction(Command c, Displayable d) {
				if(d == CommCareListView.this && c.equals(CommCareListView.this.SELECT_COMMAND)) {
					if(!((CustomChoiceGroup)CommCareListView.this.choiceGroup).isFireable()) {
						return;
					}
				}
				//otherwise
				wrapped.commandAction(c, d);
			} 
		});
	}
}<commit_msg>take advantage of new audio control abilities<commit_after>/**
 * 
 */
package org.commcare.view;

import java.util.Vector;

import org.commcare.util.CommCareSense;
import org.commcare.util.MultimediaListener;
import org.javarosa.formmanager.view.CustomChoiceGroup;
import org.javarosa.utilities.media.MediaUtils;

import de.enough.polish.ui.ChoiceGroup;
import de.enough.polish.ui.Command;
import de.enough.polish.ui.CommandListener;
import de.enough.polish.ui.Displayable;
import de.enough.polish.ui.List;

/**
 * @author ctsims
 *
 */
public class CommCareListView extends List implements MultimediaListener {	
	
	private Vector<String> audioLocations = new Vector<String>();
	
	public CommCareListView(String title) {
		this(title, CommCareSense.formEntryQuick(), !CommCareSense.formEntryQuick());
	}
	
	public CommCareListView(String title, boolean autoSelect, boolean numericNavigation) {
		super(title, List.IMPLICIT);
		this.choiceGroup = new CustomChoiceGroup(null, ChoiceGroup.IMPLICIT, autoSelect, numericNavigation) {
			public void playAudio(int index) {
				if(audioLocations.size() > index && audioLocations.elementAt(index) != null) {
					MediaUtils.playOrPauseAudio(audioLocations.elementAt(index), String.valueOf(index));
				}
			}
		};
		this.choiceGroup.isFocused = true;
		this.container = this.choiceGroup;
	}

	public void registerAudioTrigger(int index, String audioURI) {
		if(audioLocations.size() < index+1) {
			audioLocations.setSize(index+1);
		}
		audioLocations.setElementAt(audioURI, index);
	}
	
	protected CommandListener wrapped;
	public void setCommandListener(CommandListener cl) {
		wrapped = cl;
		super.setCommandListener(new CommandListener(){
			public void commandAction(Command c, Displayable d) {
				if(d == CommCareListView.this && c.equals(CommCareListView.this.SELECT_COMMAND)) {
					if(!((CustomChoiceGroup)CommCareListView.this.choiceGroup).isFireable()) {
						return;
					}
				}
				//All list view actions should stop any currently playing audio
				MediaUtils.stopAudio();
				
				//otherwise
				wrapped.commandAction(c, d);
			} 
		});
	}
}
{'fraction_non_alphanumeric': 0.11514702248579195, 'fraction_numerical': 0.0009883864591055103, 'mean_word_length': 4.782857142857143, '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': '369353', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1242, 'n_words': 232}