Back to project page NetworkFacade.
The source code is released under:
Apache License
If you think the Android project NetworkFacade 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.saguinav.networkfacade.sample; //ww w. j a v a 2s. c o m import android.app.Activity; import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.SearchView; import android.widget.Toast; import java.util.List; public class MainActivity extends Activity implements HeadlessFragment.Presenter { private static final String HEADLESS_FRAGMENT_TAG = "HEADLESS_FRAGMENT_TAG"; private HeadlessFragment mHeadlessFragment; private ProgressBar mProgressBar; private ListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mListView = (ListView) findViewById(android.R.id.list); mHeadlessFragment = (HeadlessFragment) getFragmentManager().findFragmentByTag(HEADLESS_FRAGMENT_TAG); if (mHeadlessFragment == null) { mHeadlessFragment = new HeadlessFragment(); getFragmentManager().beginTransaction() .add(mHeadlessFragment, HEADLESS_FRAGMENT_TAG) .commit(); } handleIntent(getIntent()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the options menu from XML MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.search, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default return true; } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); handleIntent(intent); } private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); doSearch(query); } } private void doSearch(String query) { mHeadlessFragment.searchRepositories(query); } @Override public void showProgress() { mProgressBar.setVisibility(View.VISIBLE); mListView.setVisibility(View.GONE); } @Override public void showRepositories(List<Repository> repositories) { mProgressBar.setVisibility(View.GONE); mListView.setVisibility(View.VISIBLE); mListView.setAdapter(new ArrayAdapter<Repository>(this, android.R.layout.simple_list_item_1, repositories)); } @Override public void showError(String error) { Toast.makeText(this, error, Toast.LENGTH_LONG).show(); } }