Android Open Source - fonticon Main Activity






From Project

Back to project page fonticon.

License

The source code is released under:

Apache License

If you think the Android project fonticon 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.shamanland.fonticon.example;
/*  w w w.j  ava2  s.c  om*/
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.SoundEffectConstants;

public class MainActivity extends ActionBarActivity implements MenuListener {
    protected DrawerLayout mDrawerLayout;
    protected ActionBarDrawerToggle mDrawerToggle;

    @Override
    protected void onCreate(Bundle state) {
        super.onCreate(state);
        setContentView(R.layout.a_main);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        if (state == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.menu, new MenuFragment())
                    .commit();

            mDrawerLayout.openDrawer(GravityCompat.START);
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle state) {
        super.onSaveInstanceState(state);
    }

    @Override
    protected void onPostCreate(Bundle state) {
        super.onPostCreate(state);

        mDrawerToggle.syncState();
    }

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

        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            // override hardware menu key to open/close menu
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
                mDrawerLayout.closeDrawer(GravityCompat.START);
            } else {
                mDrawerLayout.openDrawer(GravityCompat.START);
            }

            mDrawerLayout.playSoundEffect(SoundEffectConstants.CLICK);
            return true;
        }

        return super.onKeyUp(keyCode, event);
    }

    @Override
    public void onMenuClicked(int menuViewId, String menuText, boolean selectionChanged) {
        if (selectionChanged) {
            changeContent(menuViewId);
        } else {
            // user clicks already selected menu item
            // custom behavior can be implemented here
        }

        getSupportActionBar().setTitle(menuText);

        mDrawerLayout.closeDrawer(GravityCompat.START);
    }

    protected void changeContent(int menuViewId) {
        final Fragment fragment;

        switch (menuViewId) {
            case R.id.scaled:
                fragment = new ScaledIconsFragment();
                break;

            case R.id.glowing:
                fragment = new GlowingIconsFragment();
                break;

            case R.id.compound:
                fragment = new CompoundIconsFragment();
                break;

            default:
                throw new IllegalStateException();
        }

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, fragment)
                .commit();
    }
}




Java Source Code List

com.shamanland.fonticon.CompoundDrawables.java
com.shamanland.fonticon.FontIconButton.java
com.shamanland.fonticon.FontIconDrawable.java
com.shamanland.fonticon.FontIconEditText.java
com.shamanland.fonticon.FontIconTextView.java
com.shamanland.fonticon.FontIconToggleButton.java
com.shamanland.fonticon.FontIconTypefaceHolder.java
com.shamanland.fonticon.FontIconView.java
com.shamanland.fonticon.TextPaintHelper.java
com.shamanland.fonticon.example.CompoundIconsFragment.java
com.shamanland.fonticon.example.ContentFragment.java
com.shamanland.fonticon.example.GlowingIconsFragment.java
com.shamanland.fonticon.example.MainActivity.java
com.shamanland.fonticon.example.MenuFragment.java
com.shamanland.fonticon.example.MenuListener.java
com.shamanland.fonticon.example.MyApplication.java
com.shamanland.fonticon.example.ScaledIconsFragment.java