I'm developing app for Chromecast. I'v tried Android Sample from https://github.com/googlecast/cast-android-sample, and he works fine - I may click on Cast icon, select device and start streaming. So, MediaRouter.Callback looks like this:
private class MyMediaRouterCallback extends MediaRouter.Callback {
#Override
public void onRouteSelected(MediaRouter router, RouteInfo route) {
MediaRouteHelper.requestCastDeviceForRoute(route);
}
}
And it works. But I want to start streaming on my device without stream button. So I'v changed this callback to:
private class MyMediaRouterCallback extends MediaRouter.Callback {
#Override
public void onRouteAdded (MediaRouter router, RouteInfo route)
MediaRouteHelper.requestCastDeviceForRoute(route);
}
}
But this doesn't work. This callback fires, requestCastDeviceForRoute returns true with required device (I see it by route.getName()), but onDeviceAvailable from CastSampleActivity never called. I'v tried delayed call of requestCastDeviceForRoute using Handler.postDelayed, and still nothing.
So, how to use requestCastDeviceForRoute properly to stream on Chromecast device without Media Button, right after he will be detected in MediaRouter.Callback?
Try calling
mediaRouter.selectRoute(route);
instead of using the MediaRouterHelper. This has worked for me when calling from within onRouteAdded()
Just to make sure I understand your question, are you trying to start streaming automatically as soon as the system "discovers" a cast device, without user clicking on the cast icon and selecting the device? Or are you trying to start streaming of the media immediately after user clicks on the cast icon and selects a target (i.e. removing the need to click on the Play button)?
The recommended flow is to let user choose the device manually, so what you are trying to do breaks the flow completely. What would user expect to happen if there is more than one chromecast device on the network? So it is strongly recommended not to go down that route.
Related
I have a Timer in a fragment and I want the timer to pause when the app is minimize(user clicks home or recent apps).
What should I do?
It seems that the fragment doesnt have onPause! The parent activity has it, which is useless because there I don't have access to the timer.
I also tried to make home button and set on click listener for it but I got null pointer exception error and when I used the code below
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==android.R.id.home)
{
Log.d("IT home","clicked");
}
return super.onOptionsItemSelected(item);
}
but it doesn't work. I didn't see anything it the Log cat.
according to the documentation , fragments have an onPause method. you can use it normally like you would do in an activity.
read more about it in the documentation.
I hope this helps you.
i want to update the text field value when i was changed.for this i use action listener because every updation time one trigger was fired in my code so,that's the reason i used action listener instead of data changed listener.for data changed listener on key pressed the listener is called updation done but my requirement is after completion of entering the data on text field only the listener is called.but it is not calling properly.
please find the below code,
agencyWorker.addActionListener(createAgencyActionListener(agencyWorker,eventPostchedules.getSerialId()));
private ActionListener createAgencyActionListener(final TextField searchField, String serialId){
return new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
String agencyText = searchField.getText();
searchField.setPreferredW(110);
roasterDao = RoasterDao.getInstance();
roasterDao.updateEventPostScheduleAgency(agencyText, serialId, "supervisor");
}
};
}
thanks in advance.
I just tested this on my iPad and action listener was invoked as expected. Check that you don't have a different error that is causing this e.g. networking error related to https change in iOS.
FYI on a side note, it's really bad to write this:
searchField.setPreferredW(110);
You are limiting the size of the field based in pixels which is rarely the right thing to do. The method is deprecated for a reason...
I am trying to use the SFAutoComplete control from SyncFusion in a Xamarin iPad app. (only iPad).
I am not able to get any sort of change event to fire.
What I've tried:
If you download SyncFusion and install it, it comes with a "SampleBrowser" app that has samples for all the controls in the suite.
If you open that SampleBrowser in visual studio and open the AutoComplete_Tablet.cs file after line 97, I've added this code:
countryAutoComplete.ValueChanged += (sender, args) =>
{
suggestionModeLabel.Text = "IT WORKED!";
};
But it never fires.
I've tried to use several different events from the list of events this control has (partial list from screenshot):
None of them seem to fire (I haven't tried ALL of them).
What do I need to do to get one of these events to fire? What am I missing?
Thanks for using Syncfusion Controls.
Delegate property can be used to hook the SFAutoComplete's events as per in the following code example,
Declaration code for Delegate property
SFAutoComplete autocomplete = new SFAutoComplete();
autocomplete.Delegate = new SFAutoCompleteDelegate();
The way to hook the events in SFAutoComplete
public class SFAutoCompleteDelegate : AutoCompleteDelegate
{
public override void DidTextChange(SFAutoComplete SFAutoComplete, string value)
{
//It fired while changing the text in AutoComplete
}
public override void DidSelectionChange(SFAutoComplete SFAutoComplete, string value)
{
//It fired while changing the suggestion from suggestion box.
}
}
We have created a sample for achieving your requirement. Please download the same from the following link
Link:http://www.syncfusion.com/downloads/support/forum/125261/ze/testingAutoComplete_21799375630
Thanks & Regards,
Hemalatha M.R
Nowadays, I am working on a java swing application using DJ NativeSwing as my embed browser to do something automatic work. The scenario of my application is that a user click start button and the embed browser auto click some position of the current page and then redirect to another one and then execute some other operations like click or something other. Now here is my solution. First, I will define a webbrowser class (extends JWebBrowser) and webbrowser listener class (implements WebBrowserListener), which represents a webbrowser and contains loadingProgressChanged, windowOpening and so on separately. Second, I define a thread class to do some logic computing and execute my browser operations as mentioned above by webbrowser.executeJavascript. At last, I add mouseListener for start and stop button to start or stop the task. When I open my application, the JFrame add the browser and its listener class. I click the start button, the browser works and will click the target position as I expected and then the page will redirect to another one. As we all know, js code can’t be executed until the page was loaded completely. So I set a global flag to check whether the page has loaded completely or not in loadingProgressChanged (code:if(e.getWebBrowser().getLoadingProgress() == 100)globalflag = true;) within webbrowser listener class. And in the thread class, I use code( while(globalflag == false){Thread.sleep(500);}) after first click to detect if the current page was loaded completely. However, when browser first click the target position and the page redirects successfully, I find that the current page has changed but blocked. After some debugging, I find it. In my thread class, browser will execute js code by webbrowser.executeJavascript("document.getElementById(‘target’).click();") to click the target position and then java code (while(globalflag == false){Thread.sleep(500);}) to detect if the current page was loaded completely and then execute some other java code. I find that the globalflag will never change and the current page’s loadingProgressChanged listener will never work because the java code (while(globalflag == false)). Because after I remove all java code after the first webbrowser.executeJavascript("document.getElementById(‘target’).click();"), the current page’s loadingProgressChanged listener works and the page was not blocked. With the DJ NativeSwing demo, I could execute my js in the loadingProgressChanged. However, I want to do a series of operations with my browser and also want to stop the task whenever need. So, I prefer to my solution for my demand rather than the provided one by demo. So, I wonder that after webbrowser.executeJavascript the DJ NativeSwing thread will wait my thread? And, in my software architecture, does anyone could have any suggestions? Thanks a lot. Any suggestion is appreciated!
PS.my application works fine with jdic-0.9.5, but it supports IE7 only.
I paste my code here to demonstrate my problem:
After I click the start button in JFrame, I will new a thread as follow
public class MyVisit implements Runnable{
private void doClick1(){
webbrowser.executeJavascript("document.getElementById('n').value='test'");
webbrowser.executeJavascript("document.getElementById('f').submit()");
}
public void run() {
globalFlag=false;
webbrowser.executeJavascript("document.getElementById(‘t’).click();") ;
while(!globalFlag){
Thread.sleep(500);
}
this.doClick1();
}
}
listener:
public class MyListener implements WebBrowserListener {
…
public void loadingProgressChanged(WebBrowserEvent e) {
if (e.getWebBrowser().getLoadingProgress() == 100) {
globalFlag=true;
}
}
}
DJ Native Swing enforces the Swing approach to threading: manipulate the components in the AWT Event Dispatch thread (a.k.a. UI thread). But also, do not block that thread, because listeners are triggered in that thread too.
So, you should not have a "while" loop in the UI thread, but should instead spawn a new thread. I hope your global variable is volatile, or AtomicBoolean or all accesses to it protected by synchronized block, otherwise you might have interesting threading side effects.
Im currently trying to figure out which notification string is sent if the app gets pushed to background. Is there an enumerator in MT I keep on overseeing or do I really have to use strings as shown in this example:
NSNotificationCenter.DefaultCenter.AddObserver ( "UIKeyboardDidShowNotification", MyNotification);
If there are no constants: where can I find the valid strings? Which one do I need for my "pushed to background" notification?
The other thing: is there a way to make a specific controller observer a notification? In my example I want to get rid of the popover controller a controller is currently showing. So I would like that MY controller observers the notifcation instead of having the global approach as shown above.
The problem is: if I do it like above in my view controller, remove the view controller and show a different one, the removed one still gets the notification. This means I don't get rid of the reference to that controller.
Yes, there are constants. You can find them as static properties on the class that the notification refers to. For instance, to receive a notification when the app moves to the background, you could do something like this:
NSObject enterBackgroundObserver;
//...
enterBackgroundObserver = NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.DidEnterBackgroundNotification,
delegate(NSNotification ntf) {
Console.WriteLine ("Entered background!");
});
Don't forget to remove the observer when you no longer need it:
NSNotificationCenter.DefaultCenter.RemoveObserver (enterBackgroundObserver);
Sure is. I believe this is what you want. UIApplicationState.Active
As in
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
if(application.ApplicationState == UIApplicationState.Active)
{
// this means your app is currently in the foreground
}
else
{
// this means a notification came in when your app was in the background.
}
}