Java 类android.widget.TabHost.TabContentFactory 实例源码

项目:faims-android    文件:FileGalleryPreviewDialog.java   
public void addCameraPreview(final View view) {
    TabHost.TabSpec tab = tabHost.newTabSpec("camera_preview");
    tab.setIndicator("Image Preview");
    tab.setContent(new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            ScrollView scrollView = new ScrollView(getContext());
            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.VERTICAL);
            scrollView.addView(layout);

            layout.addView(view);

            return scrollView;
        }
    });
    tabHost.addTab(tab);
}
项目:faims-android    文件:FileGalleryPreviewDialog.java   
public void addVideoPreview(View view) {
    if (view instanceof VideoView) {
        videoView = (VideoView) view;
    }

    TabHost.TabSpec tab = tabHost.newTabSpec("video_preview");
    tab.setIndicator("Video Preview");
    tab.setContent(new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.VERTICAL);

            layout.addView(videoView, new LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.MATCH_PARENT));

            return layout;
        }
    });
    tabHost.addTab(tab);
}
项目:faims-android    文件:FileGalleryPreviewDialog.java   
public void addActionsTab(final String label, final View.OnClickListener listener) {
    TabHost.TabSpec tab = tabHost.newTabSpec("file_actions");
    tab.setIndicator("Actions");
    tab.setContent(new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.VERTICAL);

            Button remove = (Button) LayoutInflater.from(getContext()).inflate(R.layout.button_danger, null);
            LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            params.topMargin = (int) ScaleUtil.getDip(getContext(), 10);
            remove.setLayoutParams(params);
            remove.setText(label);
            remove.setOnClickListener(listener);
            layout.addView(remove);

            return layout;
        }
    });
    tabHost.addTab(tab);
}
项目:faims-android    文件:LabelDialog.java   
public void addAnnotationTab() {
    addTab(ANNOTATION_TAB, "Annotation", new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.VERTICAL);

            TextView textView = new TextView(getContext());
            textView.setText("    Set the annotation text for the field");
            layout.addView(textView);

            annotationText = new EditText(getContext());
            layout.addView(annotationText);

            updateAnnotation();

            return layout;
        }
    });
}
项目:faims-android    文件:AttributeLabelDialog.java   
public void addInfoTab(final String description, final String moduleDir) {
    addTab(INFO_TAB, "Info", new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            LinearLayout layout = new LinearLayout(getContext());
            infoWebView = new WebView(tabHost.getContext());
            infoWebView.getSettings().setBuiltInZoomControls(true);
            infoWebView.getSettings().setDisplayZoomControls(false);
            layout.addView(infoWebView);
            infoDescription = description;
            infoModuleDir = moduleDir;
            updateInfo();
            return layout;
        }
    });
}
项目:faims-android    文件:AttributeLabelDialog.java   
public void addDirtyTab() {
    addTab(DIRTY_TAB, "Dirty", new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            ScrollView scrollView = new ScrollView(getContext());
            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.VERTICAL);

            TextView label = new TextView(getContext());
            label.setText("Dirty Reason:");
            layout.addView(label);

            dirtyReasonText = new EditText(getContext());
            dirtyReasonText.setEnabled(false);
            layout.addView(dirtyReasonText);

            scrollView.addView(layout);

            updateDirtyReason();

            return scrollView;
        }
    });
}
项目:OschinaMainFrameWorkWithToolBar    文件:MainActivity.java   
private void initTabs() {
    MainTab[] tabs = MainTab.values();
    final int size = tabs.length;
    for (int i = 0; i < size; i++) {
        MainTab mainTab = tabs[i];
        TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));

        View indicator = inflateView(R.layout.v2_tab_indicator);
        ImageView icon = (ImageView) indicator.findViewById(R.id.tab_icon);
        icon.setImageResource(mainTab.getResIcon());
        TextView title = (TextView) indicator.findViewById(R.id.tab_titile);
        title.setText(getString(mainTab.getResName()));
        tab.setIndicator(indicator);
        tab.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new View(MainActivity.this);
            }
        });

        mTabHost.addTab(tab, mainTab.getClz(), null);

    }
}
项目:FullRobolectricTestSample    文件:TabSpecTest.java   
@Test
public void shouldSetTheContentView() throws Exception {
  TabHost.TabSpec foo = new TabHost(Robolectric.application).newTabSpec("Foo").setContent(
      new TabContentFactory() {
        public View createTabContent(String tag) {
          TextView tv = new TextView(Robolectric.application);
          tv.setText("The Text of " + tag);
          return tv;
        }
      });

  ShadowTabHost.ShadowTabSpec shadowFoo = shadowOf(foo);
  TextView textView = (TextView) shadowFoo.getContentView();


  assertThat(textView.getText().toString()).isEqualTo("The Text of Foo");
}
项目:FullRobolectricTestSample    文件:TabHostTest.java   
@Test
public void shouldRetrieveTheCurrentViewFromTabContentFactory() {
  TabHost tabHost = new TabHost(Robolectric.application);

  TabHost.TabSpec foo = tabHost.newTabSpec("Foo").setContent(
  new TabContentFactory() {
    public View createTabContent(String tag) {
      TextView tv = new TextView(Robolectric.application);
      tv.setText("The Text of " + tag);
      return tv;
    }
  });

  tabHost.addTab(foo);
  tabHost.setCurrentTabByTag("Foo");
  TextView textView = (TextView) tabHost.getCurrentView();

  assertThat(textView.getText().toString()).isEqualTo("The Text of Foo");
}
项目:faims-android    文件:FileGalleryPreviewDialog.java   
public void addFileMetadataTab(final ArrayList<NameValuePair> metadata) {
    TabHost.TabSpec tab = tabHost.newTabSpec("file_metadata");
    tab.setIndicator("File Metadata");
    tab.setContent(new TabContentFactory() {

        @Override
        public View createTabContent(String tag) {
            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.VERTICAL);

            TableLayout table = new TableLayout(getContext());
            LayoutInflater inflater = (LayoutInflater) FileGalleryPreviewDialog.this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            for (NameValuePair dataItem : metadata) {
                TableRow rowView = (TableRow) inflater.inflate(R.layout.static_module_data_row, null);
                TextView label = (TextView) rowView.findViewById(R.id.static_data_label);
                label.setText(dataItem.getName());
                TextView value = (TextView) rowView.findViewById(R.id.static_data_value);
                value.setText(dataItem.getValue());
                table.addView(rowView);
            }

            layout.addView(table);
            return layout;
        }
    });
    tabHost.addTab(tab);
}
项目:faims-android    文件:LabelDialog.java   
protected void addTab(String id, String title, TabContentFactory content) {
    TabHost.TabSpec tab = tabHost.newTabSpec(id);
    tab.setIndicator(title);
    tab.setContent(content);
    tabs.add(id);
    tabSpecs.add(tab);
}
项目:faims-android    文件:Tab.java   
public TabSpec createTabSpec(TabHost tabHost) {
    TabSpec tabSpec = tabHost.newTabSpec(name);

    tabSpec.setContent(new TabContentFactory() {

           @Override
           public View createTabContent(String tag) {
            return view;
           }
       });

       tabSpec.setIndicator(label);

    return tabSpec;
}
项目:FragmentMixViewPager    文件:MainActivity.java   
private void initTabs() {
    MainTab[] tabs = MainTab.values();
    final int size = tabs.length;
    for (int i = 0; i < size; i++) {
        MainTab mainTab = tabs[i];
        TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));
        View indicator = LayoutInflater.from(getApplicationContext())
                .inflate(R.layout.tab_indicator, null);
        TextView title = (TextView) indicator.findViewById(R.id.tab_title);
        Drawable drawable = this.getResources().getDrawable(
                mainTab.getResIcon());
        title.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null,
                null);

        title.setText(getString(mainTab.getResName()));
        tab.setIndicator(indicator);
        tab.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new View(MainActivity.this);
            }
        });
        mTabHost.addTab(tab, mainTab.getClz(), null);

        mTabHost.getTabWidget().getChildAt(i).setOnTouchListener(this);
    }
}
项目:oschina-app    文件:MainActivity.java   
private void initTabs() {
    MainTab[] tabs = MainTab.values();
    final int size = tabs.length;
    for (int i = 0; i < size; i++) {
        MainTab mainTab = tabs[i];
        TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));

        View indicator = inflateView(R.layout.v2_tab_indicator);
        ImageView icon = (ImageView) indicator.findViewById(R.id.tab_icon);
        icon.setImageResource(mainTab.getResIcon());
        TextView title = (TextView) indicator.findViewById(R.id.tab_titile);
        title.setText(getString(mainTab.getResName()));
        tab.setIndicator(indicator);
        tab.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new View(MainActivity.this);
            }
        });

        mTabHost.addTab(tab, mainTab.getClz(), null);
        if (mainTab.equals(MainTab.ME)) {
            View con = indicator.findViewById(R.id.container);
            // con.setBackgroundColor(Color.parseColor("#00ff00"));
            mBvTweet = new BadgeView(this, con);
            mBvTweet.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
            mBvTweet.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
            mBvTweet.setBackgroundResource(R.drawable.tab_notification_bg);
        }
    }
}
项目:ima_intellj    文件:MainActivity.java   
private void initTabs() {
    MainTab[] tabs = MainTab.values();
    final int size = tabs.length;
    for (int i = 0; i < size; i++) {
        MainTab mainTab = tabs[i];
        TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));

        View indicator = inflateView(R.layout.v2_tab_indicator);
        ImageView icon = (ImageView) indicator.findViewById(R.id.tab_icon);
        icon.setImageResource(mainTab.getResIcon());
        TextView title = (TextView) indicator.findViewById(R.id.tab_titile);
        title.setText(getString(mainTab.getResName()));
        tab.setIndicator(indicator);
        tab.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new View(MainActivity.this);
            }
        });

        mTabHost.addTab(tab, mainTab.getClz(), null);
        if (mainTab.equals(MainTab.ME)) {
            View con = indicator.findViewById(R.id.container);
            // con.setBackgroundColor(Color.parseColor("#00ff00"));
            mBvTweet = new BadgeView(this, con);
            mBvTweet.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
            mBvTweet.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
            mBvTweet.setBackgroundResource(R.drawable.tab_notification_bg);
        }
    }
}
项目:irma_future_id    文件:PluginActivity.java   
/**
    * Sets up each tab of the TabHost with the corresponding contents.
    */
   private void setUpTabHost() {
TabHost tabs = (TabHost) this.findViewById(R.id.my_tabhost);
tabs.setup();

TabContentFactory tabContentFactory = new TabContentFactory() {

    @Override
    public View createTabContent(String tag) {
    LinearLayout ll = new LinearLayout(PluginActivity.this);
    ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    View v;
    if (tag.equals(tabIndexes[0])) {
        v = createDescriptionView();
    } else if (tag.equals(tabIndexes[1])) {
        v = createActionsView();
    } else {
        v = createSettingsView();
    }
    ll.addView(v);
    return ll;
    }
};

TabSpec tspec1 = tabs.newTabSpec(tabIndexes[0]);
tspec1.setIndicator(lang.translationForKey(DESCRIPTION));
tspec1.setContent(tabContentFactory);
tabs.addTab(tspec1);
TabSpec tspec2 = tabs.newTabSpec(tabIndexes[1]);
tspec2.setIndicator(lang.translationForKey(ACTIONS));
tspec2.setContent(tabContentFactory);
tabs.addTab(tspec2);
TabSpec tspec3 = tabs.newTabSpec(tabIndexes[2]);
tspec3.setIndicator(lang.translationForKey(SETTINGS));
tspec3.setContent(tabContentFactory);
tabs.addTab(tspec3);
   }
项目:StudyGroupX    文件:TabActivityMainActivity.java   
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab_activity_main);

    TabHost tabHost=getTabHost();
    // no need to call TabHost.Setup()        

    //First Tab
    TabSpec spec1=tabHost.newTabSpec("Tab 1");
    spec1.setIndicator("Tab 1",getResources().getDrawable(android.R.drawable.arrow_up_float));
    Intent in1=new Intent(this, Act1.class);
    spec1.setContent(in1);

    TabSpec spec2=tabHost.newTabSpec("Tab 2");
    spec2.setIndicator("Tab 2",getResources().getDrawable(android.R.drawable.arrow_down_float));
    Intent in2=new Intent(this,Act2.class);
    spec2.setContent(in2);

    //Dynamically Adding tabs
    TabSpec spec3=tabHost.newTabSpec("Tab 3");
    spec3.setIndicator("Tab 3",getResources().getDrawable(android.R.drawable.btn_plus));
    spec3.setContent(new TabContentFactory() {

           @Override
           public View createTabContent(String tag) {
            // TODO Auto-generated method stub
               TextView tv = new TextView(TabActivityMainActivity.this);
               tv.setText("HELLO WORK");
            tv.setBackgroundColor(Color.GREEN);
            return (tv);//new AnalogClock(TabActivityMainActivity.this));
           }
          });

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