当前位置: 首页>>代码示例>>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;未经允许,请勿转载。