Android Open Source - sdl_tester_android Button Unsubscription 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;
/* w  w  w . ja v a  2 s .  c o m*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.content.Context;
import android.content.DialogInterface;

import com.livio.sdl.SdlRequestFactory;
import com.livio.sdl.dialogs.BaseMultipleListViewDialog;
import com.livio.sdl.enums.SdlButton;
import com.livio.sdl.enums.SdlCommand;
import com.smartdevicelink.proxy.RPCRequest;

 * Shows a dialog allowing the user to unsubscribe from buttons that have been subscribed to.  This class
 * requires an input list of SDL buttons that have been subscribed to so far.  Button subscriptions should
 * be queried from the SDL service prior to showing this dialog to be sure information is up to date.
 * The result of this dialog is a list of RPC requests, one request per selected item since SDL can't do
 * these as a batch as of version 2.0.
 * @author Mike Burke
public class ButtonUnsubscriptionDialog extends BaseMultipleListViewDialog<SdlButton> {

  private static final SdlCommand SYNC_COMMAND = SdlCommand.UNSUBSCRIBE_BUTTON;
  private static final String DIALOG_TITLE = SYNC_COMMAND.toString();
  public ButtonUnsubscriptionDialog(Context context, List<SdlButton> buttonSubscriptions) {
    super(context, DIALOG_TITLE, buttonSubscriptions);
  //dialog button click listeners
  private final DialogInterface.OnClickListener positiveButton = new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
      // called when the OK button is clicked.
      if(selectedItems == null || selectedItems.size() == 0){
        // if no items were selected, send an empty list as the result
        List<RPCRequest> buttonUnsubscribeMessages = new ArrayList<RPCRequest>(selectedItems.size());
        // loop through the selected items and create RPC requests for each one since they can't be done in a batch.
        for(SdlButton button : selectedItems){
          RPCRequest temp = SdlRequestFactory.unsubscribeButton(SdlButton.translateToLegacy(button));

Java Source Code List