Example usage for android.widget TabHost addTab

List of usage examples for android.widget TabHost addTab

Introduction

In this page you can find the example usage for android.widget TabHost addTab.

Prototype

public void addTab(TabSpec tabSpec) 

Source Link

Document

Add a tab.

Usage

From source file:org.smap.smapTask.android.activities.MainTabsActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // must be at the beginning of any activity that can be called from an external intent
    try {/*from  w w w . j a v  a2s .  c  o  m*/
        Collect.createODKDirs();
    } catch (RuntimeException e) {
        createErrorDialog(e.getMessage(), true);
        return;
    }

    setContentView(R.layout.main_tabs);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec;
    Intent intent;

    tabHost.setBackgroundColor(Color.WHITE);
    tabHost.getTabWidget().setBackgroundColor(Color.DKGRAY);

    // Initialise a TabSpec and intent for each tab and add it to the TabHost
    intent = new Intent().setClass(this, MainListActivity.class);
    spec = tabHost.newTabSpec("taskList").setIndicator(getString(R.string.smap_taskList)).setContent(intent);
    tabHost.addTab(spec);

    /*
     * Initialise a Map tab
     */
    Log.i("trial", "Creating Maps Activity");
    intent = new Intent().setClass(this, MapsActivity.class);
    spec = tabHost.newTabSpec("taskMap").setIndicator(getString(R.string.smap_taskMap)).setContent(intent);
    tabHost.addTab(spec);

    // hack to set font size
    LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
    TabWidget tw = (TabWidget) ll.getChildAt(0);

    int fontsize = Collect.getQuestionFontsize();

    ViewGroup rllf = (ViewGroup) tw.getChildAt(0);
    mTVFF = getTextViewChild(rllf);
    if (mTVFF != null) {
        mTVFF.setTextSize(fontsize);
        mTVFF.setTextColor(Color.WHITE);
        mTVFF.setPadding(0, 0, 0, 6);
    }

    ViewGroup rlrf = (ViewGroup) tw.getChildAt(1);
    mTVDF = getTextViewChild(rlrf);
    if (mTVDF != null) {
        mTVDF.setTextSize(fontsize);
        mTVDF.setTextColor(Color.WHITE);
        mTVDF.setPadding(0, 0, 0, 6);
    }

}

From source file:nl.spellenclubeindhoven.dominionshuffle.SelectActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.select);//from   w w  w  .  j  ava  2 s.c  o  m

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    application = (Application) getApplication();
    dataReader = application.getDataReader();
    cardSelector = application.getCardSelector();

    TabHost tabs = getTabHost();

    TabHost.TabSpec spec = tabs.newTabSpec("inex");
    spec.setContent(R.id.inex_fastscrollview);
    spec.setIndicator(getResources().getString(R.string.tab_select),
            getResources().getDrawable(R.drawable.select_tab));
    tabs.addTab(spec);

    spec = tabs.newTabSpec("constraint");
    spec.setContent(R.id.constraint_fastscrollview);
    spec.setIndicator(getResources().getString(R.string.tab_constraints),
            getResources().getDrawable(R.drawable.limits_tab));
    tabs.addTab(spec);

    spec = tabs.newTabSpec("generate");
    spec.setContent(R.id.generateButtons);
    spec.setIndicator(getResources().getString(R.string.tab_generate),
            getResources().getDrawable(R.drawable.shuffle_tab));
    tabs.addTab(spec);

    inexFastScrollView = ((CustomFastScrollView) findViewById(R.id.inex_fastscrollview));
    inexFastScrollView.setOnScrollListener(this);

    constraintFastScrollView = ((CustomFastScrollView) findViewById(R.id.constraint_fastscrollview));
    constraintFastScrollView.setOnScrollListener(this);

    groupsAndCards = new LinkedList<Object>();

    inExAdapter = new InExAdapter(this, groupsAndCards, cardSelector, getPreferredCardComparator());
    inexList = (ListView) findViewById(R.id.inexList);
    inexList.setAdapter(inExAdapter);
    inexList.setOnItemClickListener(onItemClickListener);
    inexList.setOnItemLongClickListener(onItemLongClickListener);

    constraintList = (ListView) findViewById(R.id.constraintList);
    constraintAdapter = new ConstraintAdapter(this, groupsAndCards, cardSelector, getPreferredCardComparator());
    constraintList.setAdapter(constraintAdapter);
    constraintList.setOnItemClickListener(onItemClickListener);
    constraintList.setOnTouchListener(onConstraintListTouchListener);
    constraintList.setOnKeyListener(onConstraintKeyListener);
    constraintList.setOnItemLongClickListener(onItemLongClickListener);

    Button generateButton = (Button) findViewById(R.id.generateButton);
    generateButton.setOnClickListener(onGenerateClickListener);

    Button lastResultButton = (Button) findViewById(R.id.lastResultButton);
    lastResultButton.setOnClickListener(onLastResultClickListener);

    if (savedInstanceState != null) {
        dialogMessage = savedInstanceState.getString("dialogMessage");
        if (dataReader.getData() != null) {
            selectedGroup = dataReader.getData().getGroup(savedInstanceState.getString("selectedGroup"));
        }
    }

    SharedPreferences prefs = getPreferences(MODE_PRIVATE);

    dialogMimimumCount = getResources().getStringArray(R.array.minumum_items_conditional).length;
    dialogMaximumCount = getResources().getStringArray(R.array.maximum_items).length;
}

