@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Firebase.setAndroidContext(this); this.mFirebaseRef = new Firebase("https://crackling-torch-7607.firebaseIO.com"); this.mMessageEdit = (EditText) this.findViewById(R.id.message_text); this.mListAdapter = new FirebaseListAdapter<ChatMessage>( mFirebaseRef, ChatMessage.class, R.layout.message_layout, this) { @Override protected void populateView(View v, ChatMessage model) { ((TextView) v.findViewById(R.id.username_text_view)).setText(model.getName()); ((TextView) v.findViewById(R.id.message_text_view)).setText(model.getMessage()); } }; setListAdapter(mListAdapter); mFirebaseRef.addAuthStateListener( new Firebase.AuthStateListener() { @Override public void onAuthStateChanged(AuthData authData) { if (authData != null) { mUsername = ((String) authData.getProviderData().get("email")); findViewById(R.id.login).setVisibility(View.INVISIBLE); } else { mUsername = null; findViewById(R.id.login).setVisibility(View.VISIBLE); } } }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_my_task, container, false); url = new Firebase(linkFirst); url.addAuthStateListener( new Firebase.AuthStateListener() { @Override public void onAuthStateChanged(AuthData authData) { if (authData != null) { // userId = authData.getUid(); Log.d("Data Authentication->", "User Id is " + authData.getUid()); userId = authData.getUid(); url = new Firebase(linkFirst + "/" + userId + "/usertask"); Log.d("New URL is->", "Url is " + url.getPath().toString()); addValues(); } // else { // new MainActivity().logout(); // } } }); taskList = (ListView) view.findViewById(R.id.listOfTaskToDo); companyName = (TextView) view.findViewById(R.id.companyName); addTaskButton = (ImageView) view.findViewById(R.id.addImageButton); adapter = new TaskAdaptorIn(dbTaskTemp, getActivity().getApplicationContext()); taskList.setAdapter(adapter); addNewTaskMethod(); return view; }
/** * *********************************************************************************************** * Method: Description: Parameters: N/A Returned: N/A * ********************************************************************************************** */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Setting up the Google API object to allow Google logins */ GoogleSignInOptions GSO = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build(); /** * Building our GoogleApiClient so that is has access to the Google Sign-In API and the options * specified by the GoogleSignInOptions GSO from above */ mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /*Fragment Activity*/, this /* OnConnectionFailedListener*/) .addApi(Auth.GOOGLE_SIGN_IN_API, GSO) .build(); /** Getting mProvider and mEncodedEmail from SharedPreferences */ final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(BaseActivity.this); /* Get mEncodedEmail and mProvider from SharedPreferences, use null as default value */ mEncodedEmail = sp.getString(Constants.KEY_ENCODED_EMAIL, null); mProvider = sp.getString(Constants.KEY_PROVIDER, null); if (null == mEncodedEmail) { bUsingOffline = true; } else { bUsingOffline = false; } if (!((this instanceof MainSignInActivity) || (this instanceof CreateAccountActivity) || (this instanceof PasswordRecoveryActivity) || bUsingOffline)) { mFirebaseRef = new Firebase(Constants.FIREBASE_URL); mAuthListener = new Firebase.AuthStateListener() { @Override public void onAuthStateChanged(AuthData authData) { /* The user has been logged out */ if (authData == null) { /* Clear out shared preferences */ SharedPreferences.Editor spe = sp.edit(); spe.putString(Constants.KEY_ENCODED_EMAIL, null); spe.putString(Constants.KEY_PROVIDER, null); spe.commit(); takeUserToSignInScreenOnUnAuth(); } } }; mFirebaseRef.addAuthStateListener(mAuthListener); } invalidateOptionsMenu(); }
public boolean isLoggedIn() { final boolean[] state = {false}; ref.addAuthStateListener( new Firebase.AuthStateListener() { @Override public void onAuthStateChanged(AuthData authData) { if (authData != null) { // user logged on state[0] = true; } else { // user is not logged in state[0] = false; } } }); return state[0]; }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); ref.setAndroidContext(this); ref = DataStorage.getRef(); final Thread timerThread = new Thread() { public void run() { try { sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } finally { } } }; ref.addAuthStateListener( new Firebase.AuthStateListener() { public void onAuthStateChanged(AuthData authData) { if (authData != null) { DataStorage.setUID(authData.getUid()); final Intent i = new Intent(getApplicationContext(), MainActivity.class); ref.child("users") .child(DataStorage.getUID()) .addValueEventListener( new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Map<String, Object> newUser = (Map<String, Object>) dataSnapshot.getValue(); Log.d("E-Test", newUser.toString()); DataStorage.setEmail(newUser.get("email").toString()); DataStorage.setFullName(newUser.get("full_name").toString()); } @Override public void onCancelled(FirebaseError firebaseError) {} }); Timer t = new Timer(); TimerTask tt = new TimerTask() { @Override public void run() { startActivity(i); } }; t.schedule(tt, 2000); } else { final Intent i = new Intent(getApplicationContext(), Login.class); Timer t = new Timer(); TimerTask tt = new TimerTask() { @Override public void run() { startActivity(i); } }; t.schedule(tt, 2000); } } }); timerThread.start(); }