Android Open Source - android-shuite-smoking Base Activity






From Project

Back to project page android-shuite-smoking.

License

The source code is released under:

GNU General Public License

If you think the Android project android-shuite-smoking 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 udl.eps.smokerscontrol;
/*from w  w w .j av a  2 s. c om*/
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Marc on 15/12/2014.
 */
public abstract class BaseActivity extends ActionBarActivity {

    private Toolbar toolbar;
    private DrawerLayout drawerLayout;
    private ActionBarDrawerToggle drawerToggle;
    private ListView leftDrawerList;
    private ArrayAdapter<String> navigationDrawerAdapter;
    private List<String> leftMenuItems;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResourceId());
        setMenuCategories();
        initView();
        if (toolbar != null) {
            setSupportActionBar(toolbar);
        }
        initDrawer();
    }
    protected abstract int getLayoutResourceId();

    private void setMenuCategories(){
        leftMenuItems = new ArrayList<>();
        leftMenuItems.add(getResources().getString(R.string.profile));
        leftMenuItems.add(getResources().getString(R.string.community));
        leftMenuItems.add(getResources().getString(R.string.achievements));
        leftMenuItems.add(getResources().getString(R.string.stats));
        leftMenuItems.add(getResources().getString(R.string.messages));
    }

    private void initView() {
        leftDrawerList = (ListView) findViewById(R.id.left_drawer);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        navigationDrawerAdapter=new ArrayAdapter<>( this, android.R.layout.simple_list_item_1, leftMenuItems);
        leftDrawerList.setAdapter(navigationDrawerAdapter);
    }

    private void initDrawer() {

        drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);

            }

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);

            }
        };
        drawerLayout.setDrawerListener(drawerToggle);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        drawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        drawerToggle.onConfigurationChanged(newConfig);
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
    }
}




Java Source Code List

udl.eps.smokerscontrol.ApplicationTest.java
udl.eps.smokerscontrol.BaseActivity.java
udl.eps.smokerscontrol.CommunityFragment.java
udl.eps.smokerscontrol.ImageButtonAdapter.java
udl.eps.smokerscontrol.ImageButton.java
udl.eps.smokerscontrol.MainActivity.java
udl.eps.smokerscontrol.MenuFragment.java
udl.eps.smokerscontrol.StatsFragment.java