From source file:org.exobel.routerkeygen.ui.Preferences.java

protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new Builder(this);
    switch (id) {
    case DIALOG_ABOUT: {
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.about_dialog, (ViewGroup) findViewById(R.id.tabhost));
        TabHost tabs = (TabHost) layout.findViewById(R.id.tabhost);
        tabs.setup();/*from   www.  j a  v  a 2  s .c  o m*/
        TabSpec tspec1 = tabs.newTabSpec("about");
        tspec1.setIndicator(getString(R.string.pref_about));

        tspec1.setContent(R.id.text_about_scroll);
        TextView text = ((TextView) layout.findViewById(R.id.text_about));
        text.setMovementMethod(LinkMovementMethod.getInstance());
        text.append(VERSION + "\n" + LAUNCH_DATE);
        tabs.addTab(tspec1);
        TabSpec tspec2 = tabs.newTabSpec("credits");
        tspec2.setIndicator(getString(R.string.dialog_about_credits));
        tspec2.setContent(R.id.about_credits_scroll);
        ((TextView) layout.findViewById(R.id.about_credits))
                .setMovementMethod(LinkMovementMethod.getInstance());
        tabs.addTab(tspec2);
        TabSpec tspec3 = tabs.newTabSpec("license");
        tspec3.setIndicator(getString(R.string.dialog_about_license));
        tspec3.setContent(R.id.about_license_scroll);
        ((TextView) layout.findViewById(R.id.about_license))
                .setMovementMethod(LinkMovementMethod.getInstance());
        tabs.addTab(tspec3);
        builder.setNeutralButton(R.string.bt_close, new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                removeDialog(DIALOG_ABOUT);

            }
        });
        builder.setView(layout);
        break;
    }
    case DIALOG_ASK_DOWNLOAD: {
        DialogInterface.OnClickListener diOnClickListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // Check if we have the latest dictionary version.
                try {
                    checkCurrentDictionary();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        builder.setTitle(R.string.pref_download);
        builder.setMessage(R.string.msg_dicislarge);
        builder.setCancelable(false);
        builder.setPositiveButton(android.R.string.yes, diOnClickListener);
        builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                removeDialog(DIALOG_ASK_DOWNLOAD);
            }
        });
        break;
    }
    case DIALOG_UPDATE_NEEDED: {
        builder.setTitle(R.string.update_title)
                .setMessage(getString(R.string.update_message, lastVersion.version))
                .setNegativeButton(R.string.bt_close, new OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        removeDialog(DIALOG_UPDATE_NEEDED);
                    }
                }).setPositiveButton(R.string.bt_website, new OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(lastVersion.url)));
                    }
                });
        break;
    }
    case DIALOG_WAIT: {
        ProgressDialog pbarDialog = new ProgressDialog(Preferences.this);
        pbarDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pbarDialog.setMessage(getString(R.string.msg_wait));
        return pbarDialog;
    }
    case DIALOG_ERROR_TOO_ADVANCED: {
        builder.setTitle(R.string.msg_error).setMessage(R.string.msg_err_online_too_adv);
        break;
    }
    case DIALOG_ERROR: {
        builder.setTitle(R.string.msg_error).setMessage(R.string.msg_err_unkown);
        break;
    }
    case DIALOG_CHANGELOG: {
        LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ChangeLogListView chgList = (ChangeLogListView) layoutInflater.inflate(R.layout.dialog_changelog,
                (ViewGroup) this.getWindow().getDecorView().getRootView(), false);
        builder.setTitle(R.string.pref_changelog).setView(chgList).setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                });
        break;
    }
    }
    return builder.create();
}

