└── FirebaseReadData ├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tabian │ │ └── firebasereaddata │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tabian │ │ │ └── firebasereaddata │ │ │ ├── MainActivity.java │ │ │ ├── UserInformation.java │ │ │ └── ViewDatabase.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── view_database_layout.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tabian │ └── firebasereaddata │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /FirebaseReadData/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /FirebaseReadData/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /FirebaseReadData/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /FirebaseReadData/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /FirebaseReadData/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /FirebaseReadData/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FirebaseReadData/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /FirebaseReadData/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /FirebaseReadData/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.1" 6 | defaultConfig { 7 | applicationId "com.tabian.firebasereaddata" 8 | minSdkVersion 18 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:24.2.1' 28 | compile 'com.google.firebase:firebase-auth:10.0.1' 29 | compile 'com.google.firebase:firebase-database:10.0.1' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | apply plugin: 'com.google.gms.google-services' 33 | -------------------------------------------------------------------------------- /FirebaseReadData/app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "800691418019", 4 | "firebase_url": "https://fir-readdata-d6ba5.firebaseio.com", 5 | "project_id": "fir-readdata-d6ba5", 6 | "storage_bucket": "fir-readdata-d6ba5.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:800691418019:android:b7d7c1930bdd44e7", 12 | "android_client_info": { 13 | "package_name": "com.tabian.firebasereaddata" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "800691418019-nvs67vm7nh8pr8tqubvam2kp4ne7f75b.apps.googleusercontent.com", 19 | "client_type": 3 20 | } 21 | ], 22 | "api_key": [ 23 | { 24 | "current_key": "AIzaSyDV5lJxIC7MHPK3K96SaVdXrCWcAVpH4-Y" 25 | } 26 | ], 27 | "services": { 28 | "analytics_service": { 29 | "status": 1 30 | }, 31 | "appinvite_service": { 32 | "status": 2, 33 | "other_platform_oauth_client": [ 34 | { 35 | "client_id": "800691418019-nvs67vm7nh8pr8tqubvam2kp4ne7f75b.apps.googleusercontent.com", 36 | "client_type": 3 37 | } 38 | ] 39 | }, 40 | "ads_service": { 41 | "status": 2 42 | } 43 | } 44 | } 45 | ], 46 | "configuration_version": "1" 47 | } -------------------------------------------------------------------------------- /FirebaseReadData/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\User\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /FirebaseReadData/app/src/androidTest/java/com/tabian/firebasereaddata/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tabian.firebasereaddata; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.tabian.firebasereaddata", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /FirebaseReadData/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /FirebaseReadData/app/src/main/java/com/tabian/firebasereaddata/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tabian.firebasereaddata; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.EditText; 11 | import android.widget.Toast; 12 | 13 | import com.google.firebase.auth.FirebaseAuth; 14 | import com.google.firebase.auth.FirebaseUser; 15 | 16 | public class MainActivity extends AppCompatActivity { 17 | private static final String TAG = "MainActivity"; 18 | 19 | private FirebaseAuth mAuth; 20 | private FirebaseAuth.AuthStateListener mAuthListener; 21 | 22 | // UI references. 23 | private EditText mEmail, mPassword; 24 | private Button btnSignIn,btnSignOut,btnViewDatabase; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | //declare buttons and edit texts in oncreate 31 | mEmail = (EditText) findViewById(R.id.email); 32 | mPassword = (EditText) findViewById(R.id.password); 33 | btnSignIn = (Button) findViewById(R.id.email_sign_in_button); 34 | btnSignOut = (Button) findViewById(R.id.email_sign_out_button); 35 | btnViewDatabase = (Button) findViewById(R.id.view_items_screen); 36 | 37 | 38 | mAuth = FirebaseAuth.getInstance(); 39 | 40 | mAuthListener = new FirebaseAuth.AuthStateListener() { 41 | @Override 42 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 43 | FirebaseUser user = firebaseAuth.getCurrentUser(); 44 | if (user != null) { 45 | // User is signed in 46 | Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); 47 | toastMessage("Successfully signed in with: " + user.getEmail()); 48 | } else { 49 | // User is signed out 50 | Log.d(TAG, "onAuthStateChanged:signed_out"); 51 | toastMessage("Successfully signed out."); 52 | } 53 | // ... 54 | } 55 | }; 56 | 57 | btnSignIn.setOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View view) { 60 | String email = mEmail.getText().toString(); 61 | String pass = mPassword.getText().toString(); 62 | if(!email.equals("") && !pass.equals("")){ 63 | mAuth.signInWithEmailAndPassword(email,pass); 64 | }else{ 65 | toastMessage("You didn't fill in all the fields."); 66 | } 67 | } 68 | }); 69 | 70 | btnSignOut.setOnClickListener(new View.OnClickListener() { 71 | @Override 72 | public void onClick(View view) { 73 | mAuth.signOut(); 74 | toastMessage("Signing Out..."); 75 | } 76 | }); 77 | 78 | btnViewDatabase.setOnClickListener(new View.OnClickListener() { 79 | @Override 80 | public void onClick(View view) { 81 | Intent intent = new Intent(MainActivity.this, ViewDatabase.class); 82 | startActivity(intent); 83 | } 84 | }); 85 | 86 | 87 | } 88 | 89 | @Override 90 | public void onStart() { 91 | super.onStart(); 92 | mAuth.addAuthStateListener(mAuthListener); 93 | } 94 | 95 | @Override 96 | public void onStop() { 97 | super.onStop(); 98 | if (mAuthListener != null) { 99 | mAuth.removeAuthStateListener(mAuthListener); 100 | } 101 | } 102 | 103 | 104 | /** 105 | * customizable toast 106 | * @param message 107 | */ 108 | private void toastMessage(String message){ 109 | Toast.makeText(this,message,Toast.LENGTH_SHORT).show(); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /FirebaseReadData/app/src/main/java/com/tabian/firebasereaddata/UserInformation.java: -------------------------------------------------------------------------------- 1 | package com.tabian.firebasereaddata; 2 | 3 | /** 4 | * Created by User on 2/8/2017. 5 | */ 6 | 7 | public class UserInformation { 8 | 9 | private String name; 10 | private String email; 11 | private String phone_num; 12 | 13 | public UserInformation(){ 14 | 15 | } 16 | 17 | public String getEmail() { 18 | return email; 19 | } 20 | 21 | public void setEmail(String email) { 22 | this.email = email; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public String getPhone_num() { 34 | return phone_num; 35 | } 36 | 37 | public void setPhone_num(String phone_num) { 38 | this.phone_num = phone_num; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /FirebaseReadData/app/src/main/java/com/tabian/firebasereaddata/ViewDatabase.java: -------------------------------------------------------------------------------- 1 | package com.tabian.firebasereaddata; 2 | 3 | import android.os.Bundle; 4 | import android.provider.ContactsContract; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.util.Log; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.ListView; 11 | import android.widget.Toast; 12 | 13 | import com.google.firebase.auth.FirebaseAuth; 14 | import com.google.firebase.auth.FirebaseUser; 15 | import com.google.firebase.database.DataSnapshot; 16 | import com.google.firebase.database.DatabaseError; 17 | import com.google.firebase.database.DatabaseReference; 18 | import com.google.firebase.database.FirebaseDatabase; 19 | import com.google.firebase.database.ValueEventListener; 20 | 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * Created by User on 2/8/2017. 25 | */ 26 | 27 | public class ViewDatabase extends AppCompatActivity { 28 | private static final String TAG = "ViewDatabase"; 29 | 30 | //add Firebase Database stuff 31 | private FirebaseDatabase mFirebaseDatabase; 32 | private FirebaseAuth mAuth; 33 | private FirebaseAuth.AuthStateListener mAuthListener; 34 | private DatabaseReference myRef; 35 | private String userID; 36 | 37 | private ListView mListView; 38 | 39 | @Override 40 | protected void onCreate(@Nullable Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | setContentView(R.layout.view_database_layout); 43 | 44 | mListView = (ListView) findViewById(R.id.listview); 45 | 46 | //declare the database reference object. This is what we use to access the database. 47 | //NOTE: Unless you are signed in, this will not be useable. 48 | mAuth = FirebaseAuth.getInstance(); 49 | mFirebaseDatabase = FirebaseDatabase.getInstance(); 50 | myRef = mFirebaseDatabase.getReference(); 51 | FirebaseUser user = mAuth.getCurrentUser(); 52 | userID = user.getUid(); 53 | 54 | mAuthListener = new FirebaseAuth.AuthStateListener() { 55 | @Override 56 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 57 | FirebaseUser user = firebaseAuth.getCurrentUser(); 58 | if (user != null) { 59 | // User is signed in 60 | Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); 61 | toastMessage("Successfully signed in with: " + user.getEmail()); 62 | } else { 63 | // User is signed out 64 | Log.d(TAG, "onAuthStateChanged:signed_out"); 65 | toastMessage("Successfully signed out."); 66 | } 67 | // ... 68 | } 69 | }; 70 | 71 | myRef.addValueEventListener(new ValueEventListener() { 72 | @Override 73 | public void onDataChange(DataSnapshot dataSnapshot) { 74 | // This method is called once with the initial value and again 75 | // whenever data at this location is updated. 76 | showData(dataSnapshot); 77 | } 78 | 79 | @Override 80 | public void onCancelled(DatabaseError databaseError) { 81 | 82 | } 83 | }); 84 | 85 | } 86 | 87 | private void showData(DataSnapshot dataSnapshot) { 88 | for(DataSnapshot ds : dataSnapshot.getChildren()){ 89 | UserInformation uInfo = new UserInformation(); 90 | uInfo.setName(ds.child(userID).getValue(UserInformation.class).getName()); //set the name 91 | uInfo.setEmail(ds.child(userID).getValue(UserInformation.class).getEmail()); //set the email 92 | uInfo.setPhone_num(ds.child(userID).getValue(UserInformation.class).getPhone_num()); //set the phone_num 93 | 94 | //display all the information 95 | Log.d(TAG, "showData: name: " + uInfo.getName()); 96 | Log.d(TAG, "showData: email: " + uInfo.getEmail()); 97 | Log.d(TAG, "showData: phone_num: " + uInfo.getPhone_num()); 98 | 99 | ArrayList array = new ArrayList<>(); 100 | array.add(uInfo.getName()); 101 | array.add(uInfo.getEmail()); 102 | array.add(uInfo.getPhone_num()); 103 | ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,array); 104 | mListView.setAdapter(adapter); 105 | } 106 | } 107 | 108 | @Override 109 | public void onStart() { 110 | super.onStart(); 111 | mAuth.addAuthStateListener(mAuthListener); 112 | } 113 | 114 | @Override 115 | public void onStop() { 116 | super.onStop(); 117 | if (mAuthListener != null) { 118 | mAuth.removeAuthStateListener(mAuthListener); 119 | } 120 | } 121 | 122 | 123 | /** 124 | * customizable toast 125 | * @param message 126 | */ 127 | private void toastMessage(String message){ 128 | Toast.makeText(this,message,Toast.LENGTH_SHORT).show(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /FirebaseReadData/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 14 | 15 | 20 | 21 | 22 | 23 | 30 | 31 | 32 | 33 | 43 | 44 |