Android Open Source - whoisit-android Carousel Activity






From Project

Back to project page whoisit-android.

License

The source code is released under:

MIT License

If you think the Android project whoisit-android 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.mitchbarry.android.whoisit.ui;
//from www .  j  a va 2 s. co m
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.ActionBar;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.view.*;

import com.mitchbarry.android.whoisit.R;
import com.mitchbarry.android.whoisit.core.PhoneGroup;
import com.mitchbarry.android.whoisit.db.DatabaseManager;
import com.viewpagerindicator.TitlePageIndicator;

import butterknife.InjectView;
import butterknife.Views;

import static com.mitchbarry.android.whoisit.core.Constants.Extra.PHONE_GROUP;

/**
 * Activity to view the carousel and view pager indicator with fragments.
 */
public class CarouselActivity extends BootstrapFragmentActivity {

    @InjectView(R.id.tpi_header) TitlePageIndicator indicator;
    @InjectView(R.id.vp_pages) ViewPager pager;

    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    private CharSequence mDrawerTitle;
    private CharSequence mTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

        super.onCreate(savedInstanceState);

        setContentView(R.layout.carousel_view);

        // View injection with Butterknife
        Views.inject(this);

        // Set up navigation drawer
        mTitle = mDrawerTitle = getTitle();
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                    /* Host activity */
                mDrawerLayout,           /* DrawerLayout object */
                R.drawable.ic_drawer,    /* nav drawer icon to replace 'Up' caret */
                R.string.drawer_open,    /* "open drawer" description */
                R.string.drawer_close) { /* "close drawer" description */

            /** Called when a drawer has settled in a completely closed state. */
            public void onDrawerClosed(View view) {
                getSupportActionBar().setTitle(mTitle);
                supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                getSupportActionBar().setTitle(mDrawerTitle);
                supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.setDrawerListener(mDrawerToggle);

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

        initScreen();

        DatabaseManager.init(this);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.groups, menu);
        return super.onCreateOptionsMenu(menu);
    }


    private void initScreen() {
        pager.setAdapter(new BootstrapPagerAdapter(getResources(), getSupportFragmentManager()));

        indicator.setViewPager(pager);
        pager.setCurrentItem(1);

        setNavListeners();
    }

    private void setNavListeners() {
        findViewById(R.id.menu_item_home).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDrawerLayout.closeDrawers();
            }
        });
        findViewById(R.id.menu_item_about).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) { mDrawerLayout.closeDrawers(); navigateToAbout(); }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if(mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }

        switch(item.getItemId()) {
            case android.R.id.home:
                return true;
            case R.id.add_phone_group:
                navigateToModifyPhoneGroup(null);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private void navigateToAbout() {
        final Intent i = new Intent(this, AboutActivity.class);
        startActivity(i);
    }
    private void navigateToModifyPhoneGroup(PhoneGroup group) {
        startActivity(new Intent(this, PhoneGroupActivity.class).putExtra(PHONE_GROUP, group));
    }
}




Java Source Code List

com.mitchbarry.android.whoisit.AndroidModule.java
com.mitchbarry.android.whoisit.Injector.java
com.mitchbarry.android.whoisit.RootModule.java
com.mitchbarry.android.whoisit.WhoIsItApplication.java
com.mitchbarry.android.whoisit.WhoIsItModule.java
com.mitchbarry.android.whoisit.core.Constants.java
com.mitchbarry.android.whoisit.core.PhoneCallListener.java
com.mitchbarry.android.whoisit.core.PhoneCallReceiver.java
com.mitchbarry.android.whoisit.core.PhoneGroup.java
com.mitchbarry.android.whoisit.core.PhoneMatch.java
com.mitchbarry.android.whoisit.core.SMSReceiver.java
com.mitchbarry.android.whoisit.core.WhoIsItMatcher.java
com.mitchbarry.android.whoisit.db.DatabaseHelper.java
com.mitchbarry.android.whoisit.db.DatabaseManager.java
com.mitchbarry.android.whoisit.ui.AboutActivity.java
com.mitchbarry.android.whoisit.ui.AsyncLoader.java
com.mitchbarry.android.whoisit.ui.BootstrapActivity.java
com.mitchbarry.android.whoisit.ui.BootstrapFragmentActivity.java
com.mitchbarry.android.whoisit.ui.BootstrapPagerAdapter.java
com.mitchbarry.android.whoisit.ui.CarouselActivity.java
com.mitchbarry.android.whoisit.ui.HeaderFooterListAdapter.java
com.mitchbarry.android.whoisit.ui.ItemListFragment.java
com.mitchbarry.android.whoisit.ui.PhoneGroupActivity.java
com.mitchbarry.android.whoisit.ui.PhoneGroupListAdapter.java
com.mitchbarry.android.whoisit.ui.PhoneGroupListFragment.java
com.mitchbarry.android.whoisit.ui.PhoneMatchListAdapter.java
com.mitchbarry.android.whoisit.ui.PhoneMatchListFragment.java
com.mitchbarry.android.whoisit.ui.ThrowableLoader.java
com.mitchbarry.android.whoisit.ui.view.CapitalizedTextView.java
com.mitchbarry.android.whoisit.util.Ln.java
com.mitchbarry.android.whoisit.util.SafeAsyncTask.java
com.mitchbarry.android.whoisit.util.Strings.java