Android Open Source - sdl_tester_android Slider 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;
/*from  ww w.  j a  v a  2  s.c o  m*/
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
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.SdlRequestFactory;
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.RPCRequest;

public class SliderDialog extends BaseOkCancelDialog {

  private static final SdlCommand SYNC_COMMAND = SdlCommand.SLIDER;
  private static final String DIALOG_TITLE = SYNC_COMMAND.toString();
  
  private static final int NUM_OF_TICKS_MIN = SdlConstants.SliderConstants.NUM_OF_TICKS_MIN;
  private static final int NUM_OF_TICKS_MAX = SdlConstants.SliderConstants.NUM_OF_TICKS_MAX;
  private static final int START_POSITION_MIN = SdlConstants.SliderConstants.START_POSITION_MIN;
  private static final int TIMEOUT_MIN = SdlConstants.SliderConstants.TIMEOUT_MIN;
  private static final int TIMEOUT_MAX = SdlConstants.SliderConstants.TIMEOUT_MAX;
  
  private static final int NUM_OF_TICKS_DEFAULT = 10;
  private static final int START_POSITION_DEFAULT = 1;
  private static final int TIMEOUT_DEFAULT = 10;
  
  private EditText et_slider_title, et_slider_footer;
  private SeekBar seek_slider_numOfTicks, seek_slider_startPosition, seek_slider_timeout;
  private TextView tv_slider_numOfTicks, tv_slider_startPosition, tv_slider_timeout;
  private CheckBox cb_dynamicFooter;
  private SeekBarCalculator numOfTicksCalculator, startPositionCalculator, timeoutCalculator;
  
  private String numOfTicks, startPosition, timeout;
  
  public SliderDialog(Context context) {
    super(context, DIALOG_TITLE, R.layout.slider);
    cb_dynamicFooter.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
                if(isChecked){
                    StringBuilder builder = new StringBuilder();
                    int numTicks = (int) numOfTicksCalculator.calculateValue(seek_slider_numOfTicks.getProgress());
                    for(int i=1; i<=numTicks; i++){
                        builder.append(i).append(",");
                    }
                    builder.deleteCharAt(builder.length()-1);
                    et_slider_footer.setText(builder.toString());
                }
                else{
                    et_slider_footer.setText("");
                }
            }
        });
    setPositiveButton(okButtonListener);
    createDialog();
  }

  @Override
  protected void findViews(View parent) {
    numOfTicksCalculator = new SeekBarCalculator(NUM_OF_TICKS_MIN, NUM_OF_TICKS_MAX);
    startPositionCalculator = new SeekBarCalculator(START_POSITION_MIN, NUM_OF_TICKS_MAX);
    timeoutCalculator = new SeekBarCalculator(TIMEOUT_MIN, TIMEOUT_MAX);
    
    Resources res = context.getResources();
    numOfTicks = res.getString(R.string.slider_ticks);
    startPosition= res.getString(R.string.slider_start_position);
    timeout = res.getString(R.string.timeout);
    
    et_slider_title = (EditText) parent.findViewById(R.id.et_slider_title);
    et_slider_footer = (EditText) parent.findViewById(R.id.et_slider_footer);
    tv_slider_numOfTicks = (TextView) parent.findViewById(R.id.tv_slider_numOfTicks);
    tv_slider_startPosition = (TextView) parent.findViewById(R.id.tv_slider_startPosition);
    tv_slider_timeout = (TextView) parent.findViewById(R.id.tv_slider_timeout);
    cb_dynamicFooter = (CheckBox) parent.findViewById(R.id.cb_dynamicFooter);

    updateTicks(NUM_OF_TICKS_DEFAULT);
    updateStartPosition(START_POSITION_DEFAULT);
    updateTimeout(TIMEOUT_DEFAULT);

    seek_slider_numOfTicks = (SeekBar) parent.findViewById(R.id.seek_slider_numOfTicks);
    seek_slider_numOfTicks.setMax(numOfTicksCalculator.getMaxProgress());
    seek_slider_numOfTicks.setProgress(numOfTicksCalculator.calculateProgress(NUM_OF_TICKS_DEFAULT));
    seek_slider_numOfTicks.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
      @Override public void onStopTrackingTouch(SeekBar seekBar) {}
      @Override public void onStartTrackingTouch(SeekBar seekBar) {}
      
      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        int adjustedProgress = (int) numOfTicksCalculator.calculateValue(progress);
        updateTicks(adjustedProgress);
        updateStartPositionMax(adjustedProgress);
      }
    });
    
    seek_slider_startPosition = (SeekBar) parent.findViewById(R.id.seek_slider_startPosition);
    seek_slider_startPosition.setProgress(startPositionCalculator.calculateProgress(START_POSITION_DEFAULT));
    seek_slider_startPosition.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
      @Override public void onStopTrackingTouch(SeekBar seekBar) {}
      @Override public void onStartTrackingTouch(SeekBar seekBar) {}
      
      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        updateStartPosition((int) startPositionCalculator.calculateValue(progress));
      }
    });
    
    seek_slider_timeout = (SeekBar) parent.findViewById(R.id.seek_slider_timeout);
    seek_slider_timeout.setMax(timeoutCalculator.getMaxProgress());
    seek_slider_timeout.setProgress(timeoutCalculator.calculateProgress(TIMEOUT_DEFAULT));
    seek_slider_timeout.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
      @Override public void onStopTrackingTouch(SeekBar seekBar) {}
      @Override public void onStartTrackingTouch(SeekBar seekBar) {}
      
      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        updateTimeout((int) timeoutCalculator.calculateValue(progress));
      }
    });
    
    updateStartPositionMax(NUM_OF_TICKS_DEFAULT);
  }
  
  private void updateTicks(int ticks){
    tv_slider_numOfTicks.setText(new StringBuilder().append(numOfTicks).append(ticks).toString());
  }
  
  private void updateStartPosition(int start){
    tv_slider_startPosition.setText(new StringBuilder().append(startPosition).append(start).toString());
  }
  
  private void updateStartPositionMax(int numOfTicks){
    startPositionCalculator.setMaxValue(numOfTicks);
    seek_slider_startPosition.setMax(startPositionCalculator.getMaxProgress());
  }
  
  private void updateTimeout(int newTimeout){
    tv_slider_timeout.setText(new StringBuilder().append(timeout).append(newTimeout).append(" s").toString());
  }
  
  //dialog button listeners
  private final DialogInterface.OnClickListener okButtonListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
      String sliderTitle = et_slider_title.getText().toString();
      String sliderFooter = et_slider_footer.getText().toString();
      boolean dynamicFooter = cb_dynamicFooter.isChecked();

      int numOfTicks = (int) numOfTicksCalculator.calculateValue(seek_slider_numOfTicks.getProgress());
      int startPosition = (int) startPositionCalculator.calculateValue(seek_slider_startPosition.getProgress());
      
      int timeout = (int) timeoutCalculator.calculateValue(seek_slider_timeout.getProgress());
      timeout = MathUtils.convertSecsToMillisecs(timeout);
      
      if(sliderTitle.length() <= 0){
        sliderTitle = " ";
      }
      if(sliderFooter.length() <= 0){
        sliderFooter = " ";
      }
      
      RPCRequest result = SdlRequestFactory.slider(sliderTitle, sliderFooter, dynamicFooter, numOfTicks, startPosition, timeout);
      notifyListener(result);
    }
  };

}




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