本文整理匯總了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);
}
}