Пример #1
0
 @Override
 public void onValidationFinished(ValidationType validationType) {
   if (validationType.equals(ValidationType.SKIPPED)) {
     Log.d("ValidationType: ", "SKIPPED. Launching login activity...");
     startActivityForResult(new Intent(getBaseContext(), WelcomeActivity.class), 364);
     Bundle data = new Bundle();
     data.putString(WelcomeActivity.VALIDATION_TYPE, ValidationType.SKIPPED.name());
     Intent missingToken = new Intent(getBaseContext(), WelcomeActivity.class);
     missingToken.putExtras(data);
     startActivityForResult(missingToken, 364);
   } else if (validationType.equals(ValidationType.MISSING_CREDENTIALS)) {
     Log.d("ValidationType: ", "MISSING_CREDENTIALS. Launching login activity...");
     Bundle data = new Bundle();
     data.putString(WelcomeActivity.VALIDATION_TYPE, ValidationType.MISSING_CREDENTIALS.name());
     Intent missingToken = new Intent(getBaseContext(), WelcomeActivity.class);
     missingToken.putExtras(data);
     startActivityForResult(missingToken, 364);
   } else if (validationType.equals(ValidationType.MISSING_TOKEN)) {
     Log.d("ValidationType:", "MISSING_TOKEN. Launching Login Activity");
     Bundle data = new Bundle();
     data.putString(WelcomeActivity.VALIDATION_TYPE, ValidationType.MISSING_TOKEN.name());
     Intent missingToken = new Intent(getBaseContext(), WelcomeActivity.class);
     missingToken.putExtras(data);
     startActivityForResult(missingToken, 364);
   } else if (validationType.equals(ValidationType.SUCCESS)) {
     Log.d("ValidationType: ", "SUCCESS. Get user info/retrieve updated data from server");
     onLoginSuccess(
         new LinodeUser(
             LinodeApi.getInstance().getPreferences().getCurrentUsername(),
             LinodeApi.getInstance().getPreferences().getCurrentPassword(),
             LinodeApi.getInstance().getPreferences().getCurrentApiKey()));
   } else if (validationType.equals(ValidationType.UNKNOWN_ERROR)) {
     AndroidHelper.shortToast(getBaseContext(), "Unknown error. ¯\\_(ツ)_/¯");
   }
 }
Пример #2
0
 @Override
 public void onLoginSuccess(final LinodeUser linodeUser) {
   LinodeApi.getInstance().saveLinodeUser(linodeUser);
   LinodeApi.getInstance().switchAccount(linodeUser);
   ProfileDrawerItem profileDrawerItem =
       new ProfileDrawerItem()
           .withName(linodeUser.getUsername())
           .withIcon(linodeUser.getProfileImageUrl());
   accountHeader.setActiveProfile(profileDrawerItem);
 }
Пример #3
0
  private AccountHeader buildHeader() {

    final AccountHeaderBuilder headerBuilder =
        new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header_img);

    headerBuilder.withOnAccountHeaderListener(this);

    final long PROFILE = 100000;

    ProfileSettingDrawerItem settingDrawerItem =
        new ProfileSettingDrawerItem()
            .withName("Add Account")
            .withDescription("Sign into another Linode account")
            .withIcon(
                new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add)
                    .actionBar()
                    .paddingDp(5)
                    .colorRes(R.color.material_drawer_primary_text))
            .withIdentifier(PROFILE);

    headerBuilder.addProfiles(settingDrawerItem);

    if (!LinodeApi.getInstance().getLinodeUsers().isEmpty()) {

      String username, password, token;

      username = LinodePreferences.getInstance(getBaseContext()).getCurrentUsername();
      password = LinodePreferences.getInstance(getBaseContext()).getCurrentPassword();
      token = LinodePreferences.getInstance(getBaseContext()).getCurrentApiKey();

      final LinodeUser user = new LinodeUser(username, password, token);

      ProfileDrawerItem profileDrawerItem =
          new ProfileDrawerItem()
              .withName(LinodePreferences.getInstance(getBaseContext()).getCurrentUsername())
              .withIcon(user.getProfileImageUrl());

      headerBuilder.addProfiles(profileDrawerItem);
    }

    return headerBuilder.build();
  }
