Android Open Source - sdl_tester_android Soft Button List 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;
/*from  w ww .  j  a v  a2s  .  co m*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.livio.sdl.SdlImageItem;
import com.livio.sdl.SdlImageItem.SdlImageItemComparator;
import com.livio.sdl.adapters.SdlImageAdapter;
import com.livio.sdl.dialogs.BaseAlertDialog;
import com.livio.sdl.dialogs.BaseOkCancelDialog;
import com.livio.sdl.dialogs.TextViewOkCancelDialog;
import com.livio.sdltester.R;
import com.smartdevicelink.proxy.rpc.SoftButton;
import com.smartdevicelink.proxy.rpc.enums.FileType;

public class SoftButtonListDialog extends BaseOkCancelDialog{

    private static final String DIALOG_TITLE = "Create Soft Buttons";

    private static final int MAX_BUTTONS = 10;
    private List<SoftButton> softButtonItemList = new ArrayList<SoftButton>(MAX_BUTTONS);
    private Button but_addItem;
    private ListView lv_softButtonItems;
    private ArrayAdapter<SdlImageItem> adapter;
    private List<SdlImageItem> adapterList = new ArrayList<SdlImageItem>(MAX_BUTTONS);
    private BaseAlertDialog softButtonDialog = null;
    private List<SdlImageItem> allImages;
    public SoftButtonListDialog(Context context, List<SdlImageItem> images){
        super(context, DIALOG_TITLE, R.layout.create_choice_interaction_set);
        adapter = new SdlImageAdapter(context, adapterList);
        this.allImages = images;

    protected void findViews(View parent) {
        lv_softButtonItems = (ListView) view.findViewById(;
        lv_softButtonItems.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
                BaseAlertDialog deleteDialog = new TextViewOkCancelDialog(context, "Delete", "Do you want to delete this item?");
                deleteDialog.setListener(new BaseAlertDialog.Listener() {
                    public void onResult(Object resultData) {
                        boolean delete = (Boolean) resultData;
        but_addItem = (Button) view.findViewById(;
        but_addItem.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
    private void showSoftButtonDialog(){
        softButtonDialog = new SoftButtonItemDialog(context, allImages);
        softButtonDialog.setListener(new BaseAlertDialog.Listener() {
            public void onResult(Object resultData) {
                SoftButton button = (SoftButton) resultData;
    private void addSoftButtonToList(SoftButton button){
        if(button.getImage() != null){
            // if user selected an image, figure out which one they selected
            int imageIndex = Collections.binarySearch(allImages, new SdlImageItem(null, button.getImage().getValue(), null), new SdlImageItemComparator());
            if(imageIndex >= 0 && imageIndex < allImages.size()){
                SdlImageItem item = allImages.get(imageIndex);
                adapter.add(new SdlImageItem(item.getBitmap(), button.getText(), FileType.GRAPHIC_JPEG));
            // if the user didn't select an image, we'll create an empty one to display in the adapter
            Bitmap image = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
            adapter.add(new SdlImageItem(image, button.getText(), FileType.GRAPHIC_JPEG));
    //dialog button listeners
    private final DialogInterface.OnClickListener okButtonListener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Vector<SoftButton> softButtonItems = new Vector<SoftButton>(softButtonItemList);
            if(softButtonItems.size() > 0){


Java Source Code List