本文整理汇总了Java中com.firebase.client.Firebase.getKey方法的典型用法代码示例。如果您正苦于以下问题:Java Firebase.getKey方法的具体用法?Java Firebase.getKey怎么用?Java Firebase.getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.firebase.client.Firebase
的用法示例。
在下文中一共展示了Firebase.getKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUserInfoPassword
import com.firebase.client.Firebase; //导入方法依赖的package包/类
public String addUserInfoPassword() {
//TODO: (Optional) Update for any new fields added to DbUserInfo class
// set user id
String uid = mRef.getAuth().getUid();
// create record
String profileImageUrl = "Not provided by authData";
String provider = mRef.getAuth().getProvider();
EditText nameView = (EditText) mView.findViewById(R.id.register_name);
String displayName = nameView.getText().toString();
if(mRef.getAuth().getProviderData().containsKey("profileImageURL")) profileImageUrl = mRef.getAuth().getProviderData().get("profileImageURL").toString();
// define users
DbUserInfo newUserInfo = new DbUserInfo(provider, email, profileImageUrl, displayName);
Firebase pushUser = mRef.child("userInfo/users").push();
pushUser.setValue(newUserInfo);
// define userMap
LoginActivity.populateUserMap(mRef, uid, pushUser.getKey());
return pushUser.getKey();
}
示例2: addUserInfo
import com.firebase.client.Firebase; //导入方法依赖的package包/类
public String addUserInfo(AuthData authData) {
//TODO: (Optional) Update for any new fields added to DbUserInfo class
// set user id
String uid = authData.getUid();
// create record
String provider = authData.getProvider();
String email = getResources().getString(R.string.missing_user_data);
String profileImageUrl = getResources().getString(R.string.missing_user_data);
String displayName = getResources().getString(R.string.missing_user_data);
if(authData.getProviderData().containsKey("email")) email = authData.getProviderData().get("email").toString();
if(authData.getProviderData().containsKey("profileImageURL")) profileImageUrl = authData.getProviderData().get("profileImageURL").toString();
if(authData.getProviderData().containsKey("displayName")) displayName = authData.getProviderData().get("displayName").toString();
// define users
DbUserInfo newUserInfo = new DbUserInfo(provider, email, profileImageUrl, displayName);
Firebase pushUser = mRef.child("userInfo/users").push();
pushUser.setValue(newUserInfo);
// define userMap
populateUserMap(mRef, uid, pushUser.getKey());
return pushUser.getKey();
}
示例3: saveChanges
import com.firebase.client.Firebase; //导入方法依赖的package包/类
private void saveChanges() {
//save title
if (isTitleVisible) {
if (!Utils.isEmpty(mEdtDiaryNoteTitle)) {
mDiaryNote.setTitle(mEdtDiaryNoteTitle.getText().toString());
} else {
Toast.makeText(getContext(), R.string.title_field_is_empty, Toast.LENGTH_SHORT).show();
mEdtDiaryNoteTitle.requestFocus();
return;
}
} else {
if (!Utils.isEmpty(mBigTitle)) {
mDiaryNote.setTitle(mBigTitle.getText().toString());
} else {
Toast.makeText(getContext(), R.string.title_field_is_empty, Toast.LENGTH_SHORT).show();
mBigTitle.requestFocus();
return;
}
}
//save text
mDiaryNote.setText(mRtEditText.getText(RTFormat.HTML));
//save images
mDiaryNote.setPhotos(mImages);
if (mKey != null) {
mItemRef.setValue(mDiaryNote);
} else {
Firebase newTravelRef = mItemRef.push();
newTravelRef.setValue(mDiaryNote);
mKey = newTravelRef.getKey();
addDataChangeListener();
}
if (!mImages.isEmpty()) {
Intent uploadIntent = new Intent(getContext(), UploadPhotoService.class);
uploadIntent.putExtra(UploadPhotoService.EXTRA_REF, mItemRef.toString());
uploadIntent.putExtra(UploadPhotoService.EXTRA_IMAGES, mImages);
getActivity().startService(uploadIntent);
}
mRtEditText.resetHasChanged();
enableReviewingMode();
if (showSavedToast) {
Toast.makeText(getContext(), R.string.saved, Toast.LENGTH_SHORT).show();
}
}
示例4: 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;
}
示例5: 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);
}
}
}
}