/** View that corresponds to a CPU freq state row as specified by the state parameter */
  private void generateStateRow(
      CpuStateMonitor.CpuState state, ViewGroup parent, CpuStateMonitor monitor) {
    // inflate the XML into a view in the parent
    LinearLayout layout =
        (LinearLayout)
            LayoutInflater.from(getActivity()).inflate(R.layout.state_row, parent, false);

    // what percentage we've got
    float per = (float) state.duration * 100 / monitor.getTotalStateTime();
    String sPer = (int) per + "%";

    // state name
    String sFreq = state.freq == 0 ? getString(R.string.deep_sleep) : state.freq / 1000 + "MHz";

    // duration
    long tSec = state.duration / 100;
    String sDur = sToString(tSec);

    // map UI elements to objects
    TextView freqText = (TextView) layout.findViewById(R.id.ui_freq_text);
    TextView durText = (TextView) layout.findViewById(R.id.ui_duration_text);
    TextView perText = (TextView) layout.findViewById(R.id.ui_percentage_text);
    ProgressBar bar = (ProgressBar) layout.findViewById(R.id.ui_bar);

    // modify the row
    freqText.setText(sFreq);
    perText.setText(sPer);
    durText.setText(sDur);
    bar.setProgress(Math.round(per));

    // add it to parent and return
    parent.addView(layout);

    if (Utils.isTV(getActivity())) {
      layout.setFocusable(true);
      layout.setFocusableInTouchMode(true);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TypedArray ta =
            getActivity().obtainStyledAttributes(new int[] {R.attr.selectableItemBackground});
        Drawable d = ta.getDrawable(0);
        ta.recycle();
        layout.setBackground(d);
      }
    }
  }
Ejemplo n.º 2
0
  private void initView() {

    // scrollView_course_detail = (ScrollView) mView.findViewById(R.id.scrollView_course_detail);
    // 设置 scrollView 定位到顶部
    ll_course_detail = (LinearLayout) findViewById(R.id.ll_course_detail);
    ll_course_detail.setFocusable(true);
    ll_course_detail.setFocusableInTouchMode(true);
    ll_course_detail.requestFocus();
    mLayoutInflater = LayoutInflater.from(this);
    // 找到TabHost
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
    mAbSlidingPlayView = (AbSlidingPlayView) findViewById(R.id.mAbSlidingPlayView);
    mAbSlidingPlayView.setNavHorizontalGravity(Gravity.CENTER);
    // mAbSlidingPlayView.setParentHScrollView(menuLayout);
    mAbSlidingPlayView.startPlay();
    // 得到fragment的个数
    int count = mFragmentArray.length;
    for (int i = 0; i < count; i++) {
      // 给每个Tab按钮设置图标、文字和内容
      TabSpec tabSpec = mTabHost.newTabSpec(mTextArray[i]).setIndicator(getTabItemView(i));
      Bundle bundle = new Bundle();
      bundle.putString(Constants.KEY_ID, id);
      // 将Tab按钮添加进Tab选项卡中
      mTabHost.addTab(tabSpec, mFragmentArray[i], bundle);
      // 设置Tab按钮的背景
      mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.selector_detail_tab);
    }
    titlebar = (TitleBar) findViewById(R.id.index_titlebar);
    titlebar.setTitleBarTitle(title);

    ivShare = (ImageView) findViewById(R.id.title_share);
    btZixun = (Button) findViewById(R.id.bt_book);
    btBuy = (Button) findViewById(R.id.bt_buy);
    dialog = new CustomProgressDialog(this, R.string.laoding_tips, R.anim.frame2);
    dialog.show();
  }