Example usage for android.widget TabHost getTabWidget

List of usage examples for android.widget TabHost getTabWidget

Introduction

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

Prototype

public TabWidget getTabWidget() 

Source Link

Usage

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  w w  w .ja v  a2 s  .co 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:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java

@NonNull
@Override//  w w w  .j  a  v  a 2  s  .  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:com.momock.outlet.tab.PagerTabOutlet.java

public void attach(TabHolder target) {
    Logger.check(target != null, "Parameter target cannot be null!");
    Logger.check(target.getTabContent() instanceof ViewPager,
            "The PagerTabOutlet must contains a ViewPager content!");
    this.target = target;
    final TabHost tabHost = target.getTabHost();
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    plugs = getPlugs();//from www  .  j a va 2s. co m

    ViewPager pager = (ViewPager) target.getTabContent();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "The plug of PagerTabOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getContent()).reset();
    }
    pager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return plugs.getItemCount();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ITabPlug plug = (ITabPlug) plugs.getItem(position);
            View view = ((ViewHolder) plug.getContent()).getView();
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });

    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

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

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    tabHost.setup();
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "Plug in PagerTabOutlet must contains a ViewHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                View v = new View(tabHost.getContext());
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }

        });
        tabHost.addTab(spec);
        if (getActivePlug() == plug)
            tabHost.setCurrentTab(i);
    }
}

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

/** Called when the activity is first created. */
@Override/*from  w  ww.  ja  v  a 2s  .c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detail);
    WidgetUtil.addLegacyOverflowButton(getWindow());

    Intent intent = getIntent();
    mID = intent.getLongExtra("ID", -1);
    String mode = intent.getStringExtra("mode");

    mDBHelper = new DBHelper(this);
    mDB = mDBHelper.getReadableDatabase();
    uploadManager = new UploadManager(this);
    formatter = new Formatter(this);

    if (mode.contentEquals("save")) {
        this.mode = MODE_SAVE;
    } else if (mode.contentEquals("details")) {
        this.mode = MODE_DETAILS;
    } else {
        assert (false);
    }

    saveButton = (Button) findViewById(R.id.save_button);
    discardButton = (Button) findViewById(R.id.discard_button);
    resumeButton = (Button) findViewById(R.id.resume_button);
    uploadButton = (Button) findViewById(R.id.upload_button);
    activityTime = (TextView) findViewById(R.id.activity_time);
    activityDistance = (TextView) findViewById(R.id.activity_distance);
    activityPace = (TextView) findViewById(R.id.activity_pace);
    sport = (TitleSpinner) findViewById(R.id.summary_sport);
    notes = (EditText) findViewById(R.id.notes_text);
    notes.setHint("Notes about your workout");
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (map != null) {
        map.setOnCameraChangeListener(new OnCameraChangeListener() {

            @Override
            public void onCameraChange(CameraPosition arg0) {
                if (mapBounds != null) {
                    // Move camera.
                    map.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds, 5));
                    // Remove listener to prevent position reset on camera
                    // move.
                    map.setOnCameraChangeListener(null);
                }
            }
        });
    }
    saveButton.setOnClickListener(saveButtonClick);
    uploadButton.setOnClickListener(uploadButtonClick);
    if (this.mode == MODE_SAVE) {
        resumeButton.setOnClickListener(resumeButtonClick);
        discardButton.setOnClickListener(discardButtonClick);
        setEdit(true);
    } else if (this.mode == MODE_DETAILS) {
        resumeButton.setVisibility(View.GONE);
        discardButton.setVisibility(View.GONE);
        setEdit(false);
    }
    uploadButton.setVisibility(View.GONE);

    fillHeaderData();
    requery();

    loadRoute();

    TabHost th = (TabHost) findViewById(R.id.tabhost);
    th.setup();
    TabSpec tabSpec = th.newTabSpec("notes");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Notes"));
    tabSpec.setContent(R.id.tab_main);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("laps");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Laps"));
    tabSpec.setContent(R.id.tab_lap);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("map");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Map"));
    tabSpec.setContent(R.id.tab_map);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("graph");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Graph"));
    tabSpec.setContent(R.id.tab_graph);
    th.addTab(tabSpec);

    tabSpec = th.newTabSpec("share");
    tabSpec.setIndicator(WidgetUtil.createHoloTabIndicator(this, "Upload"));
    tabSpec.setContent(R.id.tab_upload);
    th.addTab(tabSpec);

    th.getTabWidget().setBackgroundColor(Color.DKGRAY);

    {
        ListView lv = (ListView) findViewById(R.id.laplist);
        LapListAdapter adapter = new LapListAdapter();
        adapters.add(adapter);
        lv.setAdapter(adapter);
    }
    {
        ListView lv = (ListView) findViewById(R.id.report_list);
        ReportListAdapter adapter = new ReportListAdapter();
        adapters.add(adapter);
        lv.setAdapter(adapter);
    }
    graphTab = (LinearLayout) findViewById(R.id.tab_graph);
    {
        graphView = new LineGraphView(this, "Pace") {
            @Override
            protected String formatLabel(double value, boolean isValueX) {
                if (!isValueX) {
                    return formatter.formatPace(Formatter.TXT_SHORT, value);
                } else
                    return formatter.formatDistance(Formatter.TXT_SHORT, (long) value);
            }
        };

        graphView2 = new LineGraphView(this, "HRM") {
            @Override
            protected String formatLabel(double value, boolean isValueX) {
                if (!isValueX) {
                    return Integer.toString((int) Math.round(value));
                } else {
                    return formatter.formatDistance(Formatter.TXT_SHORT, (long) value);
                }
            }
        };
    }
    hrzonesBarLayout = (LinearLayout) findViewById(R.id.hrzonesBarLayout);
    hrzonesBar = new HRZonesBar(this);
}

From source file:com.momock.outlet.tab.FragmentPagerTabOutlet.java

public void attach(final FragmentTabHolder tabHolder) {
    Logger.check(tabHolder != null, "Parameter tabHolder cannot be null!");
    this.target = tabHolder;
    final TabHost tabHost = target.getTabHost();
    plugs = getPlugs();/*from   w ww  .  jav a 2 s . co  m*/
    Logger.check(target.getTabContent() instanceof ViewPager, "The tab content container must be a ViewPager!");
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    tabContent.setOffscreenPageLimit(plugs.getItemCount());
    tabContent.setAdapter(new FragmentPagerAdapter(target.getFragmentManager()) {

        @Override
        public Fragment getItem(final int position) {
            final ITabPlug plug = (ITabPlug) plugs.getItem(position);
            Fragment f = ((FragmentHolder) plug.getContent()).getFragment();
            if (f instanceof CaseFragment) {
                CaseFragment cf = (CaseFragment) f;
                cf.setActiveCaseIndicator(new IActiveCaseIndicator() {

                    @Override
                    public boolean isActiveCase() {
                        return getActivePlug() == plug;
                    }

                });
            }
            return f;
        }

        @Override
        public int getCount() {
            return plugs.getItemCount();
        }

        void doFinishUpdate(ViewGroup container) {
            super.finishUpdate(container);
        }

        @Override
        public void finishUpdate(final ViewGroup container) {
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    doFinishUpdate(container);
                }

            });
        }

        @Override
        public void setPrimaryItem(ViewGroup container, int position, final Object object) {
            super.setPrimaryItem(container, position, object);
            new Handler().post(new Runnable() {

                @Override
                public void run() {

                    if (object instanceof CaseFragment) {
                        CaseFragment cf = (CaseFragment) object;
                        if (cf.getCase() != null && cf.getCase().getParent() != null)
                            cf.getCase().getParent().setActiveCase(cf.getCase());
                    }
                }

            });
        }
    });
    tabHost.setup();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof FragmentHolder,
                "Plug in PagerTabOutlet must contains a FragmentHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                View v = new View(tabHost.getContext());
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }

        });
        tabHost.addTab(spec);
        if (getActivePlug() == plug) {
            tabHost.setCurrentTab(i);
            tabContent.setCurrentItem(i, true);
        }
    }
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

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

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
}