Search in sources :

Example 51 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project bugzy by cpunq.

the class HomeActivity method onViewsReady.

protected void onViewsReady() {
    mFragmentManager = getSupportFragmentManager();
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.setDrawerListener(toggle);
    toggle.syncState();
    navigationView.setNavigationItemSelectedListener(this);
    mUserName = navigationView.getHeaderView(0).findViewById(R.id.user_name);
    mUserEmail = navigationView.getHeaderView(0).findViewById(R.id.user_email);
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    setupFab();
}
Also used : ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Toolbar(android.support.v7.widget.Toolbar)

Example 52 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project Slide by ccrama.

the class MainActivity method doDrawer.

public void doDrawer() {
    drawerSubList = (ListView) findViewById(R.id.drawerlistview);
    drawerSubList.setDividerHeight(0);
    drawerSubList.setDescendantFocusability(ListView.FOCUS_BEFORE_DESCENDANTS);
    final LayoutInflater inflater = getLayoutInflater();
    final View header;
    if (Authentication.isLoggedIn && Authentication.didOnline) {
        header = inflater.inflate(R.layout.drawer_loggedin, drawerSubList, false);
        headerMain = header;
        hea = header.findViewById(R.id.back);
        drawerSubList.addHeaderView(header, null, false);
        ((TextView) header.findViewById(R.id.name)).setText(Authentication.name);
        header.findViewById(R.id.multi).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                if (runAfterLoad == null) {
                    Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                    MainActivity.this.startActivity(inte);
                }
            }
        });
        header.findViewById(R.id.multi).setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (runAfterLoad == null) {
                            Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                            inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                            MainActivity.this.startActivity(inte);
                        }
                    }
                }).negativeText(R.string.btn_cancel).show();
                return true;
            }
        });
        header.findViewById(R.id.discover).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Discover.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.prof_click).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.saved).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_SAVED, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.later).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, PostReadLater.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.history).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_HISTORY, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.commented).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_COMMENT, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.submitted).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_SUBMIT, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.upvoted).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_UPVOTE, true);
                MainActivity.this.startActivity(inte);
            }
        });
        /**
         * If the user is a known mod, show the "Moderation" drawer item quickly to
         * stop the UI from jumping
         */
        if (modOf != null && !modOf.isEmpty() && Authentication.mod) {
            header.findViewById(R.id.mod).setVisibility(View.VISIBLE);
        }
        // update notification badge
        final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
        profStuff.setVisibility(View.GONE);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (profStuff.getVisibility() == View.GONE) {
                    expand(profStuff);
                    flipAnimator(false, header.findViewById(R.id.headerflip)).start();
                } else {
                    collapse(profStuff);
                    flipAnimator(true, header.findViewById(R.id.headerflip)).start();
                }
            }
        });
        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
            if (s.contains(":")) {
                accounts.put(s.split(":")[0], s.split(":")[1]);
            } else {
                accounts.put(s, "");
            }
        }
        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
        final String guest = getString(R.string.guest);
        keys.add(guest);
        final LinearLayout accountList = header.findViewById(R.id.accountsarea);
        for (final String accName : keys) {
            LogUtil.v(accName);
            final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
            ((TextView) t.findViewById(R.id.name)).setText(accName);
            LogUtil.v("Adding click to " + ((TextView) t.findViewById(R.id.name)).getText());
            if (!accName.equals(guest)) {
                t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog2, int which2) {
                                Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                                Set<String> done = new HashSet<>();
                                for (String s : accounts2) {
                                    if (!s.contains(accName)) {
                                        done.add(s);
                                    }
                                }
                                Authentication.authentication.edit().putStringSet("accounts", done).commit();
                                dialog2.dismiss();
                                accountList.removeView(t);
                                if (accName.equalsIgnoreCase(Authentication.name)) {
                                    boolean d = false;
                                    for (String s : keys) {
                                        if (!s.equalsIgnoreCase(accName)) {
                                            d = true;
                                            LogUtil.v("Switching to " + s);
                                            for (Map.Entry<String, String> e : accounts.entrySet()) {
                                                LogUtil.v(e.getKey() + ":" + e.getValue());
                                            }
                                            if (accounts.containsKey(s) && !accounts.get(s).isEmpty()) {
                                                Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
                                            } else {
                                                ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                                                int index = keys.indexOf(s);
                                                if (keys.indexOf(s) > tokens.size()) {
                                                    index -= 1;
                                                }
                                                Authentication.authentication.edit().putString("lasttoken", tokens.get(index)).remove("backedCreds").commit();
                                            }
                                            Authentication.name = s;
                                            UserSubscriptions.switchAccounts();
                                            Reddit.forceRestart(MainActivity.this, true);
                                            break;
                                        }
                                    }
                                    if (!d) {
                                        Authentication.name = "LOGGEDOUT";
                                        Authentication.isLoggedIn = false;
                                        Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
                                        UserSubscriptions.switchAccounts();
                                        Reddit.forceRestart(MainActivity.this, true);
                                    }
                                } else {
                                    accounts.remove(accName);
                                    keys.remove(accName);
                                }
                            }
                        }).setPositiveButton(R.string.btn_cancel, null).show();
                    }
                });
            } else {
                t.findViewById(R.id.remove).setVisibility(View.GONE);
            }
            t.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String accName = ((TextView) t.findViewById(R.id.name)).getText().toString();
                    LogUtil.v("Found name is " + accName);
                    if (!accName.equalsIgnoreCase(Authentication.name)) {
                        LogUtil.v("Switching to " + accName);
                        if (!accName.equals(guest)) {
                            if (!accounts.get(accName).isEmpty()) {
                                LogUtil.v("Using token " + accounts.get(accName));
                                Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").apply();
                            } else {
                                ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                                Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").apply();
                            }
                            Authentication.name = accName;
                        } else {
                            Authentication.name = "LOGGEDOUT";
                            Authentication.isLoggedIn = false;
                            Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").apply();
                        }
                        UserSubscriptions.switchAccounts();
                        Reddit.forceRestart(MainActivity.this, true);
                    }
                }
            });
            accountList.addView(t);
        }
        header.findViewById(R.id.godown).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                LinearLayout body = header.findViewById(R.id.expand_profile);
                if (body.getVisibility() == View.GONE) {
                    expand(body);
                    flipAnimator(false, view).start();
                } else {
                    collapse(body);
                    flipAnimator(true, view).start();
                }
            }
        });
        header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Login.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(MainActivity.this);
            }
        });
        header.findViewById(R.id.inbox).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Inbox.class);
                MainActivity.this.startActivityForResult(inte, INBOX_RESULT);
            }
        });
        headerMain = header;
        if (runAfterLoad == null) {
            new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    } else if (Authentication.didOnline) {
        header = inflater.inflate(R.layout.drawer_loggedout, drawerSubList, false);
        drawerSubList.addHeaderView(header, null, false);
        headerMain = header;
        hea = header.findViewById(R.id.back);
        final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
        profStuff.setVisibility(View.GONE);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (profStuff.getVisibility() == View.GONE) {
                    expand(profStuff);
                    flipAnimator(false, header.findViewById(R.id.headerflip)).start();
                } else {
                    collapse(profStuff);
                    flipAnimator(true, header.findViewById(R.id.headerflip)).start();
                }
            }
        });
        final HashMap<String, String> accounts = new HashMap<>();
        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
            if (s.contains(":")) {
                accounts.put(s.split(":")[0], s.split(":")[1]);
            } else {
                accounts.put(s, "");
            }
        }
        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
        final String guest = getString(R.string.guest);
        keys.add(guest);
        final LinearLayout accountList = header.findViewById(R.id.accountsarea);
        for (final String accName : keys) {
            LogUtil.v(accName);
            final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
            ((TextView) t.findViewById(R.id.name)).setText(accName);
            if (!accName.equals(guest)) {
                t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog2, int which2) {
                                Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                                Set<String> done = new HashSet<>();
                                for (String s : accounts2) {
                                    if (!s.contains(accName)) {
                                        done.add(s);
                                    }
                                }
                                Authentication.authentication.edit().putStringSet("accounts", done).commit();
                                dialog2.dismiss();
                                accountList.removeView(t);
                                if (accName.equalsIgnoreCase(Authentication.name)) {
                                    boolean d = false;
                                    for (String s : keys) {
                                        if (!s.equalsIgnoreCase(accName)) {
                                            d = true;
                                            LogUtil.v("Switching to " + s);
                                            if (!accounts.get(s).isEmpty()) {
                                                Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
                                            } else {
                                                ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                                                Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(s))).remove("backedCreds").commit();
                                            }
                                            Authentication.name = s;
                                            UserSubscriptions.switchAccounts();
                                            Reddit.forceRestart(MainActivity.this, true);
                                        }
                                    }
                                    if (!d) {
                                        Authentication.name = "LOGGEDOUT";
                                        Authentication.isLoggedIn = false;
                                        Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
                                        UserSubscriptions.switchAccounts();
                                        Reddit.forceRestart(MainActivity.this, true);
                                    }
                                } else {
                                    accounts.remove(accName);
                                    keys.remove(accName);
                                }
                            }
                        }).setPositiveButton(R.string.btn_cancel, null).show();
                    }
                });
            } else {
                t.findViewById(R.id.remove).setVisibility(View.GONE);
            }
            t.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    if (!accName.equalsIgnoreCase(Authentication.name) && !accName.equals(guest)) {
                        if (!accounts.get(accName).isEmpty()) {
                            Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").commit();
                        } else {
                            ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                            Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").commit();
                        }
                        Authentication.isLoggedIn = true;
                        Authentication.name = accName;
                        UserSubscriptions.switchAccounts();
                        Reddit.forceRestart(MainActivity.this, true);
                    }
                }
            });
            accountList.addView(t);
        }
        header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Login.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(MainActivity.this);
            }
        });
        headerMain = header;
        header.findViewById(R.id.multi).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (runAfterLoad == null) {
                            Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                            inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                            MainActivity.this.startActivity(inte);
                        }
                    }
                }).negativeText(R.string.btn_cancel).show();
            }
        });
    } else {
        header = inflater.inflate(R.layout.drawer_offline, drawerSubList, false);
        headerMain = header;
        drawerSubList.addHeaderView(header, null, false);
        hea = header.findViewById(R.id.back);
        header.findViewById(R.id.online).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().remove("forceoffline").commit();
                Reddit.forceRestart(MainActivity.this);
            }
        });
    }
    header.findViewById(R.id.manage).setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View view) {
            Intent i = new Intent(MainActivity.this, ManageOfflineContent.class);
            startActivity(i);
        }
    });
    if (Authentication.didOnline) {
        View support = header.findViewById(R.id.support);
        if (SettingValues.tabletUI) {
            support.setVisibility(View.GONE);
        } else {
            header.findViewById(R.id.support).setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View view) {
                    new AlertDialogWrapper.Builder(MainActivity.this).setTitle(R.string.settings_support_slide).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            try {
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                            } catch (ActivityNotFoundException e) {
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                            }
                        }
                    }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    }).show();
                }
            });
        }
        header.findViewById(R.id.prof).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_goto).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Intent inte = new Intent(MainActivity.this, Profile.class);
                        // noinspection ConstantConditions
                        inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                        MainActivity.this.startActivity(inte);
                    }
                }).negativeText(R.string.btn_cancel).show();
            }
        });
    }
    header.findViewById(R.id.settings).setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View v) {
            Intent i = new Intent(MainActivity.this, Settings.class);
            startActivity(i);
            // Cancel sub loading because exiting the settings will reload it anyway
            if (mAsyncGetSubreddit != null)
                mAsyncGetSubreddit.cancel(true);
            drawerLayout.closeDrawers();
        }
    });
    /*  footer.findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent inte = new Intent(Overview.this, Setting.class);
                Overview.this.startActivityForResult(inte, 3);
            }
        });*/
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, drawerLayout, toolbar, R.string.btn_open, R.string.btn_close) {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            // this disables the animation
            super.onDrawerSlide(drawerView, 0);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
                int current = pager.getCurrentItem();
                if (current == toOpenComments && toOpenComments != 0) {
                    current -= 1;
                }
                String compare = usedArray.get(current);
                if (compare.equals("random") || compare.equals("myrandom") || compare.equals("randnsfw")) {
                    if (adapter != null && adapter.getCurrentFragment() != null && ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom != null) {
                        String sub = ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom;
                        doSubSidebarNoLoad(sub);
                        doSubSidebar(sub);
                    }
                } else {
                    doSubSidebar(usedArray.get(current));
                }
            }
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(drawerLayout.getWindowToken(), 0);
        }
    };
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();
    header.findViewById(R.id.back).setBackgroundColor(Palette.getColor("alsdkfjasld"));
    accountsArea = header.findViewById(R.id.accountsarea);
    if (accountsArea != null) {
        accountsArea.setBackgroundColor(Palette.getDarkerColor("alsdkfjasld"));
    }
    setDrawerSubList();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) NonNull(android.support.annotation.NonNull) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) HashSet(java.util.HashSet) Toolbar(android.support.v7.widget.Toolbar) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) Map(java.util.Map) HashMap(java.util.HashMap) Set(java.util.Set) HashSet(java.util.HashSet) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) LinearLayout(android.widget.LinearLayout)