From source file:fr.mixit.android.ui.StarredActivity.java

/** Build and add "sessions" tab. */
private void setupSessionsTab() {
    final TabHost host = getTabHost();

    final Uri uri = MixItContract.Sessions.CONTENT_STARRED_URI.buildUpon()
            .appendQueryParameter(MixItContract.SessionCounts.SESSION_INDEX_EXTRAS, Boolean.TRUE.toString())
            .build();/*from w  w  w .j  a  v a  2 s . c o  m*/
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addCategory(Intent.CATEGORY_TAB);
    final boolean highlightParalleStarred = settingsPrefs
            .getBoolean(getString(R.string.visualize_parallel_starred_sessions_key), false);
    intent.putExtra(SessionsActivity.EXTRA_HIHGLIGHT_PARALLEL_STARRED, highlightParalleStarred);
    intent.putExtra(SessionsActivity.EXTRA_FOCUS_CURRENT_NEXT_SESSION, true);

    // Sessions content comes from reused activity
    host.addTab(host.newTabSpec(TAG_SESSIONS).setIndicator(buildIndicator(R.string.starred_sessions))
            .setContent(intent));
}

From source file:com.tutor.fragment.ViewPageFragment.java

private boolean initialjfTabHostFromWeb(LayoutInflater inflater, View mView) {
    List<FDItemTyeModel> jfItems = GetjfItems();
    if (jfItems == null || jfItems.size() == 0) {
        return false;
    }/* w  ww  . ja v  a 2  s .co  m*/
    final TabHost tabHost = (TabHost) mView.findViewById(R.id.jf_tabhost);
    tabHost.setup();
    View tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
    TextView tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
    for (int i = 0; i < 3; i++) {

        if (i == 2) {
            tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
            tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
            tbTabItemTitle.setText("");
            tabHost.addTab(tabHost.newTabSpec("-1").setIndicator(tabItem).setContent(R.id.tab3));
            setJFListViewAdapter(tabHost);
            break;
        }
        switch (i) {
        case 0:
            InitialJfItemInf(jfItems.get(i).getItem_ID());
            tbTabItemTitle.setText(jfItems.get(i).getItem_Name());
            tabHost.addTab(tabHost.newTabSpec(jfItems.get(i).getItem_Name()).setIndicator(tabItem)
                    .setContent(R.id.tab1));
            break;
        case 1:
            tabItem = inflater.inflate(R.layout.tab_fd_widebg, null);
            tbTabItemTitle = (TextView) tabItem.findViewById(R.id.tvTabItemTitle);
            tbTabItemTitle.setText(jfItems.get(i).getItem_Name());
            tabHost.addTab(tabHost.newTabSpec(jfItems.get(i).getItem_Name()).setIndicator(tabItem)
                    .setContent(R.id.tab2));
            break;
        }
    }

    tabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (tabId != "-1") {
                int itemId = Integer.parseInt(jfTypesMap.get(tabId.toString()).toString());
                InitialJfItemInf(itemId);
                setJFListViewAdapter(tabHost);
            } else {
                tabHost.setCurrentTab(0);
                Intent intent = new Intent(getActivity(), MoreActivity.class);

                intent.putExtra("Flag", "jf");
                startActivity(intent);
            }
        }
    });

    return true;
}

From source file:com.mychild.view.Parent.CustomTabActivity.java

