Skip to content
Snippets Groups Projects
Commit d9fde98c authored by Andrej Rasevic's avatar Andrej Rasevic
Browse files

initial version of firebase demo app

parent a332c87e
No related branches found
No related tags found
No related merge requests found
Showing
with 364 additions and 0 deletions
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
/build
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.andrejrasevic.firebasedemo"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-database:9.0.2'
}
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
{
"project_info": {
"project_number": "77138995653",
"firebase_url": "https://fir-demo-d5acb.firebaseio.com",
"project_id": "fir-demo-d5acb",
"storage_bucket": "fir-demo-d5acb.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:77138995653:android:3bbf6679b995f089",
"android_client_info": {
"package_name": "com.example.andrejrasevic.firebasedemo"
}
},
"oauth_client": [
{
"client_id": "77138995653-bmqmnhtg7v4541nqomd5naaerpb3b09s.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.andrejrasevic.firebasedemo",
"certificate_hash": "aa7678e284ae6dfe2dff484bc15e39584babf847"
}
},
{
"client_id": "77138995653-sd30rjcl79cre19f6rsd4lhr8pvkue4c.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCOy_SFjTswVh7DrmL54LJHUOLdmB2y_Ys"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 2,
"other_platform_oauth_client": [
{
"client_id": "77138995653-sd30rjcl79cre19f6rsd4lhr8pvkue4c.apps.googleusercontent.com",
"client_type": 3
}
]
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/andrej.rasevic/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.example.andrejrasevic.firebasedemo;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.example.andrejrasevic.firebasedemo", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.andrejrasevic.firebasedemo">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.example.andrejrasevic.firebasedemo;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get ListView object from xml
final ListView listView = (ListView) findViewById(R.id.listView);
// Create a new Adapter
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, android.R.id.text1);
// Assign adapter to ListView
listView.setAdapter(adapter);
// Connect to the Firebase database
FirebaseDatabase database = FirebaseDatabase.getInstance();
// Get a reference to the todoItems child items it the database
final DatabaseReference myRef = database.getReference("todoItems");
// Assign a listener to detect changes to the child items
// of the database reference.
myRef.addChildEventListener(new ChildEventListener(){
// This function is called once for each child that exists
// when the listener is added. Then it is called
// each time a new child is added.
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
String value = dataSnapshot.getValue(String.class);
adapter.add(value);
}
// This function is called each time a child item is removed.
public void onChildRemoved(DataSnapshot dataSnapshot){
String value = dataSnapshot.getValue(String.class);
adapter.remove(value);
}
// The following functions are also required in ChildEventListener implementations.
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName){}
public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName){}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("TAG:", "Failed to read value.", error.toException());
}
});
// Add items via the Button and EditText at the bottom of the window.
final EditText text = (EditText) findViewById(R.id.todoText);
final Button button = (Button) findViewById(R.id.addButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Create a new child with a auto-generated ID.
DatabaseReference childRef = myRef.push();
// Set the child's data to the value passed in from the text box.
childRef.setValue(text.getText().toString());
}
});
// Delete items when clicked
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Query myQuery = myRef.orderByValue().equalTo((String)
listView.getItemAtPosition(position));
myQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChildren()) {
DataSnapshot firstChild = dataSnapshot.getChildren().iterator().next();
firstChild.getRef().removeValue();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
})
;}
})
;}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:orientation="vertical">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
<EditText
android:id="@+id/todoText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/addButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add New Item"/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.andrejrasevic.firebasedemo.MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.andrejrasevic.firebasedemo.MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
LectureExamples/FirebaseDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png

3.34 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png

4.11 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png

2.15 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png

2.5 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png

4.73 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png

5.97 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png

7.54 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png

9.82 KiB

LectureExamples/FirebaseDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

10.2 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment