コード例 #1
0
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   if (!mNavigationDrawerFragment.isDrawerOpen()) {
     // Only show items in the action bar relevant to this screen
     // if the drawer is not showing. Otherwise, let the drawer
     // decide what to show in the action bar.
     getMenuInflater().inflate(R.menu.main, menu);
     restoreActionBar();
     return true;
   }
   return super.onCreateOptionsMenu(menu);
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNavigationDrawerFragment =
        (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = "Today's Hunts";

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
        R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    JsonObject json = new JsonObject();
    json.addProperty("client_id", Constants.API_CLIENT_ID);
    json.addProperty("client_secret", Constants.API_CLIENT_SECRET);
    json.addProperty("grant_type", "client_credentials");

    Ion.with(getApplicationContext())
        .load("https://api.producthunt.com/v1/oauth/token")
        .setJsonObjectBody(json)
        .asJsonObject()
        .setCallback(
            new FutureCallback<JsonObject>() {
              @Override
              public void onCompleted(Exception e, JsonObject result) {
                if (result != null && result.has("access_token")) {
                  Constants.CLIENT_TOKEN = result.get("access_token").getAsString();
                  Constants.TOKEN_EXPIRES =
                      System.currentTimeMillis()
                          + ((long) result.get("expires_in").getAsInt()) * 1000l;
                  browsingFragment.refresh(getApplicationContext());
                }
              }
            });
  }