當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSnapshot類代碼示例

本文整理匯總了Java中com.firebase.client.DataSnapshot的典型用法代碼示例。如果您正苦於以下問題:Java DataSnapshot類的具體用法?Java DataSnapshot怎麽用?Java DataSnapshot使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DataSnapshot類屬於com.firebase.client包,在下文中一共展示了DataSnapshot類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: renderData

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
private void renderData() {
    Query queryRef = mRootRef.child("users").orderByChild(getOrderBy()).limitToLast(100);//we need to iterate them backwards
    queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {

            for (DataSnapshot userSnapshot : snapshot.getChildren()) {
                mUsersDataset.add(userSnapshot.getValue(User.class));
            }
            Collections.reverse(mUsersDataset);
            mAdapter = new UserListAdapter(mUsersDataset, getActivity(), getmTabType());
            mRecyclerView.setAdapter(mAdapter);
            mLoadingWrapper.setVisibility(View.GONE);
            mRecyclerView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}
 
開發者ID:silva96,項目名稱:guessthehashtag,代碼行數:23,代碼來源:WeeklyFragment.java

示例2: onChildAdded

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    final String placeId=dataSnapshot.getKey();
    if(placeId!=null)
    {
        Places.GeoDataApi
                .getPlaceById(mGoogleApiClient,placeId)
                .setResultCallback(new ResultCallback<PlaceBuffer>() {
                    @Override
                    public void onResult(@NonNull PlaceBuffer places) {
                        LatLng location=places.get(0).getLatLng();
                        //CharSequence userName=places.get(1).getName();

                        //Toast.makeText(getApplicationContext(),"reached onChildAdded",Toast.LENGTH_SHORT).show();
                        addPointToView(location);
                        mMap.addMarker(new MarkerOptions()
                                .position(location));
                        //Toast.makeText(getApplicationContext(),"place added",Toast.LENGTH_SHORT).show();
                        places.release();
                    }
                });
    }

}
 
開發者ID:agarwal-akash,項目名稱:BonAppetit_Android-Project,代碼行數:25,代碼來源:MapsActivity.java

示例3: getPresenceImpl

import com.firebase.client.DataSnapshot; //導入依賴的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();
}
 
開發者ID:aluxian,項目名稱:Codementor,代碼行數:20,代碼來源:FirebaseTasks.java

示例4: checkThings

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
private void checkThings() {
    Calendar cal = Calendar.getInstance();
    boolean monday = cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;
    mWeekResetRef = mRootRef.child("settings").child("week_reset");
    if (monday) {
        mWeekResetRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                boolean is_reseted = snapshot.getValue(boolean.class);
                if (!is_reseted) {
                    updateAllWeekScores();
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });
    } else {
        mWeekResetRef.setValue(false);
    }
}
 
開發者ID:silva96,項目名稱:guessthehashtag,代碼行數:24,代碼來源:MainActivity.java

示例5: updateAllWeekScores

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
private void updateAllWeekScores() {
    mRootRef.child("users").addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            Map<String, Object> week_scores = new HashMap<String, Object>();
            for (DataSnapshot userSnapshot : snapshot.getChildren()) {
                week_scores.put(userSnapshot.child("username").getValue() + "/week_score", 0);
            }
            mRootRef.child("users").updateChildren(week_scores);
            mWeekResetRef.setValue(true);
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}
 
開發者ID:silva96,項目名稱:guessthehashtag,代碼行數:19,代碼來源:MainActivity.java

示例6: DataPresenter

import com.firebase.client.DataSnapshot; //導入依賴的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();
        }
    };
}
 
開發者ID:googlesamples,項目名稱:android-OurStreets,代碼行數:31,代碼來源:DataPresenter.java

示例7: sendRegistrationToServer

import com.firebase.client.DataSnapshot; //導入依賴的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);
                    }
                }
            }
        });
    }
}
 
開發者ID:Sefford,項目名稱:BeAuthentic,代碼行數:30,代碼來源:RegistrationIntentService.java

示例8: addToiletToFirebase

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
public void addToiletToFirebase(View v) {
    // Look up all the data: Assumes that no values are NULL
    Firebase rootRef = new Firebase(MainActivity.FIREBASE_URL);
    final Firebase array = rootRef.child("toilets");
    array.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Toilet t = new Toilet(mName, mLocation, mRating, mNotes, mFamilyFriendly, mGenderNeutral, mHandicapAccessible, "");
            array.push().setValue(t);
            // Actually ends the activity
            finish();
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
        }
    });
}
 
開發者ID:thorsteinson,項目名稱:porcelain,代碼行數:19,代碼來源:AddToiletActivity.java

示例9: retrieveData

import com.firebase.client.DataSnapshot; //導入依賴的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();
        }
    });
}
 
開發者ID:trigor74,項目名稱:travelers-diary,代碼行數:17,代碼來源:ReminderItemFragment.java

示例10: notifyLoginToGCM

import com.firebase.client.DataSnapshot; //導入依賴的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);
                }
            }
        });
    }
}
 
開發者ID:Sefford,項目名稱:BeAuthentic,代碼行數:25,代碼來源:LoginActivity.java

示例11: onPause

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
@Override
protected void onPause() {
    super.onPause();
    firebase.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            updater = (long) dataSnapshot.getValue();
            updater--;
            firebase.setValue(updater);
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
    Log.v(this.getClass().getSimpleName(), "onPause()");

    if (tts != null) {
        tts.stop();
        tts.shutdown();
    }
}
 
開發者ID:siddhantvinchurkar,項目名稱:Marv,代碼行數:24,代碼來源:MainActivity.java

示例12: convert

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
@Override
protected CollaborativeMenuAnswer convert(DataSnapshot data) {
    if (data == null) return null;

    CollaborativeMenuAnswer collaborativeMenuAnswer = new CollaborativeMenuAnswer();
    collaborativeMenuAnswer.setId(data.getKey());

    for (DataSnapshot d : data.getChildren()) {
        if ("guest".equals(d.getKey())) {
            collaborativeMenuAnswer.setGuest(d.getValue(String.class));
        } else if ("date".equals(d.getKey())) {
            collaborativeMenuAnswer.setDate(d.getValue(Date.class));
        } else if ("offeredDishes".equals(d.getKey())) {
            List<String> dishes = new ArrayList<>();
            for (DataSnapshot dish : d.getChildren()) {
                dishes.add(dish.getKey());
            }
            collaborativeMenuAnswer.setOfferedDishes(dishes);
        }else if ("menuId".equals(d.getKey())) {
            collaborativeMenuAnswer.setMenuId(d.getValue(String.class));
        }
    }
    return collaborativeMenuAnswer;

}
 
開發者ID:BlunchDev,項目名稱:blunch_android,代碼行數:26,代碼來源:CollaborativeMenuAnswerRepository.java

示例13: convert

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
@Override
protected Valoration convert(DataSnapshot data) {
    if (data == null) return null;

    Valoration valoration = new Valoration();
    valoration.setId(data.getKey());

    for (DataSnapshot d : data.getChildren()) {
        if ("points".equals(d.getKey())) {
            valoration.setPoints(d.getValue(Double.class));
        }else if ("comment".equals(d.getKey())) {
            valoration.setComment(d.getValue(String.class));
        }else if ("menu".equals(d.getKey())) {
            valoration.setMenu(d.getValue(String.class));
        }else if ("host".equals(d.getKey())) {
            valoration.setHost(d.getValue(String.class));
        }else if ("guest".equals(d.getKey())) {
            valoration.setGuest(d.getValue(String.class));
        }
    }
    return valoration;

}
 
開發者ID:BlunchDev,項目名稱:blunch_android,代碼行數:24,代碼來源:ValorationRepository.java

示例14: convert

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
@Override
protected Dish convert(DataSnapshot data) {
    if (data == null) return null;

    Dish dish = new Dish();
    dish.setId(data.getKey());
    for (DataSnapshot d : data.getChildren()) {
        if (d.getKey().equals("name")) {
            dish.setName(d.getValue(String.class));
        } else if (d.getKey().equals("price")) {
            dish.setPrice(d.getValue(Double.class));
        } else if (d.getKey().equals("author")) {
            dish.setAuthor(d.getValue(String.class));
        }
    }
    return dish;
}
 
開發者ID:BlunchDev,項目名稱:blunch_android,代碼行數:18,代碼來源:DishRepository.java

示例15: convert

import com.firebase.client.DataSnapshot; //導入依賴的package包/類
@Override
protected PaymentMenuAnswer convert(DataSnapshot data) {
    if (data == null) return null;

    PaymentMenuAnswer answer = new PaymentMenuAnswer();
    answer.setId(data.getKey());
    for (DataSnapshot d : data.getChildren()) {
        if (d.getKey().equals("idMenu"))
            answer.setIdMenu(d.getValue(String.class));
        else if (d.getKey().equals("guest"))
            answer.setGuest(d.getValue(String.class));
        else if (d.getKey().equals("choosenDishes")) {
            List<String> dishes = new ArrayList<>();
            for (DataSnapshot dish : d.getChildren()) {
                dishes.add(dish.getKey());
            }
            answer.setChoosenDishesKeys(dishes);
        }
    }
    return answer;
}
 
開發者ID:BlunchDev,項目名稱:blunch_android,代碼行數:22,代碼來源:PaymentMenuAnswerRepository.java


注:本文中的com.firebase.client.DataSnapshot類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。