Search in sources :

Example 6 with CallbackWithObject

use of net.osmand.CallbackWithObject in project Osmand by osmandapp.

the class OsmandApplication method initVoiceCommandPlayer.

public void initVoiceCommandPlayer(final Activity uiContext, ApplicationMode applicationMode, boolean warningNoneProvider, Runnable run, boolean showDialog, boolean force) {
    String voiceProvider = osmandSettings.VOICE_PROVIDER.get();
    if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
        if (warningNoneProvider && voiceProvider == null) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(uiContext);
            View view = uiContext.getLayoutInflater().inflate(R.layout.select_voice_first, null);
            ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(getIconsCache().getIcon(R.drawable.ic_action_volume_up, getSettings().isLightContent()));
            view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    RoutePreferencesMenu.selectVoiceGuidance((MapActivity) uiContext, new CallbackWithObject<String>() {

                        @Override
                        public boolean processResult(String result) {
                            boolean acceptableValue = !RoutePreferencesMenu.MORE_VALUE.equals(firstSelectedVoiceProvider);
                            if (acceptableValue) {
                                ((TextView) v.findViewById(R.id.selectText)).setText(RoutePreferencesMenu.getVoiceProviderName(uiContext, result));
                                firstSelectedVoiceProvider = result;
                            }
                            return acceptableValue;
                        }
                    });
                }
            });
            ((ImageView) view.findViewById(R.id.dropDownIcon)).setImageDrawable(getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, getSettings().isLightContent()));
            builder.setCancelable(true);
            builder.setNegativeButton(R.string.shared_string_cancel, null);
            builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (!Algorithms.isEmpty(firstSelectedVoiceProvider)) {
                        RoutePreferencesMenu.applyVoiceProvider((MapActivity) uiContext, firstSelectedVoiceProvider);
                    }
                }
            });
            builder.setNeutralButton(R.string.shared_string_do_not_use, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    osmandSettings.VOICE_PROVIDER.set(OsmandSettings.VOICE_PROVIDER_NOT_USE);
                }
            });
            builder.setView(view);
            builder.show();
        }
    } else {
        if (player == null || !Algorithms.objectEquals(voiceProvider, player.getCurrentVoice()) || force) {
            appInitializer.initVoiceDataInDifferentThread(uiContext, applicationMode, voiceProvider, run, showDialog);
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CallbackWithObject(net.osmand.CallbackWithObject) TextView(android.widget.TextView) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

CallbackWithObject (net.osmand.CallbackWithObject)6 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)4 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 View (android.view.View)2 TextView (android.widget.TextView)2 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 ImageView (android.widget.ImageView)1 RadioButton (android.widget.RadioButton)1 SeekBar (android.widget.SeekBar)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WptPt (net.osmand.plus.GPXUtilities.WptPt)1 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 MapActivity (net.osmand.plus.activities.MapActivity)1 GPXRouteParamsBuilder (net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder)1