当前位置: 首页>>代码示例>>Java>>正文


Java AwarenessFence类代码示例

本文整理汇总了Java中com.google.android.gms.awareness.fence.AwarenessFence的典型用法代码示例。如果您正苦于以下问题:Java AwarenessFence类的具体用法?Java AwarenessFence怎么用?Java AwarenessFence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AwarenessFence类属于com.google.android.gms.awareness.fence包,在下文中一共展示了AwarenessFence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
protected void registerFence(final String fenceKey, final AwarenessFence fence) {
    Awareness.FenceApi.updateFences(
            client,
            new FenceUpdateRequest.Builder()
                    .addFence(fenceKey, fence, myPendingIntent)             //Add fence to the pendingIntent
                    .build())
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.e(fenceKey, "Fence was successfully registered.");
                    } else {
                        Log.e(fenceKey, "Fence could not be registered: " + status);
                    }
                }
            });
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:18,代码来源:AwarenessMotionUpdatesProvider.java

示例2: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@Override
AwarenessFence getAwarenessFence(Context ctx) {
    if (ActivityCompat.checkSelfPermission(ctx,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        switch (mTransitionType) {
            case ENTER_TYPE:
                return LocationFence.entering(mLatitude, mLongitude, mRadius);
            case EXIT_TYPE:
                return LocationFence.exiting(mLatitude, mLongitude, mRadius);
            case IN_TYPE:
                return LocationFence.in(mLatitude, mLongitude, mRadius, mDwellTimeMillis);
        }
    }

    return null;
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:17,代码来源:StorableLocationFence.java

示例3: addFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
/**
 * Add a fence to the Google API
 * If not connected, this will only trigger a connection.
 * This call requires that the following granted permissions:
 *      - ACCESS_FINE_LOCATION if one of the fence is a {@link StorableLocationFence}
 *      - ACTIVITY_RECOGNITION if one of the fence is a {@link StorableActivityFence}
 * @param id the unique id of the fence.
 * @param fence the fence to store
 * @param pendingIntentClassName the class name of the pending intent to call when the fence will be valid.
 * @param status the status that will be called when the addition fails or succeed.
 * @return true if add has been asked, false otherwise.
 */
boolean addFence(@NonNull String id, @NonNull AwarenessFence fence,
                        @NonNull String pendingIntentClassName, ResultCallback<Status> status) {
    if (mGoogleApiClient.isConnected()) {
        FenceUpdateRequest.Builder requestBuilder = new FenceUpdateRequest.Builder()
                .addFence(id, fence, createRequestPendingIntent(pendingIntentClassName));

        Awareness.FenceApi.updateFences(mGoogleApiClient, requestBuilder.build())
                .setResultCallback(status);

        return true;
    } else {
        connect();
        return false;
    }
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:28,代码来源:GapiFenceManager.java

示例4: subscribeToBackgroundFenceWithData

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void subscribeToBackgroundFenceWithData() {
    long now = System.currentTimeMillis();
    long in5seconds = now + 5000;
    long in10seconds = now + 10000;

    Bundle bundle = new Bundle();
    bundle.putLong("start", now);

    disposables.add(BackgroundFence.query(this)
            .subscribe(
                    fenceStateMap -> {
                        if (!fenceStateMap.getFenceKeys().contains(ExampleFenceReceiver.TIME)) {
                            AwarenessFence fence = TimeFence.inInterval(in5seconds, in10seconds);
                            BackgroundFence.registerWithData(this, ExampleFenceReceiver.TIME, fence, bundle);
                        }
                    },
                    throwable -> logError(throwable, "query")
            )
    );
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:21,代码来源:MainActivity.java

示例5: addHeadphoneFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void addHeadphoneFence() {
    Intent intent = new Intent(MY_FENCE_RECEIVER_ACTION);
    PendingIntent mFencePendingIntent = PendingIntent.getBroadcast(FenceActivity.this,
            10001,
            intent,
            0);

    AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
    Awareness.FenceApi.updateFences(
            mGoogleApiClient,
            new FenceUpdateRequest.Builder()
                    .addFence(HEADPHONE_FENCE_KEY, headphoneFence, mFencePendingIntent)
                    .build())
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Fence was successfully registered.");
                    } else {
                        Log.e(TAG, "Fence could not be registered: " + status);
                    }
                }
            });
}
 
开发者ID:obaro,项目名称:UsingAwarenessAPI,代码行数:25,代码来源:FenceActivity.java

示例6: addHeadphoneAndLocationFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void addHeadphoneAndLocationFence() {
        Intent intent = new Intent(MY_FENCE_RECEIVER_ACTION);
        PendingIntent mFencePendingIntent = PendingIntent.getBroadcast(FenceActivity.this,
                10001,
                intent,
                0);

        AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
        AwarenessFence activityFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);
        AwarenessFence jointFence = AwarenessFence.and(headphoneFence, activityFence);
        Awareness.FenceApi.updateFences(
                mGoogleApiClient,
                new FenceUpdateRequest.Builder()
                        .addFence(HEADPHONE_AND_WALKING_FENCE_KEY,
                                jointFence, mFencePendingIntent)
                        .build())
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "Headphones AND Walking Fence was successfully registered.");
                        } else {
                            Log.e(TAG, "Headphones AND Walking Fence could not be registered: " + status);
                        }
                    }
                });
}
 
开发者ID:obaro,项目名称:UsingAwarenessAPI,代码行数:28,代码来源:FenceActivity.java

示例7: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@Override
AwarenessFence getAwarenessFence(Context ctx) {
    switch (mTriggerType) {
        case STATE:
            return HeadphoneFence.during(mHeadphoneState);
        case PLUGGING_IN:
            return HeadphoneFence.pluggingIn();
        case UNPLUGGING:
            return HeadphoneFence.unplugging();
    }
    return null;
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:13,代码来源:StorableHeadphoneFence.java

示例8: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@RequiresPermission("com.google.android.gms.permission.ACTIVITY_RECOGNITION")
@Override
AwarenessFence getAwarenessFence(Context ctx) {
    switch (mTransitionType) {
        case DURING_TYPE:
            return DetectedActivityFence.during(mActivityTypes);
        case START_TYPE:
            return DetectedActivityFence.starting(mActivityTypes);
        case STOP_TYPE:
            return DetectedActivityFence.stopping(mActivityTypes);
    }
    return null;
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:14,代码来源:StorableActivityFence.java

示例9: getAwarenessFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@Override
AwarenessFence getAwarenessFence(Context ctx) {
    switch (mTimingType) {
        case ABSOLUTE:
            return TimeFence.inInterval(mStartTime, mStopTime);
        case DAILY:
            return TimeFence.inDailyInterval(mTimeZone, mStartTime, mStopTime);
        case DAY_OF_WEEK:
            return TimeFence.inIntervalOfDay(mDayOfWeek, mTimeZone, mStartTime, mStopTime);
        case TIME_INTERVAL:
            if (ActivityCompat.checkSelfPermission(ctx,
                    Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                return TimeFence.inTimeInterval(mTimeInterval);
            }
            break;
        case TIME_INSTANT:
            return TimeFence.aroundTimeInstant(mTimeInstant, mStartOffset, mStopOffset);
        case MONDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_MONDAY, mTimeZone, mStartTime, mStopTime);
        case TUESDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_TUESDAY, mTimeZone, mStartTime, mStopTime);
        case WEDNESDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_WEDNESDAY, mTimeZone, mStartTime, mStopTime);
        case THURSDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_THURSDAY, mTimeZone, mStartTime, mStopTime);
        case FRIDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_FRIDAY, mTimeZone, mStartTime, mStopTime);
        case SATURDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_SATURDAY, mTimeZone, mStartTime, mStopTime);
        case SUNDAY:
            return TimeFence.inIntervalOfDay(DAY_OF_WEEK_SUNDAY, mTimeZone, mStartTime, mStopTime);

    }
    return null;
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:36,代码来源:StorableTimeFence.java

示例10: addFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
@Override
boolean addFence(@NonNull String id, @NonNull AwarenessFence fence, @NonNull String pendingIntentClassName, ResultCallback<Status> status) {
    if (isConnected) {
        addResultDict.put(id, status);
    }
    return isConnected();
}
 
开发者ID:djavan-bertrand,项目名称:JCVD,代码行数:8,代码来源:StorableFenceManagerTest.java

示例11: RegisterBackgroundFenceAction

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private RegisterBackgroundFenceAction(Context context,
                                      String name,
                                      AwarenessFence fence,
                                      @Nullable Bundle data) {
    this.context = context;
    this.name = name;
    this.fence = fence;
    this.data = data;

    Servant.actions(context, Awareness.API, this::onClientConnected, this::onClientError);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:12,代码来源:RegisterBackgroundFenceAction.java

示例12: subscribeToBackgroundFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void subscribeToBackgroundFence() {
    disposables.add(BackgroundFence.query(this)
            .subscribe(
                    fenceStateMap -> {
                        if (!fenceStateMap.getFenceKeys().contains(ExampleFenceReceiver.HEADPHONES)) {
                            AwarenessFence fence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
                            BackgroundFence.register(this, ExampleFenceReceiver.HEADPHONES, fence);
                        }
                    },
                    throwable -> logError(throwable, "query")
            )
    );
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:14,代码来源:MainActivity.java

示例13: subscribeToRuntimeFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void subscribeToRuntimeFence() {
    long now = System.currentTimeMillis();
    long inHalfASecond = now + 500;
    long inASecond = now + 1000;
    AwarenessFence fence = TimeFence.inInterval(inHalfASecond, inASecond);
    disposables.add(
            ObservableFence.create(this, fence)
                    .subscribe(
                            isTrue -> Log.e("TEST", "Runtime Fence: " + isTrue),
                            throwable -> logError(throwable, "observable fence")
                    )
    );
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:14,代码来源:MainActivity.java

示例14: addHeadphoneOrLocationFence

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
private void addHeadphoneOrLocationFence() {
    Intent intent = new Intent(MY_FENCE_RECEIVER_ACTION);
    PendingIntent mFencePendingIntent = PendingIntent.getBroadcast(FenceActivity.this,
            10001,
            intent,
            0);

    AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);
    AwarenessFence activityFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);

    AwarenessFence orFence = AwarenessFence.or(headphoneFence, activityFence);
    Awareness.FenceApi.updateFences(
            mGoogleApiClient,
            new FenceUpdateRequest.Builder()
                    .addFence(HEADPHONE_OR_WALKING_FENCE_KEY,
                            orFence, mFencePendingIntent)
                    .build())
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Headphones OR Walking Fence was successfully registered.");
                    } else {
                        Log.e(TAG, "Headphones OR Walking Fence could not be registered: " + status);
                    }
                }
            });
}
 
开发者ID:obaro,项目名称:UsingAwarenessAPI,代码行数:29,代码来源:FenceActivity.java

示例15: setupFences

import com.google.android.gms.awareness.fence.AwarenessFence; //导入依赖的package包/类
/**
 * Sets up {@link AwarenessFence}'s for the sample app, and registers callbacks for them
 * with a custom {@link BroadcastReceiver}
 */
private void setupFences() {
    // DetectedActivityFence will fire when it detects the user performing the specified
    // activity.  In this case it's walking.
    AwarenessFence walkingFence = DetectedActivityFence.during(DetectedActivityFence.WALKING);

    // There are lots of cases where it's handy for the device to know if headphones have been
    // plugged in or unplugged.  For instance, if a music app detected your headphones fell out
    // when you were in a library, it'd be pretty considerate of the app to pause itself before
    // the user got in trouble.
    AwarenessFence headphoneFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN);

    // Combines multiple fences into a compound fence.  While the first two fences trigger
    // individually, this fence will only trigger its callback when all of its member fences
    // hit a true state.
    AwarenessFence walkingWithHeadphones = AwarenessFence.and(walkingFence, headphoneFence);

    // We can even nest compound fences.  Using both "and" and "or" compound fences, this
    // compound fence will determine when the user has headphones in and is engaging in at least
    // one form of exercise.
    // The below breaks down to "(headphones plugged in) AND (walking OR running OR bicycling)"
    AwarenessFence exercisingWithHeadphonesFence = AwarenessFence.and(
            headphoneFence,
            AwarenessFence.or(
                    walkingFence,
                    DetectedActivityFence.during(DetectedActivityFence.RUNNING),
                    DetectedActivityFence.during(DetectedActivityFence.ON_BICYCLE)));


    // Now that we have an interesting, complex condition, register the fence to receive
    // callbacks.

    // Register the fence to receive callbacks.
    Awareness.getFenceClient(this).updateFences(new FenceUpdateRequest.Builder()
            .addFence(FENCE_KEY, exercisingWithHeadphonesFence, mPendingIntent)
            .build())
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    Log.i(TAG, "Fence was successfully registered.");
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.e(TAG, "Fence could not be registered: " + e);
                }
            });
}
 
开发者ID:googlesamples,项目名称:android-play-awareness,代码行数:53,代码来源:MainActivity.java


注:本文中的com.google.android.gms.awareness.fence.AwarenessFence类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。