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


Java Button类代码示例

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


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

示例1: initPIO

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
/**
 * This method should only be called when running on an Android Things device.
 */
private void initPIO() {
    PeripheralManagerService pioService = new PeripheralManagerService();
    try {
        mReadyLED = pioService.openGpio(BoardDefaults.getGPIOForLED());
        mReadyLED.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        mButtonDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForButton(),
                Button.LogicState.PRESSED_WHEN_LOW,
                KeyEvent.KEYCODE_ENTER);
        mButtonDriver.register();
    } catch (IOException e) {
        mButtonDriver = null;
        Log.w(TAG, "Could not open GPIO pins", e);
    }
}
 
开发者ID:androidthings,项目名称:sample-tensorflow-imageclassifier,代码行数:19,代码来源:ImageClassifierActivity.java

示例2: GpioHandler

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private GpioHandler() {
    EventBus.getDefault().register(this);
    mContext = ContextHolder.getAppContext();
    manager = new PeripheralManagerService();
    try {
        mAlarmGpio = manager.openGpio(GPIO_ALARM_TRIGGER);
        mAlarmGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);

        mMotion = new Button(GPIO_ALARM_MOTION,
                Button.LogicState.PRESSED_WHEN_HIGH
        );

        mMotion.setOnButtonEventListener(this);
    } catch (IOException e) {
        Log.e(BurglarAlarmConstants.LOG_TAG, "IOException :" + e);
    }

}
 
开发者ID:freeloki,项目名称:AndroidThings-BurglarAlarm,代码行数:19,代码来源:GpioHandler.java

示例3: onCreate

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Starting ButtonActivity");

    PeripheralManagerService pioService = new PeripheralManagerService();
    try {
        Log.i(TAG, "Configuring GPIO pins");
        mLedGpio = pioService.openGpio(BoardDefaults.getGPIOForLED());
        mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);

        Log.i(TAG, "Registering button driver");
        // Initialize and register the InputDriver that will emit SPACE key events
        // on GPIO state changes.
        mButtonInputDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForButton(),
                Button.LogicState.PRESSED_WHEN_LOW,
                KeyEvent.KEYCODE_SPACE);
        mButtonInputDriver.register();
    } catch (IOException e) {
        Log.e(TAG, "Error configuring GPIO pins", e);
    }
}
 
开发者ID:androidthings,项目名称:sample-button,代码行数:24,代码来源:ButtonActivity.java

示例4: testButtonNull

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
/**
 * Verify that the button is null if not passed as a parameter.
 */
@Test
@UiThreadTest
public void testButtonNull() throws IOException {
    InstrumentationTestUtils.assertRaspberryPiOnly();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            try {
                Button button = VoiceHat.openButton();
                Assert.assertNotNull(button);
                button.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
 
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:21,代码来源:VoiceHatPeripheralInstrumentationTest.java

示例5: onButtonEvent

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
@Override
public void onButtonEvent(Button button, boolean pressed) {
    try {
        if (mLed != null) {
            mLed.setValue(pressed);
        }
    } catch (IOException e) {
        Log.d(TAG, "error toggling LED:", e);
    }
    if (pressed) {
        mAssistantHandler.post(mStartAssistantRequest);
    } else {
        mAssistantHandler.post(mStopAssistantRequest);
    }
}
 
开发者ID:googlecodelabs,项目名称:androidthings-googleassistant,代码行数:16,代码来源:AssistantActivity.java

示例6: initPIO

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private void initPIO() {
    PeripheralManagerService pioService = new PeripheralManagerService();
    try {
        mReadyLED = pioService.openGpio(BoardDefaults.getGPIOForLED());
        mReadyLED.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        mButtonDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForButton(),
                Button.LogicState.PRESSED_WHEN_LOW,
                KeyEvent.KEYCODE_ENTER);
        mButtonDriver.register();
    } catch (IOException e) {
        mButtonDriver = null;
        Log.w(TAG, "Could not open GPIO pins", e);
    }
}
 
开发者ID:FoxLabMakerSpace,项目名称:SIGHT-For-the-Blind,代码行数:16,代码来源:ImageClassifierActivity.java

示例7: onButtonEvent

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
@Override
public void onButtonEvent(Button button, boolean pressed) {
    try {
        if (mLed != null) {
            mLed.setValue(pressed);
        }
    } catch (IOException e) {
        Log.d(TAG, "error toggling LED:", e);
    }
    if (pressed) {
        mEmbeddedAssistant.startConversation();
    }
}
 
开发者ID:androidthings,项目名称:sample-googleassistant,代码行数:14,代码来源:AssistantActivity.java

示例8: configureButton

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private void configureButton() {
    try {
        mPairingButtonDriver = new ButtonInputDriver(BoardDefaults.getGPIOForPairing(),
                Button.LogicState.PRESSED_WHEN_LOW, KeyEvent.KEYCODE_P);
        mPairingButtonDriver.register();
        mDisconnectAllButtonDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForDisconnectAllBTDevices(),
                Button.LogicState.PRESSED_WHEN_LOW, KeyEvent.KEYCODE_D);
        mDisconnectAllButtonDriver.register();
    } catch (IOException e) {
        Log.w(TAG, "Could not register GPIO button drivers. Use keyboard events to trigger " +
                "the functions instead", e);
    }
}
 
开发者ID:androidthings,项目名称:sample-bluetooth-audio,代码行数:15,代码来源:A2dpSinkActivity.java

示例9: initPIO

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private void initPIO() {
    try {
        mButtonInputDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForButton(),
                Button.LogicState.PRESSED_WHEN_LOW,
                KeyEvent.KEYCODE_ENTER);
        mButtonInputDriver.register();
    } catch (IOException e) {
        mButtonInputDriver = null;
        Log.w(TAG, "Could not open GPIO pins", e);
    }
}
 
开发者ID:androidthings,项目名称:doorbell,代码行数:13,代码来源:DoorbellActivity.java

示例10: registerButtonDriver

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private static ButtonInputDriver registerButtonDriver(String pin, int keycode) throws IOException {
    ButtonInputDriver driver = new ButtonInputDriver(pin, Button.LogicState.PRESSED_WHEN_LOW, keycode);
    driver.register();
    return driver;
}
 
开发者ID:JeppeLeth,项目名称:android-things-rainbow-hat-sample,代码行数:6,代码来源:Buttons.java

示例11: setupButton

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private Button setupButton(String pin, Button.OnButtonEventListener buttonEventListener) throws IOException {
    Button button = new Button(pin, Button.LogicState.PRESSED_WHEN_HIGH);
    button.setDebounceDelay(BUTTON_DEBOUNCE_DELAY_MS);
    button.setOnButtonEventListener(buttonEventListener);
    return button;
}
 
开发者ID:mguntli,项目名称:sonos-remote-things,代码行数:7,代码来源:MainActivity.java

示例12: OLEDBlock

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
public OLEDBlock() throws IOException {
    PeripheralManagerService peripheralManagerService = new PeripheralManagerService();

    // Make sure GPIO is available for buttons
    List<String> gpioList = peripheralManagerService.getGpioList();
    if (gpioList.isEmpty()) {
        Log.i(TAG, "No GPIO available on this device.");
        throw new IOException("GPIO interface is require");
    } else {
        Log.i(TAG, "List of available GPIO : " + gpioList);
        for ( int i = 0; i < GPIOButtons.length; i ++ ) {
            if ( gpioList.contains(GPIOButtons[i]) == false )
                Log.i(TAG, "GPIO "+GPIOButtons[i]+" is not available on this device.");
        }
        // SSD1306
        if (gpioList.contains("GP14")== false )
            Log.i(TAG, "GPIO GP14 is not available on this device.");
        if (gpioList.contains("GP15")== false )
            Log.i(TAG, "GPIO GP15 is not available on this device.");
    }

    // SPI will be use by SSD1306 OLED display
    List<String> spiList = peripheralManagerService.getSpiBusList();
    if (spiList.isEmpty()) {
        Log.i(TAG, "No SPI available on this device.");
        throw new IOException("SPI interface is require");
    } else {
        Log.i(TAG, "List of available SPI : " + spiList);
    }

    // Setup button
    for ( int i = 0 ; i < GPIOButtons.length; i++ ) {
        ButtonInputDriver buttonInputDriver = new ButtonInputDriver(GPIOButtons[i],
                Button.LogicState.PRESSED_WHEN_LOW,
                buttons[i] // the keycode to send
        );
        buttonInputDriver.register();
        buttonInputDriverList.add(buttonInputDriver);
    }

    try {
        ssd1306 = new SSD1306(spiList.get(0));
    } catch (InterruptedException e) {
        Log.e(TAG,"error",e);
        throw new IOException("Unable to init SSD1306");
    }

    Log.i(TAG, "Completed init");
}
 
开发者ID:hongcheng79,项目名称:androidthings,代码行数:50,代码来源:OLEDBlock.java

示例13: onButtonEvent

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
@Override
public void onButtonEvent(Button button, boolean pressed) {
    Log.i(BurglarAlarmConstants.LOG_TAG, "INPUT :" + pressed);
    lastMotionState = pressed;
}
 
开发者ID:freeloki,项目名称:AndroidThings-BurglarAlarm,代码行数:6,代码来源:GpioHandler.java

示例14: openButtonA

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
public static Button openButtonA() throws IOException {
    return openButton(BOARD.getButtonA());
}
 
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:4,代码来源:RainbowHat.java

示例15: openButtonB

import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
public static Button openButtonB() throws IOException {
    return openButton(BOARD.getButtonB());
}
 
开发者ID:androidthings,项目名称:contrib-drivers,代码行数:4,代码来源:RainbowHat.java


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