Android Open Source - sdl_tester_android Set Media Clock Timer 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;
//w ww.  ja  v  a  2s.  co m
import android.content.Context;
import android.content.DialogInterface;
import android.text.InputFilter;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
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.enums.SdlUpdateMode;
import com.livio.sdl.utils.AndroidUtils;
import com.livio.sdl.viewhelpers.MinMaxInputFilter;
import com.livio.sdltester.R;
import com.smartdevicelink.proxy.RPCRequest;
import com.smartdevicelink.proxy.rpc.enums.UpdateMode;

public class SetMediaClockTimerDialog extends BaseOkCancelDialog {

  private static final SdlCommand SYNC_COMMAND = SdlCommand.SET_MEDIA_CLOCK_TIMER;
  private static final String DIALOG_TITLE = SYNC_COMMAND.toString();

  private static final int HOURS_MIN = SdlConstants.SetMediaClockTimerConstants.HOURS_MINIMUM;
  private static final int HOURS_MAX = SdlConstants.SetMediaClockTimerConstants.HOURS_MAXIMUM;
  private static final int MINS_MIN = SdlConstants.SetMediaClockTimerConstants.MINUTES_MINIMUM;
  private static final int MINS_MAX = SdlConstants.SetMediaClockTimerConstants.MINUTES_MAXIMUM;
  private static final int SECS_MIN = SdlConstants.SetMediaClockTimerConstants.SECONDS_MINIMUM;
  private static final int SECS_MAX = SdlConstants.SetMediaClockTimerConstants.SECONDS_MAXIMUM;
  
  private Spinner spin_mediaClock_type;
  private EditText et_mediaClock_hrs, et_mediaClock_mins, et_mediaClock_secs;
  private TextView tv_mediaClock_clock;
  private LinearLayout ll_mediaClock_clockContainer;
  
  public SetMediaClockTimerDialog(Context context) {
    super(context, DIALOG_TITLE, R.layout.set_media_clock_timer);
    setPositiveButton(okButtonListener);
    createDialog();
  }

  @Override
  protected void findViews(View parent) {
    spin_mediaClock_type = (Spinner) parent.findViewById(R.id.spin_mediaClock_updateMode);
    spin_mediaClock_type.setAdapter(AndroidUtils.createSpinnerAdapter(context, SdlUpdateMode.values()));
    spin_mediaClock_type.setOnItemSelectedListener(new OnItemSelectedListener() {
      @Override public void onNothingSelected(AdapterView<?> arg0) {}

      @Override
      public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        SdlUpdateMode mode = (SdlUpdateMode) parent.getAdapter().getItem(position);
        onModeUpdated(mode);
      }
    });
    
    et_mediaClock_hrs = (EditText) parent.findViewById(R.id.et_mediaClockHours);
    et_mediaClock_hrs.setFilters(new InputFilter[]{new MinMaxInputFilter(HOURS_MIN, HOURS_MAX)});
    et_mediaClock_mins = (EditText) parent.findViewById(R.id.et_mediaClockMins);
    et_mediaClock_mins.setFilters(new InputFilter[]{new MinMaxInputFilter(MINS_MIN, MINS_MAX)});
    et_mediaClock_secs = (EditText) parent.findViewById(R.id.et_mediaClockSecs);
    et_mediaClock_secs.setFilters(new InputFilter[]{new MinMaxInputFilter(SECS_MIN, SECS_MAX)});
    
    tv_mediaClock_clock = (TextView) parent.findViewById(R.id.tv_mediaClock_clock);
    
    ll_mediaClock_clockContainer = (LinearLayout) parent.findViewById(R.id.ll_clock);
  }
  
  private void onModeUpdated(SdlUpdateMode mode){
    enableClockView( (mode == SdlUpdateMode.COUNT_DOWN || mode == SdlUpdateMode.COUNT_UP) );
  }
  
  private void enableClockView(boolean enable){
    int visibility = (enable) ? View.VISIBLE : View.GONE;
    tv_mediaClock_clock.setVisibility(visibility);
    ll_mediaClock_clockContainer.setVisibility(visibility);
  }
  
  //dialog button listeners
  private final DialogInterface.OnClickListener okButtonListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
      SdlUpdateMode mode = (SdlUpdateMode) spin_mediaClock_type.getSelectedItem();
      UpdateMode legacyMode = SdlUpdateMode.translateToLegacy(mode);
      RPCRequest result;
      
      if(mode == SdlUpdateMode.COUNT_UP || mode == SdlUpdateMode.COUNT_DOWN){
        String hours = et_mediaClock_hrs.getText().toString();
        String mins = et_mediaClock_mins.getText().toString();
        String secs = et_mediaClock_secs.getText().toString();

        // if user left a field blank, let's assume it's a 0
        hours = (hours.length() > 0) ? hours : "0";
        mins = (mins.length() > 0) ? mins : "0";
        secs = (secs.length() > 0) ? secs : "0";

        result = SdlRequestFactory.setMediaClockTimer(legacyMode, Integer.parseInt(hours), Integer.parseInt(mins), Integer.parseInt(secs));
      }
      else{
        result = SdlRequestFactory.setMediaClockTimer(legacyMode);
      }
      
      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