I am loading a web page in the web view, the view loads properly but the LoadFinished delegate method is not invoked, all other delegate methods are invoked properly. Here is my code
public partial class TestViewController
{
public TestViewController(){}
public override void ViewDidLoad()
{
base.ViewDidLoad();
MyWebViewDelegate webDelegate = new MyWebViewDelegate();
myWebView.Delegate = webDelegate;
string webUrl = "https://www.google.co.in/"
if (Connectivity.CheckForInternetConnection() && webUrl != null)
{
myWebView.LoadRequest(new NSUrlRequest(new NSUrl(webUrl)));
ProgressView.Show();
}
else
{
ProgressView.Hide();
}
myWebView.ScalesPageToFit = true;
}
}
public class MyWebViewDelegate : UIWebViewDelegate
{
public MyWebViewDelegate() : base(){}
public override void LoadFailed(UIWebView webView, NSError error)
{
ProgressView.Hide();
}
public override bool ShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
return true;
}
public override void LoadingFinished(UIWebView webView)
{
ProgressView.Hide();
}
}
I need to detect the load finish, to hide the progress view, But I don't know what is wrong with my code Please help me. Thanks in Advance
Related
how to send verificationId from SendOtpCodeAsync() to SendCode_Button_Clicked()
Share Project code
IAuth auth;
auth = DependencyService.Get<IAuth>();
private async void SendCode_Button_Clicked(object sender, EventArgs e)
{
bool result = await auth.SendOtpCodeAsync(PhonenumberEntry.Text);
}
android project code
[assembly: Dependency(typeof(AuthDriod))]
namespace TestApp_MiniApps.Droid
{
public class AuthDriod : PhoneAuthProvider.OnVerificationStateChangedCallbacks, IAuth
{
private TaskCompletionSource<bool> _phoneAuthTcs;
public Task<bool> SendOtpCodeAsync(string phonenumber)
{
_phoneAuthTcs = new TaskCompletionSource<bool>();
Java.Lang.Long num = (Java.Lang.Long)60;
PhoneAuthOptions options =
PhoneAuthOptions.NewBuilder(FirebaseAuth.Instance)
.SetPhoneNumber(phonenumber) // Phone number to verify
.SetTimeout(num, TimeUnit.Seconds) // Timeout and unit
.SetActivity(Platform.CurrentActivity) // Activity (for callback binding)
.SetCallbacks(this) // OnVerificationStateChangedCallbacks
.Build();
PhoneAuthProvider.VerifyPhoneNumber(options);
return _phoneAuthTcs.Task;
}
public override void OnVerificationCompleted(PhoneAuthCredential credential)
{
}
public override void OnVerificationFailed(FirebaseException exception)
{
_phoneAuthTcs?.TrySetResult(false);
}
public override void OnCodeSent(string verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken)
{
base.OnCodeSent(verificationId, forceResendingToken);
_phoneAuthTcs?.TrySetResult(true);
}
}//end of class
}
share project interface
namespace TestApp_MiniApps.Views.Xamarin.FireBase
{
public interface IAuth
{
Task<bool> SendOtpCodeAsync(string phonenumber);
}//end of class
}
To summarise what Leo had put in the comments you can check what is returned from your method call.
Change from bool to your own class. For the purpose of this answer I will call it OtpResult.
// The new class definition:
public class OtpResult
{
public bool Success { get; set; }
// Define whatever you like here
public string StringValue { get; set; }
}
public interface IAuth
{
Task<OtpResult> SendOtpCodeAsync(string phonenumber);
}
I have project in Unity and also new to C#. Problem is that I got error The script needs to Derive from MonoBehaviour. I understand what does that mean but when I use MonoBehaviour I'm getting tons of Errors like this:
Errors in console
Will be glad if anyone can explain what am i doing wrong - thank you good people of stackoverflow!
Every script is connected to BaseWindow
namespace BlGame.View
{
public abstract class BaseWindow
{
protected Transform mRoot;
protected EScenesType mScenesType;
protected string mResName;
protected bool mResident;
protected bool mVisible = false;
public abstract void Init();
public abstract void Realse();
protected abstract void InitWidget();
protected abstract void RealseWidget();
protected abstract void OnAddListener();
protected abstract void OnRemoveListener();
public abstract void OnEnable();
public abstract void OnDisable();
public virtual void Update(float deltaTime) { }
public EScenesType GetScenseType()
{
return mScenesType;
}
public bool IsVisible() { return mVisible; }
public bool IsResident() { return mResident; }
public void Show()
{
if (mRoot == null)
{
if (Create())
{
InitWidget();
}
}
if (mRoot && mRoot.gameObject.activeSelf == false)
{
mRoot.gameObject.SetActive(true);
mVisible = true;
OnEnable();
OnAddListener();
}
}
public void Hide()
{
if (mRoot && mRoot.gameObject.activeSelf == true)
{
OnRemoveListener();
OnDisable();
if (mResident)
{
mRoot.gameObject.SetActive(false);
}
else
{
RealseWidget();
Destroy();
}
}
mVisible = false;
}
//预加载
public void PreLoad()
{
if (mRoot == null)
{
if (Create())
{
InitWidget();
}
}
}
//延时删除
public void DelayDestory()
{
if (mRoot)
{
RealseWidget();
Destroy();
}
}
private bool Create()
{
if (mRoot)
{
Debug.LogError("Window Create Error Exist!");
return false;
}
if (mResName == null || mResName == "")
{
Debug.LogError("Window Create Error ResName is empty!");
return false;
}
if (GameMethod.GetUiCamera.transform== null)
{
Debug.LogError("Window Create Error GetUiCamera is empty! WindowName = " + mResName);
return false;
}
GameObject obj = LoadUiResource.LoadRes(GameMethod.GetUiCamera.transform, mResName);
if (obj == null)
{
Debug.LogError("Window Create Error LoadRes WindowName = " + mResName);
return false;
}
mRoot = obj.transform;
mRoot.gameObject.SetActive(false);
return true;
}
//销毁窗体
protected void Destroy()
{
if (mRoot)
{
LoadUiResource.DestroyLoad(mRoot.gameObject);
mRoot = null;
}
}
public Transform GetRoot()
{
return mRoot;
}
}
}
Something like This:
public class UIGuideWindow : BaseWindow
{
public UIGuideWindow()
{
//mScenesType = EScenesType.EST_Login;
//mResName = GameConstDefine.UIGuideRestPath;
//mResident = false;
}
Unity Update Function cannot have any paramaters like this : Update(float deltaTime), this is unity not unreal engine:))
To fix this, Remove float deltaTime , and instead use Time.deltaTime inside the function implementation itself
I try to pass the bool bake value from one class(attribute class) to the solve instance(buttonTest class).
I already tried several things as the Get Method and write a property without sucess.
namespace buttonTest
{
public class buttonTestComponent : GH_Component
{
public override void CreateAttributes()
{
m_attributes = new Attributes_Custom(this);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Circle circle = new Circle(2.00);
//here I want to bake
}
public class Attributes_Custom : GH_ComponentAttributes
{
public Attributes_Custom(GH_Component owner) : base(owner) { }
protected override void Layout()
bool bake;
public bool Bake
{
get { return bake; }
}
public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
{
if (e.Button == MouseButtons.Left)
{
RectangleF rec = ButtonBounds;
if (rec.Contains(e.CanvasLocation))
{
bool bake = true;
MessageBox.Show("Hello World", "Hello World", MessageBoxButtons.OK);
return GH_ObjectResponse.Handled;
}
}
return base.RespondToMouseDown(sender, e);
}
}
}
I am a beginner so I hope it is possible to understand.
Thanks to everybody
if I try to use m_attributes.Bake I get the following error message:
error message
If I understood the question correctly, you need something like the following.
The buttonTestComponent class:
public class buttonTestComponent : GH_Component
{
private Attributes_Custom m_attributes;
public override void CreateAttributes()
{
m_attributes = new Attributes_Custom(this);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
Circle circle = new Circle(2.00);
//use m_attributes.Bake here
}
}
And you leave Attributes_Custom class as it is.
What I want to do is basically what was answered here:
how to get html content from a webview?
However, I'm working with Xamarin in C#, and the code given in the top answer is in java. I tried to translate it to C# as follows:
public class LoginWebViewController : Activity
{
WebView localWebView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.WebView);
localWebView = FindViewById<WebView>(Resource.Id.LocalWebView);
localWebView.SetWebViewClient(new JustWebViewClient());
localWebView.LoadUrl(LoginOperations.GetTPLoginUrl());
localWebView.Settings.JavaScriptEnabled = true;
localWebView.AddJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");
}
class MyJavaScriptInterface
{
private Context ctx;
MyJavaScriptInterface(Context ctx)
{
this.ctx = ctx;
}
public void showHTML(String html)
{
Console.WriteLine(html);
}
}
}
But I get the following error:
I tried changing the class to public but it still gives the same error. What is wrong?
Additional code:
public class MyWebViewClient : WebViewClient
{
public override void OnPageFinished(WebView view, String url)
{
base.OnPageFinished(view,url);
Console.WriteLine("DONE LOADING PAGE");
view.LoadUrl("javascript:HtmlViewer.showHTML" +
"('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
}
}
Your constructor is not public and you have to inherit from Java.Lang.Object. You have to add the Export attribute, too.
class MyJavaScriptInterface : Java.Lang.Object
{
private Context ctx;
public MyJavaScriptInterface(Context ctx)
{
this.ctx = ctx;
}
public MyJavaScriptInterface(IntPtr handle, JniHandleOwnership transfer)
: base (handle, transfer)
{
}
[Export("showHTML")]
public void showHTML(string html)
{
Console.WriteLine(html);
}
}
And in your javascript code is an error, too. You are missing a opening ( after showHTML.
view.LoadUrl("javascript:HtmlViewer.showHTML(" + ...
I have a simple wifi app. It is just scanning wifis and listing them. I figured out my ScanResult List is filling in another method but in OnPrepare/CreateOptionsMenu it is always null.
This method calls first when program starts I know that, but when i try to call it again with InvalidateOptionsMenu(); nothing changes. Here is my piec of code:
MainActivity:
public class MainActivity : Activity
{
public static Context context;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button wifiButton = FindViewById<Button>(Resource.Id.popupButton);
RegisterReceiver(new WiFiReceiver(), new IntentFilter(WifiManager.ScanResultsAvailableAction));
((WifiManager)GetSystemService(WifiService)).StartScan();
wifiButton.Click += (s, arg) => {
InvalidateOptionsMenu();
PopupMenu menu = new PopupMenu(this, wifiButton);
menu.Inflate(Resource.Menu.menu);
menu.Show();
};
}
public override bool OnCreateOptionsMenu(IMenu menu) {
WiFiReceiver wifiReceiver = new WiFiReceiver();
IList<ScanResult> availableWifis = wifiReceiver.GetWifiList();//This is always null
if (availableWifis != null) {
foreach (ScanResult token in availableWifis) {
menu.Add(token.Ssid);
}
}
return base.OnCreateOptionsMenu(menu);
}
}
WiFi Scanning this class:
class WiFiReceiver : BroadcastReceiver {
private IList<ScanResult> wifiList;
private string message;
public override async void OnReceive(Context context, Intent intent) {
MainActivity mainActivity = (MainActivity)context;
WifiManager wifiManager = (WifiManager)mainActivity.GetSystemService(Context.WifiService);
this.message = string.Join("\r\n", wifiManager.ScanResults
.Select(r => $"{r.Ssid} - {r.Level} dB"));
this.wifiList = wifiManager.ScanResults.ToList(); //This has connection informations
mainActivity.DisplayText(message);
await Task.Delay(TimeSpan.FromSeconds(1));
wifiManager.StartScan();
}
public IList<ScanResult> GetWifiList() {
return wifiList;
}