Search in sources :

Example 21 with TabWidget

use of android.widget.TabWidget 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)

Example 22 with TabWidget

use of android.widget.TabWidget in project android-support-v4-googlemaps by petedoyle.

the class FragmentTabHost method initFragmentTabHost.

private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();
    super.setOnTabChangedListener(this);
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0));
        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));
        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
Also used : TypedArray(android.content.res.TypedArray) FrameLayout(android.widget.FrameLayout) TabWidget(android.widget.TabWidget) LinearLayout(android.widget.LinearLayout)

Example 23 with TabWidget

use of android.widget.TabWidget in project android_frameworks_base by ParanoidAndroid.

the class RenderSessionImpl method setupTabHost.

/**
     * Sets up a {@link TabHost} object.
     * @param tabHost the TabHost to setup.
     * @param projectCallback The project callback object to access the project R class.
     * @throws PostInflateException
     */
private void setupTabHost(TabHost tabHost, IProjectCallback projectCallback) throws PostInflateException {
    // look for the TabWidget, and the FrameLayout. They have their own specific names
    View v = tabHost.findViewById(android.R.id.tabs);
    if (v == null) {
        throw new PostInflateException("TabHost requires a TabWidget with id \"android:id/tabs\".\n");
    }
    if ((v instanceof TabWidget) == false) {
        throw new PostInflateException(String.format("TabHost requires a TabWidget with id \"android:id/tabs\".\n" + "View found with id 'tabs' is '%s'", v.getClass().getCanonicalName()));
    }
    v = tabHost.findViewById(android.R.id.tabcontent);
    if (v == null) {
        // TODO: see if we can fake tabs even without the FrameLayout (same below when the framelayout is empty)
        throw new PostInflateException("TabHost requires a FrameLayout with id \"android:id/tabcontent\".");
    }
    if ((v instanceof FrameLayout) == false) {
        throw new PostInflateException(String.format("TabHost requires a FrameLayout with id \"android:id/tabcontent\".\n" + "View found with id 'tabcontent' is '%s'", v.getClass().getCanonicalName()));
    }
    FrameLayout content = (FrameLayout) v;
    // now process the content of the framelayout and dynamically create tabs for it.
    final int count = content.getChildCount();
    // this must be called before addTab() so that the TabHost searches its TabWidget
    // and FrameLayout.
    tabHost.setup();
    if (count == 0) {
        // Create a dummy child to get a single tab
        TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label", tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details)).setContent(new TabHost.TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new LinearLayout(getContext());
            }
        });
        tabHost.addTab(spec);
        return;
    } else {
        // for each child of the framelayout, add a new TabSpec
        for (int i = 0; i < count; i++) {
            View child = content.getChildAt(i);
            String tabSpec = String.format("tab_spec%d", i + 1);
            int id = child.getId();
            Pair<ResourceType, String> resource = projectCallback.resolveResourceId(id);
            String name;
            if (resource != null) {
                name = resource.getSecond();
            } else {
                // default name if id is unresolved.
                name = String.format("Tab %d", i + 1);
            }
            tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
        }
    }
}
Also used : TabHost(android.widget.TabHost) ResourceType(com.android.resources.ResourceType) TabWidget(android.widget.TabWidget) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) TabSpec(android.widget.TabHost.TabSpec) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Example 24 with TabWidget

use of android.widget.TabWidget in project android-support-v4-googlemaps by petedoyle.

the class FragmentTabHost method initFragmentTabHost.

private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();
    super.setOnTabChangedListener(this);
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0));
        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));
        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, 0, 1));
    }
}
Also used : TypedArray(android.content.res.TypedArray) FrameLayout(android.widget.FrameLayout) TabWidget(android.widget.TabWidget) LinearLayout(android.widget.LinearLayout)

Example 25 with TabWidget

use of android.widget.TabWidget in project ride-read-android by Ride-Read.

the class MainFragmentTabHost method ensureHierarchy.

private void ensureHierarchy(Context context) {
    // we will construct a standard one here.
    if (findViewById(android.R.id.tabs) == null) {
        LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.VERTICAL);
        addView(ll, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        TabWidget tw = new TabWidget(context);
        tw.setId(android.R.id.tabs);
        tw.setOrientation(TabWidget.HORIZONTAL);
        ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0));
        FrameLayout fl = new FrameLayout(context);
        fl.setId(android.R.id.tabcontent);
        ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0));
        mRealTabContent = fl = new FrameLayout(context);
        mRealTabContent.setId(mContainerId);
        ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
    }
}
Also used : FrameLayout(android.widget.FrameLayout) TabWidget(android.widget.TabWidget) LinearLayout(android.widget.LinearLayout)

Aggregations

TabWidget (android.widget.TabWidget)37 View (android.view.View)21 FrameLayout (android.widget.FrameLayout)16 TabHost (android.widget.TabHost)15 LinearLayout (android.widget.LinearLayout)14 ViewGroup (android.view.ViewGroup)13 ListView (android.widget.ListView)12 TextView (android.widget.TextView)12 AdapterView (android.widget.AdapterView)9 AbsListView (android.widget.AbsListView)7 ExpandableListView (android.widget.ExpandableListView)6 ImageView (android.widget.ImageView)6 TabSpec (android.widget.TabHost.TabSpec)6 ResourceType (com.android.resources.ResourceType)6 ActionMenuView (android.widget.ActionMenuView)5 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)5 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)5 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)5 MenuView (com.android.internal.view.menu.MenuView)5 SuppressLint (android.annotation.SuppressLint)3