/** * Called when application is first created. <b>Set up:</b> * * <ol> * <li>Create and open the main space and put the primary user (the user that started this * application) into the space * <li>Initialize button functionality: main button * </ol> * * <b>Assumptions:</b> * * <ul> * <li>The main space is created by the primary user * <li>XMPPConnection is established and authorized before this Activity is called * </ul> */ @Override public void onCreate(Bundle savedInstanceState) { if (D) Log.d(TAG, "onCreate - Started the MainApplication activity"); super.onCreate(savedInstanceState); ContextTracker.setContext(this); // Open up the layout specified by the main XML setContentView(R.layout.main); // Change the parameters of the appearance according to screen size // adjustLayoutParams(); // This spaceview already created for you in the XML file, so retrieve // it screen = (SpaceView) findViewById(R.id.space_view); // Check if the mainspace was already created if (Space.getMainSpace() == null) { // Obtain username used to log into the application Intent start_intent = getIntent(); username = start_intent.getStringExtra(Network.KEY_USERNAME); // Create instance of primary user if (userPrimary == null) { userPrimary = new User(username, username.split("@")[0], R.drawable.question); } try { // create the mainspace SpaceController.createMainSpace(this); // create an empty private space // SpaceController.addSpace(this); // TODO add private space preview } catch (XMPPException e) { // Log.e(TAG, "onCreate - Error (" + e.getXMPPError().getCode() // + ") " + e.getXMPPError().getMessage()); e.printStackTrace(); } screen.setSpace(Space.getMainSpace()); // screen.getSpaceViewController().changeSpace(Space.getMainSpace()); Space.getMainSpace().setScreenOn(true); // Space.getMainSpace().setEntered(true); font = Typeface.createFromAsset(getAssets(), Values.font); // Button mainButtonText = (Button) findViewById(R.id.main_button); // mainButtonText.setTypeface(font); } // this.plusButtonSetUp(0); initializeButtons(); // Initializes the onKeyListener to record keypad events screen.setOnKeyListener(onKeyListener); // DEBUG: create User object to test invitations and kickouts debug = new User("opencommsec@" + Network.DEFAULT_HOSTNAME, "opencommsec", 0); // for (Space s : Space.allSpaces) Log.v(TAG, s.getRoomID()); debug1 = new User("mucopencomm@" + Network.DEFAULT_HOSTNAME, "mucopencomm", 0); // Change screen dimensions to 480x800 Values.setValues(480, 800); }
/** * Removes all UI traces of a privatespace/sidechat 1) Removes space from hashmap of all spaces 2) * Removes the corresponding privatespaceButton 3) Changes the space to the Mainspace (but only if * wasn't a mainspace) However, if you are leaving the mainspace, then start a new activity and go * ack to the dashboard */ public void delPrivateSpaceUI(Space space, boolean isMainSpace) { if (isMainSpace) { Intent i = new Intent(MainApplication.screen.getSpace().getContext(), DashboardView.class); MainApplication.screen.getSpace().getContext().startActivity(i); } else { // 1 Space.allSpaces.remove(space.getRoomID()); // 2 PrivateSpaceIconView foundIcon = null; for (PrivateSpaceIconView ps : PrivateSpaceIconView.allPSIcons) { if (ps.getSpace() == space) foundIcon = ps; } if (foundIcon != null) delPrivateSpaceButton(foundIcon); // 3 screen.getSpaceViewController().changeSpace(Space.getMainSpace()); } }
/** * You are exiting the application! Definitely tell the network so it can tell EVERYONE else and * remove you from rooms that you were in. Save any history (new friends made, recordings of * discussions, chats, etc.), and delete the the unimportant data. Delete privateSpaces that you * were moderator of */ public void disconnect() { // Leave all side chats (after leaving all of the side chats, the screen // should be at the main space for (Space s : Space.getAllSpaces().values()) { if (!s.isMainSpace()) { if (D) Log.v(TAG, "leaving a side chat"); // s.getParticipantController().leaveSpace(false); s.getMUC().leave(); } else { // Leave main space if (D) Log.v(TAG, "leaving the main space"); s.getMUC().leave(); } } userPrimary = null; Space.setMainSpace(null); buddyList = null; buddySelection = null; PrivateSpaceIconView.allPSIcons.clear(); // Disconnect if (D) Log.v(TAG, "starting disconnect"); // Disconnect and return to login screen LoginController.xmppService.disconnect(); LoginController.xmppService = null; // if (D) Log.v(TAG, // "is there a connection? "+LoginController.xmppService.getXMPPConnection().isConnected()); finishFromChild(this); if (D) Log.v(TAG, "starting intent stuff"); Intent i = new Intent(MainApplication.this, LoginView.class); startActivity(i); }
public void draw(Canvas canvas) { // This current version draws will draw the icon, and will draw // a colored rectangle around the person's icon if selected super.onDraw(canvas); // Log.v("UserView", "UserView's onDraw()"); int b = Values.iconBorderPadding; int namebox = Values.iconTextH; // the namebox height if (isSelected) { RectShape rect2 = new RectShape(); ShapeDrawable s = new ShapeDrawable(rect2); s.getPaint().setColor(Color.YELLOW); s.setBounds( x - b - Values.selectedBorder, y - b - Values.selectedBorder, x + image.getWidth() + 2 * Values.selectedBorder + b, y + image.getHeight() + 2 * Values.selectedBorder + b + namebox); s.draw(canvas); } /*if(nameBoxImage!=null){ canvas.drawBitmap(nameBoxImage, x, y + Values.userIconH - Values.iconTextH, null); canvas.drawText(person.getUsername(), 0, Math.min(11,(person.getUsername()).length()), x + Values.iconTextPadding, y + Values.userIconH - Values.iconTextPadding, paint); }*/ // Crystal if (person != null) { // Crystal // Log.v(LOG_TAG, "FINAL!"); RectShape rect1 = new RectShape(); ShapeDrawable bord = new ShapeDrawable(rect1); // Log.v(LOG_TAG,"person color"+person.user_color); // bord.getPaint().setStyle(Style.STROKE); // bord.getPaint().setStrokeWidth(b); bord.getPaint().setColor(getResources().getColor(person.user_color)); bord.setAlpha(204); bord.setBounds(x - b, y - b, x + image.getWidth() + b, y + image.getHeight() + b); Log.v(LOG_TAG, "SIZE" + (image.getWidth() + 2 * b) + "" + (image.getHeight() + 2 * b)); // border.setPadding(b,b,b,b); bord.draw(canvas); // Crystal image Bitmap overlay = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(overlay); paint.setAntiAlias(true); paint.setTextSize(Values.nameTextSize); c.drawBitmap(image, 0, 0, null); RectShape nTag = new RectShape(); ShapeDrawable nameTag = new ShapeDrawable(nTag); nameTag.getPaint().setColor(getResources().getColor(person.user_color)); nameTag.setAlpha(204); nameTag.setBounds(0, image.getHeight() - namebox, image.getWidth(), image.getHeight()); nameTag.draw(c); c.drawText( person.getUsername(), 0, Math.min(11, (person.getUsername()).length()), 0 /*Values.iconTextPadding*/, image.getHeight() - namebox + Values.nameTextSize /*5/2*Values.iconBorderPadding+10*/, paint); canvas.drawBitmap(overlay, x, y, null); if (person == space.getOwner()) { Bitmap adminTag = Bitmap.createBitmap(image.getWidth() + 2 * b, 20, Bitmap.Config.ARGB_8888); Canvas ac = new Canvas(adminTag); Paint ad = new Paint(); ad.setColor(Color.rgb(0, 0, 0)); ad.setAlpha(204); ac.drawRect(0, 0, image.getWidth() + 2 * b, 20, ad); ad.setAlpha(255); ad.setColor(Color.WHITE); ad.setStyle(Paint.Style.FILL); ad.setAntiAlias(true); ad.setTextSize(Values.adminTextSize); ac.drawText("admin", Values.textAdjust, (Values.adminBox - Values.textAdjust), ad); canvas.drawBitmap(adminTag, x - b, y - b, null); } } else { canvas.drawBitmap(image, x, y, null); } }
/** * Remove this person from this space, take away that person's icon from the SpaceView as well. * Could be situations where: you do not want this person in your mainspace, this person removed * him/herself from the privatespace, the privatespace got deleted, you kicked someone out of the * group (if you are moderator) * * @throws XMPPException */ public void deletePerson(Space space, User person) throws XMPPException { space.getKickoutController().kickoutUser(person, Network.DEFAULT_KICKOUT); LinearLayout screen = (LinearLayout) findViewById(R.id.space_view); screen.invalidate(); }
/** * Remove an existing PrivateSpace for yourself. Make sure to also delete the PrivateSpace's * corresponding PrivateSpaceIconView and SpaceView. This method also called (by network) if * someone else deleted a PrivateSpace that you were a part of, or if you decided to leave but are * not moderator of the space */ public void deletePrivateSpace(Space spaceToDelete) { spaceToDelete.getSpaceController().deleteSpace(); }
/** * Initialize the buttons declared in the xml. In this case just the MAIN button. Main button: add * a touch listener, when clicked should take you back to the main conversation */ public void initializeButtons() { // set listener to main button // Button mainButton = (Button) findViewById(R.id.main_button); /* * mainButton.setOnTouchListener(new View.OnTouchListener() { * * @Override public boolean onTouch(View view, MotionEvent evt) { switch * (evt.getAction()) { case MotionEvent.ACTION_DOWN: break; case * MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: * if(!(screen.getSpace()==Space.getMainSpace())){ * MainApplication.screen * .getSpaceViewController().changeSpace(Space.getMainSpace()); } break; * } return false; } }); */ try { // sidechat 1 // Log.v("C", "Problem on adding space"); Space newSpace = SpaceController.addSpace(Space.getMainSpace().getContext()); side1 = new PrivateSpaceIconView(Space.getMainSpace().getContext(), newSpace); newSpace.getSpaceController().setPSIV(side1); // main chat PrivateSpaceIconView main = new PrivateSpaceIconView(Space.getMainSpace().getContext(), Space.getMainSpace()); Space.getMainSpace().getSpaceController().setPSIV(main); // sidechat 2 Space newSpace2 = SpaceController.addSpace(Space.getMainSpace().getContext()); side2 = new PrivateSpaceIconView(Space.getMainSpace().getContext(), newSpace2); newSpace2.getSpaceController().setPSIV(side2); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } TextView logo = (TextView) findViewById(R.id.logo); logo.setClickable(true); logo.setOnClickListener(this.logoOnClickListener()); // ImageView soundButton = (ImageView) findViewById(R.id.sound_button); // soundButton.setClickable(true); // soundButton.setOnClickListener(this.getSoundButtonOnClickListener()); /* * Log.v(TAG, "Clicked on MENU key"); LayoutInflater inflater = * (LayoutInflater) MainApplication.this * .getSystemService(Context.LAYOUT_INFLATER_SERVICE); MenuView menuView * = new MenuView(inflater); menuView.launch(); */ ImageView spatializationButton = (ImageView) findViewById(R.id.auto_spatialization); spatializationButton.setClickable(true); spatializationButton.setOnClickListener(this.getSpatializationListener()); }
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (!D) return true; if (event.getAction() != KeyEvent.ACTION_DOWN) { return true; } switch (keyCode) { case KeyEvent.KEYCODE_1: { Log.v(TAG, "pressed 1 key - confirmation screen"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ConfirmationView confirmationView = new ConfirmationView(inflater); confirmationView.launch(); break; } case KeyEvent.KEYCODE_2: { Log.v(TAG, "pressed 2 key - invitation screen"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); InvitationView invitationView = new InvitationView(inflater); invitationView.launch(); break; } case KeyEvent.KEYCODE_3: { Log.v(TAG, "pressed 3 key - login screen"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // LoginView loginView = new LoginView(inflater); // loginView.launch(); break; } case KeyEvent.KEYCODE_4: { Log.v(TAG, "pressed 4 key - tip screen"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); TipView tipView = new TipView(inflater); tipView.launch(); break; } case KeyEvent.KEYCODE_5: { Log.v(TAG, "pressed 5 key - admin tip screen"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); AdminTipView adminTipView = new AdminTipView(inflater); adminTipView.launch(); break; } case KeyEvent.KEYCODE_6: { Log.v(TAG, "pressed 6 key - dashboard screen"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // DashboardView dashboardView = new DashboardView(inflater); // dashboardView.launch(); break; } case KeyEvent.KEYCODE_7: { Log.v(TAG, "pressed 7 key - sound settings screen"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); SoundSettingsView soundSettingsView = new SoundSettingsView(inflater); soundSettingsView.launch(); break; } case KeyEvent.KEYCODE_8: { Log.v(TAG, "Pressed 8 key - Signup"); SignupView view = new SignupView(MainApplication.this); view.launch(); break; } case KeyEvent.KEYCODE_M: { // invite a user to the mainspace. Assume inviter is owner int i = 0; Log.v(TAG, "pressed M key - invitation" + i++); (Space.getMainSpace().getInvitationController()).inviteUser(debug, "You're fun!"); break; } case KeyEvent.KEYCODE_N: { Log.v(TAG, "pressed N key - kickout"); Space.getMainSpace().getKickoutController().kickoutUser(debug, "You suck!"); break; } case KeyEvent.KEYCODE_V: { Log.v(TAG, "pressed V key - change owner"); Space.getMainSpace() .getParticipantController() .grantOwnership("opencommsec@" + Network.DEFAULT_HOSTNAME, false); break; } case KeyEvent.KEYCODE_Z: { Iterator<String> affiliates = Space.getMainSpace().getMUC().getOccupants(); while (affiliates.hasNext()) { String a = affiliates.next(); Log.v( TAG, a + "'s affiliaton is " + Space.getMainSpace().getMUC().getOccupant(a).getAffiliation()); } break; } case KeyEvent.KEYCODE_J: { Log.v(TAG, "Pressed J key - join"); Space.getMainSpace() .getParticipantStatusController() .joined("roomname@" + Network.DEFAULT_CONFERENCE + "/" + debug1.getNickname()); break; } case KeyEvent.KEYCODE_S: { Log.v(TAG, "Pressed S key - create a new private space"); try { SpaceController.addSpace((Context) MainApplication.screen.getContext()); } catch (XMPPException e) { Log.v(TAG, "Can't create another private space :("); } break; } case KeyEvent.KEYCODE_MENU: { Log.v(TAG, "Clicked on MENU key"); LayoutInflater inflater = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); MenuView menuView = new MenuView(inflater); menuView.launch(); break; } case KeyEvent.KEYCODE_B: { Log.v(TAG, "pressed B key - leave space"); Space.getMainSpace().getParticipantController().leaveSpace(false); break; } case KeyEvent.KEYCODE_Q: { Log.v(TAG, "pressed Q key - you (a moderator) received an invite request"); InvitationController ic = MainApplication.screen.getSpace().getInvitationController(); // fake invite request String inviteRequest = "" + Network.REQUEST_INVITE + "@inviter" + debug.getUsername() + "@invitee" + debug1.getUsername() + "@reason" + "Because you're a cool cat."; ic.receiveInvitationRequest(inviteRequest); break; } case KeyEvent.KEYCODE_W: { Log.v(TAG, "pressed W key - you received an invite to a chat"); InvitationController ic = MainApplication.screen.getSpace().getInvitationController(); // fake invite request String inviteRequest = "" + Network.REQUEST_INVITE + "@requester" + debug.getUsername() + "@invitee" + MainApplication.userPrimary.getUsername() + "@reason" + "Because you're a cool cat."; ic.receiveInvitationRequest(inviteRequest); /* * LoginController.xmppService.getInvitiationListener(). * invitationReceived(LoginController.xmppConnection, "", * debug.getUsername(), "reason", "password", new * Message("blah message")); */ break; } case KeyEvent.KEYCODE_E: { Log.v(TAG, "pressed E key - you (a moderator) received a kickout request"); KickoutController kc = MainApplication.screen.getSpace().getKickoutController(); // fake kickout request String kickoutRequest = "" + Network.REQUEST_KICKOUT + "@requester" + debug.getUsername() + "@kickee" + debug1.getUsername() + "@reason" + "Because you didn't give me food."; kc.receiveKickoutRequest(kickoutRequest); break; } case KeyEvent.KEYCODE_R: { Log.v(TAG, "pressed R key - you received a kickout confirmation"); KickoutController kc = MainApplication.screen.getSpace().getKickoutController(); // fake kickout request String kickoutRequest = "" + Network.REQUEST_KICKOUT + "@requester" + debug.getUsername() + "@kickee" + MainApplication.userPrimary.getUsername() + "@reason" + "Because you didn't give me food."; kc.receiveKickoutRequest(kickoutRequest); break; } case KeyEvent.KEYCODE_A: { Log.v(TAG, "pressed A key - logout"); MainApplication.this.disconnect(); break; } case KeyEvent.KEYCODE_H: { Log.v(TAG, "pressed H key - invite request"); Space.getMainSpace() .getInvitationController() .inviteUser(debug1, Network.DEFAULT_INVITE); break; } case KeyEvent.KEYCODE_Y: { Log.d(TAG, "contacts button clicked"); Intent i = new Intent(); // LayoutInflater ifl=dashboardView.getInflater(); LayoutInflater ifl = (LayoutInflater) MainApplication.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ResetPasswordView cpv = new ResetPasswordView(ifl, MainApplication.this); // cpv.setContext(Space.getMainSpace().getContext()); cpv.launch(); } } ; return true; }