Close open views on closing e4 application - eclipse-rcp

I had an e3 rcp app. When I close it and reopen it all opened views are closed.
After updating app to e4 and after close than open app the views are still opened.
Any idea how to close these views?
Iv tried to implement something like this but its not working
`
public void closeActiveViews() {
try {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage != null) {
IViewReference[] views = activePage.getViewReferences();
if (views != null) {
for (IViewReference view : views) {
activePage.hideView(view.getView(false));
}
}
}
} catch (Exception exception) {
log.error("Could not hide views ", exception);
System.exit(1);
}
}
`

Related

How to trigger a button click for deviceorientation in WebGL

I have a button to open the browser to fullscreen mode. This is the code:
private void ResizeButton_OnClick (UberButton obj)
{
if (!Screen.fullScreen)
Screen.fullScreen = true;
else
Screen.fullScreen = false;
}
How can I implement automatic button pressing when the screen orientation changes
private void Update()
{
if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft)
{
// ...
}
}

How to play video in iPhone without fullscreen mode using WebView in Xamarin.Forms?

I am using WebView for playing video in my Xamarin.Forms project. On iPhone the video is playing in fullscreen, but I need to play the video within the WebView without going to fullscreen.
I have this issue only on the iPhone. On Android, Windows, and iPad devices the video is playing without fullscreen.
Case 1: Normal WebView
<WebView
x:Name="web_view"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"/>
web_view.Source = videoUrl;
Case 2: Custom webview
On some part, I am using a custom WebView. In this case the video is also being played in full-screen mode.
public class MyWebView : WebView
{
public static readonly BindableProperty UrlProperty = BindableProperty.Create(
propertyName: "Url",
returnType: typeof(string),
declaringType: typeof(MyWebView),
defaultValue: default(string));
public string Url
{
get { return (string)GetValue(UrlProperty); }
set { SetValue(UrlProperty, value); }
}
}
In the above 2 cases, I need to play the video without full-screen mode on the iPhone.
You could set AllowsInlineMediaPlayback as True in Custom Renderer
[assembly: ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]
namespace CustomWebview.iOS
{
public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
{
WKWebView wkWebView;
protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
WKWebViewConfiguration configuration = new WKWebViewConfiguration();
configuration.AllowsInlineMediaPlayback = true;
wkWebView = new WKWebView(CGRect.Empty, configuration);
if (Element.Url != null)
{
wkWebView.LoadRequest(new NSUrlRequest(new NSUrl((Element).Url)));
}
SetNativeControl(wkWebView);
}
if (e.NewElement != null)
{
CallVideo();
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName.Equals(nameof(Element.Url)))
{
wkWebView.LoadRequest(new NSUrlRequest(new NSUrl((Element).Url)));
}
}
public override void Draw(CGRect rect)
{
base.Draw(rect);
Control.Frame = rect;
}
}
}
Added an if statement to exclude the null condition. And then load the URL when you set it in Forms. OnElementPropertyChanged will be called when the property of webview has been changed. So when you set its URL in forms, we could load requests in this method.

monotouch dispose UIWebView

Using a UIWebView in my application and I cant seem to release the memory it's using.
I have a UIButton which loads a view controller which holds the UIWebView.
When the webView is loaded the Real Memory (checking it using Instruments) rises but doesn't get lower after my attempts to release it.
When the button is pressed:
if (childBroswer != null)
{
childBroswer.Dispose();
childBroswer = null;
}
childBroswer = new ChildBrowser(url);
AppDelegate d = (AppDelegate)UIApplication.SharedApplication.Delegate;
if ( d.rootNavigationController.RespondsToSelector(
new MonoTouch.ObjCRuntime.Selector("presentViewController:animated:completion:")))
{
d.rootNavigationController.PresentViewController(childBroswer, true, null);
}
else
{
d.rootNavigationController.PresentModalViewController(childBroswer, true);
}
Child browser class:
public partial class ChildBrowser : UIViewController
{
public string _url {get;set;}
UIActivityIndicatorView activityIndicator;
UIWebView webBrowser;
NSUrl nsURL;
NSUrlRequest nsURLRequest;
public ChildBrowser (string url) : base ("ChildBrowser", null)
{
nsURL = new NSUrl(url);
nsURLRequest = new NSUrlRequest(nsURL);
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
if (webBrowser == null)
{
webBrowser = new UIWebView(new RectangleF(0,41,320,380));
}
this.Add(webBrowser);
webBrowser.LoadFinished += (object sender, EventArgs e) => {
activityIndicator.StopAnimating();
} ;
webBrowser.LoadStarted += (object sender, EventArgs e) => {
if (activityIndicator == null)
{
activityIndicator = new UIActivityIndicatorView(new RectangleF(UIScreen.MainScreen.Bounds.Width / 2 - 50,
UIScreen.MainScreen.Bounds.Height / 2 - 30,100,100));
activityIndicator.Color = UIColor.Black;
}
activityIndicator.StartAnimating();
this.Add(activityIndicator);
} ;
webBrowser.LoadHtmlString("<html><head></head><body></body></html>",null); //stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML = \"\";"];
webBrowser.LoadRequest(nsURLRequest);
closeBrowser.TouchUpInside += handleClose;
// Perform any additional setup after loading the view, typically from a nib.
}
private void handleClose(object sender, EventArgs e)
{
webBrowser.Delegate = null;
webBrowser.StopLoading();
webBrowser.Dispose();
DismissViewController(true,delegate {
closeBrowser.TouchUpInside -= handleClose;
webBrowser.RemoveFromSuperview();
this.Dispose();
} );
}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
}
public override void ViewDidDisappear(bool animated)
{
base.ViewDidDisappear(true);
//webBrowser.RemoveFromSuperview();
}
public void webViewDidFinishLoad(UIWebView webView)
{
//string u = "";
}
protected override void Dispose(bool disposing)
{
ReleaseDesignerOutlets();
base.Dispose(disposing);
}
What am i missing?
Thank you!
Memory for native objects is not reclaimed when you call Dispose. Calling Dispose only drops the managed reference - but the ObjC runtime (reference counted) won't free the object until there's no native reference as well. See this Q&A for more details...
This means that code such as:
this.Add(webBrowser);
will create such a native reference and is likely (i.e. if not removed elsewhere) to keep the webBrowser instance alive as long as this is alive. If you keep Adding then you memory usage will keep growing.
I'm the OP - It seems that releasing the memory usage of UIWebView is quite hard, even when doing so in Objective-C.
What I have eventually done, which didn't solve the problem but improved the memory release is adding the following lines when closing the UIWebView:
NSUrlCache.SharedCache.RemoveAllCachedResponses();
NSUrlCache.SharedCache.DiskCapacity = 0;
NSUrlCache.SharedCache.MemoryCapacity = 0;
webView.LoadHtmlString("",null);
webView.EvaluateJavascript("var body=document.getElementsByTagName('body')[0];body.style.backgroundColor=(body.style.backgroundColor=='')?'white':'';");
webView.EvaluateJavascript("document.open();document.close()");
webView.StopLoading();
webView.Delegate = null;
webView.RemoveFromSuperview();
webView.Dispose();

UIWebview does not get cookies

My UIWebview is not saving cookies at all. It is stuck in cookieless mode and as a result, the webpage is putting the cookie information in the url instead.
Here is what I am doing. I have a singleton for my UIWebview and 4 UITabBar buttons on the bottom. Each tabbar button takes the user to a different page on the site. Now, when the user is navigating the site through the webview itself, everything is fine and session persists. But the second a user clicks on a tabbar button, the session gets reset.
I even set NSHttpCookieStorage to always accept cookies. Still no go.
Here is the code for my singleton for UIWebview and NSMutableUrlRequest
public static UIWebView instance;
public static NSMutableUrlRequest urlRequest;
public static NSUrlConnection connection;
public static NSHttpCookieStorage cookie;
static bool TokenSent = false;
public UIWebViewSingleton () {}
public static UIWebView Instance
{
get
{
if (instance == null)
{
Debugger.Debug ("new uiwebview created");
cookie = NSHttpCookieStorage.SharedStorage;
cookie.AcceptPolicy = NSHttpCookieAcceptPolicy.Always;
connection = new NSUrlConnection();
instance = new UIWebView(new RectangleF(0f, 0f, 320f, 416f));
instance.ScalesPageToFit = true;
instance.LoadStarted += delegate {
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
};
instance.LoadFinished += delegate {
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
AcquireUserId();
};
instance.MultipleTouchEnabled = false;
}
return instance;
}
}
public static NSMutableUrlRequest UrlRequest
{
get
{
if (urlRequest == null)
{
urlRequest = new NSMutableUrlRequest();
}
return urlRequest;
}
}
This is how I change to a page based on which button was pressed. The back button is working fine.
case BTN_BACK:
btn_ret.TouchUpInside += delegate(object sender, EventArgs e) {
UIWebViewSingleton.Instance.GoBack();
};
break;
case BTN_GUIDE:
btn_ret.TouchUpInside += delegate(object sender, EventArgs e) {
UIWebViewSingleton.UrlRequest.Url = new NSUrl(StaticFileNames.GuideUrl);
UIWebViewSingleton.Instance.LoadRequest (UIWebViewSingleton.UrlRequest);
};
break;
case BTN_HOME:
btn_ret.TouchUpInside += delegate(object sender, EventArgs e) {
UIWebViewSingleton.UrlRequest.Url = new NSUrl(StaticFileNames.BaseUrl);
UIWebViewSingleton.Instance.LoadRequest (UIWebViewSingleton.UrlRequest);
};
break;
Does anyone have any ideas as to why my UIWebView is not accepting cookies? I'm still confused about NSHttpCookieStorage and if I'm using that correctly.
Thanks a lot.
I went with this work-around which was sufficient.
Since the cookie is in the url, I just parse it out and put programmatically put it into the urls that the tabbar buttons point to. Problem solved.

Open hidden view

I have a perspective with two views, at the beginning of the application shows a viewA and hides the viewB. It´s possible the user select an item from the table in viewA and that selection open viewB which at the beginning is hidden, while hiding viewA?
supouse you have a TableViewer, on your View, you do this:
this.yourTableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection .isEmpty()) {
MessageHelper.openWarning("Select something");
return;
}
try {
//opens a Editor instead a view
getSite().getPage().openEditor(new UsuarioEditorInput((Usuario) selecao.getFirstElement()), "br.com.germantech.ecf.usuarioEditor");
}
catch (PartInitException e) {
e.printStackTrace();
}
}
});