Search in sources :

Example 1 with KeyboardUtil

use of forpdateam.ru.forpda.ui.views.KeyboardUtil in project ForPDA by RadiationX.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (EmptyActivity.empty(App.get().getPreferences().getString("auth.user.nick", ""))) {
        startActivity(new Intent(this, EmptyActivity.class));
        finish();
        return;
    }
    Intent intent = getIntent();
    if (intent != null) {
        checkWebView = intent.getBooleanExtra(CHECK_WEBVIEW, checkWebView);
    }
    if (checkWebView) {
        Observable.fromCallable(() -> App.get().isWebViewFound(this)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
            if (!aBoolean) {
                startActivity(new Intent(App.getContext(), WebVewNotFoundActivity.class));
                finish();
            }
        });
    }
    currentThemeIsDark = App.get().isDarkTheme();
    setTheme(currentThemeIsDark ? R.style.DarkAppTheme_NoActionBar : R.style.LightAppTheme_NoActionBar);
    setContentView(R.layout.activity_main);
    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawerLayout.addDrawerListener(toggle);
    toggle.syncState();
    /*
        * Т.к. 2 вьюхи, делаю цвет в 2 раза прозрачнее, чтобы компенсировать это.
        * P.S. Чем больше вьюх в DrawerLayout находятся до NavigationView, тем сильнее будет затенение
        * P.S.S. Первая вьюха - контейнер фрагментов, вторая - view_for_measure
        * */
    drawerLayout.setScrimColor(0x4C000000);
    drawers = new Drawers(this, drawerLayout);
    drawers.init(savedInstanceState);
    drawerHeader = new DrawerHeader(this, drawerLayout);
    drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            if (drawerView.getId() == R.id.menu_drawer) {
                if (App.get().getPreferences().getBoolean("drawers.tooltip.link_open", true)) {
                    SimpleTooltip tooltip = new SimpleTooltip.Builder(MainActivity.this).anchorView(drawerView.findViewById(R.id.drawer_header_open_link)).text(R.string.tooltip_link).gravity(Gravity.BOTTOM).animated(false).modal(true).transparentOverlay(false).backgroundColor(Color.BLACK).textColor(Color.WHITE).padding((float) App.px16).onDismissListener(simpleTooltip -> tooltips.remove(simpleTooltip)).build();
                    tooltip.show();
                    tooltips.add(tooltip);
                    App.get().getPreferences().edit().putBoolean("drawers.tooltip.link_open", false).apply();
                }
            }
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            if (drawerView.getId() == R.id.menu_drawer) {
                if (App.get().getPreferences().getBoolean("drawers.tooltip.tabs_drawer", true)) {
                    SimpleTooltip tooltip = new SimpleTooltip.Builder(MainActivity.this).anchorView(drawers.getTabDrawer()).text(R.string.tooltip_tabs).gravity(Gravity.START).animated(false).modal(true).transparentOverlay(false).backgroundColor(Color.BLACK).textColor(Color.WHITE).padding((float) App.px16).onDismissListener(simpleTooltip -> tooltips.remove(simpleTooltip)).build();
                    tooltip.show();
                    tooltips.add(tooltip);
                    App.get().getPreferences().edit().putBoolean("drawers.tooltip.tabs_drawer", false).apply();
                }
            }
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            if (newState == DrawerLayout.STATE_DRAGGING) {
                TabFragment fragment = TabManager.get().getActive();
                if (fragment != null) {
                    fragment.hidePopupWindows();
                }
            }
        }
    });
    receiver = new NetworkStateReceiver();
    receiver.registerReceiver();
    KeyboardUtil keyboardUtil = new KeyboardUtil(this, findViewById(R.id.fragments_container));
    keyboardUtil.enable();
    final View viewDiff = findViewById(R.id.view_for_measure);
    viewDiff.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> measureView(v));
    if (Preferences.Notifications.Update.isEnabled(getApplicationContext())) {
        new SimpleUpdateChecker().checkFromGitHub(this);
    }
    checkIntent(getIntent());
}
Also used : SimpleTooltip(io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip) SimpleUpdateChecker(forpdateam.ru.forpda.ui.activities.updatechecker.SimpleUpdateChecker) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment) View(android.view.View) KeyboardUtil(forpdateam.ru.forpda.ui.views.KeyboardUtil) DrawerLayout(android.support.v4.widget.DrawerLayout) Drawers(forpdateam.ru.forpda.ui.views.drawers.Drawers) NetworkStateReceiver(forpdateam.ru.forpda.common.receivers.NetworkStateReceiver) DrawerHeader(forpdateam.ru.forpda.ui.views.drawers.DrawerHeader)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 View (android.view.View)1 NetworkStateReceiver (forpdateam.ru.forpda.common.receivers.NetworkStateReceiver)1 SimpleUpdateChecker (forpdateam.ru.forpda.ui.activities.updatechecker.SimpleUpdateChecker)1 TabFragment (forpdateam.ru.forpda.ui.fragments.TabFragment)1 KeyboardUtil (forpdateam.ru.forpda.ui.views.KeyboardUtil)1 DrawerHeader (forpdateam.ru.forpda.ui.views.drawers.DrawerHeader)1 Drawers (forpdateam.ru.forpda.ui.views.drawers.Drawers)1 SimpleTooltip (io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip)1