Accessibility Service - Hardware KeyPress - accessibility

Is it possible to send past command so that it pastes text into currently focused edit text, I am using RFID reader Hardware. Scenario:
Background service listening for notification (done)
When notification is received text needs to be copied to clipboard (done)
Paste text to any currently focused field (done)
On Hardware RFID reader button trigger, I am getting source as null
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.e("-onAccessibilityEvent-", "----------");
AccessibilityNodeInfo source2 = event.getSource();
if (source2 == null) {
return;
}
// if (source2 != null && event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", r);
clipboard.setPrimaryClip(clip);
source2.performAction(AccessibilityNodeInfo.ACTION_PASTE);
}
}
I know how to copy text with ClipboardManager.

Related

Return value from async Hook.GlobalEvents()MouseDown

At the moment I am using a example code from the internet, but I want to change it so I can get the value of the mousebutton that is pressed down as an string value to use further in the Form1.cs under a button.
The problem is I can't really get the return value from the mousebutton that is pressed down. It keeps giving me null values. Is this because its a anonymous async method? Im new to async and anonoymous methods, but read some information about this on the internet. Here is the code in the class I used. Also I used the MouseKeyHook NuGet package from George Mamaladze. I want to get the result to return or "save" somewhere so it stays as an constant. Now the result changes directly after the input of the mousebutton, because its probably a async method that runs on the background.
public class ClickDetector
{
public ClickDetector() { }
public static void ListenForMouseEvents()
{
Console.WriteLine("Listening to mouse clicks.");
//When a mouse button is pressed
Hook.GlobalEvents().MouseDown += async (sender, e) =>
{
Form1.label1.Text = $"Mouse {e.Button} Down"; //This should modify label1.Text.
var result = e.Button.ToString();
};
//When a double click is made
Hook.GlobalEvents().MouseDoubleClick += async (sender, e) =>
{
Form1.label1.Text = $"Mouse {e.Button} button double clicked."; //This should modify label1.Text.
};
}
}

Xamarin Forms: Pause the video or audio playing in webview programattically

I am using custom webview for playing video and audio. I need to pause the video when clicking the back button from the video or audio page. I tried the below solution from this thread but it not working.
string pausefunctionString = #"var videos = document.querySelectorAll('video');
[].forEach.call(videos, function(video) { video.pause(); });
";
web_view.Eval(pausefunctionString);
My data is in 2 formats:
Video or audio link alone.
HTML data having multiple video links.
The above solution is not working for ios and windows in both formats. But it is working for android when the source of the webview is a video URL. When the source is an HTML data, this solution is not working in android.
For parsing the HTML data I am using the below code:
string htmlData = "htmldata";
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = htmlData;
advanced_web_view.Source = htmlSource;
Also, I need a transparent background for my webview. I tried the following 2 codes but not getting a transparent background.
//code1
this.BackgroundColor = UIColor.Clear;
//code2
this.Opaque = false;
this.BackgroundColor = Color.Transparent.ToUIColor();
UPDATE
I have solved the video or audio pausing issue on ios in an easy tricky way.
I just set the webview source or Url value to a blank data like below. So when I go to another page from the video page, the video is automatically stopping.
web_view.Source = "";
web_view.Url= "";
This method is only working for ios; for android and windows, this approach has no effect. So could you please suggest a method for pausing video in android and windows?
My data is in 2 formats:
Video or audio link alone.
HTML data having video links.
The below code is working for android when the source of the webview is a video or audio URL alone. When the source is an HTML data, this solution is not working in android.
string pausefunctionString = #"var videos = document.querySelectorAll('video');
[].forEach.call(videos, function(video) { video.pause(); });
";
web_view.Eval(pausefunctionString);
Conclusion
Video or audio pausing is not working for windows on both data formats(mentioned above), need a solution for this.
For Android, When the source is an HTML data, video is not pausing, need a solution for this.
I think we can forget the video pausing on the ios platform.
I am also attaching an updated file of different data formats.
You need to invoke the JS code in custom renderer
in custom webview
public Action<string> EvaluateJS;
public void OnEvaluate(string script)
{
EvaluateJS(script);
}
in Custom Renderer
protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var config = new WKWebViewConfiguration();
config.AllowsInlineMediaPlayback = true;
wkWebView = new WKWebView(Frame, config);
SetNativeControl(wkWebView);
}
if (e.NewElement != null)
{
Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
Element.EvaluateJS += (script) =>
{
wkWebView.EvaluateJavaScript(script, (result, error) =>
{
});
};
}
}
Usage
private void Button_Clicked(object sender, EventArgs e)
{
string pausefunctionString = #"var videos = document.querySelectorAll('video');
[].forEach.call(videos, function(video) { video.pause(); });
";
web_view.EvaluateJS(pausefunctionString);
}

How do I print the content of a TextArea?

