Android Open Source - android-placeholder Demo Fragment






From Project

Back to project page android-placeholder.

License

The source code is released under:

Apache License

If you think the Android project android-placeholder 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 se.lightside.placeholder.sample;
//from   w  ww .  ja  v  a  2 s .c o m
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 *
 */
public class DemoFragment extends Fragment {
    public static final String EXTRA_TITLE  = "title";
    public static final String EXTRA_LAYOUT = "layoutRes";
    public static final String EXTRA_MENU   = "menuRes";

    public static DemoFragment newInstance(String title, int layoutRes, int menuRes) {
        DemoFragment frag = new DemoFragment();
        Bundle args = new Bundle();
        args.putString(EXTRA_TITLE, title);
        args.putInt(EXTRA_LAYOUT, layoutRes);
        args.putInt(EXTRA_MENU, menuRes);
        frag.setArguments(args);
        return frag;
    }


    private String mTitle;
    private int mLayoutRes;
    private int mMenuRes;
    private DemoHostActivity mDemoHostActivity;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (activity instanceof DemoHostActivity) {
            mDemoHostActivity = (DemoHostActivity) activity;
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();

        mTitle = args.getString(EXTRA_TITLE);
        mLayoutRes  = args.getInt(EXTRA_LAYOUT);
        mMenuRes    = args.getInt(EXTRA_MENU);


        if (mDemoHostActivity != null && !TextUtils.isEmpty(mTitle)) {
            mDemoHostActivity.setTitle(mTitle);
        }
        if (mMenuRes != 0) {
            setHasOptionsMenu(true);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(mLayoutRes, container, false);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        if (mMenuRes != 0) {
            inflater.inflate(R.menu.demo_icon, menu);
        }
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public void onDetach() {
        mDemoHostActivity = null;
        super.onDetach();
    }
}




Java Source Code List

se.lightside.placeholder.ApplicationTest.java
se.lightside.placeholder.PlaceholderBuilder.java
se.lightside.placeholder.graphics.drawable.AbstractPlaceholderDrawable.java
se.lightside.placeholder.graphics.drawable.CrossDrawable.java
se.lightside.placeholder.graphics.drawable.DimensionsDrawable.java
se.lightside.placeholder.graphics.drawable.GridDrawable.java
se.lightside.placeholder.sample.DemoFragment.java
se.lightside.placeholder.sample.DemoHostActivity.java
se.lightside.placeholder.text.method.BlockTransformationMethod.java
se.lightside.placeholder.util.MetricsConverter.java
se.lightside.placeholder.util.ViewCompat.java
se.lightside.placeholder.view.RatioLineOverlay.java
se.lightside.placeholder.view.RatioLine.java
se.lightside.placeholder.widget.BlockedOutTextView.java
se.lightside.placeholder.widget.PlaceholderView.java