Back to project page mobile-android.
The source code is released under:
MIT License
If you think the Android project mobile-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.
package com.manyconf.conference; //from ww w. ja v a 2 s . c o m import android.app.Activity; import android.app.Application; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.content.LocalBroadcastManager; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import com.crashlytics.android.Crashlytics; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; public class MainActivity extends Activity implements View.OnClickListener { private Button reloadButton; private ListView mainListView; private ArrayAdapter mArrayAdapter; private Toast mToast; // Hashmap for ListView private LinkedHashMap<Integer, ConferenceModel> conferenceList; @Override protected void onCreate(Bundle savedInstanceState) { Log.d("manyconf.main", "onCreate()"); super.onCreate(savedInstanceState); Crashlytics.start(this); requestWindowFeature(Window.FEATURE_NO_TITLE); // Remove titlebar for this activity setContentView(R.layout.activity_main); this.reloadButton = (Button)this.findViewById(R.id.reload); this.reloadButton.setOnClickListener(this); mToast = Toast.makeText(this, "" , Toast.LENGTH_LONG); // this.reloadButton.setVisibility(View.GONE); // Kick off network action. Upon receiving an answer, forward to next screen. // See also: // http://stackoverflow.com/questions/2704084/how-to-launch-an-activity-without-a-ui this.fetchConferences(); } @Override public void onClick(View v) { Log.d("manyconf.main", "onClick()"); this.fetchConferences(); } public void fetchConferences() { Log.d("manyconf.main", "fetchConferences()"); // reloadButton.setVisibility(View.GONE); mToast.setText("Getting list of conferences"); mToast.show(); ((ConferenceApplication)getApplication()).fetchConferences(); } @Override protected void onResume() { super.onResume(); Log.d("manyconf.main", "onResume()"); LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("SERVICE_HANDLER_RESULT")); this.fetchConferences(); } @Override protected void onPause() { Log.d("manyconf.main", "onPause()"); // Unregister since the activity is about to be closed. LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); super.onPause(); } // Our handler will be called whenever the ConferenceBuilder gets results. private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d("manyconf.main", "onReceive()"); String err = ((ConferenceApplication) getApplication()).getLastError(); if (err != null) { String msg = String.format("Error: %s", err); Log.d("manyconf.main", msg); mToast.setText(msg); mToast.show(); reloadButton.setVisibility(View.VISIBLE); } else { conferenceList = ((ConferenceApplication) getApplication()).getConferenceList(); if(conferenceList == null) { mToast.setText("Internal error: no conferences received"); mToast.show(); } else { Log.d("manyconf.main", String.format("Got %d conferences", conferenceList.size())); mToast.cancel(); if(Const.singleConfApp) { Intent detailIntent = new Intent(context, ConferenceDetailActivity.class); detailIntent.putExtra("conferenceListID", Const.singleConfAppID); startActivity(detailIntent); } else { Intent i = new Intent(context, ConferenceListActivity.class); startActivity(i); } } } } }; }