public void setUpTab() {
    final TabHost tabHost = (TabHost) findViewById(R.id.tabhost2);
    tabHost.setup();/* w w  w  .  j a  va2s .c o m*/
    tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
    class TabDef {
        public final String Indicator;//, Content;

        public TabDef(String Indicator, ListView lv) {
            this.Indicator = Indicator;
            //this.Content = Content;

        } /*TabDef*/
    }
    ; /*TabDef*/
    for (TabDef thisTab : new TabDef[] { new TabDef("Exams", examsListView),
            new TabDef("Results", examsListView) }) {

        //            final TextView contentview = new TextView(this);
        //            contentview.setText(thisTab.Content);

        View indicatorview = android.view.LayoutInflater.from(this).inflate(R.layout.tabs_bg_plain, null);
        TextView tabTitle = (TextView) indicatorview.findViewById(R.id.tabsText);
        tabTitle.setText(thisTab.Indicator);

        tabHost.addTab(tabHost.newTabSpec(thisTab.Indicator).setIndicator(indicatorview)
                .setContent(new TabHost.TabContentFactory() {
                    public View createTabContent(String tag) {
                        Log.i("Tagggggg:", tag);

                        if (tag == "Exams") {
                            return examsListView;
                        } else {
                            return examsListView;
                        }
                    } /*createTabContent*/
                }));/*TabContentFactory*/

    } /*for*/
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

/** Called when the activity is first created. */
@Override/*w  w  w  . j  ava 2  s .c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.ringtone_picker);
    CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone);
    CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music);
    CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone);
    Intent intent = getIntent();
    toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);

    Log.e("duwenhua", "ringPick get toneType:" + toneType);

    //! by duwenhua
    //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND)
    //    toneType = RINGTONE_TYPE;

    //! by duwenhua
    mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem);
    if (savedInstanceState != null) {
        mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1);
    }
    //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId);      
    mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //if(mUriForDefaultItem != null)
    //{
    //    mSelectedId = ContentUris.parseId(mUriForDefaultItem);
    //}

    //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri);   
    //String action = getIntent().getAction();
    //Log.i("lys", "PT Intent action == " + action);

    if (toneType == NOTIFICATION_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI;
    } else if (toneType == RINGTONE_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
    } else if (toneType == ALARM_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI;
    }

    if (isAvailableToCheckRingtone() == true) {
        Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType);
        if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) {
            mUriForDefaultItem = ringtone_DefaultItem.getUri();
            Log.i("lys", "RingtoneManager.getRingtone  mUriForDefaultItem== " + mUriForDefaultItem);
        } else {
            //mUriForDefaultItem = 'content/medial/';
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */
            String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(),
                    "ringtone_original");
            if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) {
                mUriForDefaultItem = Uri.parse(originalRingtone);
                Log.e("liyang", "select riongtone error  ,change to originalRingtone == " + mExistingUri);
            }
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */
            Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222");
        }

        if (mExistingUri != null) {
            Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType);
            if (ringtone != null && ringtone.getUri() != null) {
                //mUriForDefaultItem = ringtone.getUri(); 
                mExistingUri = ringtone.getUri();
                Log.i("lys", "RingtoneManager.getRingtone  mExistingUri== " + mExistingUri);
            } else {
                mExistingUri = mUriForDefaultItem;
                Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri);
            }
        }
    }

    boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false);
    Log.e("lys", "includeDrm ==" + includeDrm);
    mRingtoneManager = new RingtoneManager(this);
    mRingtoneManager.setIncludeDrm(includeDrm);
    if (toneType != -1) {
        mRingtoneManager.setType(toneType);
    }

    setVolumeControlStream(mRingtoneManager.inferStreamType());
    //   toneActivityType = mRingtoneManager.getActivityType();
    if (toneType == ALARM_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone);
    } else if (toneType == NOTIFICATION_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.notification_tone);
    }

    listView = new ListView(this);
    listView.setOnItemClickListener(this);
    //listView.setBackgroundColor(#ff5a5a5a);
    listView.setFastScrollEnabled(true);
    //listView.setFastScrollAlwaysVisible(true);
    listView.setEmptyView(findViewById(android.R.id.empty));
    //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);

    //mHasDefaultItem = true; //temp
    if (mHasDefaultItem) {
        //chengcheng
        addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default);

    }

    setDefaultRingtone();

    if (mHasSilentItem) {
        // chengcheng
        addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent);
    }
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusListener = new OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {

        }
    };

    okBtn = (Button) findViewById(R.id.ok);
    okBtn.setOnClickListener(this);
    cancelBtn = (Button) findViewById(R.id.cancel);
    cancelBtn.setOnClickListener(this);

    TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this));
    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            // stopMediaPlayer();
            createTabContent(tabId);
        }
    });
}

From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesView.java

