Beispiel #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    surfaceView.getHolder().addCallback(this);
    surfaceView.setOnTouchListener(this);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    if (mDrawerLayout != null) { // xlarge-land has no drawer layout (drawer is always open)
      mDrawerToggle =
          new ActionBarDrawerToggle(
              this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
      mDrawerLayout.addDrawerListener(mDrawerToggle);
      getActionBar().setDisplayHomeAsUpEnabled(true);
      getActionBar().setHomeButtonEnabled(true);
    }

    mDrawerList = (ListView) findViewById(R.id.leftDrawer);
    mStateAdapter = new StateAdapter(this);
    mDrawerList.setAdapter(mStateAdapter);

    mApplication = (ViewerApplication) getApplication();
    mApplication.setViewerActivity(this);
  }
  protected NavigationView setupDrawer(int drawerLayoutIdToLoad) {
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    _mDrawerLayout = (DrawerLayout) findViewById(drawerLayoutIdToLoad);

    // In Android support 23.2.1, there is a bug where you can't inflate the menu in XML, must be
    // done manually
    navigationView.inflateMenu(R.menu.drawer_menu_items);
    navigationView.inflateHeaderView(R.layout.drawer_header);
    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          // This method will trigger on item Click of navigation menu
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {
            return selectDrawerItem(menuItem);
          }
        });
    _mDrawerToggle =
        new ActionBarDrawerToggle(
            this, // Host Activity
            _mDrawerLayout, // DrawerLayout object
            R.string.navigation_drawer_open, // Description for accessibility
            R.string.navigation_drawer_close // Description for accessibility
            );
    _mDrawerLayout.addDrawerListener(_mDrawerToggle);

    return navigationView;
  }
Beispiel #3
0
 private void setDrawerLayout() {
   toolbar.setTitle("QingLuan");
   toolbar.setTitleTextColor(Color.rgb(48, 48, 48));
   setSupportActionBar(toolbar);
   drawerToggle =
       new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close);
   drawerLayout.addDrawerListener(drawerToggle);
 }
Beispiel #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AppSettings.initialize(this, this);
    dataManager = new NewsManager(this);
    permissionHandler = new StoragePermissionHandler(this);

    if (AppSettings.firstStart()) {
      Intent intent = new Intent(this, SelectSitesActivity.class);
      intent.putExtra(AppCode.SEND_PURPOSE, SelectSitesActivity.For.APP_FIRST_START);
      startActivity(intent);
      finish();
      return;
    }

    setContentView(R.layout.a_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    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);
    assert navigationView != null : "Navigation view is null";
    navigationView.setNavigationItemSelectedListener(this);

    fragmentManager = new FragmentManager(this, navigationView, R.id.main_content);

    updateDrawer(true);

    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey(AppCode.SEND_NEWS_IDS)) {
      int[] news_codes = extras.getIntArray(AppCode.SEND_NEWS_IDS);
      newsFragment = NewsListFragment.instanceForNotification(news_codes);
    } else newsFragment = NewsListFragment.instanceFor(-1);

    if (extras != null && extras.containsKey(AppCode.RESTART)) {
      ScheduledDownloadReceiver.scheduleDownloads(
          this, new ScheduleManager(this).getDownloadSchedules());
    }

    newsFragment.setRetainInstance(true);

    fragmentManager.addFragment(newsFragment, R.id.nav_my_news);
  }
Beispiel #5
0
  private void setupViews() {
    setSupportActionBar(toolbar);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    navigationView.setNavigationItemSelectedListener(this);

    loadFragment(new HomeFragment());
  }
  private void setUpDrawerToggle() {
    DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.ym_drawer);
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, ym_toolbar, R.string.travelnote, R.string.travelnote) {
          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
          }
        };
    mDrawerLayout.addDrawerListener(mDrawerToggle);
  }
Beispiel #7
0
  /**
   * Main method that sets up action listeners and inflates layouts. Sets up the toolbar and the
   * tabbed view. Provides adapters that return the corresponding fragment to run. Also,
   * instantiates the drawer and attaches action listeners.
   *
   * @param savedInstanceState part of onCreate()
   */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home);

    // Set the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    SectionsPagerAdapter mSectionsPagerAdapter =
        new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    ViewPager mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // Create the tab layout for the 3 main tabs.
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    // Drawer with all the important user-related actions.
    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);

    AppCompatImageView mode = (AppCompatImageView) findViewById(R.id.home_system_mode);
    mode.setOnClickListener(
        v -> {
          AlarmStateFragment newFragment = new AlarmStateFragment();
          newFragment.show(getSupportFragmentManager(), "alarm_state");
        });
  }
Beispiel #8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    iv_search = (ImageView) findViewById(R.id.iv_search);
    iv_search.setOnClickListener(this);
    setSupportActionBar(toolbar);
    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.nv_sidebar);
    navigationView.setNavigationItemSelectedListener(this);

    doUserAction(UserAction.HOME_SCREEN, new Bundle());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // how to adjust the height of toolbar
    // http://stackoverflow.com/questions/17439683/how-to-change-action-bar-size
    // zsmth_actionbar_size @ dimen ==> ThemeOverlay.ActionBar @ styles ==> theme @ app_bar_main.xml

    // init floating action button & circular action menu
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    initCircularActionMenu(fab);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    mToggle =
        new ActionBarDrawerToggle(
            this,
            mDrawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    mDrawer.addDrawerListener(mToggle);
    mToggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
    mNavigationView.setCheckedItem(R.id.nav_guidance);

    // http://stackoverflow.com/questions/33161345/android-support-v23-1-0-update-breaks-navigationview-get-find-header
    View headerView = mNavigationView.getHeaderView(0);
    mAvatar = (WrapContentDraweeView) headerView.findViewById(R.id.nav_user_avatar);
    mAvatar.setOnClickListener(this);

    mUsername = (TextView) headerView.findViewById(R.id.nav_user_name);
    mUsername.setOnClickListener(this);

    // http://stackoverflow.com/questions/27097126/marquee-title-in-toolbar-actionbar-in-android-with-lollipop-sdk
    TextView titleTextView = null;
    try {
      Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
      f.setAccessible(true);
      titleTextView = (TextView) f.get(toolbar);
      titleTextView.setEllipsize(TextUtils.TruncateAt.START);
    } catch (NoSuchFieldException e) {
    } catch (IllegalAccessException e) {
    }

    // init all fragments
    initFragments();

    FragmentManager fm = getSupportFragmentManager();
    if (Settings.getInstance().isLaunchHotTopic()) {
      fm.beginTransaction().replace(R.id.content_frame, hotTopicFragment).commit();
    } else {
      fm.beginTransaction().replace(R.id.content_frame, favoriteBoardFragment).commit();
    }

    getSupportFragmentManager()
        .addOnBackStackChangedListener(
            new FragmentManager.OnBackStackChangedListener() {
              public void onBackStackChanged() {
                // Enable Up button only  if there are entries in the back stack
                boolean canback = getSupportFragmentManager().getBackStackEntryCount() > 0;
                if (canback) {
                  mToggle.setDrawerIndicatorEnabled(false);
                  getSupportActionBar().setDisplayShowHomeEnabled(true);
                  getSupportActionBar().setHomeButtonEnabled(true);
                  getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                } else {
                  getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                  mToggle.setDrawerIndicatorEnabled(true);
                  mDrawer.addDrawerListener(mToggle);
                }
              }
            });

    // start service to maintain user status
    setupUserStatusReceiver();
    updateUserStatusNow();
    UpdateNavigationViewHeader();

    // schedule the periodical run
    MaintainUserStatusService.schedule(MainActivity.this, mReceiver);

    if (Settings.getInstance().isFirstRun()) {
      // show info dialog after 5 seconds for the first run
      final Handler handler = new Handler();
      handler.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              showInfoDialog();
            }
          },
          2000);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mojo_menu);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
      supportActionBar.setTitle(R.string.nav_menu_title);
    }

    navigationDrawer = (DrawerLayout) findViewById(R.id.mojo_menu_drawer_layout);
    navigationDrawerToggle =
        new ActionBarDrawerToggle(
            this,
            navigationDrawer,
            toolbar,
            R.string.action_open_navigation_drawer,
            R.string.action_close_navigation_drawer) {
          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (navigationView.getMenu().findItem(R.id.nav_orders).isChecked()) {
              ActivityOptionsCompat optionsCompat =
                  ActivityOptionsCompat.makeSceneTransitionAnimation(
                      MojoMenuActivity.this, toolbar, getString(R.string.toolbar_transition));
              MojoOrderActivity.start(
                  MojoMenuActivity.this, orderItemList, optionsCompat.toBundle());
            } else if (navigationView.getMenu().findItem(R.id.nav_settings).isChecked()) {
              SettingsActivity.start(MojoMenuActivity.this);
            }
            navigationView.setCheckedItem(R.id.nav_menu);
          }
        };
    navigationDrawer.addDrawerListener(navigationDrawerToggle);

    navigationView = (NavigationView) findViewById(R.id.mojo_menu_nav_view);
    navigationView.setCheckedItem(R.id.nav_menu);
    navigationView.setNavigationItemSelectedListener(this);

    goToCartButton = (Button) findViewById(R.id.bottom_action_button);
    goToCartButton.setOnClickListener(this);

    tabLayout = (TabLayout) findViewById(R.id.mojo_menu_tab_layout);
    viewPager = (ViewPager) findViewById(R.id.mojo_menu_view_pager);

    baseReference = FirebaseDatabase.getInstance().getReference().child("data");
    mojoDataChildEventListener = new MojoDataChildEventListener();

    if (savedInstanceState != null) {
      mojoData = savedInstanceState.getParcelable(EXTRA_MOJO_DATA);
      orderItemList = savedInstanceState.getParcelableArrayList(EXTRA_ORDER_ITEM_LIST);
      updateTabLayoutAndViewPager();
      updateGoToCartButton();
    } else {
      mojoData = new MojoData();
      orderItemList = new ArrayList<>();
      showLoadingDialog();
      baseReference.addListenerForSingleValueEvent(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
              dismissLoadingDialog();
              if (dataSnapshot != null && dataSnapshot.exists()) {
                ArrayList<MojoMenu> mojoMenuList = new ArrayList<>();
                ArrayList<Topping> toppingList = new ArrayList<>();
                ArrayList<String> availableZipList = new ArrayList<>();
                Map<String, Map<String, Object>> mojoDataMap =
                    (Map<String, Map<String, Object>>) dataSnapshot.getValue();
                Map<String, Object> toppingDataMap = mojoDataMap.get("topping");
                for (Object toppingData : toppingDataMap.values()) {
                  toppingList.add(new Topping((Map<String, Object>) toppingData));
                }
                Map<String, Object> menuDataMap = mojoDataMap.get("menu");
                for (Object menuData : menuDataMap.values()) {
                  mojoMenuList.add(new MojoMenu((Map<String, Object>) menuData));
                }
                availableZipList.addAll((List<String>) mojoDataMap.get("zip"));

                mojoData.setMojoMenuList(mojoMenuList);
                mojoData.setToppingList(toppingList);
                mojoData.setAvailableZipList(availableZipList);

                updateTabLayoutAndViewPager();
              }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
              dismissLoadingDialog();
              Log.e("findme", "Load menu data failed: " + databaseError.getMessage());
            }
          });
    }
  }
