Android Open Source - sdl_tester_android Choice Item 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;
/* ww  w. j av  a  2s .co m*/
import java.util.List;

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.Toast;

import com.livio.sdl.SdlImageItem;
import com.livio.sdl.dialogs.BaseAlertDialog;
import com.livio.sdl.dialogs.BaseOkCancelDialog;
import com.livio.sdl.dialogs.ImageListDialog;
import com.livio.sdl.utils.SdlUtils;
import com.livio.sdltester.R;
import com.smartdevicelink.proxy.rpc.Choice;

public class ChoiceItemDialog extends BaseOkCancelDialog {

  private static final String DIALOG_TITLE = "Create a Choice";
  private List<SdlImageItem> availableImages;
  private EditText et_choiceName, et_choiceVr, et_imageName;
  private CheckBox cb_hasImage;
  private BaseAlertDialog imagesDialog;
  public ChoiceItemDialog(Context context, List<SdlImageItem> availableImages) {
    super(context, DIALOG_TITLE, R.layout.choice_set_item);
    this.availableImages = availableImages;
    if(availableImages == null || availableImages.size() <= 0){

  protected void findViews(View parent) {
    et_choiceName = (EditText) parent.findViewById(;
    et_choiceVr = (EditText) parent.findViewById(;
    et_imageName = (EditText) parent.findViewById(;
    cb_hasImage = (CheckBox) parent.findViewById(;
    cb_hasImage.setOnCheckedChangeListener(new OnCheckedChangeListener() {
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  private void showImagesDialog(){
    if(imagesDialog == null){
      imagesDialog = new ImageListDialog(context, availableImages);
      imagesDialog.setListener(new BaseAlertDialog.Listener() {
        public void onResult(Object resultData) {
          SdlImageItem selectedItem = (SdlImageItem) resultData;
          if(selectedItem != null){
  private DialogInterface.OnClickListener okButton = new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
      String choiceName = et_choiceName.getText().toString();
      String choiceVr = et_choiceVr.getText().toString();
      String imageName = et_imageName.getText().toString();
      if(choiceName.length() > 0){
        if(imageName.length() <= 0){
          imageName = null;
        if(choiceVr.length() > 0){
          Choice choice = SdlUtils.createChoice(choiceName, choiceVr, imageName);
          Toast.makeText(context, "Choice must have a voice-rec keyword.", Toast.LENGTH_LONG).show();
        Toast.makeText(context, "Choice must have a name.", Toast.LENGTH_LONG).show();


Java Source Code List