Search in sources :

Example 21 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project Reachability by sakebook.

the class NavigationDrawerFragment method setUp.

/**
     * Users of this fragment must call this method to set up the navigation drawer interactions.
     *
     * @param fragmentId   The android:id of this fragment in its activity's layout.
     * @param drawerLayout The DrawerLayout containing this fragment's UI.
     */
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
    R.string.navigation_drawer_close) {

        /* "close drawer" description for accessibility */
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }
            // calls onPrepareOptionsMenu()
            getActivity().invalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }
            if (!mUserLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                mUserLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }
            // calls onPrepareOptionsMenu()
            getActivity().invalidateOptionsMenu();
        }
    };
    // per the navigation drawer design guidelines.
    if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
        mDrawerLayout.openDrawer(mFragmentContainerView);
    }
    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {

        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}
Also used : SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ActionBar(android.app.ActionBar)

Example 22 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project carat by amplab.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CaratApplication.setMain(this);
    tracker = Tracker.getInstance();
    // track user clicks (taps)
    tracker.trackUser("caratstarted");
    if (!CaratApplication.isInternetAvailable()) {
        EnableInternetDialogFragment dialog = new EnableInternetDialogFragment();
        dialog.show(getSupportFragmentManager(), "dialog");
    }
    /*
		 * Activity.getWindow.requestFeature() should get invoked only before
		 * setContentView(), otherwise it will cause an app crash The progress
		 * bar doesn't get displayed when there is no update in progress
		 */
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    // Log.d(TAG, "about to set the layout");
    setContentView(R.layout.activity_main);
    ActionBar actionBar = getSupportActionBar();
    setTitleNormal();
    // read and load the preferences specified in our xml preference file
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    // Log.d(TAG, "about to initialize fragments");
    preInittializeFragments();
    // Log.d(TAG, "done with fragment initialization");
    /*
		 * Before using the field "fullVersion", first invoke setTitleNormal()
		 * or setFullVersion() to set this field
		 */
    mDrawerItems = getResources().getStringArray(R.array.drawer_items);
    List<Item> items = new ArrayList<Item>();
    //		items.add(new NavDrawerListHeader("Main"));
    items.add(new ListItem(mDrawerItems[0]));
    items.add(new ListItem(mDrawerItems[1]));
    items.add(new ListItem(mDrawerItems[2]));
    items.add(new ListItem(mDrawerItems[3]));
    items.add(new ListItem(mDrawerItems[4]));
    items.add(new NavDrawerListHeader(""));
    items.add(new ListItem(mDrawerItems[5]));
    items.add(new ListItem(mDrawerItems[6]));
    TextArrayAdapter adapter = new TextArrayAdapter(this, items);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(adapter);
    //		mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerItems));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close) {

        /* "close drawer" description for accessibility */
        public void onDrawerClosed(View view) {
        //getSupportActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mTitle);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // Enable ActionBar app icon to behave as action to toggle navigation drawer
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    if (savedInstanceState == null) {
        selectItem(0);
    }
    setTitleNormal();
// Uncomment the following to enable listening on local port 8080:
/*
		 * try {
		 *  HelloServer h = new HelloServer();
		 * } catch (IOException e) {
		 *  e.printStackTrace(); 
		 * }
		 */
}
Also used : MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) EnableInternetDialogFragment(edu.berkeley.cs.amplab.carat.android.fragments.EnableInternetDialogFragment) ActionBar(android.support.v7.app.ActionBar)

Example 23 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project AndroidPractice by lguipeng.

the class SlideMenuFragment method init.

