Android Open Source - mobile-android Conference Detail Activity






From Project

Back to project page mobile-android.

License

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.

Java Source Code

package com.manyconf.conference;
//  w  w w .  j av  a2 s.  c  o m
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Locale;

public class ConferenceDetailActivity extends Activity implements AdapterView.OnItemClickListener {

    private ConferenceModel conference;
    private int conferenceListID;
    public static final String mod = "manyconf.cdeta";

    private DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(mod, "onCreate()");
        super.onCreate(savedInstanceState);

        if(Const.singleConfApp) {
            Log.d(mod, "Using single-conference layout");
            requestWindowFeature(Window.FEATURE_NO_TITLE);  // Remove titlebar for this activity
            setContentView(R.layout.activity_single_conference);
        } else {
            Log.d(mod, "Using default layout");
            setContentView(R.layout.activity_conference_detail);
        }

        // Retrieve conference that we should display
        LinkedHashMap<Integer, ConferenceModel> conferenceList = ((ConferenceApplication)getApplication()).getConferenceList();
        conferenceListID = this.getIntent().getExtras().getInt("conferenceListID");
        conference = conferenceList.get(conferenceListID);

        // Set up user interface
        TextView nameTextView = (TextView) findViewById(R.id.name);
        nameTextView.setTypeface(Theme.current().boldFont);
        TextView descriptionTextView = (TextView) findViewById(R.id.description);
        descriptionTextView.setTypeface(Theme.current().regularFont);
        descriptionTextView.setMovementMethod(new ScrollingMovementMethod());
        TextView dateTextView  = (TextView) findViewById(R.id.startEndDate);
        dateTextView.setTypeface(Theme.current().regularFont);
        ListView navListView = (ListView) findViewById(R.id.navigation_listview);
        ImageView logoImageView = (ImageView) findViewById(R.id.logo);


        // Error checking
        if(conference == null) {
            // This can happen if the conference was deleted from the database
            String msg = String.format("Couldn't get conference for ID %d", conferenceListID);
            Log.e(mod, msg);

            nameTextView.setText("Couldn't find conference!");
            dateTextView.setText("");
            descriptionTextView.setText("This conference could not be found, perhaps it has " +
                    "already happened? Get the ManyConf client in the Google Play store!");
            return;
        }

        // Fill user interface
        nameTextView.setText(conference.name);
        descriptionTextView.setText(conference.description);

        if(conference.startdate != null && conference.enddate != null) {
            dateTextView.setText(dateFormat.format(conference.startdate) + " to " + dateFormat.format(conference.enddate));
        } else if(conference.startdate != null && conference.enddate == null) {
            dateTextView.setText(dateFormat.format(conference.startdate));
        }

        // Fill list view
        ArrayList<String> navArray = new ArrayList<String>();
        if(conference.nTotalPresentations > 0) {
            navArray.add(String.format("%d %s", conference.nTotalPresentations, "presentations"));
        }
        if(conference.speakers.size() > 0) {
            navArray.add(String.format("%d %s", conference.speakers.size(), "speakers"));
        }

        // Create an ArrayAdapter for the ListView
        String[] tmp = navArray.toArray(new String[navArray.size()]);
        ConferenceDetailAdapter navArrayAdapter = new ConferenceDetailAdapter(this,
                android.R.layout.simple_list_item_1,
                tmp);

        // Connect list view to adapter and listener
        navListView.setAdapter(navArrayAdapter);
        navArrayAdapter.notifyDataSetChanged();
        navListView.setOnItemClickListener(this);

        // Fill any images in a background thread
//        new FillTeaserImages().execute();
    }

    @Override
    public void onBackPressed() {
        if(Const.singleConfApp) {
            Log.d(mod, "Single-conference app can't go back");
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {
        Log.d(mod, "clicked");

        if(conference.nTotalPresentations > 0) {
            // There are presentations, show navigation to that screen
            if(position == 0) {
                Log.d(mod, "show all tracks and presentations");
                Intent scheduleIntent = new Intent(this, ScheduleActivity.class);
                scheduleIntent.putExtra("conferenceListID", conferenceListID);
                startActivity(scheduleIntent);
            } else {
                Log.d(mod, "show all speakers");
                Intent detailIntent = new Intent(this, SpeakerListActivity.class);
                detailIntent.putExtra("conferenceListID", conferenceListID);
                startActivity(detailIntent);
            }
        } else {
            // No presentations, so perhaps there's only a speaker list
            if(conference.speakers.size() > 0) {
                Log.d(mod, "show all speakers");
                Intent detailIntent = new Intent(this, SpeakerListActivity.class);
                detailIntent.putExtra("conferenceListID", conferenceListID);
                startActivity(detailIntent);
            }
        }

    }
/*
    private class FillTeaserImages extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... arg0) {
            if(conference.teaserImages.isEmpty()) {
                return null;
            }

            ImageView imageView = (ImageView) findViewById(R.id.teaserImage);
            URL url = conference.teaserImages.get(0);
            try {
                Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                imageView.setImageBitmap(bmp);
                Log.d("manyconf.cdeta", "Set teaser image to " + url);
            } catch(IOException e) {
                Log.e("manyconf.cdeta", "Failed to retrieve teaser image from " + url);
            }
            return null;
        }

    }
*/
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.d(mod, "onOptionsItemSelected()");
        switch (item.getItemId()) {
            case android.R.id.home:
                // If user taps the Up button in the navbar, just finish()
                Log.d(mod, "finish");
                finish();
                return true;
        }
        Log.d(mod, "call super");
        return super.onOptionsItemSelected(item);
    }

    // http://stackoverflow.com/questions/7361135/how-to-change-color-and-font-on-listview
    private class ConferenceDetailAdapter extends ArrayAdapter<String> {

        public ConferenceDetailAdapter(Context context, int textViewResourceId, String[] objects) {
            super(context, textViewResourceId, objects);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {


            View view = super.getView(position, convertView, parent);

            TextView tv = (TextView) view;
            tv.setTypeface(Theme.current().regularFont);

            return view;
        }
    }
}




Java Source Code List

com.manyconf.conference.ConferenceApplication.java
com.manyconf.conference.ConferenceBuilderDelegate.java
com.manyconf.conference.ConferenceBuilder.java
com.manyconf.conference.ConferenceDetailActivity.java
com.manyconf.conference.ConferenceListActivity.java
com.manyconf.conference.ConferenceModel.java
com.manyconf.conference.Const.java
com.manyconf.conference.IsoDateParser.java
com.manyconf.conference.MainActivity.java
com.manyconf.conference.PresentationActivity.java
com.manyconf.conference.PresentationModel.java
com.manyconf.conference.PrivateConst.java
com.manyconf.conference.ReadFile.java
com.manyconf.conference.ScheduleActivity.java
com.manyconf.conference.ServiceHandler.java
com.manyconf.conference.SpeakerActivity.java
com.manyconf.conference.SpeakerListActivity.java
com.manyconf.conference.SpeakerModel.java
com.manyconf.conference.Theme.java
com.manyconf.conference.ThemedArrayAdapter.java
com.manyconf.conference.TrackModel.java