Android Open Source - Gazetti_Newspaper_Reader Welcome Screen Fragment Exp List






From Project

Back to project page Gazetti_Newspaper_Reader.

License

The source code is released under:

MIT License

If you think the Android project Gazetti_Newspaper_Reader 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 in.sahildave.gazetti.welcomescreen;
/*w  w  w  . j  a v  a2 s  .  c o  m*/
import android.app.Activity;
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.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import in.sahildave.gazetti.R;
import in.sahildave.gazetti.welcomescreen.WelcomeScreenExpListAdapter.CheckBoxInterface;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WelcomeScreenFragmentExpList extends Fragment {

    public static final String ARG_PAGE = "page";
    private static final String LOG_TAG = WelcomeScreenFragmentExpList.class.getName();
    private static int originalBottomMargin;

    private int mPageNumber;
    private WelcomeScreenExpListAdapter expListAdapter;
    private List<String> listDataHeader;
    private HashMap<String, List<String>> listDataChild;

    private WelcomeScreenFeedSelectCallback callback;
    private Button doneButton;
    private static LinearLayout topLayer;
    public static boolean topLayerHidden;
    private static LinearLayout bottomLayer;

    public interface WelcomeScreenFeedSelectCallback {
        public void fsFragDoneButton(Map<String, Object> mChildCheckStates);
    }

    public static WelcomeScreenFragmentExpList create(int pageNumber) {
        WelcomeScreenFragmentExpList fragment = new WelcomeScreenFragmentExpList();
        Bundle args = new Bundle();
        args.putInt(ARG_PAGE, pageNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public WelcomeScreenFragmentExpList() {
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if (!(activity instanceof WelcomeScreenFeedSelectCallback)) {
            throw new IllegalStateException("Activity must implement the TaskCallbacks interface.");
        }
        callback = (WelcomeScreenFeedSelectCallback) activity;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPageNumber = getArguments().getInt(ARG_PAGE);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_welcome_screen_feed, container, false);
        topLayer = (LinearLayout) rootView.findViewById(R.id.top_layer);
        bottomLayer = (LinearLayout) rootView.findViewById(R.id.bottom_layer);
        ExpandableListView expListView = (ExpandableListView) rootView
                .findViewById(R.id.welcome_feed_select_expandable_list);

        doneButton = (Button) rootView.findViewById(R.id.welcome_feed_select_explist_done_button);
        doneButton.setEnabled(false);
        doneButton.setOnClickListener(new OnClickListener() {
            public void onClick(View next) {
                Map<String, Object> mChildCheckStates = expListAdapter.getClickedStates();
                callback.fsFragDoneButton(mChildCheckStates);
            }
        });

        prepareListData();
        expListAdapter = new WelcomeScreenExpListAdapter(getActivity(), listDataHeader, listDataChild, checkBoxInterface);
        expListAdapter.setExpList(expListView);
        expListView.setAdapter(expListAdapter);

        expListView.setOnGroupClickListener(new OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
//                Log.d(LOG_TAG, "Top Layer Hidden ? " + topLayerHidden);
                if (topLayer.getVisibility()==View.VISIBLE) {
                    LayoutParams originalParams = (LayoutParams) bottomLayer.getLayoutParams();
                    originalBottomMargin = originalParams.bottomMargin;

                    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                    params.setMargins(0, 0, 0, 0);
                    bottomLayer.setLayoutParams(params);

                    topLayer.setVisibility(View.GONE);
                    topLayerHidden = true;
                }
                return false;
            }
        });

        return rootView;
    }

    CheckBoxInterface checkBoxInterface = new CheckBoxInterface() {
        @Override
        public void checkBoxClicked(boolean isChecked) {
            if(isChecked){
                doneButton.setText(R.string.welcome_exp_list_button_enabled);
            } else {
                doneButton.setText(R.string.welcome_exp_list_button_disabled);
            }
            doneButton.setEnabled(isChecked);
        }
    };

    public static boolean handleBackPressed(){
        if(topLayerHidden){
            topLayer.setVisibility(View.VISIBLE);
            topLayerHidden = false;

            LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            params.setMargins(0,0,0,originalBottomMargin);
            bottomLayer.setLayoutParams(params);

            return false;
        } else {
            return true;
        }
    }

    private void prepareListData() {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding child data
        listDataHeader.add(0, "The Hindu");
        listDataHeader.add(1, "The Times of India");
        listDataHeader.add(2, "First Post");
        listDataHeader.add(3, "The Indian Express");

        // Adding child data
        List<String> th = new ArrayList<String>();
        th.add("National");
        th.add("International");
        th.add("Sports");
        th.add("Science");
        th.add("Entertainment");
        th.add("Business");
        th.add("Blogs and Editorials");

        List<String> toi = new ArrayList<String>();
        toi.add("National");
        toi.add("International");
        toi.add("Sports");
        toi.add("Science");
        toi.add("Entertainment");
        toi.add("Business");
        toi.add("Blogs and Editorials");

        List<String> fp = new ArrayList<String>();
        fp.add("National");
        fp.add("International");
        fp.add("Sports");
        fp.add("Science");
        fp.add("Entertainment");
        fp.add("Business");
        fp.add("Blogs and Editorials");

        List<String> tie = new ArrayList<String>();
        tie.add("National");
        tie.add("International");
        tie.add("Sports");
        tie.add("Science");
        tie.add("Entertainment");
        tie.add("Business");
        tie.add("Blogs and Editorials");


        // Header, Child data
        listDataChild.put(listDataHeader.get(0), th);
        listDataChild.put(listDataHeader.get(1), toi);
        listDataChild.put(listDataHeader.get(2), fp);
        listDataChild.put(listDataHeader.get(3), tie);
    }
}




