Beispiel #1
0
  public void centerTabItem(int position) {
    System.out.println("position " + position);
    mTabHost.setCurrentTab(position);
    final TabWidget tabWidget = mTabHost.getTabWidget();

    final int leftX = tabWidget.getChildAt(position).getLeft();
    int newX = 0;

    newX = leftX + (tabWidget.getChildAt(position).getWidth() / 2) - (screenWidth / 2);
    if (newX < 0) {
      newX = 0;
    }
    hs.scrollTo(newX, 0);
  }
  static boolean updateButtonBar(Activity a, int highlight) {
    final TabWidget ll = (TabWidget) a.findViewById(R.id.buttonbar);
    boolean withtabs = false;
    Intent intent = a.getIntent();
    if (intent != null) {
      withtabs = intent.getBooleanExtra("withtabs", false);
    }

    if (highlight == 0 || !withtabs) {
      ll.setVisibility(View.GONE);
      return withtabs;
    } else if (withtabs) {
      ll.setVisibility(View.VISIBLE);
    }
    for (int i = ll.getChildCount() - 1; i >= 0; i--) {

      View v = ll.getChildAt(i);
      boolean isActive = (v.getId() == highlight);
      if (isActive) {
        ll.setCurrentTab(i);
        sActiveTabIndex = i;
      }
      v.setTag(i);
      v.setOnFocusChangeListener(
          new View.OnFocusChangeListener() {

            public void onFocusChange(View v, boolean hasFocus) {
              if (hasFocus) {
                for (int i = 0; i < ll.getTabCount(); i++) {
                  if (ll.getChildTabViewAt(i) == v) {
                    ll.setCurrentTab(i);
                    processTabClick(
                        (Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId());
                    break;
                  }
                }
              }
            }
          });

      v.setOnClickListener(
          new View.OnClickListener() {

            public void onClick(View v) {
              processTabClick(
                  (Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId());
            }
          });
    }
    return withtabs;
  }
Beispiel #3
0
  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.mainfragment, container, false);

    screenWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth();

    event = (EventBean) getActivity().getApplicationContext();

    mTabHost = (TabHost) v.findViewById(android.R.id.tabhost);

    hs = (HorizontalScrollView) v.findViewById(R.id.horizontalScrollView1);
    mViewPager = (ViewPager) v.findViewById(R.id.pager);
    categories = event.getCategories();
    events_upcoming = event.getObject();
    category_id = new ArrayList<Integer>();
    category_name = new ArrayList<String>();

    initialiseTabHost();
    List<Fragment> fragments = getFragments();
    pageAdapter = new MyPageAdapter(getFragmentManager(), fragments);
    mViewPager.setOffscreenPageLimit(1);
    mViewPager.setAdapter(pageAdapter);

    mViewPager.setOnPageChangeListener(this);
    TabWidget widget = mTabHost.getTabWidget();
    for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
      TextView tv =
          (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
      tv.setTextColor(Color.parseColor("#ffffff"));
      if (isTabletDevice(getResources()) == true) {
        tv.setTextSize(17);
      } else {
        tv.setTextSize(14);
      }
      tv.setTypeface(event.getTextBold());
      // tv.setEllipsize(TextUtils.TruncateAt.END);
      if (Build.VERSION.SDK_INT > 11) {
        tv.setAllCaps(false);
      }
      View v1 = widget.getChildAt(i);

      // v1.setPadding(0,0,0,0);
      v1.setBackgroundResource(R.drawable.tab_selector_drawable);
    }

    return v;
  }
Beispiel #4
0
 @Override
 public void onTabChanged(String tabId) {
   int tabID = Integer.valueOf(tabId);
   for (int i = 0; i < mTabWidget.getChildCount(); i++) {
     View view = mTabWidget.getChildAt(i);
     TextView title = (TextView) view.findViewById(R.id.main_activity_tab_text);
     if (tabID == i) {
       view.setBackgroundResource(R.drawable.number_bg_pressed);
       title.setTextColor(Color.rgb(255, 255, 255));
     } else {
       view.setBackgroundResource(R.drawable.number_bg);
       title.setTextColor(Color.rgb(0, 0, 0));
     }
   }
 }
