org.cnx.openstaxcnxmusic.activity.BookmarkActivity.java Source code

Java tutorial

Introduction

Here is the source code for org.cnx.openstaxcnxmusic.activity.BookmarkActivity.java

Source

/**
 * Copyright (c) 2016 Rice University
 *
 * This software is subject to the provisions of the GNU Lesser General
 * Public License Version 2.1 (LGPL).  See LICENSE.txt for details.
 */
package org.cnx.openstaxcnxmusic.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import org.cnx.openstaxcnxmusic.helpers.MenuHelper;
import org.cnx.openstaxcnxmusic.R;
import org.cnx.openstaxcnxmusic.fragments.BookmarkFragment;

/**
 * Activity for Bookmarks
 * @author Ed Woodward
 */
public class BookmarkActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bookmarks);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(getString(R.string.title_bookmarks));

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        BookmarkFragment fragment = new BookmarkFragment();
        transaction.replace(R.id.container, fragment);
        transaction.commit();

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            Intent mainIntent = new Intent(getApplicationContext(), LandingActivity.class);
            mainIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(mainIntent);
            return true;
        } else {
            MenuHelper mh = new MenuHelper();
            return mh.handleContextMenu(item.getItemId(), this, null);
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.menu_bookmarks, menu);
        return true;

    }
}