private void playerInfo() { Player player = getGamesClient().getCurrentPlayer(); String name = player.getDisplayName(); Uri uri = player.getIconImageUri(); String displayName; if (player == null) { Log.w(TAG, "mGamesClient.getCurrentPlayer() is NULL!"); displayName = "???"; } else { displayName = player.getDisplayName(); appPreference.setLoginName(displayName); } userInfo.setText(String.format(getString(R.string.you_are_signed_in_as), displayName)); // userIcon.setImageURI(uri); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_drawer); CONTENT_VIEW_ID = R.id.content_frame; Utils.showUserGuardIfNeed(this, UserGuideActivity.START_FROM_SPLASH); mTitle = mDrawerTitle = getTitle(); // mDrawerItems = getResources().getStringArray(R.array.drawer_items_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener drawerListAdapter = new DrawerListAdapter(getApplicationContext()); drawerItemArrayList = new ArrayList<Object>(); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_DASHBOARD, getString(R.string.menu_item_dashboard))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_PUSHUPS, getString(R.string.menu_item_pushup))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_MULTI, getString(R.string.menu_item_multi))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_WRIST, getString(R.string.menu_item_wrist))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_GOOGLE, getString(R.string.menu_item_google))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_LEADERBOARD, getString(R.string.menu_item_leaderboard))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_ARCHIEVEMENT, getString(R.string.menu_item_archievement))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_HELPER, getString(R.string.menu_item_helper))); drawerItemArrayList.add( new DrawerListAdapter.DrawerItem( Constants.DRAWER_ITEM_ABOUT, getString(R.string.menu_item_about))); drawerListAdapter.setDataList(drawerItemArrayList); mDrawerList.setAdapter(drawerListAdapter); // mDrawerList.setAdapter(new ArrayAdapter<String>(this, // R.layout.drawer_list_item, mDrawerItems)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBarImpl().setDisplayHomeAsUpEnabled(true); getActionBarImpl().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */) { public void onDrawerClosed(View view) { getActionBarImpl().setTitle(mTitle); supportInvalidateOptionsMenu(); // invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBarImpl().setTitle(mDrawerTitle); supportInvalidateOptionsMenu(); // invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem((DrawerListAdapter.DrawerItem) drawerListAdapter.getItem(0)); } else { selectItem((DrawerListAdapter.DrawerItem) drawerListAdapter.getItem(0)); } bus = ServiceProvider.getBus(); bus.register(this); appPreference = AppPreference.getInstance(getApplicationContext()); titlebarHelper = new TitlebarHelper( MainActivity.this, new TitlebarHelper.OnTitlebarClickListener() { @Override public void onClickIcon() {} @Override public void onClickTitle() {} }); userIcon = (ImageView) findViewById(R.id.user_icon); userInfo = (TextView) findViewById(R.id.user_info); share = (TextView) findViewById(R.id.share_textview); userInfo.setOnClickListener(this); userIcon.setOnClickListener(this); share.setOnClickListener(this); findViewById(R.id.button_sign_in).setOnClickListener(this); findViewById(R.id.button_sign_out).setOnClickListener(this); getGamesClient() .registerConnectionCallbacks( new GooglePlayServicesClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { submitScore(); } @Override public void onDisconnected() { showAlert("Connect", "Disconnected!"); } }); getGamesClient().connect(); // if (!isSignedIn()) { // beginUserInitiatedSignIn(); // } // showDashboardFragment(); initWeChat(); }