private void addTab(final TabHost host, final int categoryId) {
    final String tabId = EmojiCategory.getCategoryName(categoryId, 0 /* categoryPageId */);
    final TabHost.TabSpec tspec = host.newTabSpec(tabId);
    tspec.setContent(R.id.emoji_keyboard_dummy);
    final ImageView iconView = (ImageView) LayoutInflater.from(getContext())
            .inflate(R.layout.emoji_keyboard_tab_icon, null);
    // TODO: Replace background color with its own setting rather than using the
    //       category page indicator background as a workaround.
    iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
    iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
    iconView.setContentDescription(mEmojiCategory.getAccessibilityDescription(categoryId));
    tspec.setIndicator(iconView);/*from  w ww  .  j a  v a  2s .  c  om*/
    host.addTab(tspec);
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // Getting the selected journey
    Journey journey = getApp().getSelectedJourney();

    // Setting up tabs
    TabHost tabs = (TabHost) findViewById(R.id.tabhost);
    tabs.setup();/*w  w w  . j  a  va  2s .c  o  m*/

    // Adding Ride tab
    TabHost.TabSpec specRide = tabs.newTabSpec("tag1");
    specRide.setContent(R.id.ride_tab);
    specRide.setIndicator("Ride");
    tabs.addTab(specRide);

    // Adding Driver tab
    TabHost.TabSpec specDriver = tabs.newTabSpec("tag2");
    specDriver.setContent(R.id.driver_tab);
    specDriver.setIndicator("Driver");
    tabs.addTab(specDriver);

    // Adding the pickup location address text
    ((AutoCompleteTextView) findViewById(R.id.pickupText))
            .setText(getIntent().getExtras().getString("pickupString"));

    // Adding the dropoff location address text
    ((AutoCompleteTextView) findViewById(R.id.dropoffText))
            .setText(getIntent().getExtras().getString("dropoffString"));

    // Drawing the pickup and dropoff locations on the map
    setPickupLocation();
    setDropOffLocation();

    // Adding image of the driver
    User driver = journey.getRoute().getOwner();
    picture = (ImageView) findViewById(R.id.mapViewPickupImage);

    // Create an object for subclass of AsyncTask
    GetImage task = new GetImage(picture, this);
    // Execute the task: Get image from url and add it to the ImageView
    task.execute(driver.getPictureURL());

    // Adding the name of the driver
    ((TextView) findViewById(R.id.mapViewPickupTextViewName)).setText(driver.getFullName());

    // Getting the drivers preferences for this ride
    TripPreferences pref = journey.getTripPreferences();

    // Setting the smoking preference
    if (pref.getSmoking()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewSmokingIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewSmokingIcon))
                .setImageResource(R.drawable.red_cross);
    }
    // Setting the animals preference
    if (pref.getAnimals()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewAnimalsIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewAnimalsIcon))
                .setImageResource(R.drawable.red_cross);
    }
    // Setting the breaks preference
    if (pref.getBreaks()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewBreaksIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewBreaksIcon))
                .setImageResource(R.drawable.red_cross);
    }
    // Setting the music preference
    if (pref.getMusic()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewMusicIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewMusicIcon)).setImageResource(R.drawable.red_cross);
    }
    // Setting the talking preference
    if (pref.getTalking()) {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewTalkingIcon))
                .setImageResource(R.drawable.green_check);
    } else {
        ((ImageView) findViewById(R.id.mapViewPickupImageViewTalkingIcon))
                .setImageResource(R.drawable.red_cross);
    }

    // Setting the number of available seats
    ((TextView) findViewById(R.id.mapViewPickupTextViewSeats))
            .setText(pref.getSeatsAvailable() + " available seats");

    // Setting the age of the driver
    ((TextView) findViewById(R.id.mapViewPickupTextViewAge)).setText("Age: " + driver.getAge());

    // Adding the gender of the driver
    if (driver.getGender() != null) {
        if (driver.getGender().equals("m")) {
            ((ImageView) findViewById(R.id.mapViewPickupImageViewGender)).setImageResource(R.drawable.male);
        } else if (driver.getGender().equals("f")) {
            ((ImageView) findViewById(R.id.mapViewPickupImageViewGender)).setImageResource(R.drawable.female);
        }
    }

    // Addring the rating of the driver
    ((TextView) findViewById(R.id.recommendations)).setText("Recommendations: " + (int) driver.getRating());

    // Setting the drivers mobile number
    ((TextView) findViewById(R.id.mapViewPickupTextViewPhone)).setText("Mobile: " + driver.getPhone());

    try {
        // Getting the car image
        Car dummyCar = new Car(driver.getCarId(), "Dummy", 0.0); //"Dummy" and 0.0 are dummy vars. getApp() etc sends the current user's carid
        Request carReq = new CarRequest(RequestType.GET_CAR, getApp().getUser(), dummyCar);
        CarResponse carRes = (CarResponse) RequestTask.sendRequest(carReq, getApp());
        Car car = carRes.getCar();
        Bitmap carImage = BitmapFactory.decodeByteArray(car.getPhoto(), 0, car.getPhoto().length);

        // Setting the car image
        ((ImageView) findViewById(R.id.mapViewPickupImageViewCar)).setImageBitmap(carImage);

        // Setting the car name
        ((TextView) findViewById(R.id.mapViewPickupTextViewCarName)).setText("Car type: " + car.getCarName());

        // Setting the comfort
        ((RatingBar) findViewById(R.id.mapViewPickupAndDropoffComfortStars))
                .setRating((float) car.getComfort());

    } catch (ClientProtocolException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (ExecutionException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // Adding the date of ride
    Date d = journey.getStart().getTime();
    SimpleDateFormat sdfDate = new SimpleDateFormat("MMM dd yyyy");
    SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm zzz");
    String dateText = "Date: " + sdfDate.format(d);
    String timeText = "Time: " + sdfTime.format(d);
    ((TextView) findViewById(R.id.mapViewPickupTextViewDate)).setText(dateText + "\n" + timeText);

    //Adding Gender to the driver
    ImageView iv_image;
    iv_image = (ImageView) findViewById(R.id.gender);

    try {
        if (driver.getGender().equals("Male")) {
            Drawable male = getResources().getDrawable(R.drawable.male);
            iv_image.setImageDrawable(male);
        } else if (driver.getGender().equals("Female")) {
            Drawable female = getResources().getDrawable(R.drawable.female);
            iv_image.setImageDrawable(female);
        }
    } catch (NullPointerException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // Initializing the two autocomplete textviews pickup and dropoff
    initAutocomplete();

    // Adding onClickListener for the button "Ask for a ride"
    btnSendRequest = (Button) findViewById(no.ntnu.idi.socialhitchhiking.R.id.mapViewPickupBtnSendRequest);
    btnSendRequest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Response res;
            NotificationRequest req;

            if (pickupPoint == null || dropoffPoint == null) {
                //makeToast("You have to choose pickup point and dropoff point.");
                AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                ad.setMessage("You have to choose pickup point and dropoff point.");
                ad.setTitle("Unable to send request");
                ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });
                ad.show();
                return;
            }

            inPickupMode = true;

            String senderID = getApp().getUser().getID();
            String recipientID = getApp().getSelectedJourney().getRoute().getOwner().getID();
            String senderName = getApp().getUser().getFullName();
            String comment = ((EditText) findViewById(R.id.mapViewPickupEtComment)).getText().toString();
            int journeyID = getApp().getSelectedJourney().getSerial();

            // Creating a new notification to be sendt to the driver
            Notification n = new Notification(senderID, recipientID, senderName, comment, journeyID,
                    NotificationType.HITCHHIKER_REQUEST, pickupPoint, dropoffPoint, Calendar.getInstance());
            req = new NotificationRequest(RequestType.SEND_NOTIFICATION, getApp().getUser(), n);

            // Sending notification
            try {
                res = RequestTask.sendRequest(req, getApp());
                if (res instanceof UserResponse) {
                    if (res.getStatus() == ResponseStatus.OK) {
                        makeToast("Ride request sent to driver");
                        finish();
                    }
                    if (res.getStatus() == ResponseStatus.FAILED) {
                        if (res.getErrorMessage().contains("no_duplicate_notifications")) {
                            //makeToast("You have already sent a request on this journey");
                            AlertDialog.Builder ad = new AlertDialog.Builder(
                                    MapActivityAddPickupAndDropoff.this);
                            ad.setMessage("You have already sent a request on this ride");
                            ad.setTitle("Unable to send request");
                            ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                            ad.show();
                        } else if (res.getErrorMessage().equals("No available seats")) {
                            //makeToast("There are no available seats on this ride");
                            AlertDialog.Builder ad = new AlertDialog.Builder(
                                    MapActivityAddPickupAndDropoff.this);
                            ad.setMessage("There are no available seats on this ride");
                            ad.setTitle("Unable to send request");
                            ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                            ad.show();
                        } else if (res.getErrorMessage().equals("User already in journey")) {
                            //makeToast("You have already hitched this ride");
                            AlertDialog.Builder ad = new AlertDialog.Builder(
                                    MapActivityAddPickupAndDropoff.this);
                            ad.setMessage("You have already hitched this ride");
                            ad.setTitle("Unable to send request");
                            ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                            ad.show();
                        } else {
                            makeToast("Could not send request");
                        }
                    }
                }
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    // Adding buttons where you choose between pickup point and dropoff point
    btnSelectPickupPoint = (Button) findViewById(R.id.mapViewPickupBtnPickup);
    btnSelectPickupPoint.setBackgroundColor(notSelected);
    btnSelectDropoffPoint = (Button) findViewById(R.id.mapViewPickupBtnDropoff);
    btnSelectDropoffPoint.setBackgroundColor(notSelected);
    // Setting the selected pickup point
    btnSelectPickupPoint.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            isSelectingDropoffPoint = false;
            isSelectingPickupPoint = true;
            btnSelectPickupPoint.setBackgroundColor(selected);
            btnSelectDropoffPoint.setBackgroundColor(notSelected);
            makeToast("Press the map to add pickup location");

        }
    });

    // Setting the selected dropoff point
    btnSelectDropoffPoint.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            isSelectingDropoffPoint = true;
            isSelectingPickupPoint = false;
            btnSelectPickupPoint.setBackgroundColor(notSelected);
            btnSelectDropoffPoint.setBackgroundColor(selected);
            makeToast("Press the map to add dropoff location");
        }
    });

    // Adding message to the user
    makeToast("Please set a pickup and dropoff location.");
}

