Back to project page Itune.
The source code is released under:
MIT License
If you think the Android project Itune 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 com.ripoff.itune; /* w w w.j a v a 2 s .c o m*/ import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.text.Editable; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.os.Build; import android.content.Intent; public class MainActivity extends ActionBarActivity { public final static String KEY_URL = "com.ripoff.itune.URL"; public final static String KEY_LIMIT = "com.ripoff.itune.LIMIT"; public final static String GET_LIMIT = "&limit="; public final static String GET_TERM="term="; public static final String URL_ITUNE = "http://itunes.apple.com/search?"; public void fetchPage(View view){ Intent intent = new Intent(this, HttpFetchActivity.class); startActivity(intent); } /** Called when the user clicks the 'Go!' button */ public void makeQuery(View view) { //Create intent to fetch and process information from iTunes API Intent intent = new Intent(this, HttpFetchActivity.class ); //To store the users input values String input; //Input for 'Term' EditText editText = (EditText) findViewById(R.id.edit_message); input = editText.getText().toString(); //construct URL with GET request for 'Term' StringBuilder stringBuild = new StringBuilder(); stringBuild.append(GET_TERM).append(input); //Input for 'Limit' editText = (EditText) findViewById(R.id.edit_limit); input = editText.getText().toString(); //Append URL with GET request for 'Limit' stringBuild.append(GET_LIMIT).append(input); String iValue = URL_ITUNE + stringBuild.toString(); /* Example of the iValue variable: http://itunes.apple.com/search?term=T.Mills&limit=1 */ //Send the constructed URL and 'Limit' to the intent //'Limit' is passed for future activities intent.putExtra(KEY_URL, iValue); intent.putExtra(KEY_LIMIT, input); //Start the intent startActivity(intent); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /*if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit(); }*/ } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main , menu); return super.onCreateOptionsMenu(menu); } @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. switch (item.getItemId()) { case R.id.action_search: /*Display the input layout only if user hits search action button*/ getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit(); return true; default: return super.onOptionsItemSelected(item); } } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } } }