Search in sources :

Example 41 with TabHost

use of android.widget.TabHost in project standup-timer by jwood.

the class TeamDetails method createTabs.

private void createTabs() {
    TabHost tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec("stats_tab").setIndicator(this.getString(R.string.stats)).setContent(createMeetingDetails(team)));
    tabHost.addTab(tabHost.newTabSpec("meetings_tab").setIndicator(this.getString(R.string.meetings)).setContent(createMeetingList()));
    getTabHost().setCurrentTab(0);
    findViewById(R.id.team_stats).bringToFront();
}
Also used : TabHost(android.widget.TabHost)

Example 42 with TabHost

use of android.widget.TabHost in project android-viewbadger by jgilfelt.

the class DemoActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final TabHost tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec("demos").setIndicator("Badge Demos").setContent(R.id.tab1));
    tabHost.addTab(tabHost.newTabSpec("adapter").setIndicator("List Adapter").setContent(R.id.tab2));
    tabHost.addTab(tabHost.newTabSpec("tests").setIndicator("Layout Tests").setContent(R.id.tab3));
    // *** default badge ***
    View target = findViewById(R.id.default_target);
    BadgeView badge = new BadgeView(this, target);
    badge.setText("1");
    badge.show();
    // *** set position ***
    btnPosition = (Button) findViewById(R.id.position_target);
    badge1 = new BadgeView(this, btnPosition);
    badge1.setText("12");
    badge1.setBadgePosition(BadgeView.POSITION_CENTER);
    btnPosition.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            badge1.toggle();
        }
    });
    // *** badge/text size & colour ***
    btnColour = (Button) findViewById(R.id.colour_target);
    badge2 = new BadgeView(this, btnColour);
    badge2.setText("New!");
    badge2.setTextColor(Color.BLUE);
    badge2.setBadgeBackgroundColor(Color.YELLOW);
    badge2.setTextSize(12);
    btnColour.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            badge2.toggle();
        }
    });
    // *** default animation ***
    btnAnim1 = (Button) findViewById(R.id.anim1_target);
    badge3 = new BadgeView(this, btnAnim1);
    badge3.setText("84");
    btnAnim1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            badge3.toggle(true);
        }
    });
    // *** custom animation ***
    btnAnim2 = (Button) findViewById(R.id.anim2_target);
    badge4 = new BadgeView(this, btnAnim2);
    badge4.setText("123");
    badge4.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
    badge4.setBadgeMargin(15, 10);
    badge4.setBadgeBackgroundColor(Color.parseColor("#A4C639"));
    btnAnim2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            TranslateAnimation anim = new TranslateAnimation(-100, 0, 0, 0);
            anim.setInterpolator(new BounceInterpolator());
            anim.setDuration(1000);
            badge4.toggle(anim, null);
        }
    });
    // *** custom background ***
    btnCustom = (Button) findViewById(R.id.custom_target);
    badge5 = new BadgeView(this, btnCustom);
    badge5.setText("37");
    badge5.setBackgroundResource(R.drawable.badge_ifaux);
    badge5.setTextSize(16);
    btnCustom.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            badge5.toggle(true);
        }
    });
    // *** clickable badge ***
    btnClick = (Button) findViewById(R.id.click_target);
    badge6 = new BadgeView(this, btnClick);
    badge6.setText("click me");
    badge6.setBadgeBackgroundColor(Color.BLUE);
    badge6.setTextSize(16);
    badge6.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(DemoActivity.this, "clicked badge", Toast.LENGTH_SHORT).show();
        }
    });
    btnClick.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            badge6.toggle();
        }
    });
    // *** tab ***
    TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
    btnTab = (Button) findViewById(R.id.tab_btn);
    badge7 = new BadgeView(this, tabs, 0);
    badge7.setText("5");
    btnTab.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            badge7.toggle();
        }
    });
    // *** increment ***
    btnIncrement = (Button) findViewById(R.id.increment_target);
    badge8 = new BadgeView(this, btnIncrement);
    badge8.setText("0");
    btnIncrement.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (badge8.isShown()) {
                badge8.increment(1);
            } else {
                badge8.show();
            }
        }
    });
    // *** list adapter ****
    listDemo = (ListView) findViewById(R.id.tab2);
    listDemo.setAdapter(new BadgeAdapter(this));
}
Also used : TabHost(android.widget.TabHost) BounceInterpolator(android.view.animation.BounceInterpolator) BadgeView(com.readystatesoftware.viewbadger.BadgeView) OnClickListener(android.view.View.OnClickListener) TranslateAnimation(android.view.animation.TranslateAnimation) TabWidget(android.widget.TabWidget) TextView(android.widget.TextView) BadgeView(com.readystatesoftware.viewbadger.BadgeView) View(android.view.View) ListView(android.widget.ListView)

Example 43 with TabHost

use of android.widget.TabHost in project coursera-android by aporter.

the class HelloTabWidget method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Resource object to get Drawables
    Resources res = getResources();
    // The activity TabHost
    TabHost tabHost = getTabHost();
    // Reusable TabSpec for each tab
    TabHost.TabSpec spec;
    // Reusable Intent for each tab
    Intent intent;
    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, ArtistsActivity.class);
    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
    tabHost.addTab(spec);
    // Do the same for the other tabs
    intent = new Intent().setClass(this, AlbumsActivity.class);
    spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
    tabHost.addTab(spec);
    intent = new Intent().setClass(this, SongsActivity.class);
    spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);
    tabHost.addTab(spec);
    tabHost.setCurrentTab(2);
}
Also used : TabHost(android.widget.TabHost) Intent(android.content.Intent) Resources(android.content.res.Resources)

Example 44 with TabHost

use of android.widget.TabHost in project Launcher3 by chislon.

the class FocusHelper method handleAppsCustomizeKeyEvent.

/**
     * Handles key events in a PageViewCellLayout containing PagedViewIcons.
     */
static boolean handleAppsCustomizeKeyEvent(View v, int keyCode, KeyEvent e) {
    ViewGroup parentLayout;
    ViewGroup itemContainer;
    int countX;
    int countY;
    if (v.getParent() instanceof ShortcutAndWidgetContainer) {
        itemContainer = (ViewGroup) v.getParent();
        parentLayout = (ViewGroup) itemContainer.getParent();
        countX = ((CellLayout) parentLayout).getCountX();
        countY = ((CellLayout) parentLayout).getCountY();
    } else {
        itemContainer = parentLayout = (ViewGroup) v.getParent();
        countX = ((PagedViewGridLayout) parentLayout).getCellCountX();
        countY = ((PagedViewGridLayout) parentLayout).getCellCountY();
    }
    // Note we have an extra parent because of the
    // PagedViewCellLayout/PagedViewCellLayoutChildren relationship
    final PagedView container = (PagedView) parentLayout.getParent();
    final TabHost tabHost = findTabHostParent(container);
    final TabWidget tabs = tabHost.getTabWidget();
    final int iconIndex = itemContainer.indexOfChild(v);
    final int itemCount = itemContainer.getChildCount();
    final int pageIndex = ((PagedView) container).indexToPage(container.indexOfChild(parentLayout));
    final int pageCount = container.getChildCount();
    final int x = iconIndex % countX;
    final int y = iconIndex / countX;
    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    ViewGroup newParent = null;
    // Side pages do not always load synchronously, so check before focusing child siblings
    // willy-nilly
    View child = null;
    boolean wasHandled = false;
    switch(keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (handleKeyEvent) {
                // Select the previous icon or the last icon on the previous page
                if (iconIndex > 0) {
                    itemContainer.getChildAt(iconIndex - 1).requestFocus();
                } else {
                    if (pageIndex > 0) {
                        newParent = getAppsCustomizePage(container, pageIndex - 1);
                        if (newParent != null) {
                            container.snapToPage(pageIndex - 1);
                            child = newParent.getChildAt(newParent.getChildCount() - 1);
                            if (child != null)
                                child.requestFocus();
                        }
                    }
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (handleKeyEvent) {
                // Select the next icon or the first icon on the next page
                if (iconIndex < (itemCount - 1)) {
                    itemContainer.getChildAt(iconIndex + 1).requestFocus();
                } else {
                    if (pageIndex < (pageCount - 1)) {
                        newParent = getAppsCustomizePage(container, pageIndex + 1);
                        if (newParent != null) {
                            container.snapToPage(pageIndex + 1);
                            child = newParent.getChildAt(0);
                            if (child != null)
                                child.requestFocus();
                        }
                    }
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            if (handleKeyEvent) {
                // Select the closest icon in the previous row, otherwise select the tab bar
                if (y > 0) {
                    int newiconIndex = ((y - 1) * countX) + x;
                    itemContainer.getChildAt(newiconIndex).requestFocus();
                } else {
                    tabs.requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (handleKeyEvent) {
                // Select the closest icon in the previous row, otherwise do nothing
                if (y < (countY - 1)) {
                    int newiconIndex = Math.min(itemCount - 1, ((y + 1) * countX) + x);
                    itemContainer.getChildAt(newiconIndex).requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (handleKeyEvent) {
                // Simulate a click on the icon
                View.OnClickListener clickListener = (View.OnClickListener) container;
                clickListener.onClick(v);
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_PAGE_UP:
            if (handleKeyEvent) {
                // if there is no previous page
                if (pageIndex > 0) {
                    newParent = getAppsCustomizePage(container, pageIndex - 1);
                    if (newParent != null) {
                        container.snapToPage(pageIndex - 1);
                        child = newParent.getChildAt(0);
                        if (child != null)
                            child.requestFocus();
                    }
                } else {
                    itemContainer.getChildAt(0).requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (handleKeyEvent) {
                // if there is no next page
                if (pageIndex < (pageCount - 1)) {
                    newParent = getAppsCustomizePage(container, pageIndex + 1);
                    if (newParent != null) {
                        container.snapToPage(pageIndex + 1);
                        child = newParent.getChildAt(0);
                        if (child != null)
                            child.requestFocus();
                    }
                } else {
                    itemContainer.getChildAt(itemCount - 1).requestFocus();
                }
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            if (handleKeyEvent) {
                // Select the first icon on this page
                itemContainer.getChildAt(0).requestFocus();
            }
            wasHandled = true;
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            if (handleKeyEvent) {
                // Select the last icon on this page
                itemContainer.getChildAt(itemCount - 1).requestFocus();
            }
            wasHandled = true;
            break;
        default:
            break;
    }
    return wasHandled;
}
Also used : TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) TabWidget(android.widget.TabWidget) ScrollView(android.widget.ScrollView) View(android.view.View)

Example 45 with TabHost

use of android.widget.TabHost in project fitscales by paulburton.

the class SettingsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.settings_fragment, container, false);
    editHeightMain = (EditText) v.findViewById(R.id.editHeightMain);
    editHeightSub = (EditText) v.findViewById(R.id.editHeightSub);
    rowHeightSub = (TableRow) v.findViewById(R.id.rowHeightSub);
    spinHeightUnit = (Spinner) v.findViewById(R.id.spinHeightUnit);
    spinWeightUnit = (Spinner) v.findViewById(R.id.spinWeightUnit);
    seekStabilityPrecision = (SeekBar) v.findViewById(R.id.seekStabilityPrecision);
    textHeightSubUnit = (TextView) v.findViewById(R.id.textHeightSubUnit);
    listSyncServices = (ListView) v.findViewById(R.id.listSyncServices);
    swSyncAuto = (Switch) v.findViewById(R.id.swSyncAuto);
    btnDonate = (Button) v.findViewById(R.id.btnDonate);
    TabHost tabHost = (TabHost) v.findViewById(android.R.id.tabhost);
    tabHost.setup();
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (DEBUG)
            Log.d(TAG, "Using horizontal layout");
        LinearLayout llMain = (LinearLayout) v.findViewById(R.id.llMain);
        llMain.setOrientation(LinearLayout.HORIZONTAL);
        TabWidget tw = tabHost.getTabWidget();
        tw.setOrientation(LinearLayout.VERTICAL);
        tw.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
        FrameLayout tc = tabHost.getTabContentView();
        tc.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f));
    }
    tabHost.addTab(tabHost.newTabSpec("tab_body").setIndicator(createIndicatorView(tabHost, "Body", null, inflater)).setContent(R.id.tabViewBody));
    tabHost.addTab(tabHost.newTabSpec("tab_sync").setIndicator(createIndicatorView(tabHost, "Sync", null, inflater)).setContent(R.id.tabViewSync));
    tabHost.addTab(tabHost.newTabSpec("tab_about").setIndicator(createIndicatorView(tabHost, "About", null, inflater)).setContent(R.id.tabViewAbout));
    tabHost.setCurrentTab(0);
    ArrayAdapter<CharSequence> heightUnitAdapter = ArrayAdapter.createFromResource(inflater.getContext(), R.array.height_units_main_array, android.R.layout.simple_spinner_item);
    heightUnitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinHeightUnit.setAdapter(heightUnitAdapter);
    spinHeightUnit.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putInt(Prefs.KEY_HEIGHTUNIT, spinHeightUnit.getSelectedItemPosition());
            Prefs.save(edit);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    editHeightMain.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            saveHeight();
        }
    });
    editHeightSub.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            saveHeight();
        }
    });
    ArrayAdapter<CharSequence> weightUnitAdapter = ArrayAdapter.createFromResource(inflater.getContext(), R.array.weight_units_main_array, android.R.layout.simple_spinner_item);
    weightUnitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinWeightUnit.setAdapter(weightUnitAdapter);
    spinWeightUnit.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putInt(Prefs.KEY_WEIGHTUNIT, spinWeightUnit.getSelectedItemPosition());
            Prefs.save(edit);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    final float stabilityPrecisionStep = 0.1f;
    seekStabilityPrecision.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (!fromUser)
                return;
            float precision = Prefs.STABILITY_PRECISION_MIN + (progress * stabilityPrecisionStep);
            if (precision == Prefs.getStabilityPrecision())
                return;
            if (DEBUG)
                Log.d(TAG, "Stability precision change to " + precision);
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putFloat(Prefs.KEY_STABILITY_PRECISION, precision);
            Prefs.save(edit);
        }
    });
    seekStabilityPrecision.setMax((int) ((Prefs.STABILITY_PRECISION_MAX - Prefs.STABILITY_PRECISION_MIN) / stabilityPrecisionStep) + 1);
    seekStabilityPrecision.setProgress((int) ((Prefs.getStabilityPrecision() - Prefs.STABILITY_PRECISION_MIN) / stabilityPrecisionStep));
    swSyncAuto.setChecked(Prefs.getSyncAuto());
    swSyncAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked == Prefs.getSyncAuto())
                return;
            SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
            edit.putBoolean(Prefs.KEY_SYNCAUTO, isChecked);
            Prefs.save(edit);
        }
    });
    btnDonate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=396BVJNLQFD62&lc=GB&item_name=FitScales%20Android%20App&currency_code=GBP&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"));
            startActivity(intent);
        }
    });
    /* Prevent onClick being passed up to the settingsView */
    v.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    listSyncServices.setAdapter(new SyncServiceAdapter(this, inflater.getContext(), R.layout.settings_sync_item, FitscalesApplication.inst.syncServices));
    loadSettings();
    return v;
}
Also used : TabWidget(android.widget.TabWidget) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) TabHost(android.widget.TabHost) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) FrameLayout(android.widget.FrameLayout) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) OnClickListener(android.view.View.OnClickListener) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Aggregations

TabHost (android.widget.TabHost)73 View (android.view.View)30 Intent (android.content.Intent)21 ViewGroup (android.view.ViewGroup)18 ListView (android.widget.ListView)18 Test (org.junit.Test)17 TabWidget (android.widget.TabWidget)15 AdapterView (android.widget.AdapterView)13 AbsListView (android.widget.AbsListView)12 ExpandableListView (android.widget.ExpandableListView)12 TextView (android.widget.TextView)11 ActionMenuView (android.widget.ActionMenuView)10 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)10 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)10 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)10 MenuView (com.android.internal.view.menu.MenuView)10 FrameLayout (android.widget.FrameLayout)7 LinearLayout (android.widget.LinearLayout)7 AbsSpinner (android.widget.AbsSpinner)6 QuickContactBadge (android.widget.QuickContactBadge)6