From source file:net.line2soft.preambul.views.ExcursionInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    //Check if this version of Android allows to use custom title bars
    boolean feature = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    /** Set layout **/
    //Base layout
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_excursion_info);
    //set title bar
    if (feature) {
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.activity_title_bar);
        TextView myTitleText = (TextView) findViewById(R.id.textView0);
        myTitleText.setText(getString(R.string.title_activity_excursion_info));
    }/*from  w ww . ja  v  a2 s  . c  o  m*/

    //Get excursion ID
    int id = getIntent().getIntExtra(ExcursionListActivity.EXCURSION_ID, 0);
    if (id > 0) {
        //Set listener
        listener = new ExcursionInfoListener(this);
        //Set tabs

        TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
        tabHost.setup();

        TabSpec spec1 = tabHost.newTabSpec("Info");
        spec1.setContent(R.id.tab1);
        spec1.setIndicator("", getResources().getDrawable(R.drawable.description_tab));
        spec1.setContent(R.id.tab1);

        TabSpec spec2 = tabHost.newTabSpec("POI");
        spec2.setIndicator("", getResources().getDrawable(R.drawable.pois_tab));
        spec2.setContent(R.id.tab2);

        TabSpec spec3 = tabHost.newTabSpec("Instructions");
        spec3.setIndicator("", getResources().getDrawable(R.drawable.instruction_tab));
        spec3.setContent(R.id.tab3);

        TabSpec spec4 = tabHost.newTabSpec("Photos");
        spec4.setIndicator("", getResources().getDrawable(R.drawable.photos_tab));
        spec4.setContent(R.id.tab4);

        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
        tabHost.addTab(spec4);

        //set the info tab
        try {
            Excursion exc = MapController.getInstance(this).getCurrentLocation().getExcursions(this).get(id);
            //Display locomotions
            Locomotion[] locomotionsItems = exc.getLocomotions();
            LinearLayout locomotionsLayout = (LinearLayout) findViewById(R.id.locomotionsLayout);
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            for (int i = 0; i < locomotionsItems.length; i++) {
                if (locomotionsItems[i].getIcon() == null) {
                    //Define icon if undefined
                    int imageResource = getResources().getIdentifier(
                            "locomotion_" + locomotionsItems[i].getKey(), "drawable", getPackageName());
                    if (imageResource != 0) {
                        Drawable ic = getResources().getDrawable(imageResource);
                        locomotionsItems[i].setIcon(ic);
                    }
                }
                ImageView img = (ImageView) inflater.inflate(R.layout.locomotion_item, null);
                img.setImageDrawable(locomotionsItems[i].getIcon());
                locomotionsLayout.addView(img);
            }

            int value = exc.getDifficulty();
            if (value == Excursion.DIFFICULTY_NONE) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte1);
            } else if (value == Excursion.DIFFICULTY_EASY) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte2);

            } else if (value == Excursion.DIFFICULTY_MEDIUM) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte3);

            } else if (value == Excursion.DIFFICULTY_HARD) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte4);

            } else if (value == Excursion.DIFFICULTY_EXPERT) {
                ImageView view = (ImageView) findViewById(R.id.ImageView2);
                view.setImageResource(R.drawable.difficulte5);

            }
            String time = ExcursionAdapter.convertTime(exc.getTime());

            TextView view = (TextView) findViewById(R.id.textView1);
            view.setText(time);

            Double length = Double.valueOf(exc.getLength() / 1000);
            String lengthString = length.toString().substring(0, length.toString().lastIndexOf(".") + 2)
                    + " km";
            view = (TextView) findViewById(R.id.textView2);
            view.setText(lengthString);

            view = (TextView) findViewById(R.id.textView3);
            view.setText(exc.getDescription());

        } catch (Exception e) {
            e.printStackTrace();
            onBackPressed();
            displayInfo(getString(R.string.message_excursion_not_found));
        }
        MapController exc = MapController.getInstance(this);

        //set the POI tab
        try {
            PointOfInterest[] pois = exc.getCurrentLocation().getExcursions(this).get(id)
                    .getSurroundingPois(this);
            List<NamedPoint> itemsList = Arrays.asList(((NamedPoint[]) pois));
            Collections.sort(itemsList, new NamedPointComparator());
            pois = itemsList.toArray(new PointOfInterest[itemsList.size()]);
            if (pois.length > 0) {
                ListView listPoi = (ListView) findViewById(R.id.listView2);
                listPoi.setAdapter(new FavoriteAdapter(getLayoutInflater(), pois, this));
                listPoi.setOnItemClickListener(listener);
                listPoi.setVisibility(View.VISIBLE);
                findViewById(R.id.NoPOIs).setVisibility(View.GONE);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Couldn't fill POI tab");
        }

        //set the instruction tab
        ListView list = (ListView) findViewById(R.id.listView1);
        if (list != null) {
            try {
                NavigationInstruction[] instructions = exc.getCurrentLocation().getExcursions(this).get(id)
                        .getInstructions();
                if (instructions.length != 0) {
                    ((TextView) findViewById(R.id.NoInstructions)).setVisibility(View.GONE);
                }
                list.setAdapter(new ExcursionInfoInstructionAdapter(this, instructions));
                list.setOnItemClickListener(listener);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        //Set the picture tab
        String imagePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "Android"
                + File.separator + "data" + File.separator + "net.line2soft.preambul" + File.separator + "files"
                + File.separator + MapController.getInstance(this).getCurrentLocation().getId() + File.separator
                + "excursions" + File.separator
                + getIntent().getIntExtra(ExcursionListActivity.EXCURSION_ID, 0);
        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.getAbsolutePath().matches(".*\\.jpg");
            }
        };
        imagesFile = new File(imagePath).listFiles(filter);
        ((TextView) findViewById(R.id.NoPhotos)).setVisibility(View.VISIBLE);
        if (imagesFile != null) {
            if (imagesFile.length > 0) {
                ((TextView) findViewById(R.id.NoPhotos)).setVisibility(View.GONE);
                ImagePagerAdapter adapter = new ImagePagerAdapter(getSupportFragmentManager(), imagesFile,
                        this);
                ViewPager myPager = (ViewPager) findViewById(R.id.pager_images);
                myPager.setAdapter(adapter);
                myPager.setOnPageChangeListener(listener);

                //Set listener on right and left buttons in picture tab
                (findViewById(R.id.imageRight)).setOnClickListener(listener);
                (findViewById(R.id.imageLeft)).setOnClickListener(listener);
                //Change visibility of these buttons
                ImageView right = (ImageView) findViewById(R.id.imageRight);
                ImageView left = (ImageView) findViewById(R.id.imageLeft);
                left.setVisibility(View.INVISIBLE);
                right.setVisibility(View.INVISIBLE);
                int idPhoto = ((ViewPager) findViewById(R.id.pager_images)).getCurrentItem();
                int nbPhotos = getImagesFile().length;
                if (idPhoto != nbPhotos - 1) {
                    right.setVisibility(View.VISIBLE);
                }
            }
        }

        //Set listener on launch button
        Button launch = (Button) findViewById(R.id.button_load_excursion);
        launch.setOnClickListener(listener);

    } else {
        onBackPressed();
        displayInfo(getString(R.string.message_excursion_not_found));
    }
}