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.sdl.menu;
//fromwww.java2s.com/**
* Represents a command button that can be clicked on the SDL-connected head-unit. A command
* button contains all the fields contained in the MenuItem parent class, as well as a parent id,
* a string representing an image on the head-unit and an OnClickListener.
*
* @author Mike Burke
*
*/publicclass CommandButton extends MenuItem {
/**
* An interface that defines a click event listener for a command button.
*
* @author Mike Burke
*
*/publicinterface OnClickListener{
void onClick(CommandButton button);
}
privateint parentId = -1;
private OnClickListener listener;
private String imageName;
public CommandButton(CommandButton copy){
super(copy.getName(), copy.getId(), false);
this.parentId = copy.getParentId();
this.listener = copy.getOnClickListener();
this.imageName = copy.getImageName();
}
public CommandButton(String name, int id) {
super(name, id, false);
}
public CommandButton(String name, int id, int parentId) {
super(name, id, false);
this.parentId = parentId;
}
public CommandButton(String name, int id, OnClickListener listener) {
super(name, id, false);
this.listener = listener;
}
public CommandButton(String name, int id, int parentId, OnClickListener listener) {
this(name, id, parentId, null, listener);
}
public CommandButton(String name, int id, String imageName) {
super(name, id, false);
this.imageName = imageName;
}
public CommandButton(String name, int id, int parentId, String imageName) {
this(name, id, parentId, imageName, null);
}
public CommandButton(String name, int id, int parentId, String imageName, OnClickListener listener) {
super(name, id, false);
this.parentId = parentId;
this.imageName = imageName;
this.listener = listener;
}
publicint getParentId() {
return parentId;
}
public OnClickListener getOnClickListener() {
return listener;
}
public String getImageName() {
return imageName;
}
/**
* Executes the code in the click listener, if it exists.
*/publicvoid dispatchClickEvent(){
if(listener != null){
listener.onClick(this);
}
}
}