Example #1
0
  private void initBarButtons() {
    final LinearLayout.LayoutParams llButtonParams =
        new LinearLayout.LayoutParams(buttonWidth, buttonWidth);
    llButtonParams.setMargins(0, 0, buttonMargin, 0);

    undoButton.setBackgroundResource(R.drawable.undo_button_selector);
    undoButton.setPadding(0, 0, 0, 0);
    undoButton.setLayoutParams(llButtonParams);
    this.addView(undoButton);

    redoButton.setBackgroundResource(R.drawable.redo_button_selector);
    redoButton.setPadding(0, 0, 0, 0);
    redoButton.setLayoutParams(llButtonParams);
    this.addView(redoButton);

    // Tool radio group
    LayoutParams radioGroupParams =
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    radioGroupParams.setMargins(0, 0, 0, 0);

    final RadioGroup toolRadioGroup = new RadioGroup(this.getContext());
    toolRadioGroup.setOrientation(RadioGroup.HORIZONTAL);
    toolRadioGroup.setLayoutParams(radioGroupParams);
    toolRadioGroup.setPadding(0, 0, 0, 0);

    final RadioGroup.LayoutParams rgButtonParams =
        new RadioGroup.LayoutParams(buttonWidth, buttonWidth);
    rgButtonParams.setMargins(0, 0, buttonMargin, 0);

    selectButton.setButtonDrawable(R.drawable.select_button_selector);
    selectButton.setLayoutParams(rgButtonParams);
    toolRadioGroup.addView(selectButton);

    eraserButton.setButtonDrawable(R.drawable.erase_button_selector);
    eraserButton.setLayoutParams(rgButtonParams);
    toolRadioGroup.addView(eraserButton);

    for (int i = 0; i < 8; i++) {
      penButtons[i] = new PenRadioButton(this.getContext());
      penButtons[i].setLayoutParams(rgButtonParams);
      toolRadioGroup.addView(penButtons[i]);
    }

    this.addView(toolRadioGroup);

    menuButtonSpacer.setLayoutParams(
        new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f));
    this.addView(menuButtonSpacer);

    menuButton.setBackgroundResource(R.drawable.ic_action_overflow);
    menuButton.setPadding(0, 0, 0, 0);
    menuButton.setLayoutParams(llButtonParams);
    menuButton.setOnClickListener(menuButtonListener);
    this.addView(menuButton);
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.stats_visitors_and_views_fragment, container, false);

    TextView titleTextView = (TextView) view.findViewById(R.id.stats_pager_title);
    titleTextView.setText(getTitle());

    mVisitorsToday =
        (TextView) view.findViewById(R.id.stats_visitors_and_views_today_visitors_count);
    mViewsToday = (TextView) view.findViewById(R.id.stats_visitors_and_views_today_views_count);
    mViewsBestEver =
        (TextView) view.findViewById(R.id.stats_visitors_and_views_best_ever_views_count);
    mViewsAllTime = (TextView) view.findViewById(R.id.stats_visitors_and_views_all_time_view_count);
    mCommentsAllTime =
        (TextView) view.findViewById(R.id.stats_visitors_and_views_all_time_comment_count);

    RadioGroup mRadioGroup = (RadioGroup) view.findViewById(R.id.stats_pager_tabs);
    mRadioGroup.setVisibility(View.VISIBLE);
    mRadioGroup.setOnCheckedChangeListener(this);

    for (int i = 0; i < TITLES.length; i++) {
      RadioButton rb =
          (RadioButton)
              LayoutInflater.from(getActivity()).inflate(R.layout.stats_radio_button, null, false);
      RadioGroup.LayoutParams params =
          new RadioGroup.LayoutParams(
              RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
      int dp8 = (int) Utils.dpToPx(8);
      params.setMargins(0, 0, dp8, 0);
      rb.setMinimumWidth((int) Utils.dpToPx(80));
      rb.setGravity(Gravity.CENTER);
      rb.setLayoutParams(params);
      rb.setText(TITLES[i]);
      mRadioGroup.addView(rb);

      if (i == mSelectedButtonIndex) rb.setChecked(true);
    }

    return view;
  }