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






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
 */*from  w  w  w.  j  ava  2 s  . c  om*/
 * 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.cpfinal;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.util.TypedValue;

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

/**
 * An activity representing a single Article detail screen. This activity is
 * only used on handset devices. On tablet-size devices, item details are
 * presented side-by-side with a list of items in a {@link ArticleListActivity}.
 * <p/>
 * This activity is mostly just a 'shell' activity containing nothing more than
 * a {@link ArticleDetailFragment}.
 */
public class ArticleDetailActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article_detail);

        // Show the Up button in the action bar.
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        ViewPager pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                Bundle arguments = new Bundle();
                arguments.putString(ArticleDetailFragment.ARG_ITEM_ID, DummyContent.ITEMS.get(i).id);
                ArticleDetailFragment fragment = new ArticleDetailFragment();
                fragment.setArguments(arguments);
                return fragment;
            }

            @Override
            public int getCount() {
                return DummyContent.ITEMS.size();
            }
        });
        pager.setPageMarginDrawable(getResources().getDrawable(R.drawable.list_divider_holo_light));
        pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
                getResources().getDisplayMetrics()));

        String startId = getIntent().getStringExtra(ArticleDetailFragment.ARG_ITEM_ID);
        for (int i = 0; i < DummyContent.ITEMS.size(); i++) {
            if (DummyContent.ITEMS.get(i).id.equals(startId)) {
                pager.setCurrentItem(i);
                return;
            }
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }
}




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