Example 53 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project YhLibraryForAndroid by android-coco.

the class DemoActivity method initWidget.

@Override
public void initWidget() {
    super.initWidget();
    changeFragment(R.id.content, oneFragment);
    FloatingActionButton fab = bindView(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
    drawer = bindView(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    // 禁止手势滑动
    drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    // 打开手势滑动
    // drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    toggle.syncState();
    // 导航图标
    // toolbar.setNavigationIcon(R.mipmap.ic_launcher);
    NavigationView navigationView = bindView(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.getMenu().getItem(0).setChecked(true);
    // NavigationView navigationView1 =bindView(R.id.nav_view1);
    // navigationView1.setNavigationItemSelectedListener(this);
    // navigationView1.getMenu().getItem(0).setChecked(true);
    // lineartlayout
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    // CardView
    // 两列
    // int spanCount = 3;
    // GridLayoutManager layoutManager = new GridLayoutManager(this,spanCount);
    // layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    // StaggeredGridLayoutManager 不能加分割线
    // StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(spanCount,
    // StaggeredGridLayoutManager.VERTICAL);
    // 分割线为LinearLayoutManager
    // 分割线
    mRecyclerView.addItemDecoration(mRecyclerView.new YHItemDecoration());
    mRecyclerView.setLayoutManager(layoutManager);
    // mRecyclerView.setEmptyView(empty_layout);//没有数据的空布局
    // 可以自定义下拉刷新的样式
    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallPulseRise);
    // 可以自定义上拉加载的样式
    mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.SquareSpin);
    mRecyclerView.setFootViewText(getString(R.string.listview_loading), "我是有底线的。");
    // 箭头
    mRecyclerView.setArrowImageView(R.mipmap.iconfont_downgrey);
    // View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);
    // mRecyclerView.addHeaderView(header);
    // View header1 = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);
    // mRecyclerView.addHeaderView(header1);
    // header1.setBackgroundColor(0xff556B2F);
    // View header2 = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup)findViewById(android.R.id.content),false);
    // mRecyclerView.addHeaderView(header2);
    // header2.setBackgroundColor(0xff1874CD);
    mAdapter = new MyRecyclerAdatpter();
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(this);
    mRecyclerView.setLoadingListener(new YHRecyclerView.LoadingListener() {

        @Override
        public void onRefresh() {
            page = 1;
            // 必须在数据更新前清空,不能太早
            mAdapter.getDatas().clear();
            getDataByLine();
        }

        @Override
        public void onLoadMore() {
            page++;
            if (page <= TOTAL_PAGE) {
                // 小于总页数就加载更多
                // loading more
                getDataByLine();
            } else {
                // the end
                mRecyclerView.setNoMore(true);
            }
        }
    });
    mRecyclerView.refresh();
}
Also used : MyRecyclerAdatpter(org.yh.yhframe.adapter.rv.MyRecyclerAdatpter) YHRecyclerView(org.yh.library.view.YHRecyclerView) NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) FloatingActionButton(android.support.design.widget.FloatingActionButton) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) NavigationView(android.support.design.widget.NavigationView) BindView(org.yh.library.ui.BindView) View(android.view.View) YHRecyclerView(org.yh.library.view.YHRecyclerView)

