Android Open Source - making-apps-beautiful Article Detail Fragment






From Project

Back to project page making-apps-beautiful.

License

The source code is released under:

Apache License

If you think the Android project making-apps-beautiful 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

/*
 * Copyright 2013 The Android Open Source Project
 */* ww w. j a v  a  2 s  .c o m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.xyzreader.cp0;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xyzreader.cp0.dummy.DummyContent;

/**
 * A fragment representing a single Article detail screen. This fragment is
 * either contained in a {@link ArticleListActivity} in two-pane mode (on
 * tablets) or a {@link ArticleDetailActivity} on handsets.
 */
public class ArticleDetailFragment extends Fragment {
    /**
     * The fragment argument representing the item ID that this fragment
     * represents.
     */
    public static final String ARG_ITEM_ID = "item_id";

    /**
     * The dummy content this fragment is presenting.
     */
    private DummyContent.DummyItem mItem;

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public ArticleDetailFragment() {
    }

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

        if (getArguments().containsKey(ARG_ITEM_ID)) {
            // Load the dummy content specified by the fragment
            // arguments. In a real-world scenario, use a Loader
            // to load content from a content provider.
            mItem = DummyContent.ITEM_MAP.get(getArguments().getString(
                    ARG_ITEM_ID));
        }

        setHasOptionsMenu(true);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.article, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // This ID represents the Home or Up button. In the case of this
                // activity, the Up button is shown. Use NavUtils to allow users
                // to navigate up one level in the application structure. For
                // more details, see the Navigation pattern on Android Design:
                //
                // http://developer.android.com/design/patterns/navigation.html#up-vs-back
                //
                NavUtils.navigateUpTo(getActivity(), new Intent(getActivity(),
                        ArticleListActivity.class));
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_article_detail,
                container, false);

        // Show the dummy content as text in a TextView.
        if (mItem != null) {
            ((TextView) rootView.findViewById(R.id.article_title))
                    .setText(mItem.title);
            ((TextView) rootView.findViewById(R.id.article_byline))
                    .setText(Html.fromHtml(mItem.time + " by " + mItem.author));
//            ((TextView) rootView.findViewById(R.id.article_date))
//                    .setText(mItem.time);
            ((TextView) rootView.findViewById(R.id.article_body))
                    .setText(Html.fromHtml(mItem.content));

            ((ImageView) rootView.findViewById(R.id.photo))
                    .setImageDrawable(getResources().getDrawable(mItem.photoResId));
        }

        return rootView;
    }
}




Java Source Code List

com.example.xyzreader.cp0.ArticleDetailActivity.java
com.example.xyzreader.cp0.ArticleDetailFragment.java
com.example.xyzreader.cp0.ArticleListActivity.java
com.example.xyzreader.cp0.ArticleListFragment.java
com.example.xyzreader.cp0.dummy.DummyContent.java
com.example.xyzreader.cp1.ArticleDetailActivity.java
com.example.xyzreader.cp1.ArticleDetailFragment.java
com.example.xyzreader.cp1.ArticleListActivity.java
com.example.xyzreader.cp1.ArticleListFragment.java
com.example.xyzreader.cp1.dummy.DummyContent.java
com.example.xyzreader.cp2.ArticleDetailActivity.java
com.example.xyzreader.cp2.ArticleDetailFragment.java
com.example.xyzreader.cp2.ArticleListActivity.java
com.example.xyzreader.cp2.ArticleListFragment.java
com.example.xyzreader.cp2.dummy.DummyContent.java
com.example.xyzreader.cp3.ArticleDetailActivity.java
com.example.xyzreader.cp3.ArticleDetailFragment.java
com.example.xyzreader.cp3.ArticleListActivity.java
com.example.xyzreader.cp3.ArticleListFragment.java
com.example.xyzreader.cp3.dummy.DummyContent.java
com.example.xyzreader.cp4.ArticleDetailActivity.java
com.example.xyzreader.cp4.ArticleDetailFragment.java
com.example.xyzreader.cp4.ArticleListActivity.java
com.example.xyzreader.cp4.ArticleListFragment.java
com.example.xyzreader.cp4.dummy.DummyContent.java
com.example.xyzreader.cp5.ArticleDetailActivity.java
com.example.xyzreader.cp5.ArticleDetailFragment.java
com.example.xyzreader.cp5.ArticleListActivity.java
com.example.xyzreader.cp5.ArticleListFragment.java
com.example.xyzreader.cp5.dummy.DummyContent.java
com.example.xyzreader.cp6.ArticleDetailActivity.java
com.example.xyzreader.cp6.ArticleDetailFragment.java
com.example.xyzreader.cp6.ArticleListActivity.java
com.example.xyzreader.cp6.ArticleListFragment.java
com.example.xyzreader.cp6.dummy.DummyContent.java
com.example.xyzreader.cp7.ArticleDetailActivity.java
com.example.xyzreader.cp7.ArticleDetailFragment.java
com.example.xyzreader.cp7.ArticleListActivity.java
com.example.xyzreader.cp7.ArticleListFragment.java
com.example.xyzreader.cp7.dummy.DummyContent.java
com.example.xyzreader.cp8.ArticleDetailActivity.java
com.example.xyzreader.cp8.ArticleDetailFragment.java
com.example.xyzreader.cp8.ArticleListActivity.java
com.example.xyzreader.cp8.ArticleListFragment.java
com.example.xyzreader.cp8.dummy.DummyContent.java
com.example.xyzreader.cpfinal.ArticleDetailActivity.java
com.example.xyzreader.cpfinal.ArticleDetailFragment.java
com.example.xyzreader.cpfinal.ArticleListActivity.java
com.example.xyzreader.cpfinal.ArticleListFragment.java
com.example.xyzreader.cpfinal.dummy.DummyContent.java