Android Open Source - GuildViewerApp2 News List Activity






From Project

Back to project page GuildViewerApp2.

License

The source code is released under:

Apache License

If you think the Android project GuildViewerApp2 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 com.skywomantechnology.app.guildviewer;
/*w ww. j a v a  2  s .c o  m*/
/*
 * Guild Viewer is an Android app that allows users to view news feeds and news feed details
 * on a mobile device and while not logged into the game servers.
 *
 * Copyright 2014 Sky Woman Technology LLC
 *
 *    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.
 */

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;


import com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter;

/**
 * An activity representing a list of News. This activity
 * has different presentations for handset and tablet-size devices. On
 * handsets, the activity presents a list of items, which when touched,
 * lead to a {@link NewsDetailActivity} representing
 * item details. On tablets, the activity presents the list of items and
 * item details side-by-side using two vertical panes.
 * <p>
 * The activity makes heavy use of fragments. The list of items is a
 * {@link NewsListFragment} and the item details (if present) is a {@link NewsDetailFragment}.
 * <p>
 * This activity also implements the required{@link NewsListFragment.Callbacks} interface
 * to listen for item selections.
 */
public class NewsListActivity extends Activity implements NewsListFragment.Callbacks {

    //public final String LOG_TAG = NewsListActivity.class.getSimpleName();

    // keep track of which layout is being used
    private boolean mTwoPane;

    /**
     * @param savedInstanceState bundle of stored data for processing
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_list);

        // initialize the preferences wherever the program has an entrance
        PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

        // if detail container is displayed then its two-pane
        mTwoPane = false;
        if (findViewById(R.id.news_detail_container) != null) {
            mTwoPane = true;
            // In two-pane mode, list items should be given the 'activated' state when touched.
            ((NewsListFragment) getFragmentManager().findFragmentById(R.id.news_list))
                    .setActivateOnItemClick(true);
        }
        GuildViewerSyncAdapter.initializeSyncAdapter(this);
    }

    /**
     * This is a callback method that needs to be implemented for the
     * NewsListFragment to be able to handle list item processing
     *
     * @param id identifier for the selected list item
     */
    @Override
    public void onNewsListItemSelected(long id) {
        if (mTwoPane) {
            // pass the list id as an argument to the details fragment so it know what to display
            Bundle arguments = new Bundle();
            arguments.putLong(NewsListFragment.NEWS_ID_KEY, id);

            //get the details fragment with correct data up and running
            NewsDetailFragment fragment = new NewsDetailFragment();
            fragment.setArguments(arguments);
            getFragmentManager().beginTransaction()
                    .replace(R.id.news_detail_container, fragment)
                    .commit();
        } else {
            // In single-pane mode, simply start the detail activity for selected item ID.
            Intent detailIntent = new Intent(this, NewsDetailActivity.class);
            detailIntent.putExtra(NewsListFragment.NEWS_ID_KEY, id);
            startActivity(detailIntent);
        }
    }

    /**
     * Any processing that needs to occur when there is no data to process
     */
    @Override
    public void onNoDataForGuild() {
//        Toast.makeText(this,
//                getString(R.string.toast_no_available_data_for_guild),Toast.LENGTH_LONG)
//                .show();
    }

    /**
     * Any processing that needs to occur when a data refresh is being requested
     */
    @Override
    public void onDataRefresh() {
        Toast.makeText(this, getString(R.string.toast_refreshing_data_message), Toast.LENGTH_LONG)
                .show();
    }

    /**
     * @param menu the options menu that is being created
     * @return true if menu is created else false
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    /**
     * @param item options menu item that has been selected
     * @return true if processed
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.action_settings:
                // edit the settings
                startActivity(new Intent(this, SetPreferenceActivity.class));
                return true;
            case R.id.action_about:
                return displayMessage(this.getString(R.string.about_msg));
            case R.id.action_legal:
                return displayMessage(this.getString(R.string.apache_license));
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private boolean displayMessage(String message) {
        new AlertDialog.Builder(this)
        .setMessage(message)
        .setNeutralButton(this.getString(R.string.ok_button),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                    }
                })
        .show();
        return true;
    }
}




Java Source Code List

com.skywomantechnology.app.guildviewer.Constants.java
com.skywomantechnology.app.guildviewer.NewsAdapter.java
com.skywomantechnology.app.guildviewer.NewsDetailActivity.java
com.skywomantechnology.app.guildviewer.NewsDetailFragment.java
com.skywomantechnology.app.guildviewer.NewsListActivity.java
com.skywomantechnology.app.guildviewer.NewsListFragment.java
com.skywomantechnology.app.guildviewer.SetPreferenceActivity.java
com.skywomantechnology.app.guildviewer.SettingsFragment.java
com.skywomantechnology.app.guildviewer.Utility.java
com.skywomantechnology.app.guildviewer.data.GuildViewerAchievement.java
com.skywomantechnology.app.guildviewer.data.GuildViewerContract.java
com.skywomantechnology.app.guildviewer.data.GuildViewerDbHelper.java
com.skywomantechnology.app.guildviewer.data.GuildViewerGuild.java
com.skywomantechnology.app.guildviewer.data.GuildViewerItem.java
com.skywomantechnology.app.guildviewer.data.GuildViewerMember.java
com.skywomantechnology.app.guildviewer.data.GuildViewerNewsItem.java
com.skywomantechnology.app.guildviewer.data.NewsProvider.java
com.skywomantechnology.app.guildviewer.sync.GuildViewerAuthenticatorService.java
com.skywomantechnology.app.guildviewer.sync.GuildViewerAuthenticator.java
com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncAdapter.java
com.skywomantechnology.app.guildviewer.sync.GuildViewerSyncService.java