Пример #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_main);

    //  Find the toolbar in XML
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    //  Set it's title text color to white
    toolbar.setTitleTextColor(Color.parseColor("#FFFFFF"));
    //  Change activity's action bar to toolbar
    setSupportActionBar(toolbar);

    LinodeApi.init(getBaseContext(), this);

    initImageLoader();

    accountHeader = buildHeader();

    //  Set up a new drawer builder
    drawer =
        new DrawerBuilder()
            .withActivity(this) //  Bind it to this activity
            .withToolbar(toolbar) //  Bind it to the toolbar attached to this activity
            .withAccountHeader(accountHeader)
            .withTranslucentNavigationBar(true) //  Disable translucent navigation menu/bar
            .addDrawerItems( //  Add our drawer items
                //  Regular drawer items
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.server) //  Icon
                    .withSelectedIcon(R.drawable.server_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item1)) //  Title
                    .withIdentifier(1) //  ID = 1
                    .withTextColor(Color.parseColor("#444444")) //  Text color
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.sitemap)
                    .withSelectedIcon(R.drawable.sitemap_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item2))
                    .withIdentifier(2) //  ID = 2
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.dns)
                    .withSelectedIcon(R.drawable.dns_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item3))
                    .withIdentifier(3) //  ID = 3
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.library)
                    .withSelectedIcon(R.drawable.library_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item4))
                    .withIdentifier(4) //  ID = 4
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),

                //  Divider
                new DividerDrawerItem(),

                //  Small/secondary drawer items
                new SecondaryDrawerItem()
                    .withIcon(R.drawable.account)
                    .withSelectedIcon(
                        R.drawable
                            .account_tinted) //  Tinted icon; not mandatory since this won't be
                                             // highlighted
                    .withName(getResources().getString(R.string.item5))
                    .withIdentifier(5) //  ID = 5
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green))
                    .withSelectable(false), //  Not a fragment; don't highlight
                new SecondaryDrawerItem()
                    .withIcon(R.drawable.information)
                    .withSelectedIcon(R.drawable.information_tinted)
                    .withName(getResources().getString(R.string.item6))
                    .withIdentifier(6) //  ID = 6
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green))
                    .withSelectable(false), //  Not a fragment; don't highlight
                new SecondaryDrawerItem()
                    .withIcon(R.drawable.logout)
                    .withSelectedIcon(R.drawable.logout_tinted)
                    .withName(getResources().getString(R.string.item7))
                    .withIdentifier(7) //  ID = 7
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green))
                    .withSelectable(false) //  Not a fragment; don't highlight
                )
            //  Attach onClickListeners for each drawer item (not dividers!)
            .withOnDrawerItemClickListener(
                new Drawer.OnDrawerItemClickListener() {

                  @Override
                  public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {

                    if (drawerItem != null) {
                      //   update the main content by replacing fragments
                      Fragment fragment = new LinodesFragment();
                      FragmentManager fragmentManager = getFragmentManager();

                      switch ((int) drawerItem.getIdentifier()) {
                        case 1:
                          fragment = new LinodesFragment();
                          break;
                        case 2:
                          fragment = new NodesFragment();
                          break;
                        case 3:
                          fragment = new DNSFragment();
                          break;
                        case 4:
                          fragment = new LibraryFragment();
                          break;
                        case 5:
                          // Account
                          Toast.makeText(getBaseContext(), "Demo Only", Toast.LENGTH_SHORT).show();
                          break;
                        case 6:
                          // About
                          Intent about = new Intent(MainActivity.this, AboutActivity.class);
                          startActivity(about);
                          break;
                        case 7:
                          // Log out
                          Toast.makeText(getBaseContext(), "Demo Only", Toast.LENGTH_SHORT).show();
                          break;
                      }
                      fragmentManager
                          .beginTransaction()
                          .replace(R.id.content_frame, fragment)
                          .commit();

                      if (drawerItem instanceof Nameable) {
                        setTitle(
                            ((Nameable) drawerItem).getName().getText(getApplicationContext()));
                      }
                    }

                    return false;
                  }
                })
            .withFireOnInitialOnClick(true)
            .withSavedInstance(savedInstanceState)
            .build();

    //  Set a custom shadow that overlays the main content when the drawer opens
    drawer.getDrawerLayout().setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    ActionBar mActionBar = getSupportActionBar();

    int color = getResources().getColor(R.color.toolbar_green);

    if (mActionBar != null) {
      toolbar.setBackgroundColor(color);
      drawer
          .getDrawerLayout()
          .setStatusBarBackgroundColor(
              AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f));

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(8);
        getWindow()
            .setNavigationBarColor(
                AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f));
      }
    }
  }