private String generateFileName() { // Get localID UserInfoStore client = new UserInfoStore(getActivity()); IdToken token = client.getSavedIdToken(); String localId = token.getLocalId(); // Generate 8 digit random number and encode it in base64 SecureRandom rand = new SecureRandom(); StringBuilder rand8Dig = new StringBuilder(8); for (int i = 0; i < 8; i++) { rand8Dig.append((char) ('0' + rand.nextInt(10))); } String randNum = rand8Dig.toString(); String randNumB64 = Utilities.base64Encoding(randNum); String fileName = localId + '.' + randNumB64; fileName += 'P'; // 'P' marks that a photo is public, future versions will allow for private photos return fileName; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mTitle = mDrawerTitle = getTitle(); mNavItems = getResources().getStringArray(R.array.nav_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // initialize Data class to retrieve navigation drawer icons and text Data data = new Data(); /* Add the header to the navigation drawer. Pulls the user's name, email address * and photo from the Google Identity Toolkit. The photo is placed into a custom * ImageView which gives the circle effect. Image loading over the network is done * with Picasso, a library from Square. */ View header = View.inflate(this, R.layout.navdrawer_header, null); BezelImageView imageView = (BezelImageView) header.findViewById(R.id.profile_image); UserInfoStore client = new UserInfoStore(getApplicationContext()); GitkitUser user = client.getSavedGitkitUser(); Log.v("foo", "user is " + user); Picasso.with(getApplicationContext()) .load(client.getSavedGitkitUser().getPhotoUrl()) .into(imageView); TextView email = (TextView) header.findViewById(R.id.profile_email_text); email.setText(Data.mEmail); TextView name = (TextView) header.findViewById(R.id.profile_name_text); name.setText(Data.mDisplayName); // set up the drawer's list view with mNavItems and click listener mDrawerList.addHeaderView(header, null, false); mDrawerList.setAdapter( new NavDrawerAdapter( getApplicationContext(), R.layout.list_item_navdrawer, data.mNavItems)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().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.app_name, /* "open drawer" description for accessibility */ R.string.app_name /* "close drawer" description for accessibility */) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(NAVDRAWER_ITEM_HOME); } }