Java Source Code List

in.sahildave.gazetti.StarterApplication.java
in.sahildave.gazetti.bookmarks.BookmarkAdapter.java
in.sahildave.gazetti.bookmarks.BookmarkDetailActivity.java
in.sahildave.gazetti.bookmarks.BookmarkDetailFragment.java
in.sahildave.gazetti.bookmarks.BookmarkListActivity.java
in.sahildave.gazetti.bookmarks.BookmarkListFragment.java
in.sahildave.gazetti.bookmarks.BookmarkLoadingCallback.java
in.sahildave.gazetti.bookmarks.sqlite.BookmarkDataSource.java
in.sahildave.gazetti.bookmarks.sqlite.BookmarkModel.java
in.sahildave.gazetti.bookmarks.sqlite.SQLiteHelper.java
in.sahildave.gazetti.homescreen.HomeScreenActivity.java
in.sahildave.gazetti.homescreen.HomeScreenFragment.java
in.sahildave.gazetti.homescreen.adapter.AddCellDialogFragment.java
in.sahildave.gazetti.homescreen.adapter.CellModel.java
in.sahildave.gazetti.homescreen.adapter.EditCellDialogFragment.java
in.sahildave.gazetti.homescreen.adapter.GridAdapter.java
in.sahildave.gazetti.homescreen.adapter.NewsCatModel.java
in.sahildave.gazetti.homescreen.newcontent.DialogNewContentExpListAdaper.java
in.sahildave.gazetti.homescreen.newcontent.DialogNewContent.java
in.sahildave.gazetti.news_activities.ArticleLoadingCallback.java
in.sahildave.gazetti.news_activities.WebViewFragment.java
in.sahildave.gazetti.news_activities.WebsiteDetailActivity.java
in.sahildave.gazetti.news_activities.WebsiteDetailFragment.java
in.sahildave.gazetti.news_activities.WebsiteListActivity.java
in.sahildave.gazetti.news_activities.WebsiteListFragment.java
in.sahildave.gazetti.news_activities.adapter.NavDrawerListAdapter.java
in.sahildave.gazetti.news_activities.adapter.NewsAdapter.java
in.sahildave.gazetti.news_activities.adapter.RobotoLight.java
in.sahildave.gazetti.news_activities.fetch.firstPost.java
in.sahildave.gazetti.news_activities.fetch.hindu.java
in.sahildave.gazetti.news_activities.fetch.indianExpressBusiness.java
in.sahildave.gazetti.news_activities.fetch.indianExpress.java
in.sahildave.gazetti.news_activities.fetch.toi.java
in.sahildave.gazetti.preference.FeedSelectFragment.java
in.sahildave.gazetti.preference.FeedSelectSettingsActivity.java
in.sahildave.gazetti.preference.LicensesActivity.java
in.sahildave.gazetti.preference.PreferenceExpListAdapter.java
in.sahildave.gazetti.preference.SettingsActivity.java
in.sahildave.gazetti.util.BitmapTransform.java
in.sahildave.gazetti.util.ConfigService.java
in.sahildave.gazetti.util.Constants.java
in.sahildave.gazetti.util.GazettiEnums.java
in.sahildave.gazetti.util.JsonHelper.java
in.sahildave.gazetti.util.NewsCatFileUtil.java
in.sahildave.gazetti.util.ShareButtonListener.java
in.sahildave.gazetti.util.UserPrefUtil.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenExpListAdapter.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenFragmentExpList.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenFragmentFirst.java
in.sahildave.gazetti.welcomescreen.WelcomeScreenViewPagerActivity.java