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


Java Firebase類代碼示例

本文整理匯總了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);
}
 
開發者ID:ruipoliveira,項目名稱:livingCity-Android,代碼行數:23,代碼來源:FireBaseModule.java

示例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;
    }
 
開發者ID:mangoblogger,項目名稱:MangoBloggerAndroidApp,代碼行數:24,代碼來源:FirebaseListFragment.java

示例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();


    }
 
開發者ID:JamesNikolaidis,項目名稱:Thesis_Farmers_Helper,代碼行數:23,代碼來源:Database_Class_Functions.java

示例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);

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

示例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);
                    }
                }
            }
        });
    }
}
 
開發者ID:Sefford,項目名稱:BeAuthentic,代碼行數:30,代碼來源:RegistrationIntentService.java

示例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();
}
 
開發者ID:cardenuto,項目名稱:FirebaseLogin,代碼行數:26,代碼來源:LoginActivity.java

示例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();
}
 
開發者ID:aluxian,項目名稱:Codementor,代碼行數:27,代碼來源:FirebaseTasks.java

示例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();
}
 
開發者ID:aluxian,項目名稱:Codementor,代碼行數:20,代碼來源:FirebaseTasks.java

示例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();
}
 
開發者ID:aluxian,項目名稱:Codementor,代碼行數:17,代碼來源:FirebaseTasks.java

示例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();
}
 
開發者ID:aluxian,項目名稱:Codementor,代碼行數:19,代碼來源:FirebaseTasks.java

示例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);
                }
            }
        });
    }
}
 
開發者ID:Sefford,項目名稱:BeAuthentic,代碼行數:25,代碼來源:LoginActivity.java

示例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);
}
 
開發者ID:C-Pro,項目名稱:Chilim,代碼行數:24,代碼來源:MainActivity.java

示例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();
        }
    };
}
 
開發者ID:googlesamples,項目名稱:android-OurStreets,代碼行數:31,代碼來源:DataPresenter.java

示例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();
        }
    });
}
 
開發者ID:trigor74,項目名稱:travelers-diary,代碼行數:17,代碼來源:ReminderItemFragment.java

示例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();
    }
}
 
開發者ID:trigor74,項目名稱:travelers-diary,代碼行數:26,代碼來源:LoginActivity.java


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