Android Open Source - sdl_tester_android Sdl Alert Dialog






From Project

Back to project page sdl_tester_android.

License

The source code is released under:

Copyright (c) 2014, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are m...

If you think the Android project sdl_tester_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.livio.sdltester.dialogs;
/*  www  .j  a  v a 2 s . co m*/
import java.util.List;
import java.util.Vector;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.livio.sdl.SdlConstants;
import com.livio.sdl.SdlImageItem;
import com.livio.sdl.SdlRequestFactory;
import com.livio.sdl.dialogs.BaseAlertDialog;
import com.livio.sdl.dialogs.BaseOkCancelDialog;
import com.livio.sdl.enums.SdlCommand;
import com.livio.sdl.utils.MathUtils;
import com.livio.sdl.viewhelpers.SeekBarCalculator;
import com.livio.sdltester.R;
import com.smartdevicelink.proxy.rpc.Alert;
import com.smartdevicelink.proxy.rpc.SoftButton;

public class SdlAlertDialog extends BaseOkCancelDialog implements OnSeekBarChangeListener{

  private static final SdlCommand SYNC_COMMAND = SdlCommand.ALERT;
  private static final String DIALOG_TITLE = SYNC_COMMAND.toString();
  
  // a seekbar cannot do decimal points, so it currently ranges 0-50, which is then
  // divided by 10.0f to give us a number of seconds, rounded to 1/10 of a second.
  private static final float TENS_PLACE_DENOMINATOR = 10.0f;
  
  //set up your min & max time allowed here. we multiply by 10 since we're allowing 1/10th of a second selections
  private static final int MINIMUM_ALERT_TONE_TIME = (int) (SdlConstants.AlertConstants.ALERT_TIME_MINIMUM * TENS_PLACE_DENOMINATOR);
  private static final int MAXIMUM_ALERT_TONE_TIME = (int) (SdlConstants.AlertConstants.ALERT_TIME_MAXIMUM * TENS_PLACE_DENOMINATOR);

  //this is your default selection for tone duration.  again, divide by 10 for the actual time in seconds.
  private static final float DEFAULT_TONE_DURATION = 5.0f;  // 5.0 seconds
  
  private EditText et_alert_textToSpeak;
  private EditText et_alert_line1;
  private EditText et_alert_line2;
  private EditText et_alert_line3;
  
  private TextView tv_alert_toneDuration;
  
  private CheckBox check_alert_playTone, check_softButtons;
  
  private SeekBar seek_alert_toneDuration;
  private SeekBarCalculator progressCalculator;
  
  private String secondsStr;
  
  private List<SoftButton> softButtons;
  
  public SdlAlertDialog(Context context) {
    this(context, null);
  }
  
