Android Open Source - android-location-notes Main Activity






From Project

Back to project page android-location-notes.

License

The source code is released under:

Apache License

If you think the Android project android-location-notes 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.nearsoft.examenboom;
//from   w  w  w  . jav a2 s .c o m
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.nearsoft.examenboom.common.Note;
import com.nearsoft.examenboom.database.repository.NoteRepository;
import com.nearsoft.examenboom.database.repository.NoteRepositoryImpl;

import java.util.List;

public class MainActivity extends Activity {

    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mActionBarDrawerToggle;
    private ActionBar mActionBar;

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

    private void initUI() {
        mActionBar = getActionBar();
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        initDrawer();

        // add notes fragment always.
        addNotesFragment();
    }

    private void addNotesFragment() {
        NotesFragment fragment = new NotesFragment();
        addFragment(fragment);
        mActionBar.setSubtitle("Love Notes");
    }

    private void initDrawer() {
        ListView drawerList = (ListView) findViewById(R.id.left_drawer);
        DrawerAdapter adapter = new DrawerAdapter(this, new String[]{"Notes List", "Notes Map"});
        drawerList.setAdapter(adapter);
        mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_launcher, 0, 0);
        mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
        mActionBar.setDisplayHomeAsUpEnabled(true);
        mActionBar.setHomeButtonEnabled(true);
        drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        addFragment(new NotesFragment());
                        mActionBar.setSubtitle("Love Notes");
                        break;
                    case 1:
                        addFragment(new NotesMapFragment());
                        mActionBar.setSubtitle("Map of Love");
                        break;
                    default:
                        throw new AssertionError("You should not be able to come here.");
                }
                mDrawerLayout.closeDrawers();
            }
        });
    }

    private void addFragment(Fragment fragment) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.content_frame, fragment)
                .commit();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (mActionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

com.nearsoft.examenboom.ApplicationTest.java
com.nearsoft.examenboom.DrawerAdapter.java
com.nearsoft.examenboom.ExamenApplication.java
com.nearsoft.examenboom.MainActivity.java
com.nearsoft.examenboom.NewNoteActivity.java
com.nearsoft.examenboom.NoteMapFragment.java
com.nearsoft.examenboom.NotesAdapter.java
com.nearsoft.examenboom.NotesFragment.java
com.nearsoft.examenboom.NotesMapFragment.java
com.nearsoft.examenboom.ViewNoteActivity.java
com.nearsoft.examenboom.common.Note.java
com.nearsoft.examenboom.database.NoteDatabaseAccess.java
com.nearsoft.examenboom.database.NotesSQLite.java
com.nearsoft.examenboom.database.repository.NoteRepositoryImpl.java
com.nearsoft.examenboom.database.repository.NoteRepository.java