So currently I'm trying to make a print feature for my Notepad application. I already have a kind of working Print feature, but it prints the full TextArea not only the string that is written into it.
I already tried to make it just print a string, but the PrintJob is not able to handle it, because it needs the actual TextArea, where the Text is written into.
My current Print Stuff:
public void doPrint() {
String toPrint = writeArea.getText();
printSetup(writeArea, Main.primaryStage);
}
private final Label jobStatus = new Label();
private void printSetup(Node node, Stage owner)
{
// Create the PrinterJob
PrinterJob job = PrinterJob.createPrinterJob();
if (job == null)
{
return;
}
// Show the print setup dialog
boolean proceed = job.showPrintDialog(owner);
if (proceed)
{
print(job, node);
}
}
private void print(PrinterJob job, Node node)
{
// Set the Job Status Message
jobStatus.textProperty().bind(job.jobStatusProperty().asString());
// Print the node
boolean printed = job.printPage(node);
if (printed)
{
job.endJob();
}
}
What I want to have:
A print that only shows the String, just like any other notepad application does if you try to print something
What I currently get:
The full textarea with frame.
As I mentioned in the comment you can wrap it into a Text, but then the first line for some reason isn't displayed correctly.
The solution would be to use a Label instead like:
printSetup(new Label(toPrint), Main.primaryStage);

Intent returns null onActivityResult in Fragment

Android 4.4 tested in Eclipse.
I've followed the lines as developers said. So in my fragment I put:
public void tomarfoto() {
// Check Camera
if (MainActivity.if_cam) {
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
this.startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
} else {
//Toast.makeText(getActivity(), "Camera not supported", Toast.LENGTH_LONG).show();
}
}
After that, I set this:
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
Toast.makeText(getActivity(), "Image saved to:\n" +data.getData(), Toast.LENGTH_LONG).show();
} else if (resultCode == Activity.RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}
}
The problem is that data intent is null and provokes this:
java.lang.RuntimeException: Failure delivering result
ResultInfo{who=android:fragment:0, request=1888, result=-1, data=null}
to activity {com.myapp.MainActivity}: java.lang.NullPointerException
I don't understand so much but apparently the onActivityResult is disconnected from the fragment who has called it so, it can't receive data results. How can I solve this?. The launchMode="singleTask" or singleInstance is not my problem, I didn't settled this.
The pictures are saved properly in the directory held by fileUri. Help.

Pause and Resume in Microphone: Windows phone 7

I am beginner in Windows phone. I created the recorder example and also executed successfully in windows phone 7. But I have to add the pause and resume functionality in my application.
Note: I used microphone for the recording.
How can I put push and resume functionality in microphone for recording?
OR give me any alternative solution for recording in windows phone.
here is my code..
Microphone mphone;
List<byte[]> memobuffercollection = new List<byte[]>();
DynamicSoundEffectInstance playback;
private void BtnRecords_Click(object sender, RoutedEventArgs e)
{
// Clear the collection for storing the buffers
memobuffercollection.Clear();
// Stop any playback in Progress
playback.Stop();
// Start Recording
mphone.Start();
BtnStop.Opacity = 1;
BtnRecords.Opacity = 0;
}
private void BtnStop_Click(object sender, RoutedEventArgs e)
{
StopRecording();
BtnStop.Opacity = 0;
BtnRecords.Opacity = 1;
}
void StopRecording()
{
// Get the last partial buffer
int sampleSize = mphone.GetSampleSizeInBytes(mphone.BufferDuration);
byte[] extraBuffer = new byte[sampleSize];
int extraBytes = mphone.GetData(extraBuffer);
// Stop Recording
mphone.Stop();
// Create MemoInfo object and add at top of collection
int totalSize = memobuffercollection.Count * sampleSize + extraBytes;
TimeSpan duration = mphone.GetSampleDuration(totalSize);
MemoInfo memoInfo = new MemoInfo(DateTime.UtcNow, totalSize, duration);
memofiles.Insert(0, memoInfo);
// Save Data in IsolatedStorage
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = storage.CreateFile(memoInfo.FileName))
{
// Write buffers from collection
foreach (byte[] buffer in memobuffercollection)
stream.Write(buffer, 0, buffer.Length);
// Write partial buffer
stream.Write(extraBuffer, 0, extraBytes);
}
}
memosListBox.UpdateLayout();
memosListBox.ScrollIntoView(memoInfo);
}
And memoinfo is my class which is used for giving the title to recorded audio.
If you look into the documentation of Microphone, you will find out that there is no Pause() or Resume() method in Microphone class. Only playback has Pause & Resume features ( read this ).
The only way to pause & resume, is to stop recording, save the audio file, and record a new one when you "resume". Last, combine the audio files together to one.
Related Question (though it's for Windows Phone 8): how to enable pause and resume in audio recorder in windows phone 8?(Details Insde)

Resources