/** * Shows the selection dialog for a given renderer. * * @param activity The parent activity. * @param title The dialog's title. * @param trackInfo The current track information. * @param rendererIndex The index of the renderer. */ public void ShowSelectionDialog(Activity activity, char[] title, MappingTrackSelector.MappedTrackInfo trackInfo, int rendererIndex) { _trackInfo = trackInfo; _rendererIndex = rendererIndex; _trackGroups = trackInfo.GetTrackGroups(rendererIndex); _trackGroupsAdaptive = new bool[_trackGroups.Length]; for (int i = 0; i < _trackGroups.Length; i++) { _trackGroupsAdaptive[i] = _adaptiveVideoTrackSelectionFactory != null && trackInfo.GetAdaptiveSupport(rendererIndex, i, false) != RendererCapabilities.AdaptiveNotSupported && _trackGroups.Get(i).Length > 1; } _isDisabled = _selector.GetRendererDisabled(rendererIndex); _override = _selector.GetSelectionOverride(rendererIndex, _trackGroups); AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.SetTitle(title.ToString()) .SetView(BuildView(LayoutInflater.From(builder.Context))) .SetPositiveButton(Android.Resource.String.Ok, this) .SetNegativeButton(Android.Resource.String.Cancel, this) .Create() .Show(); }
private static int[] GetTracksAdding(MappingTrackSelector.SelectionOverride _override, int addedTrack) { int[] tracks = _override.Tracks.ToArray(); tracks = Arrays.CopyOf(tracks, tracks.Length + 1); tracks[tracks.Length - 1] = addedTrack; return(tracks); }
private void SetOverride(int group, int[] tracks, bool enableRandomAdaptation) { ITrackSelectionFactory factory = tracks.Length == 1 ? _fixedFactory : (enableRandomAdaptation ? _randomFactory : _adaptiveVideoTrackSelectionFactory); _override = new MappingTrackSelector.SelectionOverride(factory, group, tracks); }
/** * Shows the selection dialog for a given renderer. * * @param activity The parent activity. * @param title The dialog's title. * @param trackInfo The current track information. * @param rendererIndex The index of the renderer. */ public void showSelectionDialog(Activity activity, string title, MappingTrackSelector.MappedTrackInfo trackInfo, int rendererIndex) { this.trackInfo = trackInfo; this.rendererIndex = rendererIndex; trackGroups = trackInfo.GetTrackGroups(rendererIndex); trackGroupsAdaptive = new bool[trackGroups.Length]; for (int i = 0; i < trackGroups.Length; i++) { trackGroupsAdaptive[i] = adaptiveTrackSelectionFactory != null && trackInfo.GetAdaptiveSupport(rendererIndex, i, false) != RendererCapabilities.AdaptiveNotSupported && trackGroups.Get(i).Length > 1; } isDisabled = selector.GetRendererDisabled(rendererIndex); _override = selector.GetSelectionOverride(rendererIndex, trackGroups); AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.SetTitle(title) .SetView(buildView(builder.Context)) .SetPositiveButton(global::Android.Resource.String.Ok, this) .SetNegativeButton(global::Android.Resource.String.Cancel, delegate { }) .Create() .Show(); }
private void setOverride(int group, int[] tracks, bool enableRandomAdaptation) { var factory = tracks.Length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveTrackSelectionFactory); _override = new MappingTrackSelector.SelectionOverride(factory, group, tracks); }
// View.OnClickListener public void OnClick(View view) { if (view == disableView) { isDisabled = true; _override = null; } else if (view == defaultView) { isDisabled = false; _override = null; } else if (view == enableRandomAdaptationView) { setOverride(_override.GroupIndex, _override.Tracks.ToArray(), !enableRandomAdaptationView.Checked); } else { isDisabled = false; var tag = (Pair)view.Tag; var groupIndex = (int)tag.First; var trackIndex = (int)tag.Second; if (!trackGroupsAdaptive[groupIndex] || _override == null || _override.GroupIndex != groupIndex) { _override = new MappingTrackSelector.SelectionOverride(FIXED_FACTORY, groupIndex, trackIndex); } else { // The group being modified is adaptive and we already have a non-null override. var isEnabled = ((CheckedTextView)view).Checked; var overrideLength = _override.Length; if (isEnabled) { // Remove the track from the override. if (overrideLength == 1) { // The last track is being removed, so the override becomes empty. _override = null; isDisabled = true; } else { setOverride(groupIndex, getTracksRemoving(_override, trackIndex), enableRandomAdaptationView.Checked); } } else { // Add the track to the override. setOverride(groupIndex, getTracksAdding(_override, trackIndex), enableRandomAdaptationView.Checked); } } } // Update the views with the new state. UpdateViews(); }
// Track array manipulation. private static int[] getTracksAdding(MappingTrackSelector.SelectionOverride _override, int addedTrack) { var tracks = new List <int>(_override.Tracks) { addedTrack }; return(tracks.ToArray()); }
private static int[] getTracksRemoving(MappingTrackSelector.SelectionOverride _override, int removedTrack) { var tracks = new int[_override.Length - 1]; var trackCount = 0; for (var i = 0; i < tracks.Length + 1; i++) { int track = _override.Tracks[i]; if (track != removedTrack) { tracks[trackCount++] = track; } } return(tracks); }
private static int[] GetTracksRemoving(MappingTrackSelector.SelectionOverride _override, int removedTrack) { int[] tracks = new int[_override.Length - 1]; int trackCount = 0; int[] overrideTracks = _override.Tracks.ToArray(); for (int i = 0; i < tracks.Length + 1; i++) { int track = overrideTracks[i]; if (track != removedTrack) { tracks[trackCount++] = track; } } return(tracks); }
public void OnClick(View view) { if (view == _disableView) { _isDisabled = true; _override = null; } else if (view == _defaultView) { _isDisabled = false; _override = null; } else if (view == _enableRandomAdaptationView) { SetOverride(_override.GroupIndex, _override.Tracks.ToArray(), !_enableRandomAdaptationView.Checked); } else { _isDisabled = false; //@SuppressWarnings("unchecked") Pair tag = (Pair)view.Tag; int groupIndex = (int)tag.First; int trackIndex = (int)tag.Second; if (!_trackGroupsAdaptive[groupIndex] || _override == null || _override.GroupIndex != groupIndex) { _override = new MappingTrackSelector.SelectionOverride(_fixedFactory, groupIndex, trackIndex); } else { // The group being modified is adaptive and we already have a non-null override. bool isEnabled = ((CheckedTextView)view).Checked; int overrideLength = _override.Length; if (isEnabled) { // Remove the track from the override. if (overrideLength == 1) { // The last track is being removed, so the override becomes empty. _override = null; _isDisabled = true; } else { SetOverride(groupIndex, GetTracksRemoving(_override, trackIndex), _enableRandomAdaptationView.Checked); } } else { // Add the track to the override. SetOverride(groupIndex, GetTracksAdding(_override, trackIndex), _enableRandomAdaptationView.Checked); } } } // Update the views with the new state. UpdateViews(); }