Beispiel #5
0
  private void customTabs() {
    /* 对Tab标签的定制 */
    mTabWidget = mTabHost.getTabWidget();
    for (int i = 0; i < mTabWidget.getChildCount(); i++) {
      /* 得到每个标签的视图 */
      View view = mTabWidget.getChildAt(i);
      TextView title = (TextView) view.findViewById(R.id.main_activity_tab_text);

      /* 设置每个标签的背景 */
      if (mTabHost.getCurrentTab() == i) {
        view.setBackgroundResource(R.drawable.number_bg_pressed);
        title.setTextColor(Color.rgb(255, 255, 255));
      } else {
        view.setBackgroundResource(R.drawable.number_bg);
        title.setTextColor(Color.rgb(0, 0, 0));
      }
    }
  }
  @SuppressLint("NewApi")
  public void testTabsAreSelectable() throws Throwable {
    String[] colorChooserTags = {
      mSolo.getString(R.string.color_pre), mSolo.getString(R.string.color_rgb)
    };

    assertTrue("Waiting for DrawingSurface", mSolo.waitForView(DrawingSurface.class, 1, TIMEOUT));
    mSolo.clickOnView(mButtonTopColor);
    mSolo.sleep(COLOR_PICKER_DIALOGUE_APPERANCE_DELAY);

    TabHost tabHost = (TabHost) mSolo.getView(R.id.colorview_tabColors);
    TabWidget colorTabWidget = tabHost.getTabWidget();

    assertEquals("Wrong tab count ", colorTabWidget.getTabCount(), colorChooserTags.length);
    for (int tabChildIndex = 0; tabChildIndex < colorTabWidget.getChildCount(); tabChildIndex++) {
      mSolo.clickOnView(colorTabWidget.getChildAt(tabChildIndex), true);
      mSolo.sleep(500);
      if (colorChooserTags[tabChildIndex].equalsIgnoreCase(mSolo.getString(R.string.color_pre)))
        assertFalse(
            "In preselection tab and rgb (red) string found",
            mSolo.searchText(mSolo.getString(R.string.color_red)));
      else if (colorChooserTags[tabChildIndex].equalsIgnoreCase(
          mSolo.getString(R.string.color_rgb))) {
        assertTrue(
            "In rgb tab and red string not found",
            mSolo.searchText(mSolo.getString(R.string.color_red)));
        assertTrue(
            "In rgb tab and green string not found",
            mSolo.searchText(mSolo.getString(R.string.color_green)));
        assertTrue(
            "In rgb tab and blue string not found",
            mSolo.searchText(mSolo.getString(R.string.color_blue)));
      }
    }
    mSolo.goBack();
  }