private void init() {
    final List<String> list = new ArrayList<>();
    list.add("Spring");
    list.add("Summer");
    list.add("Autumn");
    list.add("Winter");
    DrawerListAdapter adapter = new DrawerListAdapter(getActivity(), list);
    mDrawerMenuListView.setAdapter(adapter);
    mDrawerMenuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mCurrentTitlePosition = position;
            mDrawerMenuListView.setItemChecked(position, true);
            mDrawerLayout.closeDrawer(parent);
        }
    });
    mDrawerMenuListView.setItemChecked(mCurrentTitlePosition, true);
    setTitle(list.get(mCurrentTitlePosition));
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, 0, 0) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            activity.invalidateOptionsMenu();
            setTitle(R.string.slide_menu);
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            activity.invalidateOptionsMenu();
            setTitle(list.get(mCurrentTitlePosition));
        }
    };
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.setScrimColor(getColor(R.color.window_background));
}
Also used : ArrayList(java.util.ArrayList) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) AdapterView(android.widget.AdapterView) DrawerListAdapter(com.szu.androidpractice.adapter.DrawerListAdapter) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 24 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project Talon-for-Twitter by klinker24.

the class SettingsActivityOld method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);
    AppSettings.invalidate();
    setUpTheme();
    setContentView(R.layout.settings_main);
    DrawerArrayAdapter.current = 0;
    linkItems = new String[] { getResources().getString(R.string.get_help_settings), getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new), getResources().getString(R.string.rate_it) };
    settingsItems = new String[] { getResources().getString(R.string.ui_settings), getResources().getString(R.string.timelines_settings), getResources().getString(R.string.sync_settings), getResources().getString(R.string.notification_settings), getResources().getString(R.string.browser_settings), getResources().getString(R.string.advanced_settings), getResources().getString(R.string.memory_manage) };
    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    if (sharedPrefs.getBoolean("version_1.20_1", true)) {
        // necessary because i didnt start out by using sets
        boolean led = sharedPrefs.getBoolean("led", true);
        boolean sound = sharedPrefs.getBoolean("sound", true);
        boolean vibrate = sharedPrefs.getBoolean("vibrate", true);
        boolean wakeScreen = sharedPrefs.getBoolean("wake", true);
        boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true);
        boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true);
        boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true);
        boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true);
        boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true);
        boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true);
        Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>());
        alert.clear();
        if (vibrate) {
            alert.add("1");
        }
        if (led) {
            alert.add("2");
        }
        if (wakeScreen) {
            alert.add("3");
        }
        if (sound) {
            alert.add("4");
        }
        sharedPrefs.edit().putStringSet("alert_types", alert).commit();
        Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>());
        timeline.clear();
        if (timelineNot) {
            timeline.add("1");
        }
        if (mentionsNot) {
            timeline.add("2");
        }
        if (dmsNot) {
            timeline.add("3");
        }
        sharedPrefs.edit().putStringSet("timeline_set", timeline).commit();
        Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>());
        interactions.clear();
        if (favoritesNot) {
            interactions.add("1");
        }
        if (retweetNot) {
            interactions.add("2");
        }
        if (followersNot) {
            interactions.add("3");
        }
        sharedPrefs.edit().putStringSet("interactions_set", interactions).commit();
        sharedPrefs.edit().putBoolean("version_1.20_1", false).commit();
        recreate();
    }
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
    otherList = (ListView) findViewById(R.id.other_list);
    settingsList = (ListView) findViewById(R.id.settings_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);
    // Set the adapter for the list view
    otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems))));
    settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems))));
    // Set the list's click listener
    settingsList.setOnItemClickListener(new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer));
    otherList.setOnItemClickListener(new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer));
    findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            switchToSettingsList(true);
            settingsLinksActive = true;
            findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
        }
    });
    findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            switchToSettingsList(false);
            settingsLinksActive = false;
            findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
        }
    });
    if (settingsLinksActive) {
        settingsList.setVisibility(View.VISIBLE);
        otherList.setVisibility(View.GONE);
        findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
    } else {
        settingsList.setVisibility(View.GONE);
        otherList.setVisibility(View.VISIBLE);
        findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
    }
    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    resource, /* nav drawer icon to replace 'Up' caret */
    R.string.app_name, /* "open drawer" description */
    R.string.app_name);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false);
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
            DrawerArrayAdapter.current = position;
            otherList.invalidateViews();
            settingsList.invalidateViews();
        }
    });
    if (!userKnows) {
        mDrawerLayout.openDrawer(mDrawer);
    }
    HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by);
    HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number);
    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        String text = getResources().getString(R.string.created_by) + " Luke Klinker";
        String text2 = getResources().getString(R.string.version) + " " + versionName;
        createdBy.setText(text);
        versionNumber.setText(text2);
    } catch (Exception e) {
        String text = getResources().getString(R.string.created_by) + " Luke Klinker";
        String text2 = getResources().getString(R.string.version) + " 0.00";
        createdBy.setText(text);
        versionNumber.setText(text2);
    }
    LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout);
    description.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Klinker+Apps")));
        }
    });
    mDrawerLayout.openDrawer(Gravity.START);
}
Also used : ArrayList(java.util.ArrayList) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) Intent(android.content.Intent) HoloTextView(com.klinker.android.twitter.views.HoloTextView) HoloTextView(com.klinker.android.twitter.views.HoloTextView) View(android.view.View) ListView(android.widget.ListView) ViewPager(android.support.v4.view.ViewPager) TypedArray(android.content.res.TypedArray) LinearLayout(android.widget.LinearLayout)

