Android Open Source - sloop Info Bar Fragment






From Project

Back to project page sloop.

License

The source code is released under:

NON-LICENSE The Sloop data-browser source code is hereby released into the Public Domain. The original author, David Megginson, Megginson Technologies Ltd., and Acclar Open Ltd. provide no warranty:...

If you think the Android project sloop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.megginson.sloop.activities;
/*w  w w  .  j a  va  2s . com*/
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.megginson.sloop.R;

/**
 * Activity fragment for the browser info bar.
 * 
 * This fragment encapsulates part of the layout for MainActivity, including the
 * infobar (at the bottom) and the cancel button that appears when filtering is
 * active.
 * 
 * @author David Megginson
 */
public class InfoBarFragment extends Fragment {

  private MainActivity mActivity;
  private ViewGroup mLayout;
  private TextView mText;
  private Button mClearButton;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    mActivity = (MainActivity) getActivity();
    mLayout = (ViewGroup) inflater.inflate(R.layout.fragment_info_bar,
        container);
    setupText();
    setupClearButton();
    return mLayout;
  }

  /**
   * Display the position in the current data collection.
   * 
   * @param recordNumber the current record (zero-based).
   * @param filteredTotal the number of filtered records.
   * @param unfilteredTotal the total number of records.
   */
  public void displayRecordCount(int recordNumber, int filteredTotal,
      int unfilteredTotal) {
    if (unfilteredTotal == 0) {
      mText.setText(getString(R.string.msg_no_data));
      mLayout.setBackgroundColor(Color.GRAY);
      mClearButton.setVisibility(View.GONE);
    }
    if (filteredTotal == 0) {
      mText.setText(String.format(getString(R.string.info_records_none),
          unfilteredTotal));
      mLayout.setBackgroundColor(Color.argb(64, 255, 0, 0));
      mClearButton.setVisibility(View.VISIBLE);
    } else if (filteredTotal < unfilteredTotal) {
      mText.setText(String.format(
          getString(R.string.info_records_filtered),
          recordNumber + 1, filteredTotal, unfilteredTotal));
      mLayout.setBackgroundColor(Color.argb(64, 255, 255, 0));
      mClearButton.setVisibility(View.VISIBLE);
    } else {
      mText.setText(String.format(
          getString(R.string.info_records_unfiltered),
          recordNumber + 1, filteredTotal));
      mLayout.setBackgroundColor(Color.argb(64, 0, 255, 0));
      mClearButton.setVisibility(View.GONE);
    }

  }

  /**
   * Set up the text field containing the current status.
   */
  private void setupText() {
    mText = (TextView) mLayout.findViewById(R.id.info_bar);
  }

  /**
   * Set up the button for clearing any filters.
   * 
   * The button starts hidden.
   */
  private void setupClearButton() {
    mClearButton = (Button) mLayout.findViewById(R.id.button_filters_clear);

    // filter clear button is invisible until there's a filter
    mClearButton.setVisibility(View.GONE);

    // clears all filters on click
    mClearButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        mActivity.doClearFilters();
      }
    });
  }

}




Java Source Code List

com.megginson.sloop.activities.ActivitiesUtil.java
com.megginson.sloop.activities.AddressActionProvider.java
com.megginson.sloop.activities.BookmarkEditActivity.java
com.megginson.sloop.activities.BookmarkListActivity.java
com.megginson.sloop.activities.InfoBarFragment.java
com.megginson.sloop.activities.MainActivity.java
com.megginson.sloop.activities.MainDisplayFragment.java
com.megginson.sloop.activities.TextFilterFragment.java
com.megginson.sloop.activities.package-info.java
com.megginson.sloop.model.Bookmark.java
com.megginson.sloop.model.DataCollection.java
com.megginson.sloop.model.DataEntry.java
com.megginson.sloop.model.DataRecord.java
com.megginson.sloop.model.Util.java
com.megginson.sloop.model.ValueFilter.java
com.megginson.sloop.model.impl.ContainsStringFilter.java
com.megginson.sloop.model.impl.DataCollectionIO.java
com.megginson.sloop.model.impl.DataCollectionImpl.java
com.megginson.sloop.model.impl.DataEntryImpl.java
com.megginson.sloop.model.impl.DataRecordImpl.java
com.megginson.sloop.model.impl.EqualsStringFilter.java
com.megginson.sloop.model.impl.package-info.java
com.megginson.sloop.model.package-info.java
com.megginson.sloop.ui.BookmarkListAdapter.java
com.megginson.sloop.ui.DataCollectionLoader.java
com.megginson.sloop.ui.DataCollectionPagerAdapter.java
com.megginson.sloop.ui.DataCollectionResult.java
com.megginson.sloop.ui.DataRecordFragment.java
com.megginson.sloop.ui.DataRecordListAdapter.java
com.megginson.sloop.ui.package-info.java