Example 54 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project vlc-android by videolan.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!VLCInstance.testCompatibleCPU(this)) {
        finish();
        return;
    }
    Permissions.checkReadStoragePermission(this, false);
    /**
     * Start initializing the UI **
     */
    setContentView(R.layout.main);
    mDrawerLayout = (HackyDrawerLayout) findViewById(R.id.root_container);
    setupNavigationView();
    initAudioPlayerContainerActivity();
    if (savedInstanceState != null) {
        final FragmentManager fm = getSupportFragmentManager();
        mCurrentFragment = fm.getFragment(savedInstanceState, "current_fragment");
        // Restore fragments stack
        restoreFragmentsStack(savedInstanceState, fm);
        mCurrentFragmentId = savedInstanceState.getInt("current", mSettings.getInt("fragment_id", R.id.nav_video));
    } else {
        if (getIntent().getBooleanExtra(Constants.EXTRA_UPGRADE, false)) {
            /*
             * The sliding menu is automatically opened when the user closes
             * the info dialog. If (for any reason) the dialog is not shown,
             * open the menu after a short delay.
             */
            mActivityHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mDrawerLayout.openDrawer(mNavigationView);
                }
            }, 500);
        }
        reloadPreferences();
    }
    /* Set up the action bar */
    prepareActionBar();
    /* Set up the sidebar click listener
         * no need to invalidate menu for now */
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            final Fragment current = getCurrentFragment();
            if (current instanceof MediaBrowserFragment)
                ((MediaBrowserFragment) current).setReadyToDisplay(true);
        }

        // Hack to make navigation drawer browsable with DPAD.
        // see https://code.google.com/p/android/issues/detail?id=190975
        // and http://stackoverflow.com/a/34658002/3485324
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (mNavigationView.requestFocus())
                ((NavigationMenuView) mNavigationView.getFocusedChild()).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        }
    };
    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    /* Reload the latest preferences */
    mScanNeeded = savedInstanceState == null && mSettings.getBoolean("auto_rescan", true);
    mExtensionsManager = ExtensionsManager.getInstance();
    mMediaLibrary = VLCApplication.getMLInstance();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) NavigationMenuView(android.support.design.internal.NavigationMenuView) FileBrowserFragment(org.videolan.vlc.gui.browser.FileBrowserFragment) MediaBrowserFragment(org.videolan.vlc.gui.browser.MediaBrowserFragment) PreferencesFragment(org.videolan.vlc.gui.preferences.PreferencesFragment) VideoGridFragment(org.videolan.vlc.gui.video.VideoGridFragment) AudioBrowserFragment(org.videolan.vlc.gui.audio.AudioBrowserFragment) Fragment(android.support.v4.app.Fragment) NetworkBrowserFragment(org.videolan.vlc.gui.browser.NetworkBrowserFragment) MRLPanelFragment(org.videolan.vlc.gui.network.MRLPanelFragment) BaseBrowserFragment(org.videolan.vlc.gui.browser.BaseBrowserFragment) MediaBrowserFragment(org.videolan.vlc.gui.browser.MediaBrowserFragment) NavigationMenuView(android.support.design.internal.NavigationMenuView)

Example 55 with ActionBarDrawerToggle

use of android.support.v7.app.ActionBarDrawerToggle in project ShelterApp by farzamtn.

the class AdminActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    usersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
    emailBox = (EditText) findViewById(R.id.emailInput);
    ban = (Button) findViewById(R.id.ban);
    email = emailBox.getText().toString();
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
Also used : NavigationView(android.support.design.widget.NavigationView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) FloatingActionButton(android.support.design.widget.FloatingActionButton) DrawerLayout(android.support.v4.widget.DrawerLayout) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)218 View (android.view.View)153 NavigationView (android.support.design.widget.NavigationView)118 Toolbar (android.support.v7.widget.Toolbar)98 DrawerLayout (android.support.v4.widget.DrawerLayout)96 TextView (android.widget.TextView)85 AdapterView (android.widget.AdapterView)51 ImageView (android.widget.ImageView)48 ListView (android.widget.ListView)48 Intent (android.content.Intent)45 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)35 ActionBar (android.support.v7.app.ActionBar)31 SharedPreferences (android.content.SharedPreferences)30 RecyclerView (android.support.v7.widget.RecyclerView)23 Bundle (android.os.Bundle)20 FloatingActionButton (android.support.design.widget.FloatingActionButton)20 LinearLayout (android.widget.LinearLayout)19 MenuItem (android.view.MenuItem)17 BindView (butterknife.BindView)15 ArrayList (java.util.ArrayList)15