In my Edittext scrollView in the scrollview LinearLayout, sometime the edittext throws exception, i dont know why this happen. any one have idea please help me .
Thanks on Advance
This is my code:::
edittext.setOnTouchListener(new ScrollView.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
try {
int action = event.getAction();
Log.e("action:",action+"");
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
float iniY = event.getRawY();
v.getParent().getParent().getParent()
.requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
v.getParent().getParent()
.requestDisallowInterceptTouchEvent(false);
break;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("e", e.getMessage());
}
return false;
}
});
11-08 17:43:39.836: E/InputEventReceiver(10223): Exception dispatching input event.
11-08 17:43:39.836: E/MessageQueue-JNI(10223): Exception in MessageQueue callback: handleReceiveCallback
11-08 17:43:39.851: E/MessageQueue-JNI(10223): java.lang.NullPointerException
Related
After updating to the latest Android Things preview, my app is crashing when
setting a callback on by button GPIO. I have the following button callback defined:
private class ButtonCallback extends GpioCallback {
#Override
public boolean onGpioEdge(Gpio gpio) {
boolean isPressed = false;
try {
isPressed = gpio.getValue();
} catch (IOException e) {
Log.w(TAG, "Error", e);
}
if (isPressed) {
...
}
return true;
}
}
I am registering it with the GPIO in the application as follows:
Gpio button = ...;
try {
button.registerGpioCallback(new ButtonCallback());
} catch (IOException e) {
Log.w(TAG, "Error configuring GPIO pins", e);
}
When I run my app, I get an IncompatibleClassChangeError and the app crashes:
java.lang.IncompatibleClassChangeError: Superclass com.google.android.things.pio.GpioCallback of com.google.android.things.example.MainActivity$ButtonCallback is an interface (...)
This code was working before, why has this started happening after the update?
Starting in Preview 7, many of the Peripheral I/O interfaces were converted from
abstract classes to interfaces. This was done to better facilitate testability
in apps, as interfaces are easier to mock.
Be sure to update your app to use the Preview 7 SDK:
dependencies {
compileOnly 'com.google.android.things:androidthings:0.7-devpreview'
}
Then modify your callback to implement the interface instead:
private class ButtonCallback implements GpioCallback {
#Override
public boolean onGpioEdge(Gpio gpio) {
boolean isPressed = false;
try {
isPressed = gpio.getValue();
} catch (IOException e) {
Log.w(TAG, "Error", e);
}
if (isPressed) {
...
}
return true;
}
}
Review the Android Things API reference
to verify if any of the other APIs you are calling have changed.
I have an app in which i mainly have a webview. i am having a problem. i have made the back button to goto previous webpage of webview it works fine and when it has no previous pages it quits with a MessageBox(Popup). The problem is when i navigate another page and press back it recursively triggers back button event and shows the MessageBox
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, e) =>
{
e.Handled = true;
if (Web_view.CanGoBack)
{
Web_view.GoBack();
e.Handled = true;
}
else
{
quit();
e.Handled = true;
}
};
The above is code of my main page
private async void quit()
{
MessageDialog msg = new MessageDialog("Do you really want to quit?", "Quit");
msg.Commands.Add(new UICommand("Yes") { Id = 0 });
msg.Commands.Add(new UICommand("No") { Id = 1 });
var ans = await msg.ShowAsync();
if(ans.Id.Equals(0))
{
//System.Diagnostics.Debug.WriteLine("Exit");
App.Current.Exit();
}
}
this is the code of quit function.
I am navigating to another page from this using code
private void about_Click(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(BlankPage1));
}
And the backRequested code of blanckPage1 is
SystemNavigationManager.GetForCurrentView().BackRequested += (s,e)=>
{
e.Handled = true;
// Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested -= BlankPage1_BackRequested;
//System.Diagnostics.Debug.WriteLine("BackRequested");
if (Frame.CanGoBack)
{
e.Handled = true;
Frame.GoBack();
}
else
{
e.Handled = true;
}
};
To make it more clear for example when i open the app the webview navigates to www.example.com then following the links there i will get to some other page(for example www.example.com/link/firstlink). then i will navigate my frame to blankpage1 and from there i will press back. then insted of coming back to previous page (www.example.com/link/firstlink) it comes to beginning page (www.example.com) and shows the quit popup how can i fix this?
Thank you for all your replay.
Your problem is that you are still keeping the event handler: In your code when navigating back from BlankPage1, both .BackRequested handlers are called. You would need to deregister from .BackRequested on MainPage when leaving it, for example like this:
MainPage:
protected override void OnNavigatedTo(NavigationEventArgs e) {
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
}
protected override void OnNavigatedFrom(NavigationEventArgs e) {
SystemNavigationManager.GetForCurrentView().BackRequested -= OnBackRequested;
}
private void OnBackRequested(object sender, BackRequestedEventArgs e) {
// Your code to navigate back
if (Web_view.CanGoBack)
{
Web_view.GoBack();
e.Handled = true;
}
else
{
quit();
e.Handled = true;
}
}
And the same on BlankPage1... Though it would be far easier to register to BackRequested in your App.xaml.cs where you would handle your (Window.Current.Content as Frame) for the whole app, something like this. To make it "nice" code also with an interface:
INavigationPage:
public interface INavigationPage {
// When overriding the method returns true or false if the Page handled back request
bool HandleBackRequested();
}
App.xaml.cs:
// ... Code before
protected override void OnLaunched(LaunchActivatedEventArgs e) {
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
}
private void OnBackRequested(object sender, BackRequestedEventArgs e) {
Frame frame = Window.Current.Content as Frame;
if (frame == null) return;
INavigationPage page = frame.Content as INavigationPage;
if (page == null) return;
// Ask if the page handles the back request
if (page.HandleBackRequested()) {
e.Handled = true;
// If not, go back in frame
} else if (frame.CanGoBack) {
e.Handled = true;
frame.GoBack();
}
}
// ... Code after
MainPage.xaml.cs:
... class MainPage : Page, INavigationPage {
// ... Code before
// Implement the interface handling the backRequest here if possible
public bool HandleBackRequested() {
if (Web_view.CanGoBack) {
Web_view.GoBack();
return true;
}
return false;
}
// ... Code after
}
Then the BlankPage does not require any code and no subscribing to .BackRequested.
I am writing a Java program that uses a Swing-based user interface, however I needed access to WebView, so I implemented a JFXPanel to take care of that. WebView is supposed to load an advertisement banner in to the program that the user can click on if the want. Currently, when the advertisement is clicked, the new page is loading within WebView. If possible, I would like to have the page open in the user's default browser and have the page containing the advertisement refresh. How can I achieve this?
engine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>()
{
#Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue,
Worker.State newValue)
{
String toBeopen =
engine.getLoadWorker().getMessage().trim();
System.out.println("tobeopen: " + toBeopen);
if (toBeopen.contains("http://") || toBeopen.contains("https://")) {
engine.getLoadWorker().cancel();
try {
Desktop.getDesktop().browse(new URL(toBeopen).toURI());
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (URISyntaxException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
});
In my application, when i will click a button, it should open the camera flash for a long time like torch. This implementation is pretty easy in Android. But in BlackBerry i did not get any direct API for this. I have tried some sort of things by which i am able to on the Video and able to make the flash for few seconds. But if you check this app, they made it possible: Flashlight Free(in App World).
Here is my code:
if(field == btnTorch)
{
Player player;
VideoControl _videoControl;
vfmScreen.delete(btnTorch);
try {
player = Manager.createPlayer("capture://video");
player.realize();
Logger.out("Torch", "player realized");
_videoControl = (VideoControl) player.getControl("VideoControl");
FlashControl flashControl = new FlashControl()
{
public int getMode() {
// TODO Auto-generated method stub
Logger.out("Torch", "inside getmode");
return 0;
}
public int[] getSupportedModes() {
// TODO Auto-generated method stub
Logger.out("Torch", "inside getSupportedModes");
return null;
}
public boolean isFlashReady() {
// TODO Auto-generated method stub
return false;
}
public void setMode(int arg0) {
// TODO Auto-generated method stub
Logger.out("Torch", "inside setMode");
}
};
flashControl = (FlashControl) player
.getControl("javax.microedition.amms.control.camera.FlashControl");
if(flashControl!= null) {
Logger.out("Torch", "before Forced fully set the mode");
flashControl.setMode(FlashControl.FORCE);
Logger.out("Torch", "Forced fully set the mode");
}
if (_videoControl != null)
{
Field _videoField = (Field) _videoControl.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE,
"net.rim.device.api.ui.Field");
_videoControl.setVisible(true);
_videoControl.setDisplayFullScreen(true);
vfmScreen.add(_videoField);
player.start();
EnhancedFocusControl efc = (EnhancedFocusControl)player.getControl("net.rim.device.api.amms.control.camera.EnhancedFocusControl");
efc.startAutoFocus();
Logger.out("Torch", "player started ");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
So what is the possible way to make it?
Thanks,
Arindam.
I am working with a BlackBerry App that has a number of timers in it to schedule sending reports to the server platform. It is all working fine until I changed the logic to prioritize reports. Therefore, now I am checking if, for instance, Report A is switched on and the user activates Report B as well, then only Report B should go through and Report A should halt UNTIL B is activated. Once B is deactivated (timer cancelled), Report A should resume. However, even when the code loops in the cancel timer task code, Report A continues to go through while B is still activated.
FieldChangeListener reportingListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{
try {
if (field == slider) {
int i = slider.getValue();
if(i==0)
lblInterval.setText(1+" minute");
if(i==1)
lblInterval.setText(2+" minutes");
if(i==2)
lblInterval.setText(5+" minutes");
if(i==3)
lblInterval.setText(10+" minutes");
if(i==4)
lblInterval.setText(15+" minutes");
if(i==5)
lblInterval.setText(30+" minutes");
if(i==6)
lblInterval.setText(1+" hour");
if(i==7)
lblInterval.setText(2+" hours");
if(i==8)
lblInterval.setText(6+" hours");
if(i==9)
lblInterval.setText(12+" hours");
if(i==10)
lblInterval.setText(24+" hours");
setSliderPosition(i);
value=setLblIntervalValue(i);
value2=setGpsTimerIntervalValue(i);
gpsReportValue=lblInterval.getText();
gpsIntervalValue1=setGpsTimerIntervalValue(i);
}
if (PersistentStoreHelper.persistentHashtable.containsKey("image"))
{
boolean trackONOFFImage = ((Boolean) PersistentStoreHelper.persistentHashtable.get("image")).booleanValue();
if(trackONOFFImage==true)
{
if (PersistentStoreHelper.persistentHashtable.containsKey("panic"))
{
boolean panicImage = ((Boolean)PersistentStoreHelper.persistentHashtable.get("panic")).booleanValue();
if(panicImage==true)
{
MyScreen.currentlyReporting.setText("PANIC ALARM TRIGGERED");
if (PersistentStoreHelper.persistentHashtable.containsKey("tabTrackValid"))
{
boolean trackingTab = ((Boolean)PersistentStoreHelper.persistentHashtable.get("tabTrackValid")).booleanValue();
if(trackingTab==false)
{
trackSlider.cancel();
}
PersistentStoreHelper.persistentHashtable.put("tabTrackValid", Boolean.TRUE);
}
}
else
{
//int gpsIntervalValue1=setGpsTimerIntervalValue(i);
if (PersistentStoreHelper.persistentHashtable.containsKey("gpsTimerIntervalValue"))
{
String intervalValue=((String)PersistentStoreHelper.persistentHashtable.get("gpsTimerIntervalValue"));
if(gpsIntervalValue1==Integer.parseInt(intervalValue))
{
//do nothing
}
else
{
trackSlider = new TimerTask() {
public void run() {
try {
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run() {
//Dialog.alert("Invalid login details");
}
});
sendTrackingReport();
} catch (Exception e) {
Dialog.alert("Unable to track at the new interval set");
}
}
};
//trackSlider.run();
trackingTimerSlider.scheduleAtFixedRate(trackSlider , 0, gpsIntervalValue1);
PersistentStoreHelper.persistentHashtable.put("tabTrackValid", Boolean.FALSE);
}
}
}
}
}//this
}
} catch (IllegalStateException e) {
//Dialog.alert("CANCEL TRACK1");
e.printStackTrace();
} catch (NullPointerException e) {
//Dialog.alert("CANCEL TRACK2");
e.printStackTrace();
}
}
};
NOTE: Report A = Tracking. Report B = Panic. Panic has priority over Tracking. Slider is changing the timer interval value.
I debugged my code and while it goes into the loop and cancels the timer task of the requested report, I still see those reports going through. Am I not cancelling the timer correctly? Please advice.
From the TimerTask.cancel javadoc:
... If the task has been scheduled for repeated execution, it will never run again. (If the task is running when this call occurs, the task will run to completion, but will never run again.) ...
So to begin with, calling cancel from a thread does not immediatly stop the Timer thread as you can see.
Also you are creating a new Timer each time in your screen:
trackSlider = new TimerTask()
Thus it might be possible that if you create several instances of your screen during the app running, several timers of the same type will be created.