Back to project page ScoponeDaPolso.
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.
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(); } } }