protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); MAIN = this; LocationManager lm = (LocationManager)GetSystemService(LocationService); /* Used to get App manifest hash * * PackageInfo info = this.PackageManager.GetPackageInfo("UniProject.UniProject", PackageInfoFlags.Signatures); * * foreach(Android.Content.PM.Signature signature in info.Signatures) * { * MessageDigest md = MessageDigest.GetInstance("SHA"); * md.Update(signature.ToByteArray()); * * string keyHash = Convert.ToBase64String(md.Digest()); * Console.WriteLine("KH: ", keyHash); * } * // Set our view from the "main" layout resource * // SetContentView (Resource.Layout.Main); * }*/ // Init the facebook SDK FacebookSdk.SdkInitialize(this.ApplicationContext); mProfileTracker = new myProfileTracker(); mProfileTracker.mOnProfileChanged += MProfileTracker_mOnProfileChanged; mProfileTracker.StartTracking(); if (currentProfile == null) { SetContentView(Resource.Layout.Main); } else { SetContentView(Resource.Layout.Fragment1); } LoginButton button = FindViewById <LoginButton>(Resource.Id.login_button); button.SetReadPermissions("user_friends"); mCallBackManager = CallbackManagerFactory.Create(); button.RegisterCallback(mCallBackManager, this); mText = FindViewById <TextView>(Resource.Id.textView1); Button MainToFrag1 = FindViewById <Button>(Resource.Id.m1_f1); //Button Frag1ToMain = FindViewById<Button>(Resource.Id.button1); // Click Handler delegates // MainToFrag1.Click += (object e, EventArgs s) => { SetContentView(Resource.Layout.Fragment1); }; /* Frag1ToMain.Click += (object e, EventArgs s) => * { * SetContentView(Resource.Layout.Main); * };a*/ }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); FacebookSdk.SdkInitialize(this.ApplicationContext); textToSpeech = new TextToSpeech(this, this); locale = new Java.Util.Locale("pt", "BR"); SetContentView(Resource.Layout.PagInicCliente); historico = Facade.GetPesquisas(); // Facebook LoginButton loginbutton = FindViewById <LoginButton>(Resource.Id.login_button); loginbutton.SetReadPermissions("user_friends"); mCallBackManager = CallbackManagerFactory.Create(); loginbutton.RegisterCallback(mCallBackManager, this); PackageInfo info = this.PackageManager.GetPackageInfo("com.uminhomieili4.pick_a_prato", PackageInfoFlags.Signatures); foreach (Android.Content.PM.Signature signature in info.Signatures) { MessageDigest md = MessageDigest.GetInstance("SHA"); md.Update(signature.ToByteArray()); string keyhash = Convert.ToBase64String(md.Digest()); Console.WriteLine("KeyHash: " + keyhash); } var imageuser = FindViewById <ImageView>(Resource.Id.foto); byte[] a = Convert.FromBase64String(Facade.atualUserC.Foto); Bitmap b = BitmapFactory.DecodeByteArray(a, 0, a.Length); imageuser.SetImageBitmap(b); var preferenciasButtom = FindViewById <Button>(Resource.Id.pref); preferenciasButtom.Click += (sender, e) => { StartActivity(typeof(EditarPreferencias)); }; var switchpref = FindViewById <Switch>(Resource.Id.switchpref); switchpref.Checked = true; Button guardadosbottom = FindViewById <Button>(Resource.Id.selecoes); guardadosbottom.Click += (sender, e) => { ListaPratos.pratoList = Facade.GetPratosGuardados(); StartActivity(typeof(ListaPratos)); }; var gobottom = FindViewById <ImageView>(Resource.Id.go); textView = FindViewById <AutoCompleteTextView>(Resource.Id.autocomplete_prato); textView.Click += (sender, e) => { textView.Text = ""; }; var adapter = new ArrayAdapter <String>(this, Resource.Layout.ListItem, historico); textView.Adapter = adapter; gobottom.Click += (sender, e) => { if (textView.Text.Length != 0) { List <Prato> pratos; if (switchpref.Checked == true) { pratos = Facade.PesquisaPrato(textView.Text, true); } else { pratos = Facade.PesquisaPrato(textView.Text, false); } if (pratos.Count == 0) { textToSpeech.Speak("Não encontrei " + textView.Text, QueueMode.Flush, null, null); } else { ListaPratos.pratoList = pratos; ListaPratos.pesquisa = textView.Text; StartActivity(typeof(ListaPratos)); } } }; recButton = FindViewById <ImageView>(Resource.Id.rec); recButton.Click += delegate { var voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech); voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, "pr-BR"); voiceIntent.PutExtra(RecognizerIntent.ExtraPrompt, "Fale agora"); voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500); voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500); voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000); voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1); StartActivityForResult(voiceIntent, VOICE); }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); FacebookSdk.SdkInitialize(this.ApplicationContext); mProfileTracker = new MyProfileTracker(); mProfileTracker.mOnProfileChanged += mProfileTracker_mOnProfileChanged; mProfileTracker.StartTracking(); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); Button faceBookButton = FindViewById <Button>(Resource.Id.button); mTxtFirstName = FindViewById <TextView>(Resource.Id.txtFirstName); mTxtLastName = FindViewById <TextView>(Resource.Id.txtLastName); mTxtName = FindViewById <TextView>(Resource.Id.txtName); mProfilePic = FindViewById <ProfilePictureView>(Resource.Id.profilePic); mBtnShared = FindViewById <ShareButton>(Resource.Id.btnShare); mBtnGetEmail = FindViewById <Button>(Resource.Id.btnGetEmail); //if (AccessToken.CurrentAccessToken != null) //{ // //The user is logged in through Facebook // faceBookButton.Text = "Logged Out"; //} LoginButton button = FindViewById <LoginButton>(Resource.Id.login_button); button.SetReadPermissions(new List <string> { "public_profile", "user_friends", "email" }); mCallBackManager = CallbackManagerFactory.Create(); button.RegisterCallback(mCallBackManager, this); mBtnGetEmail.Click += (o, e) => { GraphRequest request = GraphRequest.NewMeRequest(AccessToken.CurrentAccessToken, this); Bundle parameters = new Bundle(); parameters.PutString("fields", "id,name,age_range,email"); request.Parameters = parameters; request.ExecuteAsync(); }; //LoginManager.Instance.RegisterCallback(mCallBackManager, this); //faceBookButton.Click += (o, e) => //{ // if (AccessToken.CurrentAccessToken != null) // { // //The user is logged in through Facebook // LoginManager.Instance.LogOut(); // faceBookButton.Text = "My Facebook login button"; // } // else // { // //The user is not logged in // LoginManager.Instance.LogInWithReadPermissions(this, new List<string> { "public_profile", "user_friends" }); // faceBookButton.Text = "Logged Out"; // } //}; ShareLinkContent content = new ShareLinkContent.Builder().Build(); mBtnShared.ShareContent = content; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); FacebookSdk.SdkInitialize(this.ApplicationContext); callbackManager = CallbackManagerFactory.Create(); var loginCallback = new FacebookCallback <LoginResult> { HandleSuccess = loginResult => { HandlePendingAction(); UpdateUI(); }, HandleCancel = () => { if (pendingAction != PendingAction.NONE) { ShowAlert( GetString(Resource.String.cancelled), GetString(Resource.String.permission_not_granted)); pendingAction = PendingAction.NONE; } UpdateUI(); }, HandleError = loginError => { if (pendingAction != PendingAction.NONE && loginError is FacebookAuthorizationException) { ShowAlert( GetString(Resource.String.cancelled), GetString(Resource.String.permission_not_granted)); pendingAction = PendingAction.NONE; } UpdateUI(); } }; LoginManager.Instance.RegisterCallback(callbackManager, loginCallback); shareCallback = new FacebookCallback <SharerResult> { HandleSuccess = shareResult => { Console.WriteLine("HelloFacebook: Success!"); if (shareResult.PostId != null) { var title = Parent.GetString(Resource.String.error); var id = shareResult.PostId; var alertMsg = Parent.GetString(Resource.String.successfully_posted_post, id); ShowAlert(title, alertMsg); } }, HandleCancel = () => { Console.WriteLine("HelloFacebook: Canceled"); }, HandleError = shareError => { Console.WriteLine("HelloFacebook: Error: {0}", shareError); var title = Parent.GetString(Resource.String.error); var alertMsg = shareError.Message; ShowAlert(title, alertMsg); } }; shareDialog = new ShareDialog(this); shareDialog.RegisterCallback(callbackManager, shareCallback); if (savedInstanceState != null) { var name = savedInstanceState.GetString(PENDING_ACTION_BUNDLE_KEY); pendingAction = (PendingAction)Enum.Parse(typeof(PendingAction), name); } SetContentView(Resource.Layout.main); profileTracker = new CustomProfileTracker { HandleCurrentProfileChanged = (oldProfile, currentProfile) => { UpdateUI(); HandlePendingAction(); } }; profilePictureView = FindViewById <ProfilePictureView> (Resource.Id.profilePicture); greeting = FindViewById <TextView> (Resource.Id.greeting); postStatusUpdateButton = FindViewById <Button> (Resource.Id.postStatusUpdateButton); postStatusUpdateButton.Click += (sender, e) => { PerformPublish(PendingAction.POST_STATUS_UPDATE, canPresentShareDialog); }; postPhotoButton = FindViewById <Button> (Resource.Id.postPhotoButton); postPhotoButton.Click += (sender, e) => { PerformPublish(PendingAction.POST_PHOTO, canPresentShareDialogWithPhotos); }; // Can we present the share dialog for regular links? canPresentShareDialog = ShareDialog.CanShow(Java.Lang.Class.FromType(typeof(ShareLinkContent))); // Can we present the share dialog for photos? canPresentShareDialogWithPhotos = ShareDialog.CanShow(Java.Lang.Class.FromType(typeof(SharePhotoContent))); }
private void IntializeUI(Bundle savestate) { EnableLocationDialog(); FacebookSdk.SdkInitialize(this.ApplicationContext); mProfileTracker = new MyProfileTracker(); SetContentView(Resource.Layout.home_page); toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.Title = "HOME"; var navigationView = FindViewById <NavigationView>(Resource.Id.nav_views); View headerview = navigationView.InflateHeaderView(Resource.Layout.drawer_header); UserName = headerview.FindViewById <TextView>(Resource.Id.userName); UserImage = headerview.FindViewById <ImageView>(Resource.Id.userImage); ISharedPreferences prefs = this.GetSharedPreferences("MYPROFILE", FileCreationMode.Private); if (prefs.GetString("username", "") != null && prefs.GetString("profilePic", "") != null) { UserImage.Visibility = ViewStates.Gone; ProfilePictureView fbProfilePicture = headerview.FindViewById <ProfilePictureView>(Resource.Id.facebook_profile_pic); fbProfilePicture.Visibility = ViewStates.Visible; string name = prefs.GetString("username", ""); string profilePic = prefs.GetString("profilepic", ""); UserName.Text = name; fbProfilePicture.ProfileId = profilePic; } TextView userLocationView = headerview.FindViewById <TextView>(Resource.Id.userLocation); userLocationView.Click += UserLocationView_Click; drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawerLayout); var drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, Resource.String.drawer_open, Resource.String.drawer_close); drawerLayout.AddDrawerListener(drawerToggle); drawerToggle.SyncState(); //SupportActionBar.Show(); // FindViewById<Button>(Resource.Id.button1).Click += HomePage_Click; iconList.Add(Resource.Raw.ic_bike); iconList.Add(Resource.Raw.ic_bike); iconList.Add(Resource.Raw.ic_service); iconList.Add(Resource.Raw.ic_gallery); dotslayout = FindViewById <LinearLayout>(Resource.Id.HomePageDotsContainer); imagePager = FindViewById <ViewPager>(Resource.Id.homePageImagePagerContainer); homeRView = FindViewById <RecyclerView>(Resource.Id.homePageRView); _layoutManager = new GridLayoutManager(this, 2); homeRView.SetLayoutManager(_layoutManager); RecycleHomeIconAdapter RVadapter = new RecycleHomeIconAdapter(this, iconList, iconNameList); homeRView.SetAdapter(RVadapter); RVadapter.ItemClick += RVadapter_ItemClick; imageList.Add(Resource.Raw.image1); imageList.Add(Resource.Raw.image4); imageList.Add(Resource.Raw.image2); PageImageAdapter adapter = new PageImageAdapter(this, imageList); imagePager.Adapter = adapter; imagePager.SetCurrentItem(0, true); imagePager.AddOnPageChangeListener(this); setUiPageViewController(); Bundle savestates = new Bundle(); // _bottomNavBar = BottomBar.Attach(this, bundle); _bottomNavBar = BottomBar.AttachShy((CoordinatorLayout)FindViewById(Resource.Id.homePageCoordinatorLayout), FindViewById(Resource.Id.homePageScrollingContent), savestates); _bottomNavBar.SetItems(Resource.Menu.bottomMenuBar); _bottomNavBar.SetOnMenuTabClickListener(this); navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected; }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); #region Facebook Auth FacebookSdk.SdkInitialize(this); #endregion #region Google Auth var serverClientId = Resources.GetString(Resource.String.serverClientId); //var clientId = Resources.GetString(Resource.String.clientId); var options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestScopes(new Scope(Scopes.PlusLogin)) //.RequestScopes(new Scope(Scopes.Profile)) //.RequestProfile() //.RequestId() .RequestIdToken(serverClientId) .RequestServerAuthCode(serverClientId) .RequestEmail() .Build(); SharedGoogleApiClient.Instance.GoogleApiClient = new GoogleApiClient.Builder(this) //.AddConnectionCallbacks(this) //.AddOnConnectionFailedListener(this) //.EnableAutoManage(this, this) .AddApi(Android.Gms.Auth.Api.Auth.GOOGLE_SIGN_IN_API, options) //.AddApi(PlusClass.API) .Build(); #endregion #region Azure Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init(); //sqlite db AzureService.DbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), AzureService.DbPath); if (!File.Exists(AzureService.DbPath)) { File.Create(AzureService.DbPath).Dispose(); } #endregion #region Mobile Center MobileCenter.Start(Keys.MobileCenterAppKey, typeof(Analytics), typeof(Crashes)); #endregion global::Xamarin.Forms.Forms.Init(this, bundle); ImageCircleRenderer.Init(); UserDialogs.Init(this); LoadApplication(new App()); }
private void ObtainAccessToken(string[] permissionNames) { lock (LoginLocker) { if (HasValidAccessToken) { SensusServiceHelper.Get().Logger.Log("Already have valid Facebook access token. No need to initialize.", LoggingLevel.Normal, GetType()); } else { #region ensure that facebook sdk is initialized if (FacebookSdk.IsInitialized) { SensusServiceHelper.Get().Logger.Log("Facebook SDK is already initialized.", LoggingLevel.Normal, GetType()); } else { SensusServiceHelper.Get().Logger.Log("Initializing Facebook SDK.", LoggingLevel.Normal, GetType()); FacebookSdk.SdkInitialize(Application.Context); Thread.Sleep(5000); // give sdk intialization a few seconds to read the access token } #endregion if (HasValidAccessToken) { SensusServiceHelper.Get().Logger.Log("Facebook access token read from cache.", LoggingLevel.Normal, GetType()); } else { ManualResetEvent loginWait = new ManualResetEvent(false); bool loginCancelled = false; string accessTokenError = null; #region prompt user to log in from main activity (SensusServiceHelper.Get() as AndroidSensusServiceHelper).RunActionUsingMainActivityAsync(mainActivity => { try { FacebookCallback <LoginResult> loginCallback = new FacebookCallback <LoginResult> { HandleSuccess = loginResult => { SensusServiceHelper.Get().Logger.Log("Facebook login succeeded.", Shared.LoggingLevel.Normal, GetType()); AccessToken.CurrentAccessToken = loginResult.AccessToken; loginWait.Set(); }, HandleCancel = () => { SensusServiceHelper.Get().Logger.Log("Facebook login cancelled.", Shared.LoggingLevel.Normal, GetType()); AccessToken.CurrentAccessToken = null; loginCancelled = true; loginWait.Set(); }, HandleError = loginResult => { SensusServiceHelper.Get().Logger.Log("Facebook login failed.", Shared.LoggingLevel.Normal, GetType()); AccessToken.CurrentAccessToken = null; loginWait.Set(); }, }; LoginManager.Instance.RegisterCallback(mainActivity.FacebookCallbackManager, loginCallback); LoginManager.Instance.LogInWithReadPermissions(mainActivity, permissionNames); } catch (Exception ex) { accessTokenError = ex.Message; loginWait.Set(); } }, true, false); #endregion loginWait.WaitOne(); if (accessTokenError != null) { SensusServiceHelper.Get().Logger.Log("Error while initializing Facebook SDK and/or logging in: " + accessTokenError, LoggingLevel.Normal, GetType()); } // if the access token is still not valid after logging in, consider it a fail. if (!HasValidAccessToken) { string message = "Failed to obtain access token."; SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType()); // if the user cancelled the login, don't prompt them to log in again if (loginCancelled) { throw new NotSupportedException(message + " User cancelled login."); } // if the user did not cancel the login, allow the login to be presented again when the health test is run else { throw new Exception(message); } } } } } }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); regularTxt = Typeface.CreateFromAsset(Assets, "fonts/SF-UI-Display-Regular.ttf"); semiboldTxt = Typeface.CreateFromAsset(Assets, "fonts/SF-UI-Display-Semibold.ttf"); //Get values UsernameEditext = FindViewById <EditText>(Resource.Id.usernamefield); PasswordEditext = FindViewById <EditText>(Resource.Id.passwordfield); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); Btn_Login = FindViewById <Button>(Resource.Id.loginButton); RegisterButton = FindViewById <Button>(Resource.Id.signUpButton); Main_LinearLayout = FindViewById <LinearLayout>(Resource.Id.mainLinearLayout); topTitile = FindViewById <TextView>(Resource.Id.titile); topTitile.Text = AppSettings.Application_Name; subTitile = FindViewById <TextView>(Resource.Id.subtitile); subTitile.Text = this.GetText(Resource.String.Lbl_Subtitile_Login); Txt_forgetpass = FindViewById <TextView>(Resource.Id.forgetpassButton); Txt_Terms_of_service = FindViewById <TextView>(Resource.Id.secTermTextView); Txt_Privacy = FindViewById <TextView>(Resource.Id.secPrivacyTextView); progressBar.Visibility = ViewStates.Invisible; UsernameEditext.SetTypeface(regularTxt, TypefaceStyle.Normal); PasswordEditext.SetTypeface(regularTxt, TypefaceStyle.Normal); topTitile.SetTypeface(regularTxt, TypefaceStyle.Normal); subTitile.SetTypeface(regularTxt, TypefaceStyle.Normal); Txt_forgetpass.SetTypeface(regularTxt, TypefaceStyle.Normal); Txt_Terms_of_service.SetTypeface(regularTxt, TypefaceStyle.Normal); Txt_Privacy.SetTypeface(regularTxt, TypefaceStyle.Normal); FontController.SetFont(Btn_Login, 1); FontController.SetFont(RegisterButton, 1); //Social Logins >> //============================== FacebookSdk.SdkInitialize(this); mprofileTracker = new FB_MyProfileTracker(); mprofileTracker.StartTracking(); BtnFBLogin = FindViewById <LoginButton>(Resource.Id.fblogin_button); BtnFBLogin.SetReadPermissions(new List <string> { "email", "public_profile" }); mFBCallManager = CallbackManagerFactory.Create(); BtnFBLogin.RegisterCallback(mFBCallManager, this); //FB accessToken var accessToken = AccessToken.CurrentAccessToken; var isLoggedIn = accessToken != null && !accessToken.IsExpired; if (isLoggedIn && Profile.CurrentProfile != null) { LoginManager.Instance.LogOut(); } // Configure sign-in to request the user's ID, email address, and basic profile. ID and basic profile are included in DEFAULT_SIGN_IN. var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(GoogleServices.ClientId) .RequestScopes(new Scope(Scopes.Profile)) .RequestScopes(new Scope(Scopes.PlusLogin)) .RequestServerAuthCode(GoogleServices.ClientId) .RequestProfile().RequestEmail().Build(); // Build a GoogleApiClient with access to the Google Sign-In API and the options specified by gso. mGoogleApiClient = new GoogleApiClient.Builder(this, this, this) .EnableAutoManage(this, this) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .Build(); mGoogleSignIn = FindViewById <Button>(Resource.Id.Googlelogin_button); if (!AppSettings.Show_Facebook_Login) { BtnFBLogin.Visibility = ViewStates.Gone; } if (!AppSettings.Show_Google_Login) { mGoogleSignIn.Visibility = ViewStates.Gone; } //============================== if (!string.IsNullOrEmpty(OneSignalNotification.OneSignalAPP_ID)) { if (AppSettings.ShowNotification) { OneSignalNotification.RegisterNotificationDevice(); } } if ((int)Build.VERSION.SdkInt < 23) { } else { RequestPermissions(new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage, }, 1); } } catch (Exception e) { Console.WriteLine(e); } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { FacebookSdk.SdkInitialize(Android.App.Application.Context); callbackManager = CallbackManagerFactory.Create(); var loginCallback = new FacebookCallback <LoginResult> { HandleSuccess = loginResult => { Console.WriteLine("1"); //HandlePendingAction(); //UpdateUI(); }, HandleCancel = () => { Console.WriteLine("2"); //if (pendingAction != PendingAction.NONE) //{ // ShowAlert( // GetString(Resource.String.cancelled), // GetString(Resource.String.permission_not_granted)); // pendingAction = PendingAction.NONE; //} //UpdateUI(); }, HandleError = loginError => { Console.WriteLine("3"); //if (pendingAction != PendingAction.NONE // && loginError is FacebookAuthorizationException) //{ // ShowAlert( // GetString(Resource.String.cancelled), // GetString(Resource.String.permission_not_granted)); // pendingAction = PendingAction.NONE; //} //UpdateUI(); } }; LoginManager.Instance.RegisterCallback(callbackManager, loginCallback); shareCallback = new FacebookCallback <SharerResult> { HandleSuccess = shareResult => { Console.WriteLine("HelloFacebook: Success!"); }, HandleCancel = () => { Console.WriteLine("HelloFacebook: Canceled"); }, HandleError = shareError => { Console.WriteLine("HelloFacebook: Error: {0}", shareError); } }; //profileTracker = new CustomProfileTracker //{ // HandleCurrentProfileChanged = (oldProfile, currentProfile) => // { // UpdateUI(); // HandlePendingAction(); // } //}; var r = (Android.Views.LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService); var containerView = r.Inflate(Resource.Layout.FacebookButton, null, false); SetNativeControl(containerView); //Activity activity = Context as Activity; //var ft = activity.FragmentManager.BeginTransaction(); //ft.Replace(Resource.Id.contentSwipe, new FragmentInbox(((SwipeCausaForms)Element).causa, activity, ((SwipeCausaForms)Element).page), "fragment_inbox"); //ft.Commit(); }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); FacebookSdk.SdkInitialize(this.ApplicationContext); SetContentView(Resource.Layout.Login); txtUserName = FindViewById <EditText>(Resource.Id.etEmailPhone); txtPassword = FindViewById <EditText>(Resource.Id.etPassword); txtForgotUsername = FindViewById <EditText>(Resource.Id.etForgotUsername); btnLogIn = FindViewById <Button>(Resource.Id.btnLogin); GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this); builder.AddConnectionCallbacks(this); builder.AddOnConnectionFailedListener(this); builder.AddApi(PlusClass.API); builder.AddScope(new Scope(Scopes.PlusLogin)); mGoogleApiClient = builder.Build(); mGoogleApiClient.Connect(); if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); Window.SetStatusBarColor(new Android.Graphics.Color(ContextCompat.GetColor(this, Resource.Color.primaryDark))); } ISharedPreferences prefs = Application.Context.GetSharedPreferences("WeClip", FileCreationMode.Private); var FromUserScreen = Intent.GetStringExtra("FromUserName"); if (!string.IsNullOrEmpty(FromUserScreen)) { var prefEditor = prefs.Edit(); prefEditor.PutBoolean("RegisterEmail", false); prefEditor.PutBoolean("RegisterPhone", false); prefEditor.Commit(); } bool RegisterEmail = prefs.GetBoolean("RegisterEmail", false); bool RegisterPhone = prefs.GetBoolean("RegisterPhone", false); llayoutSignIn = FindViewById <LinearLayout>(Resource.Id.llayoutSignIn); llayoutSignUpOptions = FindViewById <LinearLayout>(Resource.Id.llayoutSignUpOptions); llayoutForgotPassword = FindViewById <LinearLayout>(Resource.Id.llayoutForgot); btnSignUpWsocial = FindViewById <TextView>(Resource.Id.btnSignUpWsocial); btnSignUpWsocial.Click += BtnSignUpWsocial_Click; btnSignInView = FindViewById <TextView>(Resource.Id.btnSignInView); btnSignInView.Click += BtnSignInView_Click; btnForgotPassword = FindViewById <TextView>(Resource.Id.btnForgotPassword); btnForgotPassword.Click += BtnForgotPassword_Click; btnsignInInForgotPassword = FindViewById <TextView>(Resource.Id.tvSigninInForgotPassword); btnsignInInForgotPassword.Click += BtnSigninForgotPassword_Click; btnSignupWithEmail = FindViewById <Button>(Resource.Id.btnSignUpWithEmail); btnSignupWithPhone = FindViewById <Button>(Resource.Id.btnSignUpWithPhone); btnSignupWithGoogle = FindViewById <Button>(Resource.Id.btnGPlus); btnSignUpWithFacebook = FindViewById <Button>(Resource.Id.btnFacebook); btnSumitForgotPassword = FindViewById <Button>(Resource.Id.btnSubmitForgotPassword); mcallBackManager = CallbackManagerFactory.Create(); btnSignupWithPhone.Visibility = ViewStates.Gone; LoginManager.Instance.RegisterCallback(mcallBackManager, this); btnSignupWithEmail.Click += btnSignupWithEmail_Click; btnSignupWithPhone.Click += BtnSignupWithPhone_Click; btnSignupWithGoogle.Click += BtnSignupWithGoogle_Click; btnSignUpWithFacebook.Click += BtnSignUpWithFacebook_Click; btnSumitForgotPassword.Click += BtnSumitForgotPassword_Click; btnLogIn.Click += BtnLogIn_Click; if (RegisterEmail == true) { SignUpView(); } } catch (Java.Lang.Exception ex) { new CrashReportAsync("LoginActivity", "OnCreate", ex.Message + ex.StackTrace).Execute(); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); try { FacebookSdk.SdkInitialize(this.ApplicationContext); callbackManager = CallbackManagerFactory.Create(); LoginManager.Instance.RegisterCallback(callbackManager, this); LoginManager.Instance.LogInWithReadPermissions(this, LOGIN_PERMISSIONS); } catch (Exception e) { string failureInfo = e.ToString(); Console.WriteLine("FacebookActivity::onCreate() EXCEPTION " + failureInfo); } SetContentView(Resource.Layout.facebookLoginPage); profileTracker = new CustomProfileTracker { HandleCurrentProfileChanged = (oldProfile, currentProfile) => { UpdateUI(); } }; // properties applied to all buttons on Facebook login page var padding = Awpbs.Mobile.Config.OkCancelButtonsPadding; var minHeight = Awpbs.Mobile.Config.OkCancelButtonsHeight; Typeface typeface = Typeface.CreateFromAsset(Resources.Assets, "fonts/Lato-Regular.ttf"); // Profile Picture profilePictureView = FindViewById <ProfilePictureView>(Resource.Id.profilePicture); profilePictureView.SetMinimumHeight(minHeight); profilePictureView.SetPadding(padding, padding, padding, padding); // Greeting "Hello, Alex!", visible when connected to facebook account greeting = FindViewById <TextView>(Resource.Id.greeting); greeting.SetMinimumHeight(minHeight); greeting.SetPadding(padding, padding, padding, padding); greeting.SetTypeface(typeface, TypefaceStyle.Bold); greeting.SetTextSize(Android.Util.ComplexUnitType.Sp, Config.LargerFontSize); // // Cancel and Ok buttons at the bottom of the page // cancelButton = FindViewById <Button>(Resource.Id.CancelButtonFb); cancelButton.SetBackgroundColor(Config.ColorBackgroundLogo.ToAndroid()); cancelButton.SetMinimumHeight(minHeight); cancelButton.SetPadding(padding, padding, padding, padding); cancelButton.SetTypeface(typeface, TypefaceStyle.Bold); cancelButton.SetTextSize(Android.Util.ComplexUnitType.Sp, Config.DefaultFontSize); cancelButton.Click += (sender, e) => { this.Finish(); App.FacebookService.OnLoginFailed(); }; thisIsMeButton = FindViewById <Button>(Resource.Id.thisIsMeButton); thisIsMeButton.SetBackgroundColor(Config.ColorRedBackground.ToAndroid()); thisIsMeButton.SetMinimumHeight(minHeight); thisIsMeButton.SetPadding(padding, padding, padding, padding); thisIsMeButton.SetTypeface(typeface, TypefaceStyle.Bold); thisIsMeButton.SetTextSize(Android.Util.ComplexUnitType.Sp, Config.DefaultFontSize); thisIsMeButton.Click += (sender, e) => { this.Finish(); App.FacebookService.OnLoginSucessful(); }; } // onCreate()
protected override void OnCreate(Bundle bundle) { //NOTE*** you have decodebitmapfromstream and decoderesource and decodebytearray //def don't need them all base.OnCreate(bundle); //problem getting view to load with fb login button //make fresh activity and try copying xml and code there. //async it's another activity we shouldnt get the bother from fb login through a dialog' FacebookSdk.SdkInitialize(this.ApplicationContext); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); mBtnSignIn = FindViewById <Button>(Resource.Id.btnSignIn); mTxtImgChoiceInfo = FindViewById <TextView>(Resource.Id.txtOr); mBtnSignup = FindViewById <Button>(Resource.Id.btnSignUp); mProgressBar = FindViewById <ProgressBar>(Resource.Id.progressBar1); mTxtBase64String = FindViewById <TextView>(Resource.Id.txtViewImgBase64); mImgUploadedPhoto = FindViewById <ImageView>(Resource.Id.imgUploadedPhoto); mTxtTestCross = FindViewById <TextView>(Resource.Id.txtImgPath); mBtnOpenGallery = FindViewById <Button>(Resource.Id.btnOpenGallery); mBtnConverttoBase = FindViewById <Button>(Resource.Id.btnConverttoBase64); mBtnConverttoImg = FindViewById <Button>(Resource.Id.btnConverttoImg); mTblImgStrings = FindViewById <TableLayout>(Resource.Id.tblBaseStrings); mBtnGetEmail = FindViewById <Button>(Resource.Id.btnGetEmail); //string[] mImgBaseStrings = new string[] { }; //List<string> mImgBaseStrings = new List<string>(); mProfileTracker = new MyProfileTracker(); mProfileTracker.mOnProfileChanged += mProfileTracker_mOnProfileChanged; mProfileTracker.StartTracking(); mProfilePic = FindViewById <ProfilePictureView>(Resource.Id.profilePicMain); mBtnFbLogin = FindViewById <LoginButton>(Resource.Id.btnFbLoginMain); mTest = FindViewById <TextView>(Resource.Id.txtTest); mBtnFbLogin.SetReadPermissions(new List <string> { "public_profile", "user_friends", "email" }); mCallBackManager = CallbackManagerFactory.Create(); mBtnFbLogin.RegisterCallback(mCallBackManager, this); mBtnGetEmail.Click += (o, e) => { System.Diagnostics.Debug.Write("welllllllllllllllll"); GraphRequest request = GraphRequest.NewMeRequest(AccessToken.CurrentAccessToken, this); Bundle parameters = new Bundle(); parameters.PutString("fields", "id,name,age_range,email"); request.Parameters = parameters; request.ExecuteAsync(); }; mBtnSignIn.Click += (object sender, EventArgs e) => { //pull up dialog //finish matching up login dialog, some of the code here is to do with signup as its copied from elsewhere FragmentTransaction transaction = FragmentManager.BeginTransaction(); dialogue_Login signInDialog = new dialogue_Login(); signInDialog.Show(transaction, "dialog fragment"); signInDialog.mOnLoginComplete += SignInDialog_mOnSignInComplete; System.Diagnostics.Debug.Write("BTN SIGNIN CLICKED"); //Went with a fully-fledged function(name on line above) as it'd be quite a bit to write inside of a lambda expression //signInDialog.mOnLoginComplete += (object theSender, OnLoginEventArgs e) => //{ //} }; mBtnSignup.Click += (object sender, EventArgs e) => { //pull up dialog //this is used to pull up the dialog from the activity FragmentTransaction transaction = FragmentManager.BeginTransaction(); dialogue_SignUp signUpDialog = new dialogue_SignUp(); signUpDialog.Show(transaction, "dialog fragment"); //signUpDialog.mOnSignUpComplete += signUpDialog_mOnSignUpComplete; signUpDialog.mOnSignUpComplete += SignUpDialog_mOnSignUpComplete; }; mBtnOpenGallery.Click += delegate { var imageIntent = new Intent(); imageIntent.SetType("image/*"); imageIntent.SetAction(Intent.ActionGetContent); StartActivityForResult( Intent.CreateChooser(imageIntent, "Select photo"), 0); }; mBtnConverttoBase.Click += MBtnConverttoBase_Click; mBtnConverttoImg.Click += MBtnConverttoImg_Click; mImgUploadedPhoto.Click += (object sender, EventArgs e) => { Bitmap bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.mail4_small); //Convert to byte array MemoryStream memStream = new MemoryStream(); bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, memStream); byte[] byteArray = memStream.ToArray(); var intent = new Intent(this, typeof(FullscreenImage)); intent.SetType("image/*"); intent.SetAction(Intent.ActionGetContent); intent.PutExtra("MyImg", byteArray); StartActivity(intent); }; }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); IMethods.IApp.FullScreenApp(this); //View view = MyContextWrapper.GetContentView(this, Settings.Lang, Resource.Layout.Login_Layout); SetContentView(Resource.Layout.Login_Layout); regularTxt = Typeface.CreateFromAsset(Assets, "fonts/SF-UI-Display-Regular.ttf"); semiboldTxt = Typeface.CreateFromAsset(Assets, "fonts/SF-UI-Display-Semibold.ttf"); //declare layouts and editext mEditTextEmail = (EditText)FindViewById(Resource.Id.editTxtEmail); mEditTextPassword = (EditText)FindViewById(Resource.Id.editTxtPassword); mTextViewSignUp = (TextView)FindViewById(Resource.Id.tvSignUp); // Register mButtonViewSignIn = (Button)FindViewById(Resource.Id.SignInButton); // Login mTextViewForgotPwd = (TextView)FindViewById(Resource.Id.tvForgotPwd); // Forget password mTextViewCreateAccount = (TextView)FindViewById(Resource.Id.tvCreateAccount); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); progressBar.Visibility = ViewStates.Gone; mButtonViewSignIn.Visibility = ViewStates.Visible; //mTextViewSignIn.SetTypeface(semiboldTxt,TypefaceStyle.Bold); mTextViewCreateAccount.SetTypeface(regularTxt, TypefaceStyle.Normal); mTextViewForgotPwd.SetTypeface(regularTxt, TypefaceStyle.Normal); mTextViewSignUp.SetTypeface(regularTxt, TypefaceStyle.Normal); mEditTextEmail.SetTypeface(regularTxt, TypefaceStyle.Normal); mEditTextPassword.SetTypeface(regularTxt, TypefaceStyle.Normal); FacebookSdk.SdkInitialize(this); mprofileTracker = new FB_MyProfileTracker(); mprofileTracker.mOnProfileChanged += MprofileTrackerOnM_OnProfileChanged; mprofileTracker.StartTracking(); BtnFBLogin = FindViewById <LoginButton>(Resource.Id.fblogin_button); BtnFBLogin.SetReadPermissions(new List <string> { "email", "public_profile" }); mFBCallManager = CallbackManagerFactory.Create(); BtnFBLogin.RegisterCallback(mFBCallManager, this); //FB accessToken var accessToken = AccessToken.CurrentAccessToken; var isLoggedIn = accessToken != null && !accessToken.IsExpired; // Configure sign-in to request the user's ID, email address, and basic profile. ID and basic profile are included in DEFAULT_SIGN_IN. var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(GoogleServices.ClientId) .RequestScopes(new Scope(Scopes.Profile)) .RequestScopes(new Scope(Scopes.PlusLogin)) .RequestServerAuthCode(GoogleServices.ClientId) .RequestProfile().RequestEmail().Build(); // Build a GoogleApiClient with access to the Google Sign-In API and the options specified by gso. mGoogleApiClient = new GoogleApiClient.Builder(this, this, this) .EnableAutoManage(this, this) .AddApi(Auth.GOOGLE_SIGN_IN_API, gso) .Build(); mGoogleSignIn = FindViewById <SignInButton>(Resource.Id.Googlelogin_button); mGoogleSignIn.Click += MGsignBtnOnClick; mGoogleSignIn.SetSize(SignInButton.SizeStandard); if (!Settings.Show_Facebook_Login) { BtnFBLogin.Visibility = ViewStates.Invisible; } if (!Settings.Show_Google_Login) { mGoogleSignIn.Visibility = ViewStates.Invisible; } IMethods.IApp.GetKeyHashesConfigured(this); } catch (Exception exception) { Crashes.TrackError(exception); } }
public FacebookAuth() { FacebookSdk.FullyInitialize(); _callbackManager = CallbackManagerFactory.Create(); }
protected override void Initialize() { base.Initialize(); if (HasValidAccessToken) { SensusServiceHelper.Get().Logger.Log("Already have valid Facebook access token. No need to initialize.", LoggingLevel.Normal, GetType()); return; } _loginWait.Reset(); string accessTokenError = null; (SensusServiceHelper.Get() as AndroidSensusServiceHelper).GetMainActivityAsync(true, mainActivity => { if (mainActivity == null) { accessTokenError = "Failed to get main activity: activity null"; _loginWait.Set(); } else { try { if (FacebookSdk.IsInitialized) { SensusServiceHelper.Get().Logger.Log("Facebook SDK is already initialized.", LoggingLevel.Normal, GetType()); } else { SensusServiceHelper.Get().Logger.Log("Initializing Facebook SDK.", LoggingLevel.Normal, GetType()); FacebookSdk.SdkInitialize(mainActivity); Thread.Sleep(5000); // give sdk intialization a few seconds to read the access token } #region register callback FacebookCallback <LoginResult> loginCallback = new FacebookCallback <LoginResult> { HandleSuccess = loginResult => { SensusServiceHelper.Get().Logger.Log("Facebook login succeeded.", SensusService.LoggingLevel.Normal, GetType()); AccessToken.CurrentAccessToken = loginResult.AccessToken; _loginWait.Set(); }, HandleCancel = () => { SensusServiceHelper.Get().Logger.Log("Facebook login cancelled.", SensusService.LoggingLevel.Normal, GetType()); AccessToken.CurrentAccessToken = null; _loginWait.Set(); }, HandleError = loginResult => { SensusServiceHelper.Get().Logger.Log("Facebook login failed.", SensusService.LoggingLevel.Normal, GetType()); AccessToken.CurrentAccessToken = null; _loginWait.Set(); }, }; LoginManager.Instance.RegisterCallback(mainActivity.FacebookCallbackManager, loginCallback); #endregion if (HasValidAccessToken) { SensusServiceHelper.Get().Logger.Log("Facebook access token read from cache.", LoggingLevel.Normal, GetType()); _loginWait.Set(); } else { LoginManager.Instance.LogInWithReadPermissions(mainActivity, GetRequiredPermissionNames()); } } catch (Exception ex) { accessTokenError = ex.Message; _loginWait.Set(); } } }); _loginWait.WaitOne(); if (accessTokenError != null) { SensusServiceHelper.Get().Logger.Log("Error while initializing Facebook SDK and/or logging in: " + accessTokenError, LoggingLevel.Normal, GetType()); } if (!HasValidAccessToken) { string message = "Failed to obtain access token."; SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType()); throw new Exception(message); } }
// List<string> listAccount = new List<string>(); // List<string> listPass = new List<string>(); protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); FacebookSdk.SdkInitialize(this.ApplicationContext); mProfileTracker = new MyProfileTracker(); mProfileTracker.mOnProfileChanged += MProfileTracker_mOnProfileChanged; mProfileTracker.StartTracking(); SetContentView(Resource.Layout.LogIn); toolbar = FindViewById <SupportToolbar>(Resource.Id.toolbarChild); toolbar.SetTitle(Resource.String.login); SetSupportActionBar(toolbar); toolbar.SetNavigationIcon(Resource.Drawable.abc_ic_ab_back_mtrl_am_alpha); ImageView createAccountButton = FindViewById <ImageView>(Resource.Id.createAccount); createAccountButton.Click += delegate { Intent createAccount = new Intent(this, typeof(CreateAccount)); StartActivity(createAccount); }; //siggnin gg mGoogleApiClient = new GoogleApiClient.Builder(this) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .AddApi(PlusClass.API) .AddScope(PlusClass.ScopePlusProfile) .AddScope(PlusClass.ScopePlusLogin).Build(); signFace = FindViewById <ImageButton>(Resource.Id.signGoogle); signFace.Click += delegate { //Fire sign in if (!mGoogleApiClient.IsConnecting) { mSignInClicked = true; ResolveSignInError(); } }; //facebook //FacebookSdk.SdkInitialize(this.ApplicationContext); //PackageInfo info = this.PackageManager.GetPackageInfo("PlaceMap.PlaceMap", PackageInfoFlags.Signatures); //foreach (Android.Content.PM.Signature signature in info.Signatures) //{ // MessageDigest md = MessageDigest.GetInstance("SHA"); // md.Update(signature.ToByteArray()); // string keyhash = Convert.ToBase64String(md.Digest()); // Console.WriteLine("KeyHash:", keyhash); //} //facebook signFB = FindViewById <ImageButton>(Resource.Id.signFacebook); mCallBackManager = CallbackManagerFactory.Create(); LoginManager.Instance.RegisterCallback(mCallBackManager, this); signFB.Click += delegate { if (AccessToken.CurrentAccessToken != null) { //The user is logged in through Facebook LoginManager.Instance.LogOut(); return; } else { //The user is not logged in LoginManager.Instance.LogInWithReadPermissions(this, new List <string> { "public_profile", "user_friends", "email" }); } }; // LoginButton button = FindViewById<LoginButton>(Resource.Id.login_button); // mBtnShared = FindViewById<ShareButton>(Resource.Id.btnShare); // mBtnGetEmail = FindViewById<Button>(Resource.Id.btnGetEmail); //button.SetReadPermissions(new List<string> { "public_profile", "user_friends", "email" }); //mCallBackManager = CallbackManagerFactory.Create(); // button.RegisterCallback(mCallBackManager, this); //mBtnGetEmail.Click += (o, e) => //{ // GraphRequest request = GraphRequest.NewMeRequest(AccessToken.CurrentAccessToken, this); // Bundle parameters = new Bundle(); // parameters.PutString("fields", "id,name,age_range,email"); // request.Parameters = parameters; // request.ExecuteAsync(); //}; // ShareLinkContent content = new ShareLinkContent.Builder().Build(); // mBtnShared.ShareContent = content; //sign in by app account = FindViewById <EditText>(Resource.Id.username); pass = FindViewById <EditText>(Resource.Id.password); login = FindViewById <Button>(Resource.Id.buttonSignin); login.Click += async delegate { List <string> listAccount = await manager.GetListAccount(); List <string> listPass = await manager.GetListPass(); if (listAccount.Contains(account.Text) && listPass.Contains(pass.Text)) { Toast.MakeText(this, "Login successful", ToastLength.Short).Show(); } else { Toast.MakeText(this, "Username or password is wrong", ToastLength.Short).Show(); } }; }