Ionic Android TV - android

I'm doing at APK on Ionic for Android TV and I have a problem with the controls of arrows.
The APK run of the device but his behavior not is correct. When use arrows for a shift of app, the focus not work that must be. It jumps some divs.
Here some of the code that this app uses:
TS:
matrixNodes: Array<any> = [];
matrixPosX: number = 0;
matrixPosY: number = 0;
.
.
.
keyboardAction(e) {
let activeEle: any = this.matrixNodes[this.matrixPosY][this.matrixPosX];
let parent: any = activeEle.parentNode;
let moveRight = -224;
let moveLeft = +224;
if (this.matrixPosY != 0) {
moveRight = -340;
moveLeft = +340;
}
if (e.key == "ArrowRight") {
if (this.matrixPosX < (this.matrixNodes[this.matrixPosY].length - 1)) {
this.matrixPosX++;
this.matrixNodes[this.matrixPosY][this.matrixPosX].focus();
//SCROLL
if (parent.style.left == 0 + 'px' || parent.style.left == 0) {
if(this.matrixPosY != 0){
console.log(this.matrixPosY)
parent.style.left = '-350px';
}else
parent.style.left = '-240px';
} else {
let old = parent.style.left;
old = old.replace("px", "");
parent.style.left = (moveRight + parseInt(old)) + "px";
}
////////////////
}
} else if (e.key == "ArrowLeft") {
if (this.matrixPosX > 0) {
this.matrixPosX--;
this.matrixNodes[this.matrixPosY][this.matrixPosX].focus();
//SCROLL
if (parent.style.left == 0 + 'px' || parent.style.left == 0) {
if(this.matrixPosY != 0)
parent.style.left = '350px';
else
parent.style.left = '238px';
} else {
let old = parent.style.left;
old = old.replace("px", "");
parent.style.left = (moveLeft + parseInt(old)) + "px";
}
/////////////////////////////
} else {
//Moverse al TAB
let tab = document.getElementById("tab-button-home");
tab.focus();
}
This function(keyboardAction) its called with event keydown.
I want know why jumps some divs.. if is because there are use other event or other elements at HTML

When 1 line of code is the solution...
e.preventDefault()

Related

How can I use libusb to send/receive data from ubuntu to Android?

The goal I'm looking to achieve is to send/receive data to/from an Android device from a Linux server. I feel like I've tried all the examples I could find on the Internet as well as reading the libusb APIs, which don't talk at my level of a total noob. Here's what I've got so far:
I've written a program that runs on a Ubuntu server (ARMx64), from examples, I have the following code:
//Error handling removed for brevity
#define BULK_EP_IN 0x08
main(int argc, char* argv) {
libusb_context* libusb_ctxt;
int status;
bool libusb_err = false;
libusb_device** libusb_dvcs = NULL;
bool error = false;
unsigned vid = 0, pid = 0;
unsigned busnum = 0, devaddr = 0, _busnum, _devaddr;
struct libusb_device_descriptor desc;
status = libusb_init(&libusb_ctxt);
if (status < 0) {
libusb_err = true;
}
if (libusb_get_device_list(NULL, &libusb_dvcs) < 0) {
error = true;
} else {
libusb_device *dev = NULL;
for (uint16_t idx = 0; (dev = libusb_dvcs[idx]) != NULL; idx++) {
_busnum = libusb_get_bus_number(dev);
_devaddr = libusb_get_device_address(dev);
status = libusb_get_device_descriptor(dev, &desc);
if (status >= 0) {
if (desc.idVendor == vid_arg && desc.idProduct == pid_arg) {
vid = desc.idVendor;
pid = desc.idProduct;
busnum = _busnum;
devaddr = _devaddr;
fnd_dev = dev;
break;
}
}
}
if (fnd_dev == NULL) {
error = true;
} else {
libusb_device_handle* dev_hnd = NULL;
//Connect to device and write data to it.
dev_hnd = libusb_open_device_with_vid_pid(NULL, vid, pid);
if (dev_hnd) {
char str1[64], str2[64];
int e = 0,config2;
char my_string[64];
int length = 0;
int transferred = 0;
e = libusb_get_string_descriptor_ascii(dev_hnd, desc.iManufacturer, (unsigned char*)str1, sizeof(str1));
if (e < 0) {
break;
}
e = libusb_get_string_descriptor_ascii(dev_hnd, desc.iProduct, (unsigned char*)str2, sizeof(str2));
if(e < 0) {
break;
}
e = libusb_get_configuration(dev_hnd, &config2);
if (e == 0) {
if (config2 != 1)
{
libusb_set_configuration(dev_hnd, 1);
if (e!=0) {
libusb_err = true;
}
}
if (!libusb_err) {
if (libusb_kernel_driver_active(dev_hnd, 0) == 1) {
if (libusb_detach_kernel_driver(dev_hnd, 0) == 1) {
libusb_err = true;
}
}
if (!libusb_err) {
e = libusb_claim_interface(dev_hnd, 0);
if (e < 0) {
libusb_err = true;
}
if (!libusb_err) {
active_config(dev, dev_hnd);
memset(my_string, '\0', 64);
strcpy(my_string, "hello sally");
length = strlen(my_string);
e = libusb_bulk_transfer(dev_hnd, BULK_EP_IN | LIBUSB_ENDPOINT_IN, (unsigned char*)my_string, length, &transferred, 0);
if (e == 0 && transferred == length) {
child_log("Write successful!");
child_log("Sent %d bytes with string: %s", transferred, my_string);
}
else {
child_log("Error in write! e = %d and transferred = %d, error desc: %s", e, transferred, libusb_error_name(e));
}
}
}
}
}
e = libusb_release_interface(dev_hnd, 0);
libusb_close(dev_hnd);
}
}
if (libusb_dvcs != NULL) {
libusb_free_device_list(libusb_dvcs, 1);
}
}
if (!libusb_err) {
libusb_exit(libusb_ctxt);
}
}
Everything works, at least doesn't report an error, until I get to the libusb_bulk_transfer call, which it returns a -1, which translates to a LIBUSB_ERROR_IO.
The USB device I'm connecting to is a Samsung Z-Fold3 mobile phone. I'm using the phone as a test OS as I don't have access to the Android tablet that will be used in the final application.
Here's my questions:
How do I know which interface to connect to?
 a) I'll have an application running on the Android device that will be using the same library, hopefully, that will receive the data sent from the Ubuntu server.
How do I know which configuration to use?
Am I doing everything correctly?
Does anyone have any code that can run on the Android to read the data that I'm sending from this code? My goal was to write a program in C that pretty much runs like the one that runs on the Ubuntu server, but reads the data. Once I have that, my next step will be to write data from the Android device to the Ubuntu server using libusb again.
Any help, advice, alternative APIs is very much appreciated.
Thank you!

When I'm move to the next frame the text box is still selected as3?

I am doing a mental calculation game and it is the following the game consume in has the accounts to do and the user has to write with the keyboard in android the number until then I have now what I want to do is when I pass from level to Textinput is soon selected so that the users can only enter the numbers (I am also in doubt as to put only the numerical keyboard for andorid keyboards).
This is the game code:
conta.restrict = "0-9\n";
conta.maxChars = 3;
conta.background = true;
conta.backgroundColor = 0x4DFF67;
conta.border = true; // Terá borda
conta.borderColor = 0xFFCD70; // Cor da borda
conta.text = "Nº";
vala.addEventListener(MouseEvent.CLICK, tobias);
function tobias(MouseEvent){
if (conta.text == "12"){
trace("Acertou");
nextFrame();
}else{
trace("Errou");
conta.text = "";
conta.backgroundColor = 0xFF4D40;
}
}
conta.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.ENTER)
{
if (conta.text == "12"){
trace("Acertou");
nextFrame();
}else{
trace("Errou");
conta.text = "";
conta.backgroundColor = 0xFF4D40;
}
}
});
conta.addEventListener(KeyboardEvent.KEY_UP, function(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.ENTER)
{
conta.text = "";
}
});
conta.addEventListener(FocusEvent.FOCUS_IN, clearBox);
function clearBox(evt:FocusEvent):void
{
conta.text="";
}
Text Input

Can't get multitouch to work in Unity3D

after searching for a solution I still can't figure out why my multitouch script in unity isn't working. This is my code. And before you ask: All variables do exist.
void Update()
{
if (Input.touchCount > 0)
{
for (i = 0; i < Input.touchCount; i++)
{
if (Input.GetTouch(i).phase != TouchPhase.Ended)
{
hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero);
if (hit.collider != null && hit.transform.gameObject.tag == "Links")
{
cannon.GetComponent<Rigidbody2D>().MovePosition(cannon.GetComponent<Rigidbody2D>().position + new Vector2(-0.1f, 0) * Time.deltaTime * moveSpeed);
}
else if (hit.collider != null && hit.transform.gameObject.tag == "Rechts")
{
cannon.GetComponent<Rigidbody2D>().MovePosition(cannon.GetComponent<Rigidbody2D>().position + new Vector2(0.1f, 0) * Time.deltaTime * moveSpeed);
}
}
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero);
if (hit.collider != null && hit.transform.gameObject.tag == "Fire")
{
clone = Instantiate(projectile, cannon.transform.position + new Vector3(0, 1.3f, 0), transform.rotation) as Rigidbody2D;
clone.velocity = new Vector2(0, speed);
}
}
}
}
}
It only registers one input at a time. Yes my phone does support multitouch. I'll appreciate any kind of help.
your problem is very simple !
You have a "0" were you should have an "i". That's all it is.
You are looping through with i ...
for (i = 0; i < Input.touchCount; i++)
sometimes you correctly refer to
GetTouch(i)
but at other times you incorrectly refer to
GetTouch(0)
fortunately that's all it is!
Don't forget you can easily solve such problems in the future by logging as you go (use Debug.Log, or, have a Text on the screen and write your development info there, dev.text = "blah" )

Does c++/Arduino handle '?' differently compared with other chars

I have an Android app that is communicating with and arduino board via bluetooth
All the commands are going backward and forwards fine, until I wanted to send a comand of the type
"aT?bb"
from the android app, however when I print it in ardunio I am getting
"aT%3F"
I am logging the command in android and it is formed correctly My quesion is does c++/Arduino handle '?' differently then normal chars?
here is my arduino code->
while(bluetooth.available())
{
char toSend = (char)bluetooth.read();
if(toSend != '\0'){
if (toSend == 'a'){ i=0 ;}
inMsg[i] = toSend;
i++;
}
}
if(i == 5 )
{
// mock sending queries
if(inMsg[2] == '?'){
if(inMsg[1] == 'T'){
bluetooth.write("ty1");Serial.println("");
}else if(inMsg[1] == 'x'){ //normal cycle
bluetooth.write("xx1");
}else if(inMsg[1] == 'X'){ Serial.println(""); //booter
bluetooth.write("XX0");
}else if(inMsg[1] == 'N'){Serial.println(""); //On time
bluetooth.write("on1");
}else if(inMsg[1] == 'F'){ Serial.println(""); //Off time
bluetooth.write("of30");
}else if(inMsg[1] == 'S'){ Serial.println(""); //Speed percent
bluetooth.write("sp30");
}
}
// write to console
for(int j = 0; j < 5; j++){
Serial.write(inMsg[j]);
}
// new line
if(i == 5){Serial.println("");}
i = 0; // reset buffer
}
aT%3F <- this is mal formed
aS133 <- all the other are as I sent them from android
aN169
aF192
aS200
aXXXX
aYYYY
ayYYY
axXXX
my Android Code
...
command = "aT?bb";
writeCommand(command);
...
private void writeCommand(String command)
{
for (BluetoothGattCharacteristic characteristic : characteristics)
{
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) >0)
{
try {
characteristic.setValue(URLEncoder.encode(command, "utf-8"));
gatt.writeCharacteristic(characteristic);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
As pointed out in the comments above it was the URLEncoder that was changing the String. I have now changed this method to
private void writeCommand(String command)
{
for (BluetoothGattCharacteristic characteristic : characteristics)
{
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) >0)
{
characteristic.setValue(command);
gatt.writeCharacteristic(characteristic);
}else{
Log.i(TAG,"non write able");
}
}
}

android native backspace is not working on a input field which uses custom directives for validation

android native backspace button is not working while using angular and phone gap.
I've used directives and validations.
Below is my code.
It is working fine in ios and browser.
please respond as soon as possible.
note1:validations are working fine but that backspace button is not triggered when i am typing values and tap on backspace on android device moto g(4.4) ,when i tap on that input and taps backspaces it will remove one char or two..again the same process is to be repeated to remove all the test..
note2:same directive is used for password validation too ,here i don't have any problem with backspace on any device
test1=angular.module('myTest',[]);
test1.directive('isAmount', function() {
return {
restrict : 'A',
require : '?ngModel',
link : function(scope, element, attrs, ngModel) {
scope.flag = 0;
scope.count = 0;
if(!ngModel)
return;
ngModel.$parsers.unshift(function(inputValue) {
scope.flag = 0;
scope.count = 0;
var digits = inputValue.split('').filter(function(s) {
if(attrs.isAmount == "withTwoDigits") {
if(scope.flag == 0) {
if(s == '.') {
scope.flag = 1;
return true;
} else
return (!isNaN(s) && s != ' ');
} else {
if(s == '.') {
return false;
} else {
if(scope.count < 2) {
if(!isNaN(s) == true)
scope.count++;
return (!isNaN(s) && s != ' ');
} else {
return false;
}
}
}
} else if(attrs.isAmount == "justamount") {
if(s == '.') {
return false;
} else
return (!isNaN(s) && s != ' ');
}
}).join('');
ngModel.$viewValue = digits;
ngModel.$render();
element.focus = true;
return digits;
});
}
};
});
This is my directive used for validation for an input in my view(HTML)
<input type="text" placeholder="enterQuantity" name="userId" ng-model="gp.userId" ng-maxlength="30" ng-required="true" id="userId" my-maxlength =30 is-amount="withTwoDigits" ng-trim="false" clear-icon/>
<input type="password" placeholder="Password" name="passwd" ng-blur="blurField(2)" ng-focus="focusField(2)" ng-model="passwd" ng-minlength="3" ng-maxlength="12" ng-required="true" id="passwd" my-maxlength=12 is-amount="justamount" clear-icon/>

Categories

Resources