本文整理汇总了Java中com.firebase.client.ServerValue类的典型用法代码示例。如果您正苦于以下问题:Java ServerValue类的具体用法?Java ServerValue怎么用?Java ServerValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerValue类属于com.firebase.client包,在下文中一共展示了ServerValue类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addListToFirebase
import com.firebase.client.ServerValue; //导入依赖的package包/类
/********************************************************************************************
* Function name: addListToFirebase
* Description: adds the list name to the database
* Parameters: None
* Returns: None
******************************************************************************************/
private void addListToFirebase(String listName)
{
Firebase listsRef;
if (bIsGrocery)
{
listsRef = new Firebase(Constants.FIREBASE_URL_GROCERY_LISTS);
}
else
{
listsRef = new Firebase(Constants.FIREBASE_URL_KITCHEN_INVENTORY);
}
Firebase newListRef = listsRef.push();
final String listId = newListRef.getKey();
HashMap<String, Object> timestampCreated = new HashMap<>();
timestampCreated.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
SimpleList newSimpleList = new SimpleList(listName, mEncodedEmail, timestampCreated);
newListRef.setValue(newSimpleList);
}
开发者ID:cs493f15-1,项目名称:PaperOrPlastic,代码行数:31,代码来源:PoPListActivityOld.java
示例2: addListToFirebase
import com.firebase.client.ServerValue; //导入依赖的package包/类
/********************************************************************************************
* Function name: addListToFirebase
* Description: adds the list name to the database
* Parameters: None
* Returns: None
******************************************************************************************/
private void addListToFirebase(String listName)
{
Firebase listsRef;
if (mbIsGrocery)
{
listsRef = new Firebase(Constants.FIREBASE_URL_GROCERY_LISTS);
}
else
{
listsRef = new Firebase(Constants.FIREBASE_URL_KITCHEN_INVENTORY);
}
Firebase newListRef = listsRef.push();
final String listId = newListRef.getKey();
HashMap<String, Object> timestampCreated = new HashMap<>();
timestampCreated.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
SimpleList newSimpleList = new SimpleList(listName, mEncodedEmail, timestampCreated);
newListRef.setValue(newSimpleList);
}
开发者ID:cs493f15-1,项目名称:PaperOrPlastic,代码行数:31,代码来源:PoPListActivity.java
示例3: editListNameFirebase
import com.firebase.client.ServerValue; //导入依赖的package包/类
/*************************************************************************************************
* Method:
* Description:
* Parameters: N/A
* Returned: N/A
************************************************************************************************/
public void editListNameFirebase(String newListName)
{
if (!newListName.equals(mSimpleList.getmListName()))
{
HashMap<String, Object> updatedInfo = new HashMap<>();
updatedInfo.put(Constants.FIREBASE_PROPERTY_LIST_NAME, newListName);
HashMap<String, Object> updatedTimeStamp = new HashMap<>();
updatedTimeStamp.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
updatedInfo.put(Constants.FIREBASE_PROPERTY_TIMESTAMP_LAST_CHANGED, updatedTimeStamp);
mListRef.updateChildren(updatedInfo);
}
}
开发者ID:cs493f15-1,项目名称:PaperOrPlastic,代码行数:22,代码来源:PoPListItemsActivity.java
示例4: onActivityResult
import com.firebase.client.ServerValue; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_PLACE_PICKER) {
if (resultCode == Activity.RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
Map<String, Object> checkoutData = new HashMap<>();
checkoutData.put("time", ServerValue.TIMESTAMP);
mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(checkoutData);
} else if (resultCode == PlacePicker.RESULT_ERROR) {
Toast.makeText(this, "Places API failure! Check the API is enabled for your key",
Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
开发者ID:googlesamples,项目名称:io2015-codelabs,代码行数:20,代码来源:MapsActivity.java
示例5: createBoard
import com.firebase.client.ServerValue; //导入依赖的package包/类
private void createBoard() {
// create a new board
final Firebase newBoardRef = mBoardsRef.push();
Map<String, Object> newBoardValues = new HashMap<>();
newBoardValues.put("createdAt", ServerValue.TIMESTAMP);
android.graphics.Point size = new android.graphics.Point();
getWindowManager().getDefaultDisplay().getSize(size);
newBoardValues.put("width", size.x);
newBoardValues.put("height", size.y);
newBoardRef.setValue(newBoardValues, new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase ref) {
if (firebaseError != null) {
Log.e(TAG, firebaseError.toString());
throw firebaseError.toException();
} else {
// once the board is created, start a DrawingActivity on it
openBoard(newBoardRef.getKey());
}
}
});
}
开发者ID:firebase,项目名称:AndroidDrawing,代码行数:23,代码来源:BoardListActivity.java
示例6: onActivityResult
import com.firebase.client.ServerValue; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_PLACE_PICKER) {
if (resultCode == Activity.RESULT_OK) {
Place place = PlacePicker.getPlace(this,data);
Map<String,Object>shareLocation=new HashMap<>();
shareLocation.put("time", ServerValue.TIMESTAMP);
//get data from Login Activity
Intent in=getIntent();
Bundle b=in.getExtras();
String name=b.getString("name");
Long number=b.getLong("contact_no");
Toast.makeText(this,"name: "+name+" number: "+number.toString(),Toast.LENGTH_SHORT).show();
//Map<String,Long>userData=new HashMap<>();
//userData.put(name,number);
Map userData=new HashMap();
userData.put(name,number);
mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(shareLocation);
Firebase fire=new Firebase(FIREBASE_URL);
Firebase userRef=fire.child(FIREBASE_ROOT_NODE);
Firebase people=userRef.child(place.getId());
people.updateChildren(userData);
//mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId());
//mFirebase.setValue(userData);
Toast.makeText(this,"added:"+name+" "+number,Toast.LENGTH_SHORT).show();
//Toast.makeText(this,"added location",Toast.LENGTH_SHORT).show();
} else if (resultCode == PlacePicker.RESULT_ERROR) {
Toast.makeText(this, "Places API failure! Check that the API is enabled for your key",
Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
开发者ID:agarwal-akash,项目名称:BonAppetit_Android-Project,代码行数:35,代码来源:MapsActivity.java
示例7: createUserInFirebaseHelper
import com.firebase.client.ServerValue; //导入依赖的package包/类
/**
* Creates a new user in Firebase from the Java POJO
*/
private void createUserInFirebaseHelper(final String authUid) {
final Firebase userLocation = new Firebase(Constants.FIREBASE_URL_USERS).child(authUid);
// See if there is already a user (for example, if they already logged in with an associated Google account.
userLocation.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// If there is no user, make one
LogUtils.LOGE("***> userLocation", "single value event - " + dataSnapshot.getValue());
if (dataSnapshot.getValue() == null) {
// Set raw version of date to the ServerValue.TIMESTAMP value and save into dateCreatedMap
HashMap<String, Object> timestampJoined = new HashMap<>();
timestampJoined.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
User newUser = new User(authUid, timestampJoined);
userLocation.setValue(newUser);
LogUtils.LOGE("***> add new user", authUid);
PreferencesUtils.setInt(mActivity, R.string.key_device_number, 1);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
LogUtils.LOGE(MainActivity.class.getSimpleName(), getString(R.string.log_error_occurred) + firebaseError.getMessage());
}
});
}
开发者ID:kyleparker,项目名称:io16experiment-master,代码行数:32,代码来源:MainActivity.java
示例8: SimpleList
import com.firebase.client.ServerValue; //导入依赖的package包/类
public SimpleList(String listname, String owner, HashMap<String, Object>timestampCreated)
{
this.mListName = listname;
this.mOwner = owner;
this.timestampCreated = timestampCreated;
HashMap<String, Object> timestampObject = new HashMap<>();
timestampObject.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
this.timestampLastChanged = timestampObject;
}
开发者ID:cs493f15-1,项目名称:PaperOrPlastic,代码行数:11,代码来源:SimpleList.java
示例9: createUserInFirebase
import com.firebase.client.ServerValue; //导入依赖的package包/类
/***************************************************************************************************
* Method:
* Description:
* Parameters: N/A
* Returned: N/A
***************************************************************************************************/
private void createUserInFirebase() {
final String encodedEmail = Utils.encodeEmail(mUserEmail);
final Firebase userLocation = new Firebase(Constants.FIREBASE_URL_USERS).child(encodedEmail);
/**
* See if there is already a user (for example, if they already logged in with an associated
* Google account.
*/
userLocation.addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
/* If there is no user, make one */
if (dataSnapshot.getValue() == null)
{
/* Set raw version of date to the ServerValue.TIMESTAMP value and save into dateCreatedMap */
HashMap<String, Object> timestampJoined = new HashMap<>();
timestampJoined.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
User newUser = new User(mUserName, encodedEmail, timestampJoined);
userLocation.setValue(newUser);
}
}
@Override
public void onCancelled(FirebaseError firebaseError)
{
Log.d(LOG_TAG, "Error occurred: " + firebaseError.getMessage());
}
});
}
开发者ID:cs493f15-1,项目名称:PaperOrPlastic,代码行数:38,代码来源:CreateAccountActivity.java
示例10: reset
import com.firebase.client.ServerValue; //导入依赖的package包/类
private void reset(@NotNull final Firebase taskRef, @Nullable final String ownerId, @NotNull final String inProgressState, @Nullable final Listener listener, final long retries) {
taskRef.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData task) {
if(task.getValue() == null) {
return Transaction.success(task);
}
Log.log("Resetting task " + taskRef.getKey());
@SuppressWarnings("unchecked") Map<String, Object> value = task.getValue(Map.class);
Object taskOwner = value.get(Task.OWNER_KEY);
// if the ownerId is null it means that we're force resetting this task, so we allow it to go through
boolean ownersMatch = ownerId == null || ownerId.equals(taskOwner);
if(inProgressState.equals(value.get(Task.STATE_KEY)) && ownersMatch) {
value.put(Task.STATE_KEY, taskSpec.getStartState());
value.put(Task.STATE_CHANGED_KEY, ServerValue.TIMESTAMP);
value.put(Task.OWNER_KEY, null);
value.put(Task.ERROR_DETAILS_KEY, null);
task.setValue(value);
return Transaction.success(task);
}
else {
if(listener != null) listener.onResetFailed("Couldn't reset this task because it is owned by another worker", false);
if(!ownersMatch) {
Log.log("Can't reset task " + taskRef.getKey() + " on " + ownerId + " because it is owned by " + taskOwner);
}
else {
Log.log("Can't reset task " + taskRef.getKey() + " - _state != in_progress_state");
}
return Transaction.abort();
}
}
@Override
public void onComplete(FirebaseError error, boolean committed, DataSnapshot snapshot) {
String taskKey = snapshot.getKey();
if(error != null) {
final long incrementedRetries = retries + 1;
if(incrementedRetries < Queue.MAX_TRANSACTION_RETRIES) {
Log.log("Received error while resetting task " + taskKey + "...retrying", error);
reset(taskRef, ownerId, inProgressState, listener, incrementedRetries);
}
else {
Log.log("Can't reset task " + taskKey + " - transaction errored too many times, no longer retrying", error);
if(listener != null) listener.onResetFailed("Can't reset task - transaction errored too many times, no longer retrying", true);
}
}
else {
if(committed && snapshot.exists()) {
Log.log("reset " + taskKey);
}
if(listener != null) listener.onReset();
}
}
}, false);
}
开发者ID:isapp,项目名称:firebase-queue-java,代码行数:59,代码来源:TaskReset.java
示例11: resolve
import com.firebase.client.ServerValue; //导入依赖的package包/类
private void resolve(@NotNull final Map<String, Object> newTask, @Nullable final Listener listener, final long retries) {
Log.debug("Attempting to resolve task " + taskRef.getKey() + " on " + ownerId);
if(!canActionBeTakenBeforeTransaction(ACTION_RESOLVED, listener)) {
return;
}
taskRef.runTransaction(new Transaction.Handler() {
private boolean abortedTransactionBecauseOfState;
@Override
public Transaction.Result doTransaction(MutableData task) {
if(!canActionBeTakenInTransaction(listener, ACTION_RESOLVED)) {
abortedTransactionBecauseOfState = true;
return Transaction.abort();
}
// if this task no longer exists
if(task.getValue() == null) {
Log.debug("Tried resolving task " + taskRef.getKey() + " on " + ownerId + " after someone else removed it");
return Transaction.success(task);
}
@SuppressWarnings("unchecked") Map<String, Object> value = task.getValue(Map.class);
String ourInProgressState = taskSpec.getInProgressState();
Object taskState = value.get(STATE_KEY);
Object taskOwner = value.get(OWNER_KEY);
boolean ownersMatch = ownerId.equals(taskOwner);
if((ourInProgressState == taskState || (ourInProgressState != null && ourInProgressState.equals(taskState))) && ownersMatch) {
if(taskSpec.getFinishedState() == null) {
task.setValue(null);
return Transaction.success(task);
}
newTask.put(STATE_KEY, taskSpec.getFinishedState());
newTask.put(STATE_CHANGED_KEY, ServerValue.TIMESTAMP);
newTask.put(OWNER_KEY, null);
newTask.put(ERROR_DETAILS_KEY, null);
task.setValue(newTask);
return Transaction.success(task);
}
else {
if(!ownersMatch) {
Log.debug("Tried resolving task " + taskRef.getKey() + " on " + ownerId + " but it is owned by " + taskOwner);
}
else {
Log.debug("Tried resolving task " + taskRef.getKey() + " on " + ownerId + " but its _state (" + taskState + ") did not match our _in_progress_state (" + ourInProgressState + ")");
}
return Transaction.abort();
}
}
@Override
public void onComplete(FirebaseError error, boolean committed, DataSnapshot snapshot) {
final String taskKey = snapshot.getKey();
if(abortedTransactionBecauseOfState) {
return;
}
if(error != null) {
final long incrementedRetries = retries + 1;
if(incrementedRetries < Queue.MAX_TRANSACTION_RETRIES) {
Log.debug("Received onFailure while resolving task " + taskKey + " on " + ownerId + "...retrying", error);
resolve(newTask, listener, incrementedRetries);
}
else {
Log.debug("Can't resolve task " + taskKey + " on " + ownerId + " - transaction errored too many times, no longer retrying", error);
if(listener != null) listener.onFailure("Can't resolve task - transaction errored too many times, no longer retrying", true);
}
}
else {
onTransactionSuccess(committed, taskKey, ACTION_RESOLVED, listener);
}
}
}, false);
}
开发者ID:isapp,项目名称:firebase-queue-java,代码行数:79,代码来源:Task.java
示例12: removeItem
import com.firebase.client.ServerValue; //导入依赖的package包/类
/*************************************************************************************************
* Method:
* Description:
* Parameters: N/A
* Returned: N/A
************************************************************************************************/
private void removeItem (String itemId)
{
Firebase firebaseRef = new Firebase(Constants.FIREBASE_URL);
/* Make a map for the removal */
HashMap<String, Object> updatedRemoveItemMap = new HashMap<String, Object>();
/* Remove the item by passing null */
if (bIsGrocery)
{
updatedRemoveItemMap.put("/" + Constants.FIREBASE_LOCATION_GROCERY_LIST_ITEMS + "/"
+ mListId + "/" + itemId, null);
}
else
{
updatedRemoveItemMap.put("/" + Constants.FIREBASE_LOCATION_KITCHEN_INVENTORY_ITEMS + "/"
+ mListId + "/" + itemId, null);
}
/* Make the timestamp for last changed */
HashMap<String, Object> changedTimestampMap = new HashMap<>();
changedTimestampMap.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
if (bIsGrocery)
{
/* Add the updated timestamp */
updatedRemoveItemMap.put("/" + Constants.FIREBASE_LOCATION_GROCERY_LISTS +
"/" + mListId + "/" + Constants.FIREBASE_PROPERTY_TIMESTAMP_LAST_CHANGED, changedTimestampMap);
}
else
{
/* Add the updated timestamp */
updatedRemoveItemMap.put("/" + Constants.FIREBASE_LOCATION_KITCHEN_INVENTORY +
"/" + mListId + "/" + Constants.FIREBASE_PROPERTY_TIMESTAMP_LAST_CHANGED, changedTimestampMap);
}
/* Do the update */
firebaseRef.updateChildren(updatedRemoveItemMap);
}
开发者ID:cs493f15-1,项目名称:PaperOrPlastic,代码行数:48,代码来源:SimpleListItemAdapter.java
示例13: setAuthUserGoogle
import com.firebase.client.ServerValue; //导入依赖的package包/类
/***************************************************************************************************
* Method:
* Description:
* Parameters: N/A
* Returned: N/A
***************************************************************************************************/
private void setAuthUserGoogle(AuthData authData)
{
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor spe = sp.edit();
String unprocessedEmail;
if (mGoogleApiClient.isConnected())
{
unprocessedEmail = mGoogleAccount.getEmail().toLowerCase();
spe.putString(Constants.KEY_GOOGLE_EMAIL, unprocessedEmail).apply();
}
else
{
/**
* Otherwise get email from sharedPreferences, use null as default value
* (this mean that user resumes his session)
*/
unprocessedEmail = sp.getString(Constants.KEY_GOOGLE_EMAIL, null);
}
/**
* Encode user email replacing "." with "," to be able to use it
* as a Firebase db key
*/
mEncodedEmail = Utils.encodeEmail(unprocessedEmail);
/* Get username from authData */
final String userName = (String) authData.getProviderData().get(Constants.PROVIDER_DATA_DISPLAY_NAME);
/* If no user exists, make a user */
final Firebase userLocation = new Firebase(Constants.FIREBASE_URL_USERS).child(mEncodedEmail);
userLocation.addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
/* If nothing is there ...*/
if (dataSnapshot.getValue() == null)
{
HashMap<String, Object> timestampJoined = new HashMap<>();
timestampJoined.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
User newUser = new User(userName, mEncodedEmail, timestampJoined);
userLocation.setValue(newUser);
}
}
@Override
public void onCancelled(FirebaseError firebaseError)
{
Log.d(LOG_TAG, "Error occurred: " + firebaseError.getMessage());
}
});
}
开发者ID:cs493f15-1,项目名称:PaperOrPlastic,代码行数:63,代码来源:MainSignInActivity.java
注:本文中的com.firebase.client.ServerValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论