Android Open Source - rock-paper-scissors Notification Update Service






From Project

Back to project page rock-paper-scissors.

License

The source code is released under:

MIT License

If you think the Android project rock-paper-scissors listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package au.com.codeka.rps;
/*from ww w . j a  va  2 s  . com*/
import android.content.Intent;

import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.WearableListenerService;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import au.com.codeka.rps.game.StateManager;

public class NotificationUpdateService extends WearableListenerService {
    @Override
    public void onMessageReceived(MessageEvent msgEvent) {
        if (msgEvent.getPath().equals("/rps/StartGame")) {
            Intent startIntent = new Intent(this, GameActivity.class);
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startIntent);
        } else if (msgEvent.getPath().equals("/rps/StateChange")) {
            String newStateName = null;
            try {
                newStateName = new String(msgEvent.getData(), "utf-8");
            } catch (UnsupportedEncodingException e) {
            }

            StateManager.i.enterState(newStateName);
        } else if (msgEvent.getPath().equals("/rps/FinalResult")) {
            String str = null;
            try {
                str = new String(msgEvent.getData(), "utf-8");
            } catch (UnsupportedEncodingException e) {
            }

            try {
                JSONObject json = new JSONObject(str);
                StateManager.i.onFinalResult(json);
            } catch (JSONException e) {
            }
        }
    }
}




Java Source Code List

au.com.codeka.rps.ApplicationTest.java
au.com.codeka.rps.DebugLog.java
au.com.codeka.rps.FindingOpponentFragment.java
au.com.codeka.rps.GameActivity.java
au.com.codeka.rps.GameFragment.java
au.com.codeka.rps.MessageListenerService.java
au.com.codeka.rps.NotificationUpdateService.java
au.com.codeka.rps.PhoneConnection.java
au.com.codeka.rps.ResultFragment.java
au.com.codeka.rps.SplashActivity.java
au.com.codeka.rps.WatchConnection.java
au.com.codeka.rps.game.AwaitingPlayerChoiceState.java
au.com.codeka.rps.game.AwaitingPlayerChoiceState.java
au.com.codeka.rps.game.AwaitingResultState.java
au.com.codeka.rps.game.AwaitingResultState.java
au.com.codeka.rps.game.DisplayingResultState.java
au.com.codeka.rps.game.DisplayingResultState.java
au.com.codeka.rps.game.FindingOpponentState.java
au.com.codeka.rps.game.FindingOpponentState.java
au.com.codeka.rps.game.GameRunningState.java
au.com.codeka.rps.game.GameRunningState.java
au.com.codeka.rps.game.MatchInfo.java
au.com.codeka.rps.game.ResultInfo.java
au.com.codeka.rps.game.StateManager.java
au.com.codeka.rps.game.StateManager.java
au.com.codeka.rps.game.State.java
au.com.codeka.rps.game.State.java