Java tutorial
/** * Copyright 2012 Scott Weeden-Moody * * 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.lillicoder.newsblurry.feeds; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentManager; import com.lillicoder.actionbarcompatplus.ActionBarHelper; import com.lillicoder.newsblurry.BaseActivity; import com.lillicoder.newsblurry.R; /** * Activity that displays user feeds. * @author lillicoder */ public class FeedsActivity extends BaseActivity { public static final String INTENT_FEED_TO_DISPLAY = "intent_feedToDisplay"; private FeedsListFragment _feedsListFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_feeds); // Check to see if we were passed a feed in the intent. // If so, display that feed on the UI. Intent intent = this.getIntent(); IFeed feed = this.getFeedFromIntent(intent); this._feedsListFragment.setFeed(feed); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // TODO Setup support for home button ActionBarHelper helper = this.getActionBarHelper(); //helper.setDisplayHomeAsUpEnabled(true); // If we were passed a feed in the intent, // set the action bar title to that feed's name. Intent intent = this.getIntent(); IFeed feed = this.getFeedFromIntent(intent); if (feed != null) helper.setTitle(feed.getName()); } @Override protected void onInitializeChildReferences() { FragmentManager manager = this.getSupportFragmentManager(); this._feedsListFragment = (FeedsListFragment) manager .findFragmentById(R.id.FeedsActivity_feedsListFragment); } /** * Gets the {@link IFeed} contained in the given {@link Intent} under the * {@link #INTENT_FEED_TO_DISPLAY} key. * @param intent {@link Intent} to get the feed from. * @return {@link IFeed} contained in the given intent, * <code>null</code> if there was no feed found. */ private IFeed getFeedFromIntent(Intent intent) { IFeed feed = null; if (intent != null && intent.hasExtra(INTENT_FEED_TO_DISPLAY)) feed = (IFeed) intent.getSerializableExtra(INTENT_FEED_TO_DISPLAY); return feed; } }