本文整理汇总了Java中com.firebase.client.Firebase类的典型用法代码示例。如果您正苦于以下问题:Java Firebase类的具体用法?Java Firebase怎么用?Java Firebase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Firebase类属于com.firebase.client包,在下文中一共展示了Firebase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addValuesFireBase
import com.firebase.client.Firebase; //导入依赖的package包/类
public void addValuesFireBase(String temperature, String humidade, double latitude, double longitude, String currentDateandTime, String district){
mRef = new Firebase("https://livingcityapp.firebaseio.com");
Firebase usersRef = mRef.child(currentDateandTime);
SimpleDateFormat hora = new SimpleDateFormat("HH:mm:ss");
String currenthora = hora.format(new Date());
Map<String, String> map = new HashMap<>();
map.put("Temperature",temperature);
map.put("Humidade", humidade);
map.put("Hora",currenthora);
map.put("Latitude", Double.toString(latitude));
map.put("Longitude", Double.toString(longitude));
map.put("Distrito", district);
Map<String, Object> mapaCompleto = new HashMap<>();
mapaCompleto.put(currenthora, map);
usersRef.updateChildren(mapaCompleto);
}
示例2: onCreateView
import com.firebase.client.Firebase; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_recycler_view, container ,false);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
// mShimmerView = (ListShimmerView) view.findViewById(R.id.shimmer_view);
mProgressBar = (ProgressBar) view.findViewById(R.id.progress_bar);
// mShimmerView.setVisibility(View.VISIBLE);
final GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 1);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.addItemDecoration(new GridSpacingItemDecoration(1, 20, true));
mBlogList = new ArrayList<>();
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
mFirebaseRef = new Firebase(mUrl); /* connect to firebase*/
return view;
}
示例3: Database_Class_Functions
import com.firebase.client.Firebase; //导入依赖的package包/类
/*****************************************************\\
*
* Database_Class Constructor( On Private Mode )
*/
//******************************************************/
private Database_Class_Functions(Context context) {
Firebase.setAndroidContext(context);
mStocks = new Firebase("https://farmers-helper-44f7a.firebaseio.com/Stocks");
mProducts=new Firebase("https://farmers-helper-44f7a.firebaseio.com/Products/Weeds");
mProductsForFarmingShortList=new Firebase("https://farmers-helper-44f7a.firebaseio.com/Products/Farming/");
mCompany= new Firebase("https://farmers-helper-44f7a.firebaseio.com/Company");
mChat= new Firebase("https://farmers-helper-44f7a.firebaseio.com/Chat");
mDistributer= new Firebase("https://farmers-helper-44f7a.firebaseio.com/Distributers");
mCompanyObject = new Company();
mDistributerObject = new Distributer();
mDistributerList = new ArrayList<>();
MessageMaxCounter1=0;
mDistributerObject = new Distributer();
}
示例4: onCreate
import com.firebase.client.Firebase; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//preparing GoogleApiClient
mGoogleApiClient=new GoogleApiClient.Builder(this)
.addApi(Places.GEO_DATA_API)
.build();
mGoogleApiClient.connect();
//Yes! finally Firebase :P
Firebase.setAndroidContext(this);
mFirebase=new Firebase(FIREBASE_URL);
mFirebase.child(FIREBASE_ROOT_NODE).addChildEventListener(this);
}
示例5: sendRegistrationToServer
import com.firebase.client.Firebase; //导入依赖的package包/类
/**
* Persist registration to third-party servers.
* <p/>
* Modify this method to associate the user's GCM registration token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(final String token) {
final Account primaryAccount = Sessions.getPrimaryPhoneAccount(AccountManager.get(getApplicationContext()));
if (primaryAccount != null) {
final Firebase firebase = new Firebase(Constants.FIREBASE_USER_URL + Hasher.hash(primaryAccount.name));
final Firebase devices = firebase.child("devices");
devices.addListenerForSingleValueEvent(new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (!snapshot.exists()) {
devices.setValue(Arrays.asList(token));
} else {
List<String> firebaseDevices = (List<String>) snapshot.getValue();
if (!firebaseDevices.contains(token)) {
firebaseDevices.add(token);
devices.setValue(firebaseDevices);
}
}
}
});
}
}
示例6: 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();
}
示例7: authenticate
import com.firebase.client.Firebase; //导入依赖的package包/类
/**
* @param appData {@link AppData} object which contains the token to authenticate with.
* @param reAuth True if this is a re-authentication attempt.
* @return An {@link AuthData} object.
*/
public Task<AppData> authenticate(AppData appData, boolean reAuth) {
Task<AppData>.TaskCompletionSource taskSource = Task.<AppData>create();
firebaseRef.authWithCustomToken(appData.getFirebaseConfig().getToken(), new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
if (reAuth) {
userManager.setLoggedIn(appData.getUser().getUsername());
}
taskSource.setResult(appData);
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
taskSource.setError(firebaseError.toException());
}
});
return taskSource.getTask();
}
示例8: getPresenceImpl
import com.firebase.client.Firebase; //导入依赖的package包/类
private Task<PresenceType> getPresenceImpl(User user) {
Task<PresenceType>.TaskCompletionSource taskSource = Task.<PresenceType>create();
Firebase presenceRef = firebaseRef.child(user.getPresencePath());
presenceRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String status = dataSnapshot.getValue(String.class);
taskSource.setResult(PresenceType.parse(status));
}
@Override
public void onCancelled(FirebaseError firebaseError) {
taskSource.setError(firebaseError.toException());
}
});
return taskSource.getTask();
}
示例9: setPresenceImpl
import com.firebase.client.Firebase; //导入依赖的package包/类
private Task<Void> setPresenceImpl(User user, PresenceType newPresenceType) {
Task<Void>.TaskCompletionSource taskSource = Task.<Void>create();
Firebase presenceRef = firebaseRef.child(user.getPresencePath());
String value = newPresenceType.name().toLowerCase();
presenceRef.setValue(value, (firebaseError, firebase) -> {
if (firebaseError != null) {
taskSource.setError(firebaseError.toException());
} else {
taskSource.setResult(null);
}
});
return taskSource.getTask();
}
示例10: markReadImpl
import com.firebase.client.Firebase; //导入依赖的package包/类
private Task<Void> markReadImpl(Chatroom chatroom, Message message) {
Task<Void>.TaskCompletionSource taskSource = Task.<Void>create();
long value = new Date().getTime();
Firebase messageRef = firebaseRef.child(chatroom.getFirebasePath())
.child(message.getKey())
.child("read_at");
messageRef.setValue(value, (firebaseError, firebase) -> {
if (firebaseError != null) {
taskSource.setError(firebaseError.toException());
} else {
taskSource.setResult(null);
}
});
return taskSource.getTask();
}
示例11: notifyLoginToGCM
import com.firebase.client.Firebase; //导入依赖的package包/类
void notifyLoginToGCM(final int type, final String name, final String password, final String authtoken) {
final Account primaryAccount = Sessions.getPrimaryPhoneAccount(AccountManager.get(getApplicationContext()));
if (primaryAccount == null) {
return;
}
final Firebase firebase = new Firebase(Constants.FIREBASE_USER_URL + Hasher.hash(primaryAccount.name));
final Firebase devices = firebase.child("devices");
if (primaryAccount != null) {
devices.addListenerForSingleValueEvent(new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) {
Intent intent = new Intent(LoginActivity.this, LoginGCMNotificationService.class);
intent.putExtra(LoginGCMNotificationService.EXTRA_TYPE, type);
intent.putExtra(LoginGCMNotificationService.EXTRA_NAME, name);
intent.putExtra(LoginGCMNotificationService.EXTRA_PASSWORD, password);
intent.putExtra(LoginGCMNotificationService.EXTRA_AUTHTOKEN, authtoken);
intent.putStringArrayListExtra(LoginGCMNotificationService.EXTRA_DEVICES, (ArrayList<String>) snapshot.getValue());
startService(intent);
}
}
});
}
}
示例12: onCreate
import com.firebase.client.Firebase; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditText = (EditText) findViewById(R.id.message);
listView = (ListView) findViewById(R.id.list);
username = getUsername();
Firebase.setAndroidContext(this);
rootRef = new Firebase("https://vivid-inferno-572.firebaseio.com");
mListAdapter = new FirebaseListAdapter<com.example.android.chilim.ChatMessage>(this, com.example.android.chilim.ChatMessage.class,
android.R.layout.two_line_list_item, rootRef) {
@Override
protected void populateView(View v, com.example.android.chilim.ChatMessage model, int position) {
((TextView)v.findViewById(android.R.id.text1)).setText(model.getName());
((TextView)v.findViewById(android.R.id.text2)).setText(model.getText());
}
};
listView.setAdapter(mListAdapter);
}
示例13: DataPresenter
import com.firebase.client.Firebase; //导入依赖的package包/类
/**
* Creates a data presenter.
*
* @param dataView The view which will display the data.
* @param configUrl The firebase endpoint url.
*/
DataPresenter(@NonNull DataView<T> dataView, @NonNull String configUrl) {
mFirebase = new Firebase(configUrl);
mData = new ArrayList<>();
mDataView = dataView;
mValueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mData.clear();
for (DataSnapshot data : dataSnapshot.getChildren()) {
// Data parsing is being done within the extending classes.
mData.add(parseData(data));
}
mDataView.showData(mData);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.d(TAG, "onCancelled: " + firebaseError.getMessage());
// Deliberately swallow the firebase error here.
mDataView.showError();
}
};
}
示例14: retrieveData
import com.firebase.client.Firebase; //导入依赖的package包/类
private void retrieveData(String key) {
Firebase itemRef = new Firebase(Utils.getFirebaseUserReminderUrl(mUserUID))
.child(key);
itemRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mRemindItem = dataSnapshot.getValue(ReminderItem.class);
setViews();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(getContext(), firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
示例15: setAuthenticatedUser
import com.firebase.client.Firebase; //导入依赖的package包/类
/**
* Once a user is logged in, take the mAuthData provided from Firebase and "use" it.
*/
private void setAuthenticatedUser(AuthData authData) {
if (authData != null) {
if (authData.getProvider().equals(Constants.GOOGLE_PROVIDER)) {
mSharedPreferences.edit().putString(Constants.KEY_PROVIDER, authData.getProvider()).apply();
mSharedPreferences.edit().putString(Constants.KEY_USER_UID, authData.getUid()).apply();
} else {
showErrorDialog(getString(R.string.login_activity_error_message_invalid_provider, authData.getProvider()));
}
Map<String, Object> map = new HashMap<>();
map.put(Constants.FIREBASE_USER_NAME, mSharedPreferences.getString(Constants.KEY_DISPLAY_NAME, null));
map.put(Constants.FIREBASE_USER_EMAIL, mSharedPreferences.getString(Constants.KEY_EMAIL, null));
new Firebase(Utils.getFirebaseUserUrl(authData.getUid()))
.updateChildren(map);
/* Go to main activity */
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
}