Android Open Source - receiver-test-app-android Welcome Fragment






From Project

Back to project page receiver-test-app-android.

License

The source code is released under:

Apache License

If you think the Android project receiver-test-app-android 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 com.castframework.android;
//from  w  w  w  .  j  av a  2 s  . c o  m
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.davidtschida.android.cards.R;
import com.castframework.android.framework.OnCastConnectedListener;
import com.castframework.android.framework.OnMessageReceivedListener;

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

public class WelcomeFragment extends CastFragment implements OnMessageReceivedListener, OnCastConnectedListener {

    EditText send;
    Button sendButton;
    TextView receive;

    public WelcomeFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.welcome, container, false);
        send = (EditText) rootView.findViewById(R.id.send);
        sendButton = (Button) rootView.findViewById(R.id.sendButton);
        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    JSONObject o = new JSONObject(send.getText().toString());
                    host.getCastmanager().sendMessage(o);
                } catch(JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        receive = (TextView) rootView.findViewById(R.id.receive);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


    }

    @Override
    public void onMessageRecieved(JSONObject json) {
        try {
            Toast.makeText(getActivity(), "MOOO "+json.toString(4), Toast.LENGTH_LONG).show();
            receive.setText(json.toString(4));
        } catch(JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onCastConnected() {
        Toast.makeText(getActivity(), "Connected!", Toast.LENGTH_LONG).show();
    }
}




Java Source Code List

.CastmanagerHost.java
com.castframework.android.CastFragment.java
com.castframework.android.CastmanagerHost.java
com.castframework.android.MainActivity.java
com.castframework.android.WelcomeFragment.java
com.castframework.android.framework.CastApplication.java
com.castframework.android.framework.CastManager.java
com.castframework.android.framework.OnCastConnectedListener.java
com.castframework.android.framework.OnMessageReceivedListener.java