A real example
Launch you Java environment and open the corresponding sample project provided in the directory
Examples//Doc-Examples
of the Yoctopuce library.
In this example, you can recognize the functions explained above, but this time used with all the side
materials needed to make it work nicely as a small demo.
package
com.yoctopuce.doc_examples
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.AdapterView.OnItemSelectedListener
;
import
android.widget.ArrayAdapter
;
import
android.widget.EditText
;
import
android.widget.Spinner
;
import
com.yoctopuce.YoctoAPI.YAPI
;
import
com.yoctopuce.YoctoAPI.YAPI_Exception
;
import
com.yoctopuce.YoctoAPI.YDisplay
;
import
com.yoctopuce.YoctoAPI.YDisplayLayer
;
public
class
GettingStarted_Yocto_Display
extends
Activity
implements
OnItemSelectedListener
{
private
YDisplay
display
=
null
;
private
ArrayAdapter
<
String
>
aa
;
@Override
public
void
onCreate
(
Bundle savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R.
layout
.
gettingstarted_yocto_display
);
Spinner my_spin
=
(
Spinner
)
findViewById
(
R.
id
.
spinner1
);
my_spin.
setOnItemSelectedListener
(this);
aa
=
new
ArrayAdapter
<
String
>(this
, android.
R
.
layout
.
simple_spinner_item
);
aa.
setDropDownViewResource
(
android.
R
.
layout
.
simple_spinner_dropdown_item
);
my_spin.
setAdapter
(
aa
);
}
@Override
protected
void
onStart
()
{
super
.
onStart
();
aa.
clear
();
try
{
YAPI
.
EnableUSBHost
(this);
YAPI
.
RegisterHub
(
"usb"
);
YDisplay
d
=
YDisplay
.
FirstDisplay
();
while
(
d
!=
null
)
{
String
hwid
=
d.
get_hardwareId
();
aa.
add
(
hwid
);
d
=
d.
nextDisplay
();
}
}
catch
(
YAPI_Exception
e
)
{
e.
printStackTrace
();
}
aa.
notifyDataSetChanged
();
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
YAPI
.
FreeAPI
();
}
@Override
public
void
onItemSelected
(
AdapterView
<?>
parent,
View
view,
int
pos,
long
id
)
{
String
hwid
=
parent.
getItemAtPosition
(
pos
)
.
toString
();
display
=
YDisplay
.
FindDisplay
(
hwid
);
19. Using the Yocto-Display with Android
www.yoctopuce.com
117
Содержание Yocto-Display
Страница 1: ...Yocto Display User Manual...
Страница 2: ......
Страница 40: ...34 www yoctopuce com...
Страница 52: ...46 www yoctopuce com...
Страница 84: ...78 www yoctopuce com...
Страница 92: ...86 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...22 High level API Reference 152 www yoctopuce com On failure throws an exception or returns a negative error code...
Страница 422: ...416 www yoctopuce com...
Страница 424: ...24 Characteristics 418 www yoctopuce com...