• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ParticleDevice类的典型用法和代码示例

java 2次浏览

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

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

示例1: JSONCommandCCT

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
public int JSONCommandCCT(final int nodeID, final int value, final int sid) {
    new Thread() {
        @Override
        public void run() {
            // Make the Particle call here
            String json = "{\"cmd\":" + xltDevice.CMD_CCT + ",\"nd\":" + nodeID + ",\"value\":" + value + (sid != 0 ? (",\"sid\":" + sid) : "") + "}";
            ArrayList<String> message = new ArrayList<>();
            message.add(json);
            try {
                Log.d(TAG, "JSONCommandCCT" + message.get(0));
                resultCode = currDevice.callFunction("JSONCommand", message);
            } catch (ParticleCloudException | ParticleDevice.FunctionDoesNotExistException | IOException e) {
                e.printStackTrace();
            }
            message.clear();
        }
    }.start();
    return resultCode;
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:20,
代码来源:CloudBridge.java

示例2: JSONCommandQueryDevice

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
public int JSONCommandQueryDevice(final int nodeID) {
    new Thread() {
        @Override
        public void run() {
            // Make the Particle call here
            String json = "{\"cmd\":" + xltDevice.CMD_QUERY + ",\"nd\":" + (nodeID == 0 ? getNodeID() : nodeID) + "}";
            ArrayList<String> message = new ArrayList<>();
            message.add(json);
            try {
                Log.i(TAG, "JSONCommandQueryDevice" + message.get(0));
                resultCode = currDevice.callFunction("JSONCommand", message);
            } catch (ParticleCloudException | ParticleDevice.FunctionDoesNotExistException | IOException e) {
                e.printStackTrace();
            }
            message.clear();
        }
    }.start();
    return resultCode;
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:20,
代码来源:CloudBridge.java

示例3: JSONGetDeviceStatus

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
public int JSONGetDeviceStatus(final int nodeID) {
    new Thread() {
        @Override
        public void run() {
            //construct first part of string input, and store it in arraylist (of size 1)
            String json = "{\"op\":0,\"fl\":1,\"run\":0,\"uid\":\"h" + nodeID + "}";
            ArrayList<String> message = new ArrayList<>();
            message.add(json);
            //send in first part of string
            try {
                Log.d(TAG, "JSONGetDeviceStatus " + message.get(0));
                resultCode = currDevice.callFunction("JSONConfig", message);
            } catch (ParticleCloudException | ParticleDevice.FunctionDoesNotExistException | IOException e) {
                e.printStackTrace();
            }
            message.clear();
        }
    }.start();
    return resultCode;
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:21,
代码来源:CloudBridge.java

示例4: FastCallPowerSwitch

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
public int FastCallPowerSwitch(final int nodeID, final int state, final int sid) {
    new Thread() {
        @Override
        public void run() {
            // Make the Particle call here
            String strParam = String.format("%d:%d", nodeID, state);
            ArrayList<String> message = new ArrayList<>();
            message.add(strParam);
            try {
                Log.d(TAG, "FastCallPowerSwitch: " + strParam);
                resultCode = currDevice.callFunction("PowerSwitch", message);
            } catch (ParticleCloudException | ParticleDevice.FunctionDoesNotExistException | IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
    return resultCode;
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:19,
代码来源:CloudBridge.java

示例5: queryDevices

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private static int queryDevices() {
    // Make the Particle call here
    try {
        String sItem;
        m_devices = ParticleCloudSDK.getCloud().getDevices();
        m_deviceID2Name.clear();
        for (ParticleDevice device : m_devices) {
            sItem = device.getID() + ":" + device.getName();
            m_deviceID2Name.add(sItem);
        }
    } catch (ParticleCloudException e) {
        e.printStackTrace();
        resultCode = -1;
    }
    return resultCode;
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:17,
代码来源:ParticleAdapter.java

示例6: onRunStep

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
protected void onRunStep() throws SetupStepException {
    List<ParticleDevice> devices;
    try {
        devices = sparkCloud.getDevices();
    } catch (ParticleCloudException e) {
        throw new SetupStepException(e);
    }

    log.d("Got devices back from the cloud...");
    for (ParticleDevice device : devices) {
        if (deviceBeingConfiguredId.equalsIgnoreCase(device.getID())) {
            log.d("Success, device " + device.getID() + " claimed!");
            needToClaimDevice = false;
            return;
        }
    }

    // device not found in the loop
    throw new SetupStepException("Device " + deviceBeingConfiguredId + " still not claimed.");
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:22,
代码来源:CheckIfDeviceClaimedStep.java

示例7: finishSetup

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void finishSetup(Context context, String deviceName, boolean isSuccess) {
    ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, true);
    Async.executeAsync(particleCloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud cloud) throws ParticleCloudException, IOException {
            ParticleDevice device = particleCloud.getDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID));
            setDeviceName(device, deviceName);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            leaveActivity(context, isSuccess);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException e) {
            ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, false);
            deviceNameView.setError(getString(R.string.device_naming_failure));
        }
    });
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:23,
代码来源:SuccessActivity.java

示例8: write

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
void write(final PinStuff stuff, final int newValue) {
    Async.executeAsync(device, new TinkerWork(stuff) {
        @Override
        public Integer callApi(@NonNull ParticleDevice sparkDevice) throws ParticleCloudException, IOException {
            String stringValue;
            if (stuff.pinAction == PinAction.ANALOG_WRITE) {
                stringValue = String.valueOf(newValue);
            } else {
                stringValue = (newValue == DigitalValue.HIGH.asInt()) ? "HIGH" : "LOW";
            }
            try {
                return (sparkDevice.callFunction(
                        actionToFunctionName.get(stuff.pinAction),
                        list(stuff.pinName, stringValue)) == 1) ? newValue : stuff.currentValue;
            } catch (final ParticleDevice.FunctionDoesNotExistException e) {
                Toaster.s(getActivity(), e.getMessage());
                return stuff.currentValue; // it didn't change
            }
        }

        @Override
        public void onSuccess(@NonNull Integer returnValue) {
            onTinkerCallComplete(stuff, returnValue);
        }
    });
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:27,
代码来源:TinkerFragment.java

示例9: read

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
void read(PinStuff stuff) {
    Async.executeAsync(device, new TinkerWork(stuff) {
        @Override
        public Integer callApi(@NonNull ParticleDevice sparkDevice) throws ParticleCloudException,
                IOException {
            try {
                return sparkDevice.callFunction(
                        actionToFunctionName.get(stuff.pinAction),
                        list(stuff.pinName));
            } catch (ParticleDevice.FunctionDoesNotExistException e) {
                Toaster.s(getActivity(), e.getMessage());
                return stuff.currentValue;
            }
        }

        @Override
        public void onSuccess(@NonNull Integer returnValue) {
            onTinkerCallComplete(stuff, returnValue);
        }
    });
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:22,
代码来源:TinkerFragment.java

示例10: pollDataUsage

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void pollDataUsage(View rootView) {
    TextView dataUsage = Ui.findView(rootView, R.id.device_data_usage);

    Async.executeAsync(device, new Async.ApiWork<ParticleDevice, Float>() {
        @Override
        public Float callApi(@NonNull ParticleDevice particleDevice) throws ParticleCloudException, IOException {
            return particleDevice.getCurrentDataUsage();
        }

        @Override
        public void onSuccess(@NonNull Float value) {
            dataUsage.setText(getString(R.string.value_mbs, value));
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException exception) {
            dataUsage.setText(R.string.default_mbs);
        }
    });
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:21,
代码来源:InfoFragment.java

示例11: onDeviceSelected

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
    public void onDeviceSelected(@NonNull ParticleDevice device) {
        // FIXME: re-enable
//
//        return;
//
//        if (mTwoPane) {
//            // In two-pane mode, show the detail view in this activity by
//            // adding or replacing the detail fragment using a
//            // fragment transaction.
//            getSupportFragmentManager()
//                    .beginTransaction()
//                    .replace(R.id.device_detail_container, TinkerFragment.newInstance(id))
//                    .commit();
//
//        } else {
        // In single-pane mode, simply start the detail activity
        // for the selected item.
        startActivity(TinkerActivity.buildIntent(this, device));
//        }
    }
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:22,
代码来源:DeviceListActivity.java

示例12: onDeviceRowClicked

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void onDeviceRowClicked(int position) {
    log.i("Clicked on item at position: #" + position);
    if (position >= bookends.getItemCount() || position == -1) {
        // we're at the header or footer view, do nothing.
        return;
    }

    // Notify the active callbacks interface (the activity, if the
    // fragment is attached to one) that an item has been selected.
    final ParticleDevice device = adapter.getItem(position);

    if (device.isFlashing()) {
        Toaster.s(getActivity(),
                "Device is being flashed, please wait for the flashing process to end first");
    } else if (!device.isConnected() || !device.isRunningTinker()) {
        Activity activity = getActivity();
        activity.startActivity(InspectorActivity.buildIntent(activity, device));
    } else {
        callbacks.onDeviceSelected(device);
    }
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:22,
代码来源:DeviceListFragment.java

示例13: getStatusTextAndColoredDot

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private Pair<String, Integer> getStatusTextAndColoredDot(ParticleDevice device) {
    int dot;
    String msg;
    if (device.isFlashing()) {
        dot = R.drawable.device_flashing_dot;
        msg = "";

    } else if (device.isConnected()) {
        if (device.isRunningTinker()) {
            dot = R.drawable.online_dot;
            msg = "Tinker";

        } else {
            dot = R.drawable.online_non_tinker_dot;
            msg = "";
        }

    } else {
        dot = R.drawable.offline_dot;
        msg = "";
    }
    return Pair.create(msg, dot);
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:24,
代码来源:DeviceListFragment.java

示例14: doRename

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void doRename(final String newName) {
    Async.executeAsync(device, new Async.ApiProcedure<ParticleDevice>() {
        @Override
        public Void callApi(@NonNull ParticleDevice sparkDevice) throws ParticleCloudException, IOException {
            device.setName(newName);
            EventBus.getDefault().post(device);
            return null;
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException exception) {
            new MaterialDialog.Builder(activity)
                    .theme(Theme.LIGHT)
                    .title("Unable to rename core")
                    .content(exception.getBestMessage())
                    .positiveText("OK");
        }
    }).andIgnoreCallbacksIfActivityIsFinishing(activity);
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:20,
代码来源:RenameHelper.java

示例15: flashKnownApp

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private static void flashKnownApp(final Activity activity, final ParticleDevice device,
                                  final ParticleDevice.KnownApp knownApp) {
    Async.executeAsync(device, new Async.ApiProcedure<ParticleDevice>() {
        @Override
        public Void callApi(@NonNull ParticleDevice sparkDevice) throws ParticleCloudException, IOException {
            device.flashKnownApp(knownApp);
            return null;
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException exception) {
            new AlertDialog.Builder(activity)
                    .setTitle("Unable to reflash " + capitalize(knownApp.getAppName()))
                    .setMessage(exception.getBestMessage())
                    .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                    .show();
        }
    }).andIgnoreCallbacksIfActivityIsFinishing(activity);
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:20,
代码来源:FlashAppHelper.java

示例16: flashFromStream

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private static void flashFromStream(final Activity activity, final ParticleDevice device,
                                    final InputStream stream, final String name) {
    Async.executeAsync(device, new Async.ApiProcedure<ParticleDevice>() {
        @Override
        public Void callApi(@NonNull ParticleDevice sparkDevice)
                throws ParticleCloudException, IOException {
            sparkDevice.flashBinaryFile(stream);
            EZ.closeThisThingOrMaybeDont(stream);
            return null;
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException exception) {
            new AlertDialog.Builder(activity)
                    .setTitle("Unable to reflash from " + name)
                    .setMessage(exception.getBestMessage())
                    .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                    .show();
        }
    }).andIgnoreCallbacksIfActivityIsFinishing(activity);
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:22,
代码来源:FlashAppHelper.java

示例17: unclaim

点赞 3

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private static void unclaim(final Activity activity, final ParticleDevice device) {
    Async.executeAsync(device, new Async.ApiWork<ParticleDevice, Void>() {

        @Override
        public Void callApi(@NonNull ParticleDevice sparkDevice)
                throws ParticleCloudException, IOException {
            device.unclaim();
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void aVoid) {
            // FIXME: what else should happen here?
            Toaster.s(activity, "Unclaimed " + device.getName());
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException exception) {
            new AlertDialog.Builder(activity)
                    .setMessage("Error: unable to unclaim '" + device.getName() + "'")
                    .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                    .show();
        }
    }).andIgnoreCallbacksIfActivityIsFinishing(activity);
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:26,
代码来源:UnclaimHelper.java

示例18: checkDeviceID

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
public static boolean checkDeviceID(final String devID) {
    if (isAuthenticated()) {
        for (ParticleDevice device : m_devices) {
            if (devID.equalsIgnoreCase(device.getID())) {
                return true;
            }

        }
    }
    return false;
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:12,
代码来源:ParticleAdapter.java

示例19: onPostExecute

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
protected void onPostExecute(SetupProcessException error) {
    int resultCode;

    if (error != null) {
        resultCode = error.failedStep.getStepConfig().resultCode;

    } else {
        log.d("HUZZAH, VICTORY!");
        // FIXME: handle "success, no ownership" case
        resultCode = SuccessActivity.RESULT_SUCCESS;

        EZ.runAsync(() -> {
            try {
                // collect a list of unique, non-null device names
                Set<String> names = set(Funcy.transformList(
                        sparkCloud.getDevices(),
                        Funcy.notNull(),
                        ParticleDevice::getName,
                        Py::truthy
                ));
                ParticleDevice device = sparkCloud.getDevice(deviceId);
                if (device != null && !truthy(device.getName())) {
                    device.setName(CoreNameGenerator.generateUniqueName(names));
                }
            } catch (Exception e) {
                // FIXME: do real error handling here, and only
                // handle ParticleCloudException instead of swallowing everything
                e.printStackTrace();
            }
        });
    }

    startActivity(SuccessActivity.buildIntent(ConnectingActivity.this, resultCode, deviceId));
    finish();
}
 

开发者ID:Datatellit,
项目名称:xlight_android_native,
代码行数:37,
代码来源:ConnectingActivity.java

示例20: executeAsync

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
public static <T> AsyncApiWorker<ParticleDevice, T> executeAsync(ParticleDevice particleDevice,
                                                                 ApiWork<ParticleDevice, T> work) {
    try {
        return (AsyncApiWorker<ParticleDevice, T>) new AsyncApiWorker<>(particleDevice, work)
                .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } catch (RejectedExecutionException ex) {
        //FIXME just throw particle exception
        return null;
    }
}
 

开发者ID:particle-iot,
项目名称:spark-sdk-android,
代码行数:11,
代码来源:Async.java

示例21: onPostExecute

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
protected void onPostExecute(SetupProcessException error) {
    int resultCode;

    if (error != null) {
        resultCode = error.failedStep.getStepConfig().resultCode;

    } else {
        log.d("HUZZAH, VICTORY!");
        // FIXME: handle "success, no ownership" case
        resultCode = SuccessActivity.RESULT_SUCCESS;

        EZ.runAsync(() -> {
            try {
                // collect a list of unique, non-null device names
                Set<String> names = set(Funcy.transformList(
                        sparkCloud.getDevices(),
                        Funcy.notNull(),
                        ParticleDevice::getName,
                        Py::truthy
                ));
                ParticleDevice device = sparkCloud.getDevice(deviceId);
                if (device != null && !truthy(device.getName())) {
                    device.setName(CoreNameGenerator.generateUniqueName(names));
                }
            } catch (Exception e) {
                // FIXME: do real error handling here, and only
                // handle ParticleCloudException instead of swallowing everything
                e.printStackTrace();
            }
        });
    }

    Activity activity = activityReference.get();
    if (activity != null) {
        activity.startActivity(SuccessActivity.buildIntent(activity, resultCode, deviceId));
        activity.finish();
    }
}
 

开发者ID:particle-iot,
项目名称:spark-setup-android,
代码行数:40,
代码来源:ConnectingProcessWorkerTask.java

示例22: onEvent

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Subscribe
public void onEvent(ParticleDevice device) {
    //update device and UI
    //TODO update more fields
    this.device = device;
    TextView deviceNameView = Ui.findView(this, R.id.deviceName);
    deviceNameView.post(() -> deviceNameView.setText(device.getName()));
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:9,
代码来源:InspectorActivity.java

示例23: getStatusColoredDot

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private int getStatusColoredDot(ParticleDevice device) {
    if (device.isFlashing()) {
        return R.drawable.device_flashing_dot;
    } else if (device.isConnected()) {
        if (device.isRunningTinker()) {
            return R.drawable.online_dot;

        } else {
            return R.drawable.online_non_tinker_dot;
        }

    } else {
        return R.drawable.offline_dot;
    }
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:16,
代码来源:InspectorActivity.java

示例24: startEventSubscription

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void startEventSubscription(EventListAdapter adapter) {
    subscribed = true;
    Async.executeAsync(device, new Async.ApiProcedure<ParticleDevice>() {
        @Override
        public Void callApi(@NonNull ParticleDevice particleDevice) throws ParticleCloudException, IOException {
            try {
                subscriptionId = device.subscribeToEvents(null, new ParticleEventHandler() {
                    @Override
                    public void onEventError(Exception e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onEvent(String eventName, ParticleEvent particleEvent) {
                        adapter.add(new Event(eventName, particleEvent));
                        if (eventsLayoutManager.findFirstVisibleItemPosition() < 1) {
                            eventsRecyclerView.smoothScrollToPosition(0);
                        }
                        emptyView.post(() -> emptyView.setVisibility(View.GONE));
                    }
                });
            } catch (NullPointerException ignore) {
                //failed to subscribe to events, minor issue
            }
            return null;
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException exception) {
            exception.printStackTrace();
        }
    });
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:34,
代码来源:EventsFragment.java

示例25: stopEventSubscription

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void stopEventSubscription() {
    subscribed = false;
    Async.executeAsync(device, new Async.ApiProcedure<ParticleDevice>() {
        @Override
        public Void callApi(@NonNull ParticleDevice particleDevice) throws ParticleCloudException, IOException {
            device.unsubscribeFromEvents(subscriptionId);
            return null;
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException exception) {
            exception.printStackTrace();
        }
    });
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:16,
代码来源:EventsFragment.java

示例26: onCreate

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_device_detail);
    ParticleDevice device = getIntent().getParcelableExtra(TinkerFragment.ARG_DEVICE);

    // Show the Up button in the action bar.
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        // FIXME: do this with a theme attr instead.
        Drawable background = ContextCompat.getDrawable(this, R.drawable.ic_triangy_toolbar_background);
        supportActionBar.setBackgroundDrawable(background);
    }
    setTitle(getString(R.string.tinker));

    // savedInstanceState is non-null when there is fragment state
    // saved from previous configurations of this activity
    // (e.g. when rotating the screen from portrait to landscape).
    // In this case, the fragment will automatically be re-added
    // to its container so we don't need to manually add it.
    // For more information, see the Fragments API guide at:
    //
    // http://developer.android.com/guide/components/fragments.html
    //
    if (savedInstanceState == null) {
        // Create the detail fragment and add it to the activity
        // using a fragment transaction.
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.device_detail_container, TinkerFragment.newInstance(device))
                .commit();
    }

    ImageView deviceStatus = Ui.findView(this, R.id.deviceStatus);
    Animation animFade = AnimationUtils.loadAnimation(this, R.anim.fade_in_out);
    deviceStatus.startAnimation(animFade);
    deviceStatus.setImageResource(getStatusColoredDot(device));
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:40,
代码来源:TinkerActivity.java

示例27: onResume

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
public void onResume(){
    super.onResume();
    ParticleDevice device = getIntent().getParcelableExtra(TinkerFragment.ARG_DEVICE);

    TextView deviceNameView = Ui.findView(this, R.id.deviceName);
    deviceNameView.setText(device.getName());
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:9,
代码来源:TinkerActivity.java

示例28: onResume

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
public void onResume() {
    super.onResume();
    if (adapter != null) {
        List<ParticleDevice> devices = adapter.getItems();
        subscribeToSystemEvents(devices, false);
    }
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:9,
代码来源:DeviceListFragment.java

示例29: onPause

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
public void onPause() {
    if (adapter != null) {
        List<ParticleDevice> devices = adapter.getItems();
        subscribeToSystemEvents(devices, true);
    }
    super.onPause();
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:9,
代码来源:DeviceListFragment.java

示例30: onLoadFinished

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
@Override
public void onLoadFinished(Loader<DevicesLoadResult> loader, DevicesLoadResult result) {
    refreshLayout.setRefreshing(false);

    ArrayList<ParticleDevice> devices = new ArrayList<>(result.devices);
    Collections.sort(devices, comparator);

    reloadStateDelegate.onDeviceLoadFinished(loader, result);

    adapter.clear();
    adapter.addAll(devices);
    bookends.notifyDataSetChanged();
    //subscribe to system updates
    subscribeToSystemEvents(devices, false);
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:16,
代码来源:DeviceListFragment.java

示例31: subscribeToSystemEvents

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void subscribeToSystemEvents(List<ParticleDevice> devices, boolean revertSubscription) {
    for (ParticleDevice device : devices) {
        new AsyncTask<ParticleDevice, Void, Void>() {
            @Override
            protected Void doInBackground(ParticleDevice... particleDevices) {
                try {
                    if (revertSubscription) {
                        for (Long id : subscribeIds) {
                            device.unsubscribeFromEvents(id);
                        }
                    } else {
                        subscribeIds.add(device.subscribeToEvents("spark/status", new ParticleEventHandler() {
                            @Override
                            public void onEventError(Exception e) {
                                //ignore for now, events aren't vital
                            }

                            @Override
                            public void onEvent(String eventName, ParticleEvent particleEvent) {
                                refreshDevices();
                            }
                        }));
                    }
                } catch (IOException | ParticleCloudException ignore) {
                    //ignore for now, events aren't vital
                }
                return null;
            }
        }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, device);
    }
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:32,
代码来源:DeviceListFragment.java

示例32: refreshDevices

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private void refreshDevices() {
    if (adapter != null) {
        List<ParticleDevice> devices = adapter.getItems();
        subscribeToSystemEvents(devices, true);
    }
    Loader<Object> loader = getLoaderManager().getLoader(R.id.device_list_devices_loader_id);
    loader.forceLoad();
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:9,
代码来源:DeviceListFragment.java

示例33: helpfulOrderDeviceComparator

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private static Comparator<ParticleDevice> helpfulOrderDeviceComparator() {
    Comparator<ParticleDevice> deviceOnlineStatusComparator = (lhs, rhs) -> BooleanComparator.getTrueFirstComparator()
            .compare(lhs.isConnected(), rhs.isConnected());
    NullComparator<String> nullComparator = new NullComparator<>(false);
    Comparator<ParticleDevice> unnamedDevicesFirstComparator = (lhs, rhs) -> {
        String lhname = lhs.getName();
        String rhname = rhs.getName();
        return nullComparator.compare(lhname, rhname);
    };

    ComparatorChain<ParticleDevice> chain;
    chain = new ComparatorChain<>(deviceOnlineStatusComparator, false);
    chain.addComparator(unnamedDevicesFirstComparator, false);
    return chain;
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:16,
代码来源:DeviceListFragment.java

示例34: flashAppFromBinaryWithDialog

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
public static void flashAppFromBinaryWithDialog(final FragmentActivity activity,
                                                final ParticleDevice device, final File path) {
    new AlertDialog.Builder(activity)
            // FIXME: this is just for flashing Tinker for now, but later it could be used
            // for whatever file the user wants to upload (and "known apps" will work for
            // the Photon, too)
            // .content(String.format("Flash %s?", capitalize(knownApp.getAppName())))
            .setMessage("Flash Tinker?")
            .setPositiveButton(R.string.flash, (dialog, which) -> flashFromBinary(
                    activity, device, path))
            .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
            .show();
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:14,
代码来源:FlashAppHelper.java

示例35: flashPhotonTinkerWithDialog

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
static void flashPhotonTinkerWithDialog(final FragmentActivity activity,
                                        final ParticleDevice device) {
    final InputStream inputStream = activity.getResources().openRawResource(R.raw.photon_tinker);
    new AlertDialog.Builder(activity)
            .setMessage("Flash Tinker?")
            .setPositiveButton(R.string.flash, (dialog, which) -> flashFromStream(
                    activity, device, inputStream, "Tinker"))
            .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
            .show();
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:11,
代码来源:FlashAppHelper.java

示例36: flashKnownAppWithDialog

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
static void flashKnownAppWithDialog(final FragmentActivity activity,
                                    final ParticleDevice device,
                                    final ParticleDevice.KnownApp knownApp) {
    new AlertDialog.Builder(activity)
            .setMessage(String.format("Flash %s?", capitalize(knownApp.getAppName())))
            .setPositiveButton(R.string.flash, (dialog, which) -> flashKnownApp(
                    activity, device, knownApp))
            .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
            .show();
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:11,
代码来源:FlashAppHelper.java

示例37: flashFromBinary

点赞 2

import io.particle.android.sdk.cloud.ParticleDevice; //导入依赖的package包/类
private static void flashFromBinary(final Activity activity, final ParticleDevice device,
                                    final File binaryFile) {
    // FIXME: incorporate real error handling here
    try {
        FileInputStream fis = new FileInputStream(binaryFile);
        flashFromStream(activity, device, fis, binaryFile.getName());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
 

开发者ID:particle-iot,
项目名称:photon-tinker-android,
代码行数:11,
代码来源:FlashAppHelper.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)