9

注: これは Samsung 固有の質問であるため、開発者ボードでも質問しました。

現在、Android でライブ壁紙を実装しており、壁紙エンジンで onOffsetsChanged() メソッドをリッスンして、ユーザーがホームスクリーンをスワイプしたときに壁紙を変更しています。これは、CM9 カスタム ROM を使用した私のプライベート Galaxy Tab でうまく機能します。私の会社のデバイスである在庫のGalaxy S3では、機能しません。どういうわけか、ホーム画面が変更されたときに Touchwiz が onOffsetsChanged を呼び出さない。

トピックのグーグル検索では、このアプリの説明以外に重要な結果は得られませんでした。開発者は次のように述べています。今は開発者に連絡するだけですが、残念ながらこれも Samsung アプリです。

onOffsetsChanged に依存せずに現在のオフセットを取得するための回避策を知っている人はいますか? 自分の壁紙でこの問題に遭遇した人はいますか? これが意図的なものなのか、それとも将来のTouchwizバージョンでこの方法が再び使用されると想定できるのか、誰かが知っていますか?

4

1 に答える 1

7

Some developers are using touch events instead of system onOffsetsChanged() to work with TouchWiz. I think, currently the only better way is using the hybrid event system, which will work in such way:

1) Always assume that onOffsetsChanged() message is not sent correctly (make boolean property defaulting to false).
2) This means that you should implement onTouch() method to make the proper imitation of onOffsetsChanged(). Listen to onTouch() only if the boolean property is still false.
3) When onOffsetsChanged() is called, check the xOffset param. If it's neither 0.0f nor 0.5f, then change the boolean property to true and listen only to onOffsetsChanged().

Code will be sth like:

public class myEngine extends WallpaperService.Engine {
    private boolean offsetChangedWorking = false;

    public void onOffsetsChanged (float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {
        if (offsetChangedWorking == false && xOffset != 0.0f && xOffset != 0.5f) {
            offsetChangedWorking = true;
        }

        if (offsetChangedWorking == true) {
            // Do sth here
        }
    }

    public void onTouchEvent(MotionEvent paramMotionEvent) {
        if (offsetChangedWorking == false) {
            // Do sth else here
        }
    }
}

This code is only an illustration. Note, that comparing floats with == is not correct, but it might work in this case.

Also, it looks like Samsung Parallax LWPs are working the same way. If you have a device with TouchWiz and some other properly working launcher (which sends onOffsetsChanged() normally), you can try it by yourself:

1) Set parallax LWP on TouchWiz first (important!) and see that it depends only on onTouchEvent()
2) Change the launcher to the other one. See that LWP now depends on onOffsetsChanged()
3) Change the launcher to TouchWiz again and see that swiping doesn't work for this LWP anymore.

So what i recommend to add is on every onResume() event change the boolean offsetChangedWorking to false again. This should prevent such bugs with launcher changes.

于 2013-03-28T14:40:17.753 に答える