1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

muiのサンプルで点灯イベントを取得する

Posted at

この記事について

muiを入手したので、その開発情報を自分用にまとめたものです。

mui Developer Editionで遊んでみる(準備編)
mui Developer Editionで遊んでみる(HOME画面のカスタマイズ)
mui Developer EditionでSORACOMを使ってみる

点灯イベントを取得したい

muiのサンプルアプリケーションは、点灯してしばらくすると自動で消灯します。その状態でタッチすることで表示が復帰します。自分でアプリを作る場合、点灯復帰時に何か処理をしたくなることがあるかと思います。(例えば、センサーの値を最新に更新するとか)
サンプルアプリでは、消灯時のイベントは取れるのですが、タッチしての点灯復帰時のイベントが取れません。
そこで、サンプルを少し改造して点灯復帰時のイベントを取得できるようにしてみます。

対応方法

muiのサンプルでは各画面の表示状態をAbsAppクラスを継承して作っています。そこで、まずは点灯イベントのメソッドを追加した派生クラスを作成します。

class MyMUIApp(AbsApp):
    def __init__(self, appEventListener: AppEventListener):
        super().__init__(appEventListener)
        
    def onTurnOnDisplay(self):
        raise NotImplementedError

次に、各アプリケーションの定義をAbsAppではなく、ここで定義したMyMUIAppを継承するように修正します。

class DummyWeatherApp(MyMUIApp):
class DummyThermoApp(MyMUIApp):
class HomeApp(MyMUIApp, OnUpdateRequestListener, OnTouchEventListener):

修正をしたら各クラスの中でonTurnOnDisplay()メソッドを実装します。

次に、実際の呼び出し処理を追加します。点灯復帰処理はMuiMainクラスのonInputEvent()で処理が行われています。ここで、点灯復帰する際に先に定義したメソッドを呼び出すようにします。

    def onInputEvent(self, e: MotionEvent):
        if self.display_manager.on is False:
            self.app.onTurnOnDisplay()
            self.display_manager.on = True
            self.updateUI(fade=3, turn_on=True)

        # dispath touch event to current application
        self.app.dispatchTouchEvent(e)

        # pass to gesture detector
        self.gesture_detector.onTouchEvent(e)

        # reset display turn off timer
        self.display_manager.startDismissTimer()

これらの修正で点灯復帰時に処理を行うことが出来るようになりました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?