Android Open Source - sdl_tester_android Sdl Alert Dialog

From Project

Back to project page sdl_tester_android.


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(){
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
                    BaseAlertDialog softButtonDialog = new SoftButtonListDialog(context, images);
                    softButtonDialog.setListener(new BaseAlertDialog.Listener(){
                        public void onResult(Object resultData){
                            softButtons = (List<SoftButton>) resultData;
                    softButtons = null;

  protected void findViews(View parent) {
    secondsStr = context.getResources().getString(R.string.units_seconds);
    et_alert_textToSpeak = (EditText) view.findViewById(;
    et_alert_line1 = (EditText) view.findViewById(;
    et_alert_line2 = (EditText) view.findViewById(;
    et_alert_line3 = (EditText) view.findViewById(;
    tv_alert_toneDuration = (TextView) view.findViewById(;
    seek_alert_toneDuration = (SeekBar) view.findViewById(;
    check_alert_playTone = (CheckBox) view.findViewById(;
    check_softButtons = (CheckBox) view.findViewById(;
    //make initial updates to the UI using default values
    //TODO - leaving these out for now - MRB
    //check_alert_includeSoftButtons = (CheckBox) view.findViewById(;
    //but_alert_includeSoftButtons = (Button) view.findViewById(;
    //TODO - add on click listener to this button.

  private void updateProgressText(float progress){
    StringBuilder strBuilder = new StringBuilder();
  // dialog button listsners
  private final DialogInterface.OnClickListener okButtonListener = new DialogInterface.OnClickListener() {
    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();
        textToSpeak = null;
        line1 = " ";
        line2 = " ";
        line3 = " ";
      Alert result = (Alert) SdlRequestFactory.alert(textToSpeak, line1, line2, line3, playTone, toneDurationInMs);
      if(softButtons != null && softButtons.size() > 0){
          result.setSoftButtons(new Vector<SoftButton>(softButtons));

   * On Seek Bar Changed Listener Methods
  public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

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

Java Source Code List