Example 25 with ActionBarDrawerToggle

use of android.support.v4.app.ActionBarDrawerToggle in project boilerplate by koush.

the class DrawerActivity method resetDrawerToggle.

private void resetDrawerToggle() {
    getDrawer().setDrawerListener(drawerToggle = new ActionBarDrawerToggle(this, getDrawer(), getDrawerOpenString(), getDrawerCloseString()) {

        //            DecelerateInterpolator interpolator = new DecelerateInterpolator();
        ArgbEvaluator evaluator = new ArgbEvaluator();

        boolean hasOpened;

        int originalStatusBarColor;

        @Override
        public void onDrawerStateChanged(int newState) {
            super.onDrawerStateChanged(newState);
            if (newState == DrawerLayout.STATE_DRAGGING && !hasOpened) {
                hasOpened = true;
                originalStatusBarColor = WindowChromeUtils.getStatusBarColor(getWindow());
            }
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            // and don't erroneously translate this stuff.
            if (!getDrawer().isDrawerVisible(Gravity.LEFT))
                return;
            //                View content = getDrawer().getChildAt(0);
            //                View drawer = getDrawer().getChildAt(1);
            //                content.setTranslationX(Math.min(content.getMeasuredWidth(), drawer.getMeasuredWidth()) / 3 * interpolator.getInterpolation(slideOffset));
            onDrawerOpen();
            if (hasOpened)
                WindowChromeUtils.setStatusBarColor(getWindow(), (int) evaluator.evaluate(slideOffset, originalStatusBarColor, 0x4D000000));
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (hasOpened) {
                WindowChromeUtils.setStatusBarColor(getWindow(), originalStatusBarColor);
            }
            if (isFinishing())
                return;
            DrawerActivity.this.onDrawerClosed();
        }
    });
    drawerToggle.syncState();
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) View(android.view.View)

Aggregations

ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)80 View (android.view.View)76 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)34 TextView (android.widget.TextView)31 NavigationView (android.support.design.widget.NavigationView)30 AdapterView (android.widget.AdapterView)30 ListView (android.widget.ListView)29 Toolbar (android.support.v7.widget.Toolbar)25 DrawerLayout (android.support.v4.widget.DrawerLayout)23 ActionBar (android.support.v7.app.ActionBar)19 ImageView (android.widget.ImageView)16 SharedPreferences (android.content.SharedPreferences)14 Intent (android.content.Intent)12 RecyclerView (android.support.v7.widget.RecyclerView)8 SearchView (android.support.v7.widget.SearchView)8 Handler (android.os.Handler)6 PackageManager (android.content.pm.PackageManager)5 MenuItem (android.view.MenuItem)5 InjectView (butterknife.InjectView)5 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)5