Beispiel #7
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    mEmptyText = (TextView) findViewById(android.R.id.empty); // 针对SIM卡联系人部分提示
    personList = (ListView) findViewById(R.id.listview); // SIM卡联系人
    phoneList = (ListView) findViewById(R.id.listview1); // 电话联系人
    mEditText = (TextView) findViewById(android.R.id.edit); // 针对手机联系人部分提示
    inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    layout = inflater.inflate(R.layout.add, null);

    // 对话框添加
    addDlg =
        new AlertDialog.Builder(GreenActivity.this)
            .setTitle("添加")
            .setView(layout)
            .setPositiveButton(
                "确定",
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {

                    insert();
                  }
                })
            .setNegativeButton("取消", null)
            .create();

    // 删除确认对话框
    removeDlg =
        new AlertDialog.Builder(this)
            .setTitle("删除")
            .setMessage("确定删除选中的内容吗?")
            .setPositiveButton(
                "确定",
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    // delete();

                    deletesim del = new deletesim();
                    del.execute();
                  }
                })
            .setNegativeButton("取消", null)
            .create();
    // COPY拷贝对话框
    CopyDlg =
        new AlertDialog.Builder(this)
            .setTitle("拷贝到SIM卡")
            .setMessage("确定拷贝选中内容么?")
            .setPositiveButton(
                "确定",
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    copytosim cp = new copytosim();
                    cp.execute();
                  }
                })
            .setNegativeButton("取消", null)
            .create();

    // TabHost的相关设置
    int width = 55;
    int height = 60;
    final TabHost tabhost = getTabHost();
    tabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));
    // frank
    Drawable localDrawable1 = getResources().getDrawable(R.drawable.sim_icon);
    Drawable localDrawable2 = getResources().getDrawable(R.drawable.phone_icon);
    tabhost.addTab(
        tabhost.newTabSpec("sim").setIndicator("SIM卡联系人", localDrawable1).setContent(R.id.cb));
    tabhost.addTab(
        tabhost.newTabSpec("phone").setIndicator("手机联系人", localDrawable2).setContent(R.id.list));

    final TabWidget tabwidget = tabhost.getTabWidget();

    for (int i = 0; i < tabwidget.getChildCount(); i++) {
      // 设置页签高度和页签内字体属性
      TextView tv = (TextView) tabwidget.getChildAt(i).findViewById(android.R.id.title);
      tabwidget.getChildAt(i).getLayoutParams().height = height;
      tabwidget.getChildAt(i).getLayoutParams().width = width;
      // tabwidget.setBackgroundResource(R.drawable.toolbar_menu_bg);
      tv.setTextSize(15);
      tv.setTextColor(Color.BLACK);
      tv.setGravity(Gravity.CENTER_HORIZONTAL);
    }
    // 监听
    tabhost.setOnTabChangedListener(this);

    /** ************ 默认SIM卡联系人****************** */
    asyncQuery = new MyAsyncQueryHandler(getContentResolver());
    // 异步读取联系人的信息
    asyncQueryContact();
    /** ********************************************* */
  }
  public void testIfRGBSeekBarsDoChangeColor()
      throws SecurityException, IllegalArgumentException, NoSuchFieldException,
          IllegalAccessException {
    final int RGB_TAB_INDEX = 1;
    testOpenColorPickerOnClickOnColorButton();
    TabHost tabHost = (TabHost) mSolo.getView(R.id.colorview_tabColors);
    TabWidget colorTabWidget = tabHost.getTabWidget();
    mSolo.clickOnView(colorTabWidget.getChildAt(RGB_TAB_INDEX), true);
    mSolo.waitForText(mSolo.getString(R.string.color_red));
    final Paint originalStrokePaint =
        (Paint)
            PrivateAccess.getMemberValue(
                BaseTool.class, PaintroidApplication.currentTool, "mCanvasPaint");
    final int originalPaintColor = originalStrokePaint.getColor();
    final ArrayList<ProgressBar> currentProgressBars = mSolo.getCurrentViews(ProgressBar.class);
    assertEquals("No progress bars for ARGB :-(", currentProgressBars.size(), 4);
    final ArrayList<TextView> currentTextViews =
        mSolo.getCurrentViews(TextView.class, mSolo.getView(R.id.rgb_base_layout));
    assertEquals("Missing some text views RGBA and ARGV-values", 9, currentTextViews.size());
    int textValueCounter = 1;
    for (; textValueCounter < currentTextViews.size(); textValueCounter += 2) {
      int textValueAsInteger =
          Integer.parseInt((String) currentTextViews.get(textValueCounter).getText());
      assertTrue(
          "Not in range 0<=textValue<=255", textValueAsInteger >= 0 && textValueAsInteger <= 255);
    }

    textValueCounter = 1;
    for (ProgressBar barToChange : currentProgressBars) {
      int changeSeekBarTo = (barToChange.getProgress() + 33) % barToChange.getMax();
      mSolo.setProgressBar(barToChange, changeSeekBarTo);
      mSolo.sleep(50);
      if (textValueCounter == 4) { // alpha 0-100%
        int expectetAlphaTextValue = (int) (changeSeekBarTo / 2.55f);
        assertEquals(
            "Text value did not change index:" + textValueCounter,
            expectetAlphaTextValue,
            Integer.parseInt((String) currentTextViews.get(textValueCounter * 2 - 1).getText()));
      } else
        assertEquals(
            "Text value did not change index:" + textValueCounter,
            changeSeekBarTo,
            Integer.parseInt((String) currentTextViews.get(textValueCounter * 2 - 1).getText()));
      textValueCounter++;
    }
    mSolo.goBack();
    final Paint rgbChangedStrokePaint =
        (Paint)
            PrivateAccess.getMemberValue(
                BaseTool.class, PaintroidApplication.currentTool, "mCanvasPaint");
    final int rgbChangedPaintColor = rgbChangedStrokePaint.getColor();
    assertFalse(
        "Alpha value did not change",
        Color.alpha(rgbChangedPaintColor) == Color.alpha(originalPaintColor));
    assertFalse(
        "Red value did not change",
        Color.red(rgbChangedPaintColor) == Color.red(originalPaintColor));
    assertFalse(
        "Green value did not change",
        Color.green(rgbChangedPaintColor) == Color.green(originalPaintColor));
    assertFalse(
        "Blue value did not change",
        Color.blue(rgbChangedPaintColor) == Color.blue(originalPaintColor));
  }