Android Open Source - Pipe Main Activity






From Project

Back to project page Pipe.

License

The source code is released under:

MIT License

If you think the Android project Pipe 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.westudio.android.pipe;
//from   ww  w  .j ava  2  s  .  c o  m
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.westudio.android.protocol.AdRequest;
import com.westudio.android.protocol.AdResponse;
import com.westudio.android.protocol.Person;
import com.westudio.android.sdk.exceptions.ServiceClientError;
import com.westudio.android.sdk.http.ServiceCallback;
import com.westudio.android.sdk.http.ServiceClient;


public class MainActivity extends ActionBarActivity {

    private static final String LOG_TAG = "MainActivity";

    private Button btn;
    private EditText etName;
    private EditText etCountry;
    private EditText etCity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn = (Button)findViewById(R.id.button);
        etName = (EditText)findViewById(R.id.name);
        etCountry = (EditText)findViewById(R.id.country);
        etCity = (EditText)findViewById(R.id.city);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ServiceClient client = ServiceClient.getInstance();
                client.setServiceUrl("http://172.16.144.109:8080");

                // mock a AdRequest instance
                AdRequest request = null;
                Person p = new Person();
                p.setAddress1("China");
                p.setAddress2("Shanghai");
                p.setCity(etCity.getText().toString());
                p.setCountry(etCountry.getText().toString());
                p.setFirstName(etName.getText().toString());
                p.setId(1);
                p.setLastName("He");
                p.setPostCode("021");
                request = AdRequest.newBuilder().setAdBB("BeepBoop").setPerson(p).build();
                client.invoke(null, "", AdRequest.class, AdResponse.class, new ServiceCallback<AdResponse>() {
                    @Override
                    public void onResponse(AdResponse response) {
                        Log.v(LOG_TAG, "response size: " + response.getAds().size());
                        Toast.makeText(MainActivity.this, response.getAds().get(0).getFirstName(), Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onErrorResponse(ServiceClientError error) {
                        Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

com.westudio.android.pipe.ApplicationTest.java
com.westudio.android.pipe.MainActivity.java
com.westudio.android.protocol.AdRequest.java
com.westudio.android.protocol.AdResponse.java
com.westudio.android.protocol.AvroAdRequest.java
com.westudio.android.protocol.AvroAdResponse.java
com.westudio.android.protocol.Person.java
com.westudio.android.sdk.exceptions.NetworkError.java
com.westudio.android.sdk.exceptions.ServiceClientError.java
com.westudio.android.sdk.http.ResponseHandler.java
com.westudio.android.sdk.http.ServiceCallback.java
com.westudio.android.sdk.http.ServiceClient.java
com.westudio.android.sdk.loopj.android.http.AsyncHttpClient.java
com.westudio.android.sdk.loopj.android.http.AsyncHttpRequest.java
com.westudio.android.sdk.loopj.android.http.AsyncHttpResponseHandler.java
com.westudio.android.sdk.loopj.android.http.RequestParams.java
com.westudio.android.sdk.loopj.android.http.ResponseHandlerInterface.java
com.westudio.android.sdk.loopj.android.http.SimpleMultipartEntity.java
com.westudio.android.sdk.utils.ALog.java
com.westudio.android.sdk.utils.Serializer.java