本文整理汇总了Java中com.firebase.client.Firebase.push方法的典型用法代码示例。如果您正苦于以下问题:Java Firebase.push方法的具体用法?Java Firebase.push怎么用?Java Firebase.push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.firebase.client.Firebase
的用法示例。
在下文中一共展示了Firebase.push方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTable
import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
* Create an object Table in the database
* @param empty reference for table ("pointer") to the table object
* @return Firebase object with the reference to the newly created table
*/
public Firebase addTable(){
Firebase tableRef = root.child("Table");
ResturantTable table = new ResturantTable();
Firebase newTableRef = tableRef.push();
//System.out.println("Creating Table...");
newTableRef.setValue(table, new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError arg0, Firebase arg1) {
//System.out.println("Table created");
}
});
sleep(2);
table.setRef(newTableRef);
tableList.put(newTableRef.toString(), table);
return newTableRef;
}
示例2: touchFirebase
import com.firebase.client.Firebase; //导入方法依赖的package包/类
void touchFirebase(){
// Write trip to firebase
// String fbId;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.US);
Firebase tripsRef = new Firebase("https://dazzling-fire-3233.firebaseio.com/trips-started/"+
sdf.format(new Date(System.currentTimeMillis())));
Firebase newPushRef = tripsRef.push();
newPushRef.setValue(System.currentTimeMillis());
// fbId = newPushRef.getName();
}
示例3: saveItem
import com.firebase.client.Firebase; //导入方法依赖的package包/类
public boolean saveItem() {
//save title
if (isTitleVisible) {
if (!Utils.isEmpty(mRemindItemTitleEditText)) {
mRemindItem.setTitle(mRemindItemTitleEditText.getText().toString());
} else if (mRemindItem.getTitle() == null) {
Toast.makeText(getContext(), R.string.title_field_is_empty, Toast.LENGTH_SHORT).show();
mRemindItemTitleEditText.requestFocus();
return false;
}
} else {
if (!Utils.isEmpty(mBigTitle)) {
mRemindItem.setTitle(mBigTitle.getText().toString());
} else if (mRemindItem.getTitle() == null) {
Toast.makeText(getContext(), R.string.title_field_is_empty, Toast.LENGTH_SHORT).show();
mBigTitle.requestFocus();
return false;
}
}
String error = validateData();
if (error != null && !error.isEmpty()) {
showErrorDialog(error);
return false;
}
Firebase firebaseRef = new Firebase(Utils.getFirebaseUserReminderUrl(mUserUID));
if (mItemKey != null && !mItemKey.isEmpty()) {
// update item
if (mRemindItem.getUID() == 0) {
// TODO: 15.05.16 remove this after database upgrade
mRemindItem.setUID(mItemKey.hashCode());
}
Firebase updateItemRef = firebaseRef.child(mItemKey);
updateItemRef.setValue(mRemindItem);
} else {
// create item
Firebase newItemRef = firebaseRef.push();
mItemKey = newItemRef.getKey();
mRemindItem.setUID(mItemKey.hashCode());
newItemRef.setValue(mRemindItem);
}
if (mRemindItem.isActive() && !mRemindItem.isCompleted()) {
Utils.enableAlarmGeofence(getActivity().getApplicationContext(), mRemindItem, mItemKey);
} else {
Utils.disableAlarmGeofence(getActivity().getApplicationContext(), mRemindItem);
}
return true;
}
示例4: setupFirebase
import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
* Setup Firebase for the user and connected devices
*
* Update the existing user data with the number of devices selected on the previous screen
* Add the devices based on the selection
* Generate the message for the next device
*/
private void setupFirebase() {
// Update Firebase to include the total number of devices
if (!TextUtils.isEmpty(mFirebaseUid)) {
Map<String, Object> profile = new HashMap<>();
profile.put(Constants.FIREBASE_PROPERTY_NUMBER_DEVICES, mTotalDevices);
Firebase userRef = new Firebase(Constants.FIREBASE_URL_USERS).child(mFirebaseUid);
userRef.updateChildren(profile);
LogUtils.LOGE("***> setupFirebase", "update firebase uid:" + mFirebaseUid);
// Add device ids to Firebase
for (int i = 0; i < PreferencesUtils.getInt(mActivity, R.string.key_total_devices, 1); i++) {
// If the challengeCode is empty, then push a new value to the database
Firebase deviceRef = new Firebase(Constants.FIREBASE_URL_DEVICES).child(mFirebaseUid);
final Firebase newDeviceRef = deviceRef.push();
mDeviceIds[i] = newDeviceRef.getKey();
final int currentDeviceNumber = i + 1;
LogUtils.LOGE("***> new device #" + currentDeviceNumber, mDeviceIds[i]);
Device device = new Device(mDeviceIds[i], i + 1, mDeviceNum == currentDeviceNumber);
newDeviceRef.setValue(device);
newDeviceRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Device d = dataSnapshot.getValue(Device.class);
if (d != null) {
LogUtils.LOGE("***> child updated", "id: " + d.getDeviceId());
LogUtils.LOGE("***> child updated", "number: " + d.getDeviceNumber());
LogUtils.LOGE("***> child updated", "connected: " + d.isConnected());
LogUtils.LOGE("***> child updated", "next: " + currentDeviceNumber);
// Hide the button and show the message for the first device
if (d.isConnected() && d.getDeviceNumber() > 1) {
PreferencesUtils.setBoolean(mActivity, R.string.key_message_received, true);
LogUtils.LOGE("***> child updated", "unpublished: " + currentDeviceNumber);
unpublish();
mDiscover.setVisibility(View.GONE);
mIntroConnectDevice.setText(mActivity.getString(R.string.text_message_received));
}
} else {
if (!PreferencesUtils.getBoolean(mActivity, R.string.key_device_reset_done, false)) {
LogUtils.LOGE("***> setupFirebase", "reset device");
MainActivity.resetDevice();
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
// Create the message for the next device
if (i == mDeviceNum) {
LogUtils.LOGE("***> device", "message created");
String message = mActivity.getString(R.string.message_body, mFirebaseUid, mDeviceNum + 1,
mTotalDevices, newDeviceRef.getKey());
mDeviceInfoMessage = DeviceMessage.newNearbyMessage(
InstanceID.getInstance(mActivity.getApplicationContext()).getId(), message);
}
}
}
}
示例5: onClick
import com.firebase.client.Firebase; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.enter:
userName = username.getText().toString();
useremail = email.getText().toString();
Firebase ref = new Firebase("https://crombox-bd22b.firebaseio.com/");
Firebase fb_to_read = ref.child("users");
Firebase fb_put_child = fb_to_read.push(); // REMEMBER THIS FOR PUSH METHOD
// Creating Person object
Person person = new Person();
//Adding values
person.setName(userName);
person.setemail(useremail);
//Storing values to firebase
// ref.setValue(person);
fb_put_child.setValue(person);
Toast.makeText(getBaseContext(), "Welcome" + username, Toast.LENGTH_LONG).show();
Intent i=new Intent(First.this,MainActivity.class);
startActivity(i);
}
}