  public SdlAlertDialog(final Context context, final List<SdlImageItem> images){
      super(context, DIALOG_TITLE, R.layout.alert);

        check_softButtons.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
                if(isChecked){
                    BaseAlertDialog softButtonDialog = new SoftButtonListDialog(context, images);
                    softButtonDialog.setListener(new BaseAlertDialog.Listener(){
                        @SuppressWarnings("unchecked")
                        @Override
                        public void onResult(Object resultData){
                            softButtons = (List<SoftButton>) resultData;
                        }
                    });
                    softButtonDialog.show();
                }
                else{
                    softButtons = null;
                }
            }
        });
        
        setPositiveButton(okButtonListener);
        createDialog();
  }

  @Override
  protected void findViews(View parent) {
    secondsStr = context.getResources().getString(R.string.units_seconds);
    progressCalculator = new SeekBarCalculator(MINIMUM_ALERT_TONE_TIME, MAXIMUM_ALERT_TONE_TIME, TENS_PLACE_DENOMINATOR);
    
    et_alert_textToSpeak = (EditText) view.findViewById(R.id.et_alert_textToSpeak);
    et_alert_line1 = (EditText) view.findViewById(R.id.et_alert_line1);
    et_alert_line2 = (EditText) view.findViewById(R.id.et_alert_line2);
    et_alert_line3 = (EditText) view.findViewById(R.id.et_alert_line3);
    
    tv_alert_toneDuration = (TextView) view.findViewById(R.id.tv_alert_toneDuration);
    
    seek_alert_toneDuration = (SeekBar) view.findViewById(R.id.seek_alert_toneDuration);
    seek_alert_toneDuration.setMax(progressCalculator.getMaxProgress());
    seek_alert_toneDuration.setProgress(progressCalculator.calculateProgress(DEFAULT_TONE_DURATION));
    seek_alert_toneDuration.setOnSeekBarChangeListener(this);
    
    check_alert_playTone = (CheckBox) view.findViewById(R.id.check_alert_playTone);
    check_softButtons = (CheckBox) view.findViewById(R.id.cb_include_softbuttons);
    
    //make initial updates to the UI using default values
    updateProgressText(DEFAULT_TONE_DURATION);
    
    //TODO - leaving these out for now - MRB
    //check_alert_includeSoftButtons = (CheckBox) view.findViewById(R.id.check_alert_includeSoftButtons);
    //
    //but_alert_includeSoftButtons = (Button) view.findViewById(R.id.but_alert_includeSoftButtons);
    //TODO - add on click listener to this button.
  }

  private void updateProgressText(float progress){
    StringBuilder strBuilder = new StringBuilder();
    strBuilder.append(progress);
    strBuilder.append(secondsStr);
    tv_alert_toneDuration.setText(strBuilder.toString());
  }
  
  // dialog button listsners
  private final DialogInterface.OnClickListener okButtonListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
      String textToSpeak = et_alert_textToSpeak.getText().toString();
      String line1   = et_alert_line1.getText().toString();
      String line2   = et_alert_line2.getText().toString();
      String line3   = et_alert_line3.getText().toString();
      int toneDurationInS = (int) progressCalculator.calculateValue(seek_alert_toneDuration.getProgress());
      int toneDurationInMs = MathUtils.convertSecsToMillisecs(toneDurationInS);
      boolean playTone = check_alert_playTone.isChecked();
      
      if(textToSpeak.equals("")){
        textToSpeak = null;
      }
      if(line1.equals("")){
        line1 = " ";
      }
      if(line2.equals("")){
        line2 = " ";
      }
      if(line3.equals("")){
        line3 = " ";
      }
      
      Alert result = (Alert) SdlRequestFactory.alert(textToSpeak, line1, line2, line3, playTone, toneDurationInMs);
      if(softButtons != null && softButtons.size() > 0){
          result.setSoftButtons(new Vector<SoftButton>(softButtons));
      }
      notifyListener(result);
    }
  };

  /*
   * On Seek Bar Changed Listener Methods
   */
  @Override
  public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    updateProgressText(progressCalculator.calculateValue(progress));
  }

  @Override public void onStartTrackingTouch(SeekBar seekBar) {}
  @Override public void onStopTrackingTouch(SeekBar seekBar) {}
}




Java Source Code List

com.livio.sdl.IdGenerator.java
com.livio.sdl.IpAddress.java
com.livio.sdl.SdlConstants.java
com.livio.sdl.SdlImageItem.java
com.livio.sdl.SdlLogMessage.java
com.livio.sdl.SdlRequestFactory.java
com.livio.sdl.SdlResponseFactory.java
com.livio.sdl.SdlResponseTracker.java
com.livio.sdl.SdlService.java
com.livio.sdl.adapters.SdlImageAdapter.java
com.livio.sdl.adapters.SdlMessageAdapter.java
com.livio.sdl.dialogs.BaseAlertDialog.java
com.livio.sdl.dialogs.BaseImageListDialog.java
com.livio.sdl.dialogs.BaseMultipleListViewDialog.java
com.livio.sdl.dialogs.BaseOkCancelDialog.java
com.livio.sdl.dialogs.BaseSingleListViewDialog.java
com.livio.sdl.dialogs.ImageListDialog.java
com.livio.sdl.dialogs.IndeterminateProgressDialog.java
com.livio.sdl.dialogs.JsonFlipperDialog.java
com.livio.sdl.dialogs.ListViewDialog.java
com.livio.sdl.dialogs.MultipleListViewDialog.java
com.livio.sdl.dialogs.SingleJsonDialog.java
com.livio.sdl.dialogs.TextViewAlertDialog.java
com.livio.sdl.dialogs.TextViewOkCancelDialog.java
com.livio.sdl.enums.EnumClickListener.java
com.livio.sdl.enums.EnumComparator.java
com.livio.sdl.enums.SdlButton.java
com.livio.sdl.enums.SdlCommand.java
com.livio.sdl.enums.SdlImageType.java
com.livio.sdl.enums.SdlInteractionMode.java
com.livio.sdl.enums.SdlLanguage.java
com.livio.sdl.enums.SdlSpeechCapability.java
com.livio.sdl.enums.SdlSystemAction.java
com.livio.sdl.enums.SdlTextAlignment.java
com.livio.sdl.enums.SdlTransportType.java
com.livio.sdl.enums.SdlUpdateMode.java
com.livio.sdl.enums.SdlVehicleData.java
com.livio.sdl.menu.CommandButton.java
com.livio.sdl.menu.MenuItem.java
com.livio.sdl.menu.MenuManager.java
com.livio.sdl.menu.SubmenuButton.java
com.livio.sdl.utils.AndroidUtils.java
com.livio.sdl.utils.ApplicationPreferences.java
com.livio.sdl.utils.Counter.java
com.livio.sdl.utils.DownCounter.java
com.livio.sdl.utils.MathUtils.java
com.livio.sdl.utils.SdlUtils.java
com.livio.sdl.utils.StringUtils.java
com.livio.sdl.utils.Timeout.java
com.livio.sdl.utils.UpCounter.java
com.livio.sdl.utils.WifiUtils.java
com.livio.sdl.viewhelpers.MinMaxInputFilter.java
com.livio.sdl.viewhelpers.SeekBarCalculator.java
com.livio.sdltester.HelpActivity.java
com.livio.sdltester.LivioSdlTesterPreferences.java
com.livio.sdltester.MainActivity.java
com.livio.sdltester.SdlTesterImageResource.java
com.livio.sdltester.dialogs.AddCommandDialog.java
com.livio.sdltester.dialogs.AddSubMenuDialog.java
com.livio.sdltester.dialogs.ButtonSubscriptionDialog.java
com.livio.sdltester.dialogs.ButtonUnsubscriptionDialog.java
com.livio.sdltester.dialogs.ChangeRegistrationDialog.java
com.livio.sdltester.dialogs.ChoiceItemDialog.java
com.livio.sdltester.dialogs.CreateInteractionChoiceSetDialog.java
com.livio.sdltester.dialogs.DeleteCommandDialog.java
com.livio.sdltester.dialogs.DeleteFileDialog.java
com.livio.sdltester.dialogs.DeleteInteractionDialog.java
com.livio.sdltester.dialogs.DeleteSubmenuDialog.java
com.livio.sdltester.dialogs.GetDtcsDialog.java
com.livio.sdltester.dialogs.PerformInteractionDialog.java
com.livio.sdltester.dialogs.PutFileDialog.java
com.livio.sdltester.dialogs.ReadDidsDialog.java
com.livio.sdltester.dialogs.ScrollableMessageDialog.java
com.livio.sdltester.dialogs.SdlAlertDialog.java
com.livio.sdltester.dialogs.SdlConnectionDialog.java
com.livio.sdltester.dialogs.SetAppIconDialog.java
com.livio.sdltester.dialogs.SetMediaClockTimerDialog.java
com.livio.sdltester.dialogs.ShowDialog.java
com.livio.sdltester.dialogs.SliderDialog.java
com.livio.sdltester.dialogs.SoftButtonItemDialog.java
com.livio.sdltester.dialogs.SoftButtonListDialog.java
com.livio.sdltester.dialogs.SpeakDialog.java