Android Open Source - streaming_project Single Fragment Activity






From Project

Back to project page streaming_project.

License

The source code is released under:

GNU General Public License

If you think the Android project streaming_project 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.example.streaming.streaming;
/*  w  w  w.  j a  v  a 2 s .co  m*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;


// Abstract Activity class
// Every activity will require the same code so they will all be a subclass of
// SingleFragmentActivity
// NOTE 1: the layout that gets inflated is not-hardcoded so that MediaListActivity can inflate
// a single-container layout on phones and a two-container layout on tablets (i.e. a master-detail
// interface)
// NOTE 2: if a SingleFragmentActivity's subclass wants to inflate a layout other than
// activity_fragment.xml, it must override getLayoutResId() to return a layout other than the
// default one (activity_fragment.xml)
public abstract class SingleFragmentActivity extends FragmentActivity {
    // createFragment() is an abstract method. The subclasses from SingleFragmentActivity must
    // implement it.
    protected abstract Fragment createFragment();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);

        if (fragment == null) {
            fragment = createFragment();
            fm.beginTransaction()
                    .add(R.id.fragmentContainer, fragment)
                    .commit();
        }
    }

    // Returns the ID of the layout that the activity will inflate
    // NOTE: SingleFragmentActivity subclasses can choose to override getLayoutResId() to return a
    // layout other than activity_fragment.xml
    protected int getLayoutResId() {
        return R.layout.activity_fragment;
    }
}




Java Source Code List

com.example.streaming.streaming.ApplicationTest.java
com.example.streaming.streaming.AssetsPropertyReader.java
com.example.streaming.streaming.DataFetcher.java
com.example.streaming.streaming.DataLoader.java
com.example.streaming.streaming.MainActivity.java
com.example.streaming.streaming.MediaActivity.java
com.example.streaming.streaming.MediaDatabaseHelper.java
com.example.streaming.streaming.MediaFragment.java
com.example.streaming.streaming.MediaListActivity.java
com.example.streaming.streaming.MediaListFragment.java
com.example.streaming.streaming.MediaLoader.java
com.example.streaming.streaming.MediaManager.java
com.example.streaming.streaming.MediaProvider.java
com.example.streaming.streaming.Media.java
com.example.streaming.streaming.SQLiteCursorLoader.java
com.example.streaming.streaming.SingleFragmentActivity.java