@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the notification description from the intent Intent intent = getIntent(); String desc = intent.getStringExtra(KEY_NOTIF_CONFIG); if (desc == null) { Log.e(TAG, "NotifEditActivity: No notification " + "description passed. Exiting..."); finish(); return; } // Parse and load the description mNotifDesc = new NotifDesc(); if (!mNotifDesc.loadString(desc)) { Log.e( TAG, "NotifEditActivity: Failed to parse the " + "notification description passed. Exiting..."); finish(); return; } setContentView(R.layout.trigger_editor); Button b = (Button) findViewById(R.id.trig_edit_done); b.setOnClickListener(this); b = (Button) findViewById(R.id.trig_edit_cancel); b.setOnClickListener(this); // Update the GUI with the data initializeListData(); setupListAdaptor(); validateDataAndUpdateView(); }
/* * Helper function to prepare the list of active surveys corresponding * to trigger. * * A trigger is active if it has not expired (the notification duration * has not been reached) after going off the last time. * * All surveys associated with an active active trigger are active * - EXCEPT those which have already been taken by the user within * the suppression window. */ private static HashSet<String> getActiveSurveys(Context context, Cursor trig) { HashSet<String> actSurveys = new HashSet<String>(); String runTime = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_RUNTIME_DESCRIPT)); String notif = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_NOTIF_DESCRIPT)); String actions = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_TRIG_ACTION_DESCRIPT)); String campaignUrn = trig.getString(trig.getColumnIndexOrThrow(TriggerDB.KEY_CAMPAIGN_URN)); Log.i(DEBUG_TAG, "NotifSurveyAdaptor: Calculating active surveys for trigger"); TriggerRunTimeDesc rtDesc = new TriggerRunTimeDesc(); NotifDesc notifDesc = new NotifDesc(); TriggerActionDesc actDesc = new TriggerActionDesc(); if (!rtDesc.loadString(runTime) || !notifDesc.loadString(notif) || !actDesc.loadString(actions)) { Log.w(DEBUG_TAG, "NotifSurveyAdaptor: Descritptor(s) failed to parse"); return actSurveys; } if (!rtDesc.hasTriggerTimeStamp()) { Log.i(DEBUG_TAG, "NotifSurveyAdaptor: Trigger time stamp is invalid"); return actSurveys; } long now = System.currentTimeMillis(); long trigTS = rtDesc.getTriggerTimeStamp(); if (trigTS > now) { Log.w(DEBUG_TAG, "NotifSurveyAdaptor: Trigger time stamp is in the future!"); return actSurveys; } // How long it has been since the trigger went off long elapsedMS = now - trigTS; long durationMS = notifDesc.getDuration() * 60000; long suppressMS = notifDesc.getSuppression() * 60000; if (elapsedMS < durationMS) { // The trigger has not expired, check each survey String[] surveys = actDesc.getSurveys(); for (int i = 0; i < surveys.length; i++) { // Has the survey been taken in within the // suppression window? if (IsSurveyTaken(context, campaignUrn, surveys[i], trigTS - suppressMS)) { continue; } // Add the active survey to the set actSurveys.add(surveys[i]); } } return actSurveys; }