private boolean teleporting(ClientContext ctx) { if (ctx.players.local().animation() != -1) { t.reset(); // To account for small lag when the map changes and animation becomes -1 return true; } return t.isRunning(); }
/* * reads the value of the digital input of the specified channel * requires that the readArudiono() method has already been called * param 1: the channel to be read * return: value of the specified digital input */ public boolean getInput(int channelID) { byte temp; if (timer.get() > 2.0) { DriverStationLCD.getInstance() .println(DriverStationLCD.Line.kUser3, 1, " "); DriverStationLCD.getInstance().updateLCD(); timer.stop(); timer.reset(); } if (Math.abs(channelID - (13 / 2)) - (13 / 2) > 0) // returns true if less than zero or greater than thirteen { timer.start(); DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser3, 1, "Invalid ID"); DriverStationLCD.getInstance().updateLCD(); return false; } else if (channelID < 8) { temp = (byte) (loByte & (1 << channelID)); return temp != 0; } else { temp = (byte) (hiByte & (1 << channelID - 8)); return temp != 0; } }
/** * method that will be called when mouse presses * @param point , the point mouse press at */ public void onMousePress(Location point){ lastpoint = point; if (isShown && mouse.contains(point)) { isGrabbed = true; } else { isGrabbed = false; } timer.reset(); moved = false; }
/** Called every time tele-op mode starts */ public void teleopInit() { vicDriveRight.set(0); vicDriveLeft.set(0); armVictor.set(0); winchRelay.set(Relay.Value.kOff); shooterWheel.set(0); shooterLoft.set(0); bettyRelay.set(Relay.Value.kOff); lightsOutput1.set(true); lightsOutput2.set(true); lightsOutput3.set(true); lightsTimer.reset(); lightsTimer.start(); teleopActive = false; controlFlip = true; controlFlipClean = true; shootingSpeed = 0.0; starterDelay = 0; }
@Override public void onReceive(final Context context, final Intent intent) { String a = intent.getAction(); Log.d(TAG, "onReceive(" + a + ")"); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { if (Timer.TIMER_KEYS[j].equals(a)) { Timer t = new Timer(context, j); if (t.isRunning() && PreferenceManager.getDefaultSharedPreferences(context) .getBoolean("cancel_tap", false)) { t.reset(context); } else { t.start(context); } } } if (updateNotification(context)) { schedNext(context); } }
/** This function is called periodically during autonomous */ public void autonomousInit() { autoTimer.reset(); autoTimer.start(); gyro.reset(); relay.set(Relay.Value.kOn); setSpeedFast(); setLEDTeamColour(); sol4.set(false); sol5.set(true); sol7.set(true); sol8.set(false); autoStop = false; autonomousStopped = false; autoTimeAtStop = 99999; drive.setRun(false); loadAndShoot.setRun(false); autoForward(); }
@Override public void paint(Graphics g) { // Create an accelerated image to use for double buffering to make // screen updates smooth GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); Image image = gc.createCompatibleImage(getWidth(), getWidth(), Transparency.BITMASK); Graphics2D g2d = (Graphics2D) image.getGraphics(); // Call clear with g2d local variable to clear the current contents of window clear(g2d); // Draw bonus saucer bonusSaucer.draw(g2d); if (bonusSaucer.killed && resetBonusTime == 0) { bonusSaucerKillTimer.reset(); bonusSaucerInitialMoveTimer = new Timer((long) (randomBonusSaucerTime.nextInt(10) + 6) * 1000); oldBonusSaucerXPosition = bonusSaucer.xPosition; oldBonusSaucerYPosition = bonusSaucer.yPosition; resetBonusTime = resetBonusTime + 1; } if (!bonusSaucerKillTimer.expired() && resetBonusTime == 1) { bonusScore = bonusSaucer.determineBonusScore(); bonusSaucer = new BonusSaucer(INITIAL_SAUCER_X_BLOCK_POSITION, INITIAL_SAUCER_Y_BLOCK_POSITION, this); bonusScoreDisplay.set((long) 1000); resetBonusTime = resetBonusTime - 1; } if (!bonusScoreDisplay.expired()) { g2d.setFont(scoreFont); g2d.setColor(Color.white); g2d.drawString( String.valueOf(bonusScore), oldBonusSaucerXPosition, oldBonusSaucerYPosition + 20); } if (tank.killed) { bonusSaucer = new BonusSaucer(INITIAL_SAUCER_X_BLOCK_POSITION, INITIAL_SAUCER_Y_BLOCK_POSITION, this); } // Draw aliens // Define a local variable called row of type Integer and initailize it // to 0, this is used to access the aliens by row Integer row = 0; Integer yBlockPosition = INITIAL_ALIEN_Y_BLOCK_POSITION; // Loop while row is not eual to the NBR_OF_ALIEN_ROWS while (row != aliens.length) { // Number of rows // Define a local variable called column of type Integer and // initailize it to 0, this is used to access the aliens by column Integer column = 0; Integer xBlockPosition = 0; // Loop while column is not eual to the NBR_OF_ALIEN_COLUMNS while (column != aliens[row].length) { // Number of columns // Call aliens[row][column].draw with g2d local variable // to draw alien on screen aliens[row][column].draw(g2d); if (aliens[row][column].resetKilled) { aliens[row][column].resetKilled = false; nbrOfAliensKilled++; } if (nbrOfAliensKilled == 55) { if (row == 0) { // Initailize aliens[row][column] to a new Squid alien using // xBlockPosition, yBlockPosition as the block position // parameters and this are the gamePanel parameter aliens[row][column] = new Squid(xBlockPosition, yBlockPosition, this); } // End if // Else If row is equal to 1 or 2 then else if ((row == 1) || (row == 2)) { // Initailize aliens[row][column] to a new Grasshopper alien // using xBlockPosition, yBlockPosition as the block position // parameters and this are the gamePanel parameter aliens[row][column] = new Grasshopper(xBlockPosition, yBlockPosition, this); } // End else if // Else this must be rows 3 or 4 else { // Initailize aliens[row][column] to a new Skull alien using // xBlockPosition, yBlockPosition as the block position // parameters and this are the gamePanel parameter aliens[row][column] = new Skull(xBlockPosition, yBlockPosition, this); } // End else } // Increment the column local variable by 1 column = column + 1; xBlockPosition = xBlockPosition + Alien.BLOCK_WIDTH + COLUMN_SEPERATION_BLOCK; } // End while loop // Increment the row local variable by 1 row = row + 1; yBlockPosition = yBlockPosition + Alien.BLOCK_HEIGHT + ROW_SEPERATION_BLOCK; } // End while loop // Draw shields // TODO for shield starting at 0, while less than NBR_OF_SHEILDS, // increment shild by 1 for (Integer shield = 0; shield < NBR_OF_SHEILDS; shield++) { // TODO for shield starting at 0, while less than NBR_OF_SHEILD_PARTS, // increment shild by 1 for (Integer shieldPart = 0; shieldPart < NBR_OF_SHEILD_PARTS; shieldPart++) { // TODO Call shields[shield][shieldPart].draw with g2d as the parameter if (shields[shield][shieldPart].explosionState != ShieldPart.ExplosionState.EXPLOSION_DONE) { shields[shield][shieldPart].draw(g2d); } } // End for loop } // End for loop // Draw tank shots for (int i = 0; i < tankShots.size(); i++) { tankShots.get(i).draw(g2d); } // for // Draw aliens shots for (int i = 0; i < alienShots.size(); i++) { alienShots.get(i).draw(g2d); } // for bonusSaucer.draw(g2d); // Draw tank // Call tank.draw with g2d local variable to draw tank on screen tank.draw(g2d); // Driaw line at bottom of screen g2d.setColor(Color.white); g2d.fillRect(0, 560, GamePanel.FRAME_WIDTH, 3); // Draw lives area // Call livesArea.draw with g2d local variable to draw tank on screen livesArea.draw(g2d); // Draw score area // Call scoreArea.draw with g2d local variable to draw score area // on the screen scoreArea.draw(g2d); if (displayGameover == true) { g2d.setFont(gameOverFont); g2d.setColor(Color.white); g2d.drawString("Game Over", 260, 290); } // End if // Draw over entire screen g.drawImage(image, 0, 0, null); } // paint
private boolean updateNotification(final Context context) { Log.d(TAG, "updateNotification()"); lastUpdate = System.currentTimeMillis(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); ArrayList<Timer> timers = new ArrayList<Timer>(); mNow = System.currentTimeMillis(); mNextTarget = 0; boolean alert = false; Log.d(TAG, "mNow: " + mNow); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { Timer t = new Timer(context, j); timers.add(t); long tt = t.getTarget(); Log.d(TAG, "target(" + j + "): " + tt); if (tt > 0) { if (mNextTarget == 0 || tt < mNextTarget) { mNextTarget = tt; } if (tt < mNow) { alert = true; t.reset(context); } } } Log.d(TAG, "mNextTarget: " + mNextTarget); NotificationCompat.Builder b = new NotificationCompat.Builder(context); b.setPriority(1000); Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); b.setContentTitle(context.getString(R.string.app_name)); b.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)); b.setSmallIcon(R.drawable.ic_stat_timer); b.setAutoCancel(false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // GB- b.setContentText( context.getString( R.string.notification_text, timers.get(0).getFormatted(), timers.get(1).getFormatted(), timers.get(2).getFormatted())); } else { // HC+ RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.notification); for (int j = 0; j < Timer.TIMER_IDS.length; j++) { v.setTextViewText(Timer.TIMER_IDS[j], timers.get(j).getFormatted().toString()); Intent ij = new Intent(Timer.TIMER_KEYS[j], null, context, UpdateReceiver.class); v.setOnClickPendingIntent( Timer.TIMER_IDS[j], PendingIntent.getBroadcast(context, 0, ij, PendingIntent.FLAG_UPDATE_CURRENT)); } v.setOnClickPendingIntent( R.id.settings, PendingIntent.getActivity( context, 0, new Intent(context, SettingsActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); b.setContent(v); } if (mNextTarget <= 0 && !alert) { // we don't need any notification b.setOngoing(false); nm.notify(0, b.build()); return false; } else if (alert) { // show notification without running Timer b.setOngoing(mNextTarget > 0); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean("vibrate", true)) { b.setVibrate(VIBRATE); } String n = p.getString("notification", null); if (n == null) { // default b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else if (n.length() > 1) { try { b.setSound(Uri.parse(n)); } catch (Exception e) { Log.e(TAG, "invalid notification uri", e); b.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } // else: silent nm.notify(0, b.build()); return true; } else { // show notification with running Timer b.setOngoing(true); nm.notify(0, b.build()); return true; } }