Example usage for android.widget TabHost newTabSpec

List of usage examples for android.widget TabHost newTabSpec

Introduction

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

Prototype

@NonNull
public TabSpec newTabSpec(@NonNull String tag) 

Source Link

Document

Creates a new TabSpec associated with this tab host.

Usage

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

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

    // Summary content comes from existing layout
    host.addTab(host.newTabSpec(TAG_BIO).setIndicator(buildIndicator(R.string.speaker_bio))
            .setContent(R.id.tab_speaker_bio));
}

From source file:paarmann.physikprofil.MainActivity.java

private void initTabs() {
    TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();//from   w w w. j a va 2s .  c  o m

    TabHost.TabSpec tsHA = tabHost.newTabSpec("TAB_HA");
    tsHA.setIndicator("Hausaufgaben");
    tsHA.setContent(R.id.tabHA);
    tabHost.addTab(tsHA);

    TabHost.TabSpec tsDates = tabHost.newTabSpec("TAB_DATES");
    tsDates.setIndicator("Termine");
    tsDates.setContent(R.id.tabDates);
    tabHost.addTab(tsDates);
}

From source file:com.facebook.android.FieldsConnectionsDialog.java

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

    setContentView(R.layout.fields_connections_list);
    LayoutParams params = getWindow().getAttributes();
    params.width = LayoutParams.FILL_PARENT;
    params.height = LayoutParams.FILL_PARENT;
    getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);

    fieldsList = (ListView) findViewById(R.id.fields_list);
    connectionsList = (ListView) findViewById(R.id.connections_list);

    fieldsAdapter = new FieldsListAdapter();
    if (this.fieldsArray == null) {
        fieldsList.setAdapter(new ArrayAdapter<String>(explorerActivity, android.R.layout.simple_list_item_1,
                new String[] { "No fields available" }));
    } else {//from www  .j  a  va  2  s . c  o  m
        fieldsList.setAdapter(fieldsAdapter);
    }

    connectionsAdapter = new ConnectionsListAdapter();
    if (this.connectionsArray == null) {
        connectionsList.setAdapter(new ArrayAdapter<String>(explorerActivity,
                android.R.layout.simple_list_item_1, new String[] { "No connections available" }));
    } else {
        connectionsList.setAdapter(connectionsAdapter);
    }

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

    TabSpec spec1 = tabHost.newTabSpec("Tab 1");
    spec1.setIndicator(explorerActivity.getString(R.string.fields));
    spec1.setContent(R.id.fields_layout);

    TabSpec spec2 = tabHost.newTabSpec("Tab 2");
    spec2.setIndicator(explorerActivity.getString(R.string.connections));
    spec2.setContent(R.id.connections_list);

    tabHost.addTab(spec1);
    tabHost.addTab(spec2);
    tabHost.setCurrentTab(0);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = TAB_HEIGHT;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = TAB_HEIGHT;

    mGetFieldsButton = (Button) findViewById(R.id.get_fields_button);
    mGetFieldsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*
             * Source Tag:
             */
            FieldsConnectionsDialog.this.dismiss();
            if (!fieldsVector.isEmpty()) {
                explorerActivity.getFields(fieldsVector);
            } else {
                Toast.makeText(explorerActivity.getBaseContext(), "No Fields selected.", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    connectionsList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
            FieldsConnectionsDialog.this.dismiss();
            explorerActivity.getConnection(connectionsArray.get(position));
        }
    });
}

From source file:ru.gkpromtech.exhibition.events.EventsActivity.java

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

    // restore saved positions
    int savedPosition = 0;
    if (savedInstanceState != null) {
        savedFilter = savedInstanceState.getInt(SAVE_FILTER, EventReader.EVENT_FILTER_ALL);
        savedPosition = savedInstanceState.getInt(SAVE_PAGE_NUMBER, 0);
    } else {//from   w  w w .  ja  v  a2  s  .  c  o m
        // calculate day to position ViewPager
        Calendar calendar = Calendar.getInstance();
        Date d = calendar.getTime();
        List<Date> days = new ArrayList<>(EventReader.getInstance(this).getDays());
        if (days.contains(d))
            savedPosition = days.indexOf(d);
    }

    FrameLayout view = (FrameLayout) findViewById(R.id.container);
    getLayoutInflater().inflate(R.layout.activity_events, view, true);

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

    tabHost.addTab(tabHost
            .newTabSpec("tag" + EventReader.EVENT_FILTER_ALL).setIndicator(createIndicatorView(tabHost,
                    getResources().getString(R.string.all_uppercase), R.drawable.ic_events_all))
            .setContent(R.id.tab1));

    tabHost.addTab(tabHost
            .newTabSpec("tag" + EventReader.EVENT_FILTER_SHOW).setIndicator(createIndicatorView(tabHost,
                    getResources().getString(R.string.event_status_business), R.drawable.ic_white_plane))
            .setContent(R.id.tab2));

    tabHost.addTab(tabHost
            .newTabSpec("tag" + EventReader.EVENT_FILTER_MY).setIndicator(createIndicatorView(tabHost,
                    getResources().getString(R.string.event_status_my), R.drawable.ic_person))
            .setContent(R.id.tab3));

    pager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter = new EventsFragmentPagerAdapter(getSupportFragmentManager(), EventReader.getInstance(this),
            savedFilter);
    pager.setAdapter(pagerAdapter);

    // set saved page
    pager.setCurrentItem(savedPosition);
    tabHost.setCurrentTabByTag("tag" + savedFilter);

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            switch (tabId) {
            case "tag" + EventReader.EVENT_FILTER_ALL:
                savedFilter = EventReader.EVENT_FILTER_ALL;
                break;
            case "tag" + EventReader.EVENT_FILTER_SHOW:
                savedFilter = EventReader.EVENT_FILTER_SHOW;
                break;
            case "tag" + EventReader.EVENT_FILTER_MY:
                savedFilter = EventReader.EVENT_FILTER_MY;
                break;
            }
            AnalyticsManager.sendEvent(EventsActivity.this, R.string.events_category, R.string.action_change,
                    savedFilter);
            pagerAdapter.setFilter(savedFilter);
        }
    });

    AnalyticsManager.sendEvent(this, R.string.events_category, R.string.action_open, savedFilter);
}

From source file:org.inftel.ssa.mobile.ui.fragments.ProjectDetailFragment.java

private void setupLinksTab(View view) {
    TabHost mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
    mTabHost.addTab(mTabHost.newTabSpec(TAG_LINKS).setIndicator(buildIndicator(R.string.project_links, view))
            .setContent(R.id.tab_project_links));
}

From source file:org.inftel.ssa.mobile.ui.fragments.ProjectDetailFragment.java

private void setupInformationTab(View view) {
    TabHost mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
    mTabHost.addTab(mTabHost.newTabSpec(TAG_INFORMATION)
            .setIndicator(buildIndicator(R.string.project_information, view))
            .setContent(R.id.tab_project_information));
}

From source file:org.inftel.ssa.mobile.ui.fragments.ProjectDetailFragment.java

private void setupDescriptionTab(View view) {
    TabHost mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
    mTabHost.addTab(mTabHost.newTabSpec(TAG_DESCRIPTION)
            .setIndicator(buildIndicator(R.string.project_description, view))
            .setContent(R.id.tab_detail_project_description));
}

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

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

    final Intent intent = new Intent(Intent.ACTION_VIEW, buildSessionsDirUri(mSpeakerId));
    intent.addCategory(Intent.CATEGORY_TAB);

    // Sessions content comes from reused activity
    host.addTab(host.newTabSpec(TAG_PRESENTATIONS).setIndicator(buildIndicator(R.string.speaker_sessions))
            .setContent(intent));/*from w w w  .  ja  va2  s .  com*/
}

From source file:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java

@NonNull
@Override//w  w  w . java  2s . co  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    SessionInfo sessionInfo = getSessionInfo();
    List<Map<?, ?>> tags = sessionInfo == null ? null : sessionInfo.getTags();
    if (tags != null && tags.size() > 0) {
        TreeMap<String, Long> map = new TreeMap<>();
        for (Object o : tags) {
            if (o instanceof Map) {
                Map<?, ?> mapTag = (Map<?, ?>) o;
                long uid = MapUtils.getMapLong(mapTag, "uid", 0);
                String name = MapUtils.getMapString(mapTag, "name", "??");
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                if (type == 3) {
                    // type-name will be "Manual" :(
                    name = "Tag: " + name;
                } else {
                    String typeName = MapUtils.getMapString(mapTag, "type-name", null);
                    if (typeName != null) {
                        name = typeName + ": " + name;
                    }
                }
                map.put(name, uid);
            }
        }

        long[] vals = new long[map.size()];
        String[] strings = map.keySet().toArray(new String[map.keySet().size()]);
        for (int i = 0; i < vals.length; i++) {
            vals[i] = map.get(strings[i]);
        }

        filterByList = new ValueStringArray(vals, strings);
    }

    if (filterByList == null) {
        filterByList = AndroidUtils.getValueStringArray(getResources(), R.array.filterby_list);
    }

    AndroidUtils.AlertDialogBuilder alertDialogBuilder = AndroidUtils.createAlertDialogBuilder(getActivity(),
            R.layout.dialog_filter_by);

    View view = alertDialogBuilder.view;
    AlertDialog.Builder builder = alertDialogBuilder.builder;

    // get our tabHost from the xml
    TabHost tabHost = (TabHost) view.findViewById(R.id.filterby_tabhost);
    tabHost.setup();

    // create tab 1
    TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
    spec1.setIndicator("States");
    spec1.setContent(R.id.filterby_sv_state);
    tabHost.addTab(spec1);
    //create tab2
    TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
    spec2.setIndicator("Tags");
    spec2.setContent(R.id.filterby_tv_tags);
    tabHost.addTab(spec2);

    int height = AndroidUtilsUI.dpToPx(32);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;

    TextView tvState = (TextView) view.findViewById(R.id.filterby_tv_state);
    tvState.setMovementMethod(LinkMovementMethod.getInstance());

    final TextView tvTags = (TextView) view.findViewById(R.id.filterby_tv_tags);
    tvTags.setMovementMethod(LinkMovementMethod.getInstance());

    // for API <= 10 (maybe 11?), otherwise tags will display on one line
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (!tabId.equals("tab2")) {
                return;
            }
            tvTags.post(new Runnable() {
                @Override
                public void run() {
                    spanTags.updateTags();
                }
            });
        }
    });

    builder.setTitle(R.string.filterby_title);

    // Add action buttons
    builder.setPositiveButton(R.string.action_filterby, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (mapSelectedTag == null) {
                return;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            String name = MapUtils.getMapString(mapSelectedTag, "name", "??");

            mListener.filterBy(uidSelected, name, true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            DialogFragmentFilterByTags.this.getDialog().cancel();
        }
    });

    List<Map<?, ?>> manualTags = new ArrayList<>();
    List<Map<?, ?>> stateTags = new ArrayList<>();

    if (sessionInfo != null) {
        // Dialog never gets called wehn getTags has no tags
        List<Map<?, ?>> allTags = sessionInfo.getTags();
        if (allTags != null) {
            for (Map<?, ?> mapTag : allTags) {
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                switch (type) {
                case 0:
                case 1:
                case 2:
                    stateTags.add(mapTag);
                    break;
                case 3: // manual
                    manualTags.add(mapTag);
                    break;
                }
            }
        }
    }

    SpanTagsListener l = new SpanTagsListener() {
        @Override
        public void tagClicked(Map mapTag, String name) {
            mapSelectedTag = mapTag;
            // todo: long click, don't exit
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            mListener.filterBy(uidSelected, name, true);
            DialogFragmentFilterByTags.this.getDialog().dismiss();
        }

        @Override
        public int getTagState(Map mapTag, String name) {
            if (mapSelectedTag == null) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            if (uidSelected == -1) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidQuery = MapUtils.getMapLong(mapTag, "uid", -1);
            return uidQuery == uidSelected ? SpanTags.TAG_STATE_SELECTED : SpanTags.TAG_STATE_UNSELECTED;
        }
    };
    spanTags = new SpanTags(getActivity(), sessionInfo, tvTags, l);
    spanTags.setTagMaps(manualTags);
    spanTags.setShowIcon(false);
    spanTags.updateTags();

    SpanTags spanState = new SpanTags(getActivity(), sessionInfo, tvState, l);
    spanState.setTagMaps(stateTags);
    spanState.setShowIcon(false);
    spanState.updateTags();

    return builder.create();
}

From source file:org.runnerup.view.MainLayout.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.main);/* w  w w. j  av  a2 s.  c om*/

    int versionCode = 0;
    UpgradeState upgradeState = UpgradeState.UNKNOWN;
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = pref.edit();
    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionCode = pInfo.versionCode;
        int version = pref.getInt("app-version", -1);
        if (version == -1) {
            upgradeState = UpgradeState.NEW;
        } else if (versionCode == version) {
            upgradeState = UpgradeState.SAME;
        } else if (versionCode > version) {
            upgradeState = UpgradeState.UPGRADE;
        } else if (versionCode < version) {
            upgradeState = UpgradeState.DOWNGRADE;
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    editor.putInt("app-version", versionCode);
    boolean km = Formatter.getUseKilometers(getResources(), pref, editor);

    if (upgradeState == UpgradeState.NEW) {
        editor.putString(getResources().getString(R.string.pref_autolap),
                Double.toString(km ? Formatter.km_meters : Formatter.mi_meters));
    }
    editor.commit();

    // clear basicTargetType between application startup/shutdown
    pref.edit().remove(getString(R.string.pref_basic_target_type)).commit();

    Log.e(getClass().getName(),
            "app-version: " + versionCode + ", upgradeState: " + upgradeState + ", km: " + km);

    // convert pref_mute to pref_mute_bool
    Resources res = getResources();
    try {
        if (pref.contains(res.getString(R.string.pref_mute))) {
            String v = pref.getString(res.getString(R.string.pref_mute), "no");
            editor.putBoolean(res.getString(R.string.pref_mute_bool), v.equalsIgnoreCase("yes"));
            editor.remove(res.getString(R.string.pref_mute));
            editor.commit();
        }
    } catch (Exception e) {
    }

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.audio_cue_settings, true);

    TabHost tabHost = getTabHost(); // The activity TabHost

    tabHost.addTab(tabHost.newTabSpec("Start")
            .setIndicator(getString(R.string.Start), myGetDrawable(R.drawable.ic_tab_main))
            .setContent(new Intent(this, StartActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Feed")
            .setIndicator(getString(R.string.feed), myGetDrawable(R.drawable.ic_tab_feed))
            .setContent(new Intent(this, FeedActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("History")
            .setIndicator(getString(R.string.History), myGetDrawable(R.drawable.ic_tab_history))
            .setContent(new Intent(this, HistoryActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Settings")
            .setIndicator(getString(R.string.Settings), myGetDrawable(R.drawable.ic_tab_setup))
            .setContent(new Intent(this, SettingsActivity.class)));

    tabHost.setCurrentTab(0);
    WidgetUtil.addLegacyOverflowButton(getWindow());

    if (upgradeState == UpgradeState.UPGRADE) {
        whatsNew();
    }
    //GPS is essential, always nag user if not granted
    requestGpsPermissions(this, tabHost.getCurrentView());

    //Import workouts/schemes. No permission needed
    handleBundled(getApplicationContext().getAssets(), "bundled", getFilesDir().getPath() + "/..");

    // if we were called from an intent-filter because user opened "runnerup.db.export", load it
    final Uri data = getIntent().getData();
    if (data != null) {
        if (SettingsActivity.requestReadStoragePermissions(MainLayout.this)) {
            String filePath = null;
            if ("content".equals(data.getScheme())) {
                Cursor cursor = this.getContentResolver().query(data,
                        new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null,
                        null);
                cursor.moveToFirst();
                filePath = cursor.getString(0);
                cursor.close();
            } else {
                filePath = data.getPath();
            }
            Log.i(getClass().getSimpleName(), "Importing database from " + filePath);
            DBHelper.importDatabase(MainLayout.this, filePath);
        } else {
            Toast.makeText(this, "Storage permission not granted in Android settings, db is not imported.",
                    Toast.LENGTH_SHORT).show();
        }
    }
}