@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    list = new ListView(getActivity());
    list.setBackgroundColor(Color.WHITE);
    borrowedBooks = new ArrayList<>();

    // Initiate progressbar
    pb = new ProgressBar(getActivity()); // Init the progressbar
    pb.setId(1); // Give pb an id
    pb.setVisibility(View.INVISIBLE); // Set progressbar visibility

    // Progressbar details
    RelativeLayout.LayoutParams progressBarDetails =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    progressBarDetails.addRule(RelativeLayout.CENTER_HORIZONTAL);
    progressBarDetails.addRule(RelativeLayout.CENTER_VERTICAL);

    if (borrowedBooks.isEmpty()) {
      try {
        requestRequests(BookshelfConstants.CONNECTION_URI);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    } else {
      updateDisplay();
    }
    return list;
  }
예제 #2
0
  protected void buildView() {
    final Context context = getContext();

    mProgressBar = new ProgressBar(context);
    final LayoutParams progressLayoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
    progressLayoutParams.gravity = Gravity.CENTER;
    mProgressBar.setLayoutParams(progressLayoutParams);
    mProgressBar.setId(INTERNAL_PROGRESS_ID);
    mProgressBar.setIndeterminate(true);
    mProgressBar.setVisibility(View.GONE);

    addView(mProgressBar);

    mIsLoading = false;

    mImageView = new ImageView(context);
    final LayoutParams imageViewLayoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
    imageViewLayoutParams.gravity = Gravity.CENTER;
    mImageView.setLayoutParams(imageViewLayoutParams);
    mImageView.setId(INTERNAL_IMAGEVIEW_ID);
    mImageView.setVisibility(View.VISIBLE);

    addView(mImageView);

    setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
  }
  /** Create the view in which the video will be rendered. */
  private void setupView() {
    LinearLayout lLinLayout = new LinearLayout(this);
    lLinLayout.setId(1);
    lLinLayout.setOrientation(LinearLayout.VERTICAL);
    lLinLayout.setGravity(Gravity.CENTER);
    lLinLayout.setBackgroundColor(Color.BLACK);

    LayoutParams lLinLayoutParms =
        new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    lLinLayout.setLayoutParams(lLinLayoutParms);

    this.setContentView(lLinLayout);

    RelativeLayout lRelLayout = new RelativeLayout(this);
    lRelLayout.setId(2);
    lRelLayout.setGravity(Gravity.CENTER);
    lRelLayout.setBackgroundColor(Color.BLACK);
    android.widget.RelativeLayout.LayoutParams lRelLayoutParms =
        new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    lRelLayout.setLayoutParams(lRelLayoutParms);
    lLinLayout.addView(lRelLayout);

    mVideoView = new VideoView(this);
    mVideoView.setId(3);
    android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams =
        new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    mVideoView.setLayoutParams(lVidViewLayoutParams);
    lRelLayout.addView(mVideoView);

    mProgressBar = new ProgressBar(this);
    mProgressBar.setIndeterminate(true);
    mProgressBar.setVisibility(View.VISIBLE);
    mProgressBar.setEnabled(true);
    mProgressBar.setId(4);
    android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms =
        new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(lProgressBarLayoutParms);
    lRelLayout.addView(mProgressBar);

    mProgressMessage = new TextView(this);
    mProgressMessage.setId(5);
    android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms =
        new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4);
    mProgressMessage.setLayoutParams(lProgressMsgLayoutParms);
    mProgressMessage.setTextColor(Color.LTGRAY);
    mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
    mProgressMessage.setText("...");
    lRelLayout.addView(mProgressMessage);
  }
예제 #4
0
  private void showLoading() {
    ProgressBar pb = new ProgressBar(getContext());
    pb.setIndeterminateDrawable(getContext().getResources().getDrawable(R.drawable.progress));

    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    pb.setPadding(0, (int) (50 * ratio), 0, (int) (50 * ratio));
    pb.setLayoutParams(params);
    pb.setId(5000);
    TableLayout table = (TableLayout) findViewById(R.id.table);
    table.setGravity(Gravity.CENTER);
    table.addView(pb);
  }
예제 #5
0
  @Override
  @NonNull
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    setCancelable(false);

    // Add a progress bar to the dialog
    mBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleHorizontal);
    mBar.setId(android.R.id.progress);

    // Create the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.diag_back_up);
    builder.setView(mBar);

    if (isSdCardWritable(getActivity())) {
      builder.setMessage(R.string.diag_back_up_external);
    } else {
      builder.setMessage(R.string.diag_back_up_internal);
    }

    return builder.create();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);

    // Instantiate lists
    tasks = new ArrayList<>();
    tempBookList = new ArrayList<>();
    swipe = new SwipeRefreshLayout(getActivity());

    // Instantiate listview
    list = new ListView(getActivity());

    // Initiate progressbar for loading
    pb = new ProgressBar(getActivity()); // Init the progressbar
    pb.setId(1); // Give pb an id
    pb.setVisibility(View.INVISIBLE); // Set progressbar visibility

    // Set details list
    list.setBackgroundColor(Color.WHITE);
    list.setMultiChoiceModeListener(multiChoiceHandler);
    list.setOnItemClickListener(onItemClickHandler);
    list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

    swipe.setOnRefreshListener(refreshListener);

    try {
      requestData(BookshelfConstants.CONNECTION_URI);
    } catch (JSONException e) {
      e.printStackTrace();
    }

    swipe.addView(list);

    return swipe;
  }
  /**
   * Adds an action button to the compatibility action bar, using menu information from a {@link
   * android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state
   * can be changed to show a loading spinner using {@link
   * com.example.android.actionbarcompat.ActionBarHelperBase#setRefreshActionItemState(boolean)}.
   */
  private View addActionItemCompatFromMenuItem(final MenuItem item) {
    final int itemId = item.getItemId();

    final ViewGroup actionBar = getActionBarCompat();
    if (actionBar == null) {
      return null;
    }

    // Create the button
    ImageButton actionButton =
        new ImageButton(
            mActivity,
            null,
            itemId == android.R.id.home
                ? R.attr.actionbarCompatItemHomeStyle
                : R.attr.actionbarCompatItemStyle);
    actionButton.setLayoutParams(
        new ViewGroup.LayoutParams(
            (int)
                mActivity
                    .getResources()
                    .getDimension(
                        itemId == android.R.id.home
                            ? R.dimen.actionbar_compat_button_home_width
                            : R.dimen.actionbar_compat_button_width),
            ViewGroup.LayoutParams.FILL_PARENT));
    if (itemId == R.id.menu_refresh) {
      actionButton.setId(R.id.actionbar_compat_item_refresh);
    }
    actionButton.setImageDrawable(item.getIcon());
    actionButton.setScaleType(ImageView.ScaleType.CENTER);
    actionButton.setContentDescription(item.getTitle());
    actionButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
          }
        });

    actionBar.addView(actionButton);

    if (item.getItemId() == R.id.menu_refresh) {
      // Refresh buttons should be stateful, and allow for indeterminate progress indicators,
      // so add those.
      ProgressBar indicator =
          new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle);

      final int buttonWidth =
          mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_button_width);
      final int buttonHeight =
          mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height);
      final int progressIndicatorWidth = buttonWidth / 2;

      LinearLayout.LayoutParams indicatorLayoutParams =
          new LinearLayout.LayoutParams(progressIndicatorWidth, progressIndicatorWidth);
      indicatorLayoutParams.setMargins(
          (buttonWidth - progressIndicatorWidth) / 2,
          (buttonHeight - progressIndicatorWidth) / 2,
          (buttonWidth - progressIndicatorWidth) / 2,
          0);
      indicator.setLayoutParams(indicatorLayoutParams);
      indicator.setVisibility(View.GONE);
      indicator.setId(R.id.actionbar_compat_item_refresh_progress);
      actionBar.addView(indicator);
    }

    return actionButton;
  }
  private void initMainGroupCellView(Context context) {
    setOrientation(LinearLayout.VERTICAL);

    mCell = new RelativeLayout(context);
    mCell.setBackgroundResource(R.drawable.list_selector);

    mWrapper = new LinearLayout(context);
    mWrapper.setOrientation(LinearLayout.HORIZONTAL);
    mWrapper.setGravity(Gravity.CENTER_VERTICAL);

    mSectionTextView = new TextView(context);
    mSectionTextView.setTextColor(context.getResources().getColor(R.color.header_section));
    mSectionTextView.setGravity(Gravity.CENTER);
    mSectionTextView.setTypeface(null, Typeface.BOLD);
    mSectionTextView.setBackgroundColor(
        Color.WHITE); // setBackgroundResource(R.drawable.bg_section_header);
    addView(mSectionTextView);
    mSectionTextView.getLayoutParams().width = LinearLayout.LayoutParams.MATCH_PARENT;

    mImageView = new ImageView(context);
    mImageView.setId(R.id.imageView1);
    mLearningStatisticImageView = new ImageView(context);
    mLearningStatisticImageView.setId(R.id.imageView4);
    mLearningStatisticImageView.setVisibility(View.GONE);

    mTextView = new TextView(context);
    try {
      mTextView.setTextColor(
          ColorStateList.createFromXml(
              getResources(), getResources().getXml(R.color.textcolor_black_white)));
    } catch (NotFoundException e) {
    } catch (XmlPullParserException e) {
    } catch (IOException e) {
    }
    mTextView.setTextSize(14.0f);
    mTextView.setTypeface(null, Typeface.BOLD);
    mTextView.setGravity(Gravity.CENTER_VERTICAL);

    mProgressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
    try {
      mProgressBar.setProgressDrawable(
          Drawable.createFromXml(
              getResources(), getResources().getXml(R.drawable.learning_progress_bar)));
    } catch (NotFoundException e) {
    } catch (XmlPullParserException e) {
    } catch (IOException e) {
    }
    mProgressBar.setId(android.R.id.progress);
    mProgressBar.setMax(100);

    mScale = context.getResources().getDisplayMetrics().density;

    LinearLayout.LayoutParams linearParams =
        new LinearLayout.LayoutParams((int) (30 * mScale), (int) (30 * mScale));
    linearParams.rightMargin = (int) (20 * mScale);
    mWrapper.addView(mImageView, linearParams);

    linearParams =
        new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    mWrapper.addView(mTextView, linearParams);

    RelativeLayout.LayoutParams layoutParams =
        new RelativeLayout.LayoutParams((int) (70 * mScale), (int) (20 * mScale));
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    layoutParams.rightMargin = (int) (10 * mScale);
    mCell.addView(mProgressBar, layoutParams);

    layoutParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    layoutParams.rightMargin = (int) (10 * mScale);
    mCell.addView(mLearningStatisticImageView, layoutParams);

    layoutParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.LEFT_OF, mProgressBar.getId());
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.leftMargin = (int) (6 * mScale);
    layoutParams.rightMargin = (int) (10 * mScale);
    mCell.addView(mWrapper, layoutParams);

    addView(
        mCell,
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
  }