use of com.google.firebase.firestore.FirebaseFirestoreSettings in project snippets-android by firebase.
the class DocSnippets method setupCacheSize.
public void setupCacheSize() {
// [START fs_setup_cache]
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED).build();
db.setFirestoreSettings(settings);
// [END fs_setup_cache]
}
use of com.google.firebase.firestore.FirebaseFirestoreSettings in project snippets-android by firebase.
the class DocSnippets method setup.
public void setup() {
// [START get_firestore_instance]
FirebaseFirestore db = FirebaseFirestore.getInstance();
// [END get_firestore_instance]
// [START set_firestore_settings]
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(true).build();
db.setFirestoreSettings(settings);
// [END set_firestore_settings]
}
use of com.google.firebase.firestore.FirebaseFirestoreSettings in project AlphaTour by Frank99DG.
the class LoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
db = FirebaseFirestore.getInstance();
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(true).build();
db.setFirestoreSettings(settings);
auth = FirebaseAuth.getInstance();
email = findViewById(R.id.loginInputEmail);
password = findViewById(R.id.loginInputPassword);
loadingBar = findViewById(R.id.loginLoadingBar);
}
use of com.google.firebase.firestore.FirebaseFirestoreSettings in project spacecraft-android by JamesfChen.
the class FirebaseDatabaseActivity method onCreate.
// @AddTrace(name = "FirebaseDatabaseActivity_onCreateTrace", enabled = true /* optional */)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
database.setPersistenceEnabled(true);
database.setPersistenceCacheSizeBytes(50 * 1024 * 1024);
database.setLogLevel(Logger.Level.DEBUG);
DatabaseReference myRef = database.getReference();
myRef.child("user");
myRef.setValue("Hello, World!");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
Log.d("hawks", "Value is: " + value);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("hawks", "Failed to read value.", error.toException());
}
});
FirebaseFirestoreSettings build = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(true).setCacheSizeBytes(50 * 10241024).build();
databasev2.setFirestoreSettings(build);
// Create a new user with a first and last name
Map<String, Object> user = new HashMap<>();
user.put("first", "Ada");
user.put("last", "Lovelace");
user.put("born", 1815);
// Add a new document with a generated ID
databasev2.collection("users").add(user).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Log.d("hawks", "DocumentSnapshot added with ID: " + documentReference.getId());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("hawks", "Error adding document", e);
}
});
// Create a new user with a first, middle, and last name
Map<String, Object> user2 = new HashMap<>();
user.put("first", "Alan");
user.put("middle", "Mathison");
user.put("last", "Turing");
user.put("born", 1912);
// Add a new document with a generated ID
databasev2.collection("users").add(user2).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Log.d("hawks", "DocumentSnapshot added with ID: " + documentReference.getId());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("hawks", "Error adding document", e);
}
});
// Log.d("hawks", "enableNetwork : " + databasev2.enableNetwork().isSuccessful());
databasev2.collection("users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d("hawks", document.getId() + " => " + document.getData());
}
} else {
Log.w("hawks", "Error getting documents.", task.getException());
}
}
});
}
use of com.google.firebase.firestore.FirebaseFirestoreSettings in project snippets-android by firebase.
the class EmulatorSuite method emulatorSettings.
public void emulatorSettings() {
// [START fs_emulator_connect]
// 10.0.2.2 is the special IP address to connect to the 'localhost' of
// the host computer from an Android emulator.
FirebaseFirestore firestore = FirebaseFirestore.getInstance();
firestore.useEmulator("10.0.2.2", 8080);
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build();
firestore.setFirestoreSettings(settings);
// [END fs_emulator_connect]
}
Aggregations