Beispiel #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate(" + savedInstanceState + "," + getIntent().getExtras() + ")");
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
      currentFragment = savedInstanceState.getInt(CURRENT_FRAGMENT, R.id.nav_info);
    } else if (getIntent().getExtras() != null) {
      currentFragment = getIntent().getExtras().getInt(CURRENT_FRAGMENT, R.id.nav_info);
    }

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (!ecm.isConnected()) {
              connect();
            } else {
              disconnect();
            }
          }
        });

    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);

    ((TextView) navigationView.getHeaderView(0).findViewById(R.id.headerTitle))
        .setText(Utils.getAppVersion(this));

    // Bind to our service and setup the connect button
    bindService(
        new Intent(this, EcmDroidService.class), serviceConnection, Context.BIND_AUTO_CREATE);
    startService(new Intent(this, EcmDroidService.class));

    switchToFragment(currentFragment);

    // Install the database
    dbHelper = new DBHelper(this);
    if (!dbHelper.isDbInstalled()) {
      ProgressDialogTask installTask =
          new ProgressDialogTask(this, "Installing Database") {
            @Override
            protected Exception doInBackground(Void... args) {
              try {
                dbHelper.installDB(MainActivity.this);
              } catch (IOException e) {
                Log.e(TAG, "DB Install failed.", e);
                return e;
              }
              return null;
            }

            @Override
            protected void onPostExecute(Exception result) {
              super.onPostExecute(result);
              if (result != null) {
                Toast.makeText(
                        MainActivity.this, "FATAL: DB Installation failed.", Toast.LENGTH_LONG)
                    .show();
                System.exit(0);
              }
            }
          };
      installTask.execute();
    }
  }