how to get real composite name in SWT.Show event - events

I want to log the information of user's action, such as button click, show composite. So I use event listener. When I use SWT.FocusIn, I can get the real composite name, but when I use SWT.Show I can't get the real class name.
Listener listener = new Listener() {
public void handleEvent(Event event) {
switch (event.type) {
case SWT.FocusIn: {
if(event!=null&&event.widget!=null){
Control parent = ((Control)event.widget).getParent();
while(parent!=null&&(parent.toString().startsWith("Composite")
||parent.toString().startsWith("Group")
||parent.toString().startsWith("Splitter")
)){
parent = parent.getParent();
}
if(parent!=null){
**//This place I can get "SWT.FocusIn:DoSomethingComposite"(The subclass of Composite).**
log.info("SWT.FocusIn:" + parent.toString());
}
}
break;
}
case SWT.Show: {
if (event.widget != null) {
if(event.widget instanceof Composite) {
Composite composite = (Composite)(event.widget);
**//But this place I just get "SWT.Show:Composite".**
log.info("SWT.Show:" + event.widget.toString());
}
}
break;
}
default: {
break;
}
}
}
}
PlatformUI.getWorkbench().getDisplay().addFilter(SWT.Show, listener);
PlatformUI.getWorkbench().getDisplay().addFilter(SWT.FocusIn, listener);

Related

Xamarin.forms app crashes on inserting data to SQLite database

I am trying to take information entered by the user in the AddPage.Xaml.cs and add it to a SQLite database. The code runs fine until I press the add button then it crashes, I can't really figure out what is going on and I don't really know what I'm doing.
here is the necessary code and their corresponding classes.
This is in the AddPage.xaml.cs:
private async Task AddButton_Clicked(object sender, EventArgs e)
{
App.characterDatabase.SaveCharacter(new Character()
{
Name = NameTxt.Text,
Species = SpeciesTxt.Text,
ImageUrl = ImageUrlTxt.Text
});
}
The CharacterDatabaseController.cs
public class CharacterDatabaseController
{
static object locker = new object();
SQLiteConnection database;
public CharacterDatabaseController()
{
database = DependencyService.Get<IDatabaseConnection>().DbConnection();
database.CreateTable<Character>();
}
public Character GetCharacter()
{
lock (locker)
{
if (database.Table<Character>().Count() == 0)
{
return null;
}
else
{
return database.Table<Character>().First();
}
}
}
public int SaveCharacter(Character character)
{
lock (locker)
{
if (character.Id != 0)
{
database.Update(character);
return character.Id;
}
else
{
return database.Insert(character);
}
}
}
public int DeleteCharacter(int id)
{
lock (locker)
{
return database.Delete<Character>(id);
}
}
}
and the App.cs:
public static CharacterDatabaseController characterDatabase
{
get
{
if (characterDatabase == null)
{
CharacterDatabase = new CharacterDatabaseController();
}
return CharacterDatabase;
}
}

Rootpage error xamarin forms

My root page is giving error by clicking on the back, instead of being in the background, an unhandled error occurs "An unhandled exception occurred. Is something wrong with my command?
I made the following attempt, when I call other pages besides Rootpage, the error does not occur
public class RootPage : MasterDetailPage
{
Dictionary<MenuIndex, NavigationPage> Views { get; set; }
public RootPage()
{
Title = "teste";
Views = new Dictionary<MenuIndex, NavigationPage>();
Master = new MenuPage(this)
{
Icon = "ic_menu_white.png"
};
NavigateAsync(MenuIndex.Page1);
}
public void NavigateAsync(MenuIndex id)
{
Page newPage;
if (!Views.ContainsKey(id))
{
switch (id)
{
case MenuIndex.Page1:
Views.Add(id, new ControlNavigationApp(new Page1(), "#04518c"));
break;
case MenuIndex.Page2:
Views.Add(id, new ControlNavigationApp(new Page2(), "#04518c"));
break;
case MenuIndex.Page3:
Views.Add(id, new ControlNavigationApp(new Page3(), "#04518c"));
break;
default:
Views.Add(id, new ControlNavigationApp(new Page1(), "#04518c"));
break;
}
}
newPage = Views[id];
if (newPage == null)
return;
//pop to root for Windows Phone
if (Detail != null && Device.OS == TargetPlatform.WinPhone)
{
//await Detail.Navigation.PopToRootAsync();
}
Detail = newPage;
if (Device.Idiom != TargetIdiom.Tablet)
IsPresented = false;
}
//comand example
protected override bool OnBackButtonPressed()
{
return base.OnBackButtonPressed();
}
}

How to initiate a Video call using lync sdk?

My Aim: I want to initiate a video call from the start.
My Problem: It is getting initiated into audio call and then it's turning into video after end user answers the call.
void ConversationManager_ConversationAdded_Video(object sender, ConversationManagerEventArgs e)
{
Console.WriteLine("Inside conversation added for Video");
if (e.Conversation.Modalities[ModalityTypes.AudioVideo].State != ModalityState.Notified)
{
if (e.Conversation.CanInvoke(ConversationAction.AddParticipant))
{
try
{
e.Conversation.ParticipantAdded += Conversation_ParticipantAdded_Video;
e.Conversation.AddParticipant(client.ContactManager.GetContactByUri(receipient));
}
catch (ItemAlreadyExistException ex)
{
}
}
}
}
void Conversation_ParticipantAdded_Video(object source, ParticipantCollectionChangedEventArgs data)
{
if (data.Participant.IsSelf != true)
{
if (((Conversation)source).Modalities[ModalityTypes.AudioVideo].CanInvoke(ModalityAction.Connect))
{
object[] asyncState = { ((Conversation)source).Modalities[ModalityTypes.AudioVideo], "CONNECT" };
try
{
((Conversation)source).Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += _AVModality_ModalityStateChanged_Video;
Console.WriteLine("entered video Satheesh participant added");
// ((Conversation)source).Modalities[ModalityTypes.AudioVideo].BeginConnect(ModalityCallback, asyncState);
((Conversation)source).Modalities[ModalityTypes.AudioVideo].BeginConnect(ModalityCallback, asyncState);
//((Conversation)source).Modalities[ModalityTypes.AudioVideo].EndConnect(ModalityCallback, asyncState);
Thread.Sleep(6000);
Console.WriteLine(source);
Console.WriteLine("entered video participant added");
}
catch (LyncClientException lce)
{
throw new Exception("Lync Platform Exception on BeginConnect: " + lce.Message);
}
}
}
}
public void ModalityCallback(IAsyncResult ar)
{
Object[] asyncState = (Object[])ar.AsyncState;
try
{
if (ar.IsCompleted == true)
{
if (asyncState[1].ToString() == "RETRIEVE")
{
((AVModality)asyncState[0]).EndRetrieve(ar);
}
if (asyncState[1].ToString() == "HOLD")
{
((AVModality)asyncState[0]).EndHold(ar);
}
if (asyncState[1].ToString() == "CONNECT")
{
Console.WriteLine("inside connect method CONNECT");
((AVModality)asyncState[0]).EndConnect(ar);
}
if (asyncState[1].ToString() == "FORWARD")
{
((AVModality)asyncState[0]).EndForward(ar);
}
if (asyncState[1].ToString() == "ACCEPT")
{
((AVModality)asyncState[0]).Accept();
}
}
}
catch (LyncClientException)
{ }
}
public void _AVModality_ModalityStateChanged_Video(object sender, ModalityStateChangedEventArgs e)
{
Console.WriteLine(sender);
Console.WriteLine("entered video modality changed");
switch (e.NewState)
{
case ModalityState.Connected:
if (_VideoChannel == null)
{
_VideoChannel = ((AVModality)sender).VideoChannel;
_VideoChannel.StateChanged += new EventHandler<ChannelStateChangedEventArgs>(_VideoChannel_StateChanged);
}
if (_VideoChannel.CanInvoke(ChannelAction.Start))
{
Console.WriteLine("entered video modality changed123");
_VideoChannel.BeginStart(MediaChannelCallback, _VideoChannel);
}
break;
case ModalityState.OnHold:
break;
case ModalityState.Connecting:
case ModalityState.Forwarding:
break;
case ModalityState.Transferring:
break;
}
}
private void MediaChannelCallback(IAsyncResult ar)
{
((VideoChannel)ar.AsyncState).EndStart(ar);
}
I Think it is because you call _AVModality_ModalityStateChanged_Video in ParticipantAdded event.
that means that you start your video when the person you call (the new participant) joins the conversation. thats why it is getting initiated into audio call and then it's turning into video after end user answers the call.
The solution is to fire a new event : ConversationStateChangedEvent
this is where I did it and works fine :
/// <summary>
/// Handles event raised when New meetNow window change it's state
/// </summary>
private void _NewMeetNowConversation_StateChanged(object sender, ConversationStateChangedEventArgs e)
{
Conversation conference = (Conversation)sender;
switch(e.NewState)
{
case ConversationState.Active:
conference.Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += AVConferenceModalityStateChanged;
conference.ParticipantAdded += ConfParticipantAdded;
break;
case ConversationState.Terminated: //conversation window completely closed
break;
case ConversationState.Inactive:
break;
case ConversationState.Parked:
break;
case ConversationState.Invalid:
break;
}
}

Xamarin Android Google Plus SignIn

I learning Xamarin Android, and i want to implement Google SignIn... But i'm not to be able to do that. I just need to use Client ID? i catch some examples in Internet but nothing works... Can someone give a example? or step by step how i can do this in Xamarin?
Thank you!
My Code:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Gms.Common.Apis;
using Android.Gms.Common;
using System;
using Android.Gms.Plus;
using Android.Content;
using Android.Runtime;
using Android.Gms.Plus.Model.People;
namespace LoginGoogle
{
[Activity(Label = "LoginGoogle", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity, GoogleApiClient.IConnectionCallbacks,
GoogleApiClient.IOnConnectionFailedListener
{
private GoogleApiClient googleApiClient;
private SignInButton btnGooglePlus;
private ConnectionResult connectionResult;
private bool intentProgress;
private bool signInClick;
private bool infoPopulated;
private TextView lblName;
private TextView lblTagLine;
private TextView lblBraggingRights;
private TextView lblGender;
private TextView lblRelationship;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
btnGooglePlus = FindViewById<SignInButton>(Resource.Id.btnGooglePlus);
btnGooglePlus.Click += btnGooglePlus_Click;
lblName = FindViewById<TextView>(Resource.Id.lblName);
lblTagLine = FindViewById<TextView>(Resource.Id.lblTagLine);
lblBraggingRights = FindViewById<TextView>(Resource.Id.lblBraggingRights);
lblGender = FindViewById<TextView>(Resource.Id.lblGender);
lblRelationship = FindViewById<TextView>(Resource.Id.lblRelationship);
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this);
builder.AddConnectionCallbacks(this);
builder.AddOnConnectionFailedListener(this);
builder.AddApi(PlusClass.API);
builder.AddScope(PlusClass.ScopePlusProfile);
builder.AddScope(PlusClass.ScopePlusLogin);
//Build our GoogleApiClient
googleApiClient = builder.Build();
}
void btnGooglePlus_Click(object sender, EventArgs e)
{
if (!googleApiClient.IsConnecting)
{
signInClick = true;
resolveSigInError();
}
}
private void resolveSigInError()
{
if (!googleApiClient.IsConnected)
{
//No need to resolve errors
return;
}
if (connectionResult.HasResolution)
{
try
{
intentProgress = true;
StartIntentSenderForResult(connectionResult.Resolution.IntentSender, 0, null,
0, 0, 0);
} catch (Android.Content.IntentSender.SendIntentException e)
{
intentProgress = false;
googleApiClient.Connect();
}
}
}
protected override void OnActivityResult(int requestCode,
[GeneratedEnum] Result resultCode, Intent data)
{
if(requestCode == 0)
{
if(resultCode != Result.Ok)
{
signInClick = false;
}
intentProgress = false;
if (googleApiClient.IsConnecting)
{
googleApiClient.Connect();
}
}
}
protected override void OnStart()
{
base.OnStart();
googleApiClient.Connect();
}
protected override void OnStop()
{
base.OnStop();
if (googleApiClient.IsConnected)
{
googleApiClient.Disconnect();
}
}
public void OnConnected(Bundle connectionHint)
{
//Successful login
signInClick = false;
if (PlusClass.PeopleApi.GetCurrentPerson(googleApiClient) != null)
{
IPerson plusUser = PlusClass.PeopleApi.GetCurrentPerson(googleApiClient);
if (plusUser.HasDisplayName)
{
lblName.Text += plusUser.DisplayName;
}
if (plusUser.HasTagline)
{
lblTagLine.Text += plusUser.Tagline;
}
if (plusUser.HasBraggingRights)
{
lblBraggingRights.Text += plusUser.BraggingRights;
}
{
switch (plusUser.RelationshipStatus)
{
case 0:
lblRelationship.Text += "Single";
break;
case 1:
lblRelationship.Text += "In a relationship";
break;
case 2:
lblRelationship.Text += "Engaged";
break;
case 3:
lblRelationship.Text += "Married";
break;
case 4:
lblRelationship.Text += "It's complicated";
break;
case 5:
lblRelationship.Text += "In an open relationship";
break;
case 6:
lblRelationship.Text += "Widowed";
break;
case 7:
lblRelationship.Text += "In a domestic partnership";
break;
case 8:
lblRelationship.Text += "In a civil union";
break;
default:
lblRelationship.Text += "Unknown";
break;
}
}
if (plusUser.HasGender)
{
switch (plusUser.Gender)
{
case 0:
lblGender.Text += "Male";
break;
case 1:
lblGender.Text += "Female";
break;
case 2:
lblGender.Text += "Other";
break;
default:
lblGender.Text += "Unknown";
break;
}
infoPopulated = true;
}
}
}
public void OnConnectionSuspended(int cause)
{
throw new NotImplementedException();
}
public void OnConnectionFailed(ConnectionResult result)
{
if (intentProgress)
{
//Store the ConnectionResult so that we can use it later when the user
//clicks 'sign in'
connectionResult = result;
if (signInClick)
{
//The user has already clicked 'signin' so we attempt to resolve all
//errors until the user is signed in
resolveSigInError();
}
}
}
}
}
enter code here
Please refer to the xamarin sample for google sign in. In this sample you do not need Client ID. For more google sign in information please check the google development document.
I catch some examples in Internet but nothing works...
I think you may not authorized the app.
Download the sample and make sure you've authorized the app in the Google Developers Console before use.
Authorized the app
Open the link.
Create your project name(whatever you write) and add the package name for it. In this sample the package name is com.xamarin.signinquickstart.
Get your SHA-1 please refer to this link.
Build and deploy the demo app and sign in with google account.
Screen shot:
But i'm not to be able to do that. I just need to use Client ID?
How to use the Client ID login on
According to google document. I think you can try to login with client id by:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
.RequestIdToken("YOUR_CLIENT_ID")
.RequestEmail()
.Build();
mGoogleApiClient = new GoogleApiClient.Builder (this)
.EnableAutoManage(mLoginFragment, failedHandler)
.AddApi (Auth.GOOGLE_SIGN_IN_API,gso)
.Build ()

Vala GTK+. Issue with customized widget

I need to create a gtk.Entry which accepts only numbers. but I can't overwrite the key_press_event event in an heredited class. It only works if I use the original Entry by means of connect function.
What am I doing wrong?
using Gtk;
public class NumberEntry : Entry {
public void NumberEntry(){
add_events (Gdk.EventMask.KEY_PRESS_MASK);
}
//With customized event left entry editing is not possible
public override bool key_press_event (Gdk.EventKey event) {
string numbers = "0123456789.";
if (numbers.contains(event.str)){
return false;
} else {
return true;
}
}
}
public class Application : Window {
public Application () {
// Window
this.title = "Entry Issue";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (350, 70);
Grid grid = new Grid();
grid.set_row_spacing(8);
grid.set_column_spacing(8);
Label label_1 = new Label ("Customized Entry, useless:");
grid.attach (label_1,0,0,1,1);
//Customized Entry:
NumberEntry numberEntry = new NumberEntry ();
grid.attach(numberEntry, 1, 0, 1, 1);
Label label_2 = new Label ("Working only numbers Entry:");
grid.attach (label_2,0,1,1,1);
//Normal Entry
Entry entry = new Entry();
grid.attach(entry, 1, 1, 1, 1);
this.add(grid);
//With normal Entry this event works well:
entry.key_press_event.connect ((event) => {
string numbers = "0123456789.";
if (numbers.contains(event.str)){
return false;
} else {
return true;
}
});
}
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
The key_press_event of the superclass is no longer being called. You need to call the base class and return true when you have consumed the key.
public override bool key_press_event (Gdk.EventKey event) {
string numbers = "0123456789.";
if (numbers.contains(event.str)){
return base.key_press_event (event);
} else {
return true;
}
}
If you return false in a signal, this can be passed to an alternate handler, but only if you use connect and not override the signal method.

Resources