How to avoid TYPE_APPLICATION_OVERLAY float window that covers the whole screen conflicts with input board or system dialog in Andorid API 31? - android-api-31

Before API 31, this WindowManager.LayoutParams works fine. Only a little area needs to react to users' action, and the rest of the window must not cover anything behind it. Howerver, when it comes to API 31, this float window start to cover the input board and the system dialog, while it does not cover any view of my application behinds it.
What can I do to make the fullscreen float window to be compatible with input board and the system dialog again in API 31?
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
} else {
params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
params.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
params.format = PixelFormat.TRANSLUCENT;
params.gravity = (Gravity.START | Gravity.TOP);
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;

Related

Unity3D - Sizing LayoutElements Within A Layout Group

I've been trying to work on this concept for a chat system. I just wanted to create a chat message prefab with a horizontal group. And three objects inside of it. Avatar(Image), TimeStamp and User(Text), Message (Text).
The avatar needs to have the height and width locked.
The timestamp and username need to have the height locked, but stretch to the content.
The message needs to take up the rest of the width in the panel, and also stretch in height
The issue I have right now is as follows: If the message has too much text in it, squish the username and timestamp. Also, this issue also occurs when instantiating additional versions of the prefab.
Visual of what the chat looks like so far.
The avatar's layout element settings
The timestamp and username layout element settings
The message layout element settings
And then the code I use to instantiate the prefab.
void sendMessage(string m) //for testing only.
{
Message newMessage = new Message();
//GetTimeStamp
newMessage.stamp = DateTime.Now;
//AppendUserName
newMessage.stampname = newMessage.stamp.ToString("[hh:mm:ss] ") + localPlayer.name + ": "; //Takes the time stamp and the player name
//GetMessageFromParser
newMessage.text = m;
//AddToMessageList
allMessages.Add(newMessage);
parser.text = "";
GameObject nm = Instantiate(messageUI);
Vector2 font = nm.transform.GetChild(1).GetComponent<TMP_Text>().GetPreferredValues(newMessage.stampname);
Debug.Log("Pref Size" + font.x);
nm.transform.GetChild(1).GetComponent<TMP_Text>().text = newMessage.stampname;
nm.transform.GetChild(2).GetComponent<TMP_Text>().text = newMessage.text;
nm.transform.SetParent(messageList.transform, true);
}

PlatformIO in VSCode

I downloaded the latest version of VS Code with PlatformIO, i also downloaded the library Mouse.h from PlatformIO Library Manager, and even so, after i upload the code to my Micro Pro the mouse does not respond to the joystick!
But the same code works when i upload via Arduino IDE!
I compared the Mouse.h from .platformio/lib with the Mouse.h from program files\Arduino\libraries
I compared the Mouse.cpp from .platformio/lib with the Mouse.cpp from program files\Arduino\libraries
And they have exactly the same code!
This is my code for my MICRO PRO 32u4 5v:
/* HID Joystick Mouse Example
by: Jim Lindblom
date: 1/12/2012
license: MIT License - Feel free to use this code for any purpose.
No restrictions. Just keep this license if you go on to use this
code in your future endeavors! Reuse and share.
This is very simplistic code that allows you to turn the
SparkFun Thumb Joystick (http://www.sparkfun.com/products/9032)
into an HID Mouse. The select button on the joystick is set up
as the mouse left click.
*/
#include <Arduino.h>
#include <Mouse.h>
int horzPin = A0; // Analog output of horizontal joystick pin
int vertPin = A1; // Analog output of vertical joystick pin
int selPin = 9; // select button pin of joystick
int vertZero, horzZero; // Stores the initial value of each axis, usually around 512
int vertValue, horzValue; // Stores current analog output of each axis
const int sensitivity = 200; // Higher sensitivity value = slower mouse, should be <= about 500
int mouseClickFlag = 0;
void setup()
{
pinMode(horzPin, INPUT); // Set both analog pins as inputs
pinMode(vertPin, INPUT);
pinMode(selPin, INPUT); // set button select pin as input
digitalWrite(selPin, HIGH); // Pull button select pin high
delay(1000); // short delay to let outputs settle
vertZero = analogRead(vertPin); // get the initial values
horzZero = analogRead(horzPin); // Joystick should be in neutral position when reading these
}
void loop()
{
vertValue = analogRead(vertPin) - vertZero; // read vertical offset
horzValue = analogRead(horzPin) - horzZero; // read horizontal offset
//delay(3000);
if (vertValue != 0)
Mouse.move(0, vertValue/sensitivity, 0); // move mouse on y axis
if (horzValue != 0)
Mouse.move((horzValue/sensitivity) *-1, 0, 0); // move mouse on x axis
if ((digitalRead(selPin) == 0) && (!mouseClickFlag)) // if the joystick button is pressed
{
mouseClickFlag = 1;
Mouse.press(MOUSE_LEFT); // click the left button down
}
else if ((digitalRead(selPin))&&(mouseClickFlag)) // if the joystick button is not pressed
{
mouseClickFlag = 0;
Mouse.release(MOUSE_LEFT); // release the left button
}
}
Did you restart VS Code after installing the lib?
For me it fix this kind of problems in some cases.
Edit: Did you "rebuild IntelliSense Index" by press "Ctrl + shift + p"?

P5.js createCapture failure callback

Is there a callback function for p5.js’ createCapture function fails? (i.e. when user permission is denied or video camera stream is unsupported by user browser).
I notice in the src there is a success callback, but can’t seem to find one for failure.
In the browser console, p5 also reports ‘DOMException: Permission denied’, however, I would like to handle this in a more user-friendly fashion.
If there is no callback, what is the best practice for handling media failure with createCapture as it doesn’t seem to be discussed in the docs.
Ok so this answer is more than a year late but posting this as it may be useful for others stuck on the same issue. Rather than error testing the capture itself as suggested in comments below or perhaps reworking createCapture() (best done through opening an issue request if you feel it should be changed) I suggest testing the pixels array of the capture and only if it has been set then proceeding with doing whatever your script does. This could be done simply like so:
//load pixel data of webcam capture
cap.loadPixels();
//all values in the pixel array start as zero so just test if they are
//greater than zero
if (cap.pixels[1] > 0)
{
//put the rest of your script here
}
A full example of this in action is below:
var canvas;
var cap;
var xpos = 0;
function setup()
{
canvas = createCanvas(windowWidth, windowHeight);
canvas.style("display", "block");
background("#666666");
//create an instance of the webcam
cap = createCapture(VIDEO);
cap.size(640, 480);
cap.hide();
}
function draw()
{
//load pixel data of webcam capture
cap.loadPixels();
//if the first pixel's R value is set continue with the rest of the script
if (cap.pixels[1] > 0)
{
var w = cap.width;
var h = cap.height;
copy(cap, w/2, 0, 10, h, xpos, (height / 2) - (h / 2), 10, h);
xpos = xpos + 1;
if (xpos > width) xpos = 0;
}
}
I believe you can use a try and catch to detect when you get an error. Something like this:
try{
capture = createCapture(VIDEO);
}
catch(error){
// error handling here
}
More info on W3Schools and MDN.

Advise on how to edit text posted to facebook with FB.API of Unity Facebook SDK

I created a Game on Unity3D and I am in the process of adding support for Facebook. What I would like to achieve is the users posting a screenshot of the game showing the score.
I succeeded technically, but Facebook rejected my game because the text message that is posted along with the picture is pre-filled, and that violates section 2.3 of their Platform Policy.
Here is a pice of code found on the Example that comes with Facebook SDK for Unity in which I based mine... I guess this sample code created by Facebook does not comply either.
private IEnumerator TakeScreenshot()
{
yield return new WaitForEndOfFrame();
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] screenshot = tex.EncodeToPNG();
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
wwwForm.AddField("message", "herp derp. I did a thing! Did I do this right?");
FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);
}
So before investing a lot of time implementing a text editor in Unity3D for the sole purpose of posting to Facebook, I am looking for advise.
First, is there a way I can get my app approved without creating a text editor at all?
1) If I just post the screenshot will Facebook approve my game? Or I still will get rejected for posting a pre-filled image?
2) Is there a way to achieve this without creating an App on Facebook and requesting approval for "publish_actions" permission? maybe passing the image to the Facebook App?
If there is no option and I must create a text editor with a touch keyboard to allow the user to edit the message, what would be the best way to do it keeping compatibility for iOS, Android and Windows Phone 8.
I did manage to get approved by Facebook, but believe me, there is no shortcut. You need to offer a way for the user to preview what is being posted, and edit the text before submitting it.
In the end it was not that hard, thanks to the GUI controls. You can use GUI.DrawTexture to show a preview of the screen captured. You can use GUI.TextField to allow the user to edit the message and use GUI.Button to show "Share" and "Cancel" buttons. Put all this code on the OnGUI() method.
You can even add the profile picture next to the TextBox so the user gets the social feeling and also so the user knows which user is posting. During my tests I noticed the App cache the Facebook tokens and even if you change the Facebook user on the phone and Facebook App, my game kept using the original user when posting.
Since the question focus on how to edit the Text and not on how to interact with Facebook I will post the GUI code here, but not the facebook code which is similar to what I previously posted.
The code assumes you have all the textures mentioned and that the user already agreed to give permissions for: "public_profile,publish_actions".
The code also uses a Boolean named socialAskMessage that you need to set true in order to show the user interface. Also when you set socialAskMessage it is advisable that you ignore all other user input. In my game I reactivate all user input after 0.5 seconds in another function named DelayedCanClick(). The method to actually post to facebook resides inside social.PublishOnFacebook() that I do not present here.
void OnGUI() {
//GUI.Label(new Rect(10, 10, 100, 20), "Res" + Screen.width + " x " + Screen.height);
if (socialAskMessage)
{
//Background
GUI.DrawTexture(new Rect(0f, 0f, Screen.width, Screen.height / 3f),socialBackground,ScaleMode.StretchToFill);
//Screenshot
GUI.DrawTexture(new Rect(margin, margin, Screen.width/3f - margin*2f, Screen.height / 3f - margin*2f),screenshot,ScaleMode.ScaleToFit);
//Profile Picture
if (profilePicture != null)
GUI.DrawTexture(new Rect(Screen.width*7f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f), profilePicture);
//Hanlde Enter/Return event/Share Button
if (GUI.Button(new Rect(Screen.width*8f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f),shareButtonTexture,emptyGUIStyle)
||
( (Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) )
)
{
audioTac.Play();
if (socialMessage.StartsWith("Write"))
socialMessage = "";
else if (socialMessage.Length > 0)
{
socialAskMessage = false;
social.PublishOnFacebook();
}
else //If empty
socialMessage = "Write a comment...";
}
//Hanlde ESC/Cancel Button
if (GUI.Button(new Rect(Screen.width*9f/10f,Screen.height/9f,83f*Screen.width/960f,83f*Screen.width/960f),cancelButtonTexture,emptyGUIStyle)
||
( (Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape) )
)
{
audioTac.Play();
socialAskMessage = false;
}
if (socialAskMessage) //If still needed, show it
{
GUI.skin.textField.fontSize = 22;
GUI.skin.textField.fontStyle = FontStyle.Bold;
GUI.skin.textField.wordWrap = true;
GUI.skin.textField.focused.textColor = Color.white;
GUI.SetNextControlName("socialTextArea");
socialMessage = GUI.TextField(new Rect(Screen.width/3f, margin, Screen.width/2.75f - margin*2f, Screen.height / 3f - margin*2f), socialMessage, 200);
GUI.FocusControl("socialTextArea");
if ((socialMessage.Length == 17 || socialMessage.Length == 19) && socialMessage.StartsWith("Write a comment"))
socialMessage = socialMessage.Replace("Write a comment","").Replace(".","");
}
else //Dont show it anymore, reactivate click
{
StartCoroutine(DelayedCanClick());
}
}
}

System-wide tap simulation on iOS

I would like to achieve system-wide tap simulation on iOS, via a MobileSubstrate plugin. The idea is to be able to simulate touches (in a first time single touch, then multitouch) on a system-wide level, in iOS 5.1.1 .
I've been successful in implementing this article to simulate touches on a specific view, I now would like to be able to simulate them system-wide.
I understand I should use the private MobileServices framework to do so, and I've documented myself on GSEvent (I've also looked at Veency & MouseSupport sourcecodes).
I tried to hook up a view to intercept UIEvents and look at the underlying structure :
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
GSEventRef eventRef = (GSEventRef)[event performSelector:#selector( _gsEvent)];
GSEventRecord record = *_GSEventGetGSEventRecord(eventRef);
< breakpoint here to look at record >
}
and the result is extremely similar to the old (iOS 3) structure detailled above.
I then tried to fire up those events myself (on a Standalone app, not a MS tweak for now) :
+(void)simulateTouchDown:(CGPoint)point{
point.x = roundf(point.x);
point.y = roundf(point.y);
GSEventRecord record;
memset(&record, 0, sizeof(record));
record.type = kGSEventHand;
record.windowLocation = point;
record.timestamp = GSCurrentEventTimestamp();
GSSendSystemEvent(&record);
}
Now, that doesn't work at all (doesn't crash either).
Most codes (MouseSupport, Veency) look like this
// Create & populate a GSEvent
struct {
struct GSEventRecord record;
struct {
struct GSEventRecordInfo info;
struct GSPathInfo path;
} data;
} event;
memset(&event, 0, sizeof(event));
event.record.type = kGSEventHand;
event.record.windowLocation = point;
event.record.timestamp = GSCurrentEventTimestamp();
event.record.infoSize = sizeof(event.data);
event.data.info.handInfo.type = kGSHandInfoTypeTouchDown;
event.data.info.handInfo._0x44 = 0x1;
event.data.info.handInfo._0x48 = 0x1;
event.data.info.pathPositions = 1;
event.data.path.pathIndex = 0x01;
event.data.path.pathIdentity = 0x02;
event.data.path.pathProximity = 0x00;
event.data.path.pathLocation = event.record.windowLocation;
GSSendSystemEvent(&event.record);
Only :
GSEventRecordInfo is unknown (and I can't find where it might be defined)
I don't see the point of making a whole event to only pass the record
Please someone who's been through this on iOS 5 guide me.
GSEventRecordInfo may have been introduced since iOS 3.2 (that's where the Graphics Services headers you linked to are from). class-dump the framework that's actually on your device on iOS 5.1.1 and see if it's defined there?