Android Open Source - epgreader-android Header Fragment






From Project

Back to project page epgreader-android.

License

The source code is released under:

Apache License

If you think the Android project epgreader-android 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.jeffpalm.android.epg.app;
/*www .  j a  v  a2  s. c  om*/
import com.jeffpalm.android.epg.app.R;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.util.Log;

/**
 * The header bar, which contains the title, sub title, reload button, and progress spinny.
 */
public final class HeaderFragment extends Fragment {

  private static final String TAG = "HeaderFragment";

  private TextView mTitleText;
  private TextView mSubTitleText;
  private ProgressBar mProgressBar;
  private ImageView mReloadButton;

  /**
   * Stores whether we should be showing progress or not. We need this because we could call
   * startProgress and doneProgress before the activity is attached.
   */
  private boolean mInProgress;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.header, container, false);
    mTitleText = (TextView) view.findViewById(R.id.headerTitle);
    mSubTitleText = (TextView) view.findViewById(R.id.headerSubTitle);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
    mReloadButton = (ImageView) view.findViewById(R.id.reloadButton);
    mSubTitleText.setText("");

    ImageView settingsButton = (ImageView) view.findViewById(R.id.settingsButton);
    settingsButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent prefsIntent = new Intent(getActivity().getApplicationContext(),
            EPGReaderPreferencesActivity.class);
        getActivity().startActivity(prefsIntent);
      }
    });

    setReloadOnClickListener();
    setTitleTextOnClickListener();

    return view;
  }

  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Call startProgress again if we've called it before the activity we attached.
    if (mInProgress) {
      startProgress();
    }
  }

  /**
   * Sets the subtitle, which is empty by default.
   * 
   * @param subTitle the new sub title
   */
  public void setSubTitle(CharSequence subTitle) {
    mSubTitleText.setText(subTitle);
  }

  /** Starts the progress bar spinning and hides the reload button. */
  public void startProgress() {
    Log.d(TAG, "startProgress");
    mInProgress = true;
    if (getActivity() != null) {
      getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
          mReloadButton.setVisibility(View.GONE);
          mProgressBar.setIndeterminate(true);
          mProgressBar.setVisibility(View.VISIBLE);
        }
      });
    }
  }

  /** Stops the progress bar from spinning and shows the reload button. */
  public void doneProgress() {
    Log.d(TAG, "doneProgress");
    mInProgress = false;
    if (getActivity() != null) {
      getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
          mProgressBar.setIndeterminate(false);
          mProgressBar.setVisibility(View.GONE);
          mReloadButton.setVisibility(View.VISIBLE);
        }
      });
    }
  }

  private Runnable mReloadButtonOnClickRunnable;
  private Runnable mTitleTextOnClickRunnable;

  /**
   * Specifies that {@code runnable} should be run when the reload button is clicked.
   * 
   * @param runnable The runnable to run when the reload button is clicked.
   */
  public void setReloadRunable(final Runnable runnable) {
    mReloadButtonOnClickRunnable = runnable;
    setReloadOnClickListener();
  }

  /**
   * Sets the onclick listener for {@link #mReloadButton} if both
   * {@link #mReloadButtonOnClickRunnable} and the runnable set by {@link #setReloadRunable} have
   * been set.
   */
  private void setReloadOnClickListener() {
    if (mTitleText != null && mTitleTextOnClickRunnable != null) {
      mReloadButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
          mReloadButtonOnClickRunnable.run();
        }
      });
    }
  }

  /**
   * Specifies that {@code runnable} should be run when the title button is clicked.
   * 
   * @param runnable The runnable to run when the title button is clicked.
   */
  public void setTitleRunable(final Runnable runnable) {
    mTitleTextOnClickRunnable = runnable;
    setTitleTextOnClickListener();
  }

  /**
   * Sets the onclick listener for {@link #mTitleText} if both {@link #mTitleText} and the runnable
   * set by {@link #setTitleTextRunable} have been set.
   */
  private void setTitleTextOnClickListener() {
    if (mTitleText != null && mTitleTextOnClickRunnable != null) {
      mTitleText.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
          mTitleTextOnClickRunnable.run();
        }
      });
    }
  }
}




Java Source Code List

com.example.android.imagedownloader.ImageDownloader.java
com.jeffpalm.android.epg.AbstractEPGItem.java
com.jeffpalm.android.epg.AbstractEPGNode.java
com.jeffpalm.android.epg.EPGContentTest.java
com.jeffpalm.android.epg.EPGContent.java
com.jeffpalm.android.epg.EPGIndexTest.java
com.jeffpalm.android.epg.EPGIndex.java
com.jeffpalm.android.epg.EPGItemTestCase.java
com.jeffpalm.android.epg.EPGItem.java
com.jeffpalm.android.epg.EPGLinkItemTest.java
com.jeffpalm.android.epg.EPGLinkItem.java
com.jeffpalm.android.epg.EPGNode.java
com.jeffpalm.android.epg.EPGParserTest.java
com.jeffpalm.android.epg.EPGParser.java
com.jeffpalm.android.epg.EPGSectionTest.java
com.jeffpalm.android.epg.EPGSection.java
com.jeffpalm.android.epg.EPGTestUtil.java
com.jeffpalm.android.epg.EPG.java
com.jeffpalm.android.epg.app.DefaultOnActivityCreatedNotifier.java
com.jeffpalm.android.epg.app.EPGApplication.java
com.jeffpalm.android.epg.app.EPGReaderConstants.java
com.jeffpalm.android.epg.app.EPGReaderFragment.java
com.jeffpalm.android.epg.app.EPGReaderItemListFragment.java
com.jeffpalm.android.epg.app.EPGReaderPreferencesActivity.java
com.jeffpalm.android.epg.app.EPGReaderSharedPrefs.java
com.jeffpalm.android.epg.app.EPGReaderUrlFinder.java
com.jeffpalm.android.epg.app.EPGReaderUtil.java
com.jeffpalm.android.epg.app.Feature.java
com.jeffpalm.android.epg.app.FeedLoader.java
com.jeffpalm.android.epg.app.HeaderFragment.java
com.jeffpalm.android.epg.app.ItemListActivity.java
com.jeffpalm.android.epg.app.ItemListAdapter.java
com.jeffpalm.android.epg.app.ItemListFragment.java
com.jeffpalm.android.epg.app.NoContentFragment.java
com.jeffpalm.android.epg.app.OnActivityCreatedNotifier.java
com.jeffpalm.android.epg.app.PhotoGalleryAdapter.java
com.jeffpalm.android.epg.app.PhotoGalleryFragment.java
com.jeffpalm.android.epg.app.PhotoItemFragment.java
com.jeffpalm.android.epg.app.VideoItemFragment.java
com.jeffpalm.android.epg.app.WebItemFragment.java
com.jeffpalm.android.tmz.model.AbstractTMZItem.java
com.jeffpalm.android.tmz.model.AbstractTMZNode.java
com.jeffpalm.android.tmz.model.DefaultTMZAdapter.java
com.jeffpalm.android.tmz.model.TMZAdapter.java
com.jeffpalm.android.tmz.model.TMZContentCache.java
com.jeffpalm.android.tmz.model.TMZContentTest.java
com.jeffpalm.android.tmz.model.TMZContent.java
com.jeffpalm.android.tmz.model.TMZFactoryHelper.java
com.jeffpalm.android.tmz.model.TMZFactoryHolder.java
com.jeffpalm.android.tmz.model.TMZFactoryTest.java
com.jeffpalm.android.tmz.model.TMZFactory.java
com.jeffpalm.android.tmz.model.TMZIndexTest.java
com.jeffpalm.android.tmz.model.TMZIndexWrapperTest.java
com.jeffpalm.android.tmz.model.TMZIndexWrapper.java
com.jeffpalm.android.tmz.model.TMZIndex.java
com.jeffpalm.android.tmz.model.TMZItemTestCase.java
com.jeffpalm.android.tmz.model.TMZItem.java
com.jeffpalm.android.tmz.model.TMZLinkItemTest.java
com.jeffpalm.android.tmz.model.TMZLinkItem.java
com.jeffpalm.android.tmz.model.TMZNode.java
com.jeffpalm.android.tmz.model.TMZSectionTest.java
com.jeffpalm.android.tmz.model.TMZSection.java
com.jeffpalm.android.tmz.model.TMZTestCase.java
com.jeffpalm.android.tmz.model.TMZTestUtil.java
com.jeffpalm.android.tmz.model.TMZTest.java
com.jeffpalm.android.tmz.model.TMZWrapperTest.java
com.jeffpalm.android.tmz.model.TMZWrapper.java
com.jeffpalm.android.tmz.model.TMZ.java
com.jeffpalm.android.util.Asserts.java
com.jeffpalm.android.util.ExpandableValueTest.java
com.jeffpalm.android.util.ExpandableValue.java
com.jeffpalm.android.util.ShiftSetTest.java
com.jeffpalm.android.util.ShiftSet.java
com.jeffpalm.android.util.TMZUrlFinderTest.java
com.jeffpalm.android.util.UtilTest.java
com.jeffpalm.android.util.Util.java
com.jeffpalm.android.util.urls.DatabaseHandler.java
com.jeffpalm.android.util.urls.DatabaseHelper.java
com.jeffpalm.android.util.urls.StringInputStream.java
com.jeffpalm.android.util.urls.URLCache.java
com.jeffpalm.android.util.urls.WriteToDatabaseOnCloseInputStream.java