Android Open Source - ScoponeDaPolso Wear Main Activity






From Project

Back to project page ScoponeDaPolso.

License

The source code is released under:

GNU General Public License

If you think the Android project ScoponeDaPolso 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 org.gdg.bari.scopone.activity;
//w  w  w.  j a  v a 2 s  . c o m
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.wearable.DataMap;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mariux.teleport.lib.TeleportClient;

import org.gdg.bari.entities.Card;
import org.gdg.bari.scopone.R;
import org.gdg.bari.scopone.fragment.CardListFragment;

import java.lang.reflect.Type;
import java.util.List;

public class WearMainActivity extends Activity {
    private static final String TAG = WearMainActivity.class.getSimpleName();
    private TeleportClient mTeleportClient;
    private TextView mTextView;
    private HandReceiver mHandReceiver;
    public static final String HAND_ACTION = "handReceiver";
    private IntentFilter handIntentFilter = new IntentFilter(HAND_ACTION);
    private String jsonHand;
    private Gson gson;
    private List<Card> hand;
    //fragment
    private CardListFragment mCardListFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wear_main);
        mTeleportClient = new TeleportClient(this);
        mHandReceiver = new HandReceiver();
        gson = new Gson();
        final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
        stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
            @Override
            public void onLayoutInflated(WatchViewStub stub) {
                mCardListFragment = new CardListFragment();
                getFragmentManager().beginTransaction().replace(R.id.wear_fragment_container, mCardListFragment).commit();
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        mTeleportClient.connect();
        registerReceiver(mHandReceiver, handIntentFilter);
    }

    @Override
    protected void onStop() {
        super.onStop();
        mTeleportClient.disconnect();
        unregisterReceiver(mHandReceiver);
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    //BROADCAST RECEIVER
    public class HandReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            jsonHand = intent.getExtras().getString("jsonHand");
            Log.d(TAG, "WearMainActivity:OnReceive()");
            //Log.d(TAG, jsonHand);
            Type cardListType = new TypeToken<List<Card>>() {}.getType();
            hand = gson.fromJson(jsonHand, cardListType);

            for(Card card: hand){
                (mCardListFragment.getCardsAdapter()).add(card);
            }
            (mCardListFragment.getCardsAdapter()).notifyDataSetChanged();

        }
    }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.BaseGameUtils.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
com.mariux.teleport.lib.ApplicationTest.java
com.mariux.teleport.lib.TeleportClient.java
com.mariux.teleport.lib.TeleportService.java
org.gdg.bari.entities.ApplicationTest.java
org.gdg.bari.entities.Card.java
org.gdg.bari.entities.Constants.java
org.gdg.bari.entities.Deck.java
org.gdg.bari.entities.Score.java
org.gdg.bari.entities.TableTurn.java
org.gdg.bari.entities.Table.java
org.gdg.bari.entities.TeleportClientManager.java
org.gdg.bari.scopone.ApplicationTest.java
org.gdg.bari.scopone.activity.MobileGameActivity.java
org.gdg.bari.scopone.activity.MobileMainActivity.java
org.gdg.bari.scopone.activity.WearConfirmationActivity.java
org.gdg.bari.scopone.activity.WearMainActivity.java
org.gdg.bari.scopone.fragment.CardListFragment.java
org.gdg.bari.scopone.fragment.GameFragment.java
org.gdg.bari.scopone.fragment.LoginFragment.java
org.gdg.bari.scopone.fragment.MenuFragment.java
org.gdg.bari.scopone.service.MobileTeleportService.java
org.gdg.bari.scopone.services.WearTeleportService.java
org.gdg.bari.scopone.util.GoogleApiClientManager.java
org.gdg.bari.scopone.util.LogUtil.java