List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TASK
int FLAG_ACTIVITY_CLEAR_TASK
To view the source code for android.content Intent FLAG_ACTIVITY_CLEAR_TASK.
Click Source Link
From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java
private void notifySession(final long sessionStart, final long alarmOffset) { long currentTime = UIUtils.getCurrentTime(this); final long intervalEnd = sessionStart + MILLI_TEN_MINUTES; LOGD(TAG, "Considering notifying for time interval."); LOGD(TAG, " Interval start: " + sessionStart + "=" + (new Date(sessionStart)).toString()); LOGD(TAG, " Interval end: " + intervalEnd + "=" + (new Date(intervalEnd)).toString()); LOGD(TAG, " Current time is: " + currentTime + "=" + (new Date(currentTime)).toString()); if (sessionStart < currentTime) { LOGD(TAG, "Skipping session notification (too late -- time interval already started)"); return;//from ww w . j a v a 2 s.c om } if (!SettingsUtils.shouldShowSessionReminders(this)) { // skip if disabled in settings LOGD(TAG, "Skipping session notification for sessions. Disabled in settings."); return; } // Avoid repeated notifications. if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this, ScheduleContract.Blocks.generateBlockId(sessionStart, intervalEnd))) { LOGD(TAG, "Skipping session notification (already notified)"); return; } final ContentResolver cr = getContentResolver(); LOGD(TAG, "Looking for sessions in interval " + sessionStart + " - " + intervalEnd); Cursor c = null; try { c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionDetailQuery.PROJECTION, ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION, ScheduleContract.Sessions.buildAtTimeIntervalArgs(sessionStart, intervalEnd), null); int starredCount = c.getCount(); LOGD(TAG, "# starred sessions in that interval: " + c.getCount()); String singleSessionId = null; String singleSessionRoomId = null; ArrayList<String> starredSessionTitles = new ArrayList<String>(); while (c.moveToNext()) { singleSessionId = c.getString(SessionDetailQuery.SESSION_ID); singleSessionRoomId = c.getString(SessionDetailQuery.ROOM_ID); starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE)); LOGD(TAG, "-> Title: " + c.getString(SessionDetailQuery.SESSION_TITLE)); } if (starredCount < 1) { return; } // Generates the pending intent which gets fired when the user taps on the notification. // NOTE: Use TaskStackBuilder to comply with Android's design guidelines // related to navigation from notifications. Intent baseIntent = new Intent(this, MyScheduleActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); // For a single session, tapping the notification should open the session details (b/15350787) if (starredCount == 1) { taskBuilder.addNextIntent( new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(singleSessionId))); } PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentText; int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000; if (minutesLeft < 1) { minutesLeft = 1; } if (starredCount == 1) { contentText = res.getString(R.string.session_notification_text_1, minutesLeft); } else { contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft, starredCount - 1); } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText) .setColor(getResources().getColor(R.color.theme_primary)) .setTicker(res .getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); if (minutesLeft > 5) { notifBuilder.addAction(R.drawable.ic_alarm_holo_dark, String.format(res.getString(R.string.snooze_x_min), 5), createSnoozeIntent(sessionStart, intervalEnd, 5)); } if (starredCount == 1 && SettingsUtils.isAttendeeAtVenue(this)) { notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map), createRoomMapIntent(singleSessionRoomId)); } String bigContentTitle; if (starredCount == 1 && starredSessionTitles.size() > 0) { bigContentTitle = starredSessionTitles.get(0); } else { bigContentTitle = res.getQuantityString(R.plurals.session_notification_title, starredCount, minutesLeft, starredCount); } NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(bigContentTitle); // Adds starred sessions starting at this time block to the notification. for (int i = 0; i < starredCount; i++) { richNotification.addLine(starredSessionTitles.get(i)); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LOGD(TAG, "Now showing notification."); nm.notify(NOTIFICATION_ID, richNotification.build()); } finally { if (c != null) { try { c.close(); } catch (Exception ignored) { } } } }
From source file:com.emergencyskills.doe.aed.UI.activity.TabsActivity.java
void init() { // img=(ImageView)findViewById(R.id.logo); TextView build = (TextView) findViewById(R.id.checkfornew); build.setOnClickListener(new View.OnClickListener() { @Override//from w ww. j av a2 s. com public void onClick(View v) { if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } CommonUtilities.logMe("about to check for version "); try { WebServiceHandler wsb = new WebServiceHandler(); ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); String result = wsb.getWebServiceData("http://doe.emergencyskills.com/api/version.php", postParameters); JSONObject jsonObject = new JSONObject(result); String version = jsonObject.getString("version"); String features = jsonObject.getString("features"); System.err.println("version is : " + version); if (!LoginActivity.myversion.equals(version)) { MyToast.popmessagelong( "There is a new build available. Please download for these features: " + features, TabsActivity.this); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://vireo.org/esiapp")); browserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(browserIntent); } else { MyToast.popmessagelong("You have the most current version!", TabsActivity.this); } } catch (Exception exc) { exc.printStackTrace(); } } }); TextView maillog = (TextView) findViewById(R.id.maillog); maillog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(TabsActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_logout); TextView question = (TextView) dialog.findViewById(R.id.question); question.setText("Are you sure you want to email the log?"); TextView extra = (TextView) dialog.findViewById(R.id.extratext); extra.setText(""); dialog.getWindow().setBackgroundDrawable( new ColorDrawable(getResources().getColor(android.R.color.transparent))); Button yes = (Button) dialog.findViewById(R.id.yesbtn); yes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("message/rfc822"); i.putExtra(Intent.EXTRA_EMAIL, new String[] { "rachelc@gmail.com" }); i.putExtra(Intent.EXTRA_SUBJECT, "Sending Log"); i.putExtra(Intent.EXTRA_TEXT, "body of email"); try { startActivity(Intent.createChooser(i, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(TabsActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); } finish(); } }); Button no = (Button) dialog.findViewById(R.id.nobtn); no.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); ImageView close = (ImageView) dialog.findViewById(R.id.ivClose); close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }); listops listops = new listops(TabsActivity.this); CommonUtilities.logMe("logging in as: " + listops.getString("firstname")); TextView name = (TextView) findViewById(R.id.welcome); name.setText("Welcome, " + listops.getString("firstname")); TextView logoutname = (TextView) findViewById(R.id.logoutname); logoutname.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(TabsActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_logout); dialog.getWindow().setBackgroundDrawable( new ColorDrawable(getResources().getColor(android.R.color.transparent))); dialog.setContentView(R.layout.dialog_logout); Button yes = (Button) dialog.findViewById(R.id.yesbtn); yes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MyToast.popmessagelong("Logging out... ", TabsActivity.this); SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putString(Constants.loginkey, ""); editor.commit(); listops listops = new listops(TabsActivity.this); //make sure to remove the downloaded schools Intent intent = new Intent(TabsActivity.this, LoginActivity.class); startActivity(intent); ArrayList<Schoolinfomodel> ls = new ArrayList<Schoolinfomodel>(); listops.putdrilllist(ls); listops.putservicelist(ls); listops.putinstallllist(ls); ArrayList<PendingUploadModel> l = new ArrayList<PendingUploadModel>(); listops.putpendinglist(l); finish(); } }); Button no = (Button) dialog.findViewById(R.id.nobtn); no.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); ImageView close = (ImageView) dialog.findViewById(R.id.ivClose); close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }); ll1 = (LinearLayout) findViewById(R.id.ll1); ll2 = (LinearLayout) findViewById(R.id.ll2); ll3 = (LinearLayout) findViewById(R.id.ll3); ll4 = (LinearLayout) findViewById(R.id.ll4); ll5 = (LinearLayout) findViewById(R.id.ll5); ll6 = (LinearLayout) findViewById(R.id.ll6); ll1.setBackgroundColor(getResources().getColor(R.color.White)); llPickSchools = (LinearLayout) findViewById(R.id.llPickSchool); llDrills = (LinearLayout) findViewById(R.id.llDrills); llServiceCalls = (LinearLayout) findViewById(R.id.llServiceCalls); llNewInstalls = (LinearLayout) findViewById(R.id.llNewInstalls); llPendingUploads = (LinearLayout) findViewById(R.id.llPendingUploads); frameLayout = (FrameLayout) findViewById(R.id.frame); }
From source file:com.urgoo.message.activities.MainActivity.java
/** * ??dialog/* w w w . j a v a 2 s .c o m*/ */ private void showConflictDialog() { isConflictDialogShow = true; DemoHelper.getInstance().logout(false, null); String st = getResources().getString(R.string.Logoff_notification); if (!MainActivity.this.isFinishing()) { // clear up global variables try { if (conflictBuilder == null) conflictBuilder = new android.app.AlertDialog.Builder(MainActivity.this); conflictBuilder.setTitle(st); conflictBuilder.setMessage(R.string.connect_conflict); conflictBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); conflictBuilder = null; finish(); Intent intent = new Intent(MainActivity.this, HomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); conflictBuilder.setCancelable(false); conflictBuilder.create().show(); isConflict = true; } catch (Exception e) { EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage()); } } }
From source file:org.wso2.emm.agent.services.operation.OperationManagerCOSU.java
@Override public void setPasswordPolicy(Operation operation) throws AndroidAgentException { int attempts, length, history, specialChars; String alphanumeric, complex; boolean isAlphanumeric, isComplex; long timout;// w ww.jav a 2 s .co m operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); try { JSONObject policyData = new JSONObject(operation.getPayLoad().toString()); if (!policyData.isNull(getContextResources().getString(R.string.policy_password_max_failed_attempts)) && policyData.get(getContextResources() .getString(R.string.policy_password_max_failed_attempts)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_max_failed_attempts)) .toString().isEmpty()) { attempts = policyData .getInt(getContextResources().getString(R.string.policy_password_max_failed_attempts)); getDevicePolicyManager().setMaximumFailedPasswordsForWipe(getCdmDeviceAdmin(), attempts); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_min_length)) && policyData .get(getContextResources().getString(R.string.policy_password_min_length)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_min_length)).toString() .isEmpty()) { length = policyData .getInt(getContextResources().getString(R.string.policy_password_min_length)); getDevicePolicyManager().setPasswordMinimumLength(getCdmDeviceAdmin(), length); } else { getDevicePolicyManager().setPasswordMinimumLength(getCdmDeviceAdmin(), getDefaultPasswordMinLength()); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_pin_history)) && policyData .get(getContextResources().getString(R.string.policy_password_pin_history)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_pin_history)) .toString().isEmpty()) { history = policyData .getInt(getContextResources().getString(R.string.policy_password_pin_history)); getDevicePolicyManager().setPasswordHistoryLength(getCdmDeviceAdmin(), history); } else { getDevicePolicyManager().setPasswordHistoryLength(getCdmDeviceAdmin(), getDefaultPasswordLength()); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_min_complex_chars)) && policyData.get( getContextResources().getString(R.string.policy_password_min_complex_chars)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_min_complex_chars)) .toString().isEmpty()) { specialChars = policyData .getInt(getContextResources().getString(R.string.policy_password_min_complex_chars)); getDevicePolicyManager().setPasswordMinimumSymbols(getCdmDeviceAdmin(), specialChars); } else { getDevicePolicyManager().setPasswordMinimumSymbols(getCdmDeviceAdmin(), getDefaultPasswordLength()); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_require_alphanumeric)) && policyData.get(getContextResources() .getString(R.string.policy_password_require_alphanumeric)) != null) { if (policyData.get(getContextResources() .getString(R.string.policy_password_require_alphanumeric)) instanceof String) { alphanumeric = (String) policyData .get(getContextResources().getString(R.string.policy_password_require_alphanumeric)); if (alphanumeric.equals(getContextResources().getString(R.string.shared_pref_default_status))) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC); } } else if (policyData.get(getContextResources() .getString(R.string.policy_password_require_alphanumeric)) instanceof Boolean) { isAlphanumeric = policyData.getBoolean( getContextResources().getString(R.string.policy_password_require_alphanumeric)); if (isAlphanumeric) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC); } } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_allow_simple)) && policyData .get(getContextResources().getString(R.string.policy_password_allow_simple)) != null) { if (policyData.get( getContextResources().getString(R.string.policy_password_allow_simple)) instanceof String) { complex = (String) policyData .get(getContextResources().getString(R.string.policy_password_allow_simple)); if (!complex.equals(getContextResources().getString(R.string.shared_pref_default_status))) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_COMPLEX); } } else if (policyData.get(getContextResources() .getString(R.string.policy_password_allow_simple)) instanceof Boolean) { isComplex = policyData .getBoolean(getContextResources().getString(R.string.policy_password_allow_simple)); if (!isComplex) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_COMPLEX); } } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_pin_age_in_days)) && policyData.get( getContextResources().getString(R.string.policy_password_pin_age_in_days)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_pin_age_in_days)) .toString().isEmpty()) { int daysOfExp = policyData .getInt(getContextResources().getString(R.string.policy_password_pin_age_in_days)); timout = daysOfExp * getDayMillisecondsMultiplier(); getDevicePolicyManager().setPasswordExpirationTimeout(getCdmDeviceAdmin(), timout); } } if (!getDevicePolicyManager().isActivePasswordSufficient()) { Intent intent = new Intent(getContext(), AlertActivity.class); intent.putExtra(getContextResources().getString(R.string.intent_extra_type), getContextResources().getString(R.string.intent_extra_password_setting)); intent.putExtra(getContextResources().getString(R.string.intent_extra_message_text), getContextResources().getString(R.string.policy_violation_password_tail)); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); getContext().startActivity(intent); } if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Password policy set"); } } catch (JSONException e) { operation.setStatus(getContextResources().getString(R.string.operation_value_error)); operation.setOperationResponse("Error in parsing PASSWORD_POLICY payload."); getResultBuilder().build(operation); throw new AndroidAgentException("Invalid JSON format.", e); } }
From source file:com.razza.apps.iosched.service.SessionAlarmService.java
private void notifySession(final long sessionStart, final long alarmOffset) { long currentTime = UIUtils.getCurrentTime(this); final long intervalEnd = sessionStart + MILLI_TEN_MINUTES; LogUtils.LOGD(TAG, "Considering notifying for time interval."); LogUtils.LOGD(TAG, " Interval start: " + sessionStart + "=" + (new Date(sessionStart)).toString()); LogUtils.LOGD(TAG, " Interval end: " + intervalEnd + "=" + (new Date(intervalEnd)).toString()); LogUtils.LOGD(TAG, " Current time is: " + currentTime + "=" + (new Date(currentTime)).toString()); if (sessionStart < currentTime) { LogUtils.LOGD(TAG, "Skipping session notification (too late -- time interval already started)"); return;/*from ww w. java2 s . c om*/ } if (!SettingsUtils.shouldShowSessionReminders(this)) { // skip if disabled in settings LogUtils.LOGD(TAG, "Skipping session notification for sessions. Disabled in settings."); return; } // Avoid repeated notifications. if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this, ScheduleContract.Blocks.generateBlockId(sessionStart, intervalEnd))) { LogUtils.LOGD(TAG, "Skipping session notification (already notified)"); return; } final ContentResolver cr = getContentResolver(); LogUtils.LOGD(TAG, "Looking for sessions in interval " + sessionStart + " - " + intervalEnd); Cursor c = null; try { c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionDetailQuery.PROJECTION, ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION, ScheduleContract.Sessions.buildAtTimeIntervalArgs(sessionStart, intervalEnd), null); int starredCount = c.getCount(); LogUtils.LOGD(TAG, "# starred sessions in that interval: " + c.getCount()); String singleSessionId = null; String singleSessionRoomId = null; ArrayList<String> starredSessionTitles = new ArrayList<String>(); while (c.moveToNext()) { singleSessionId = c.getString(SessionDetailQuery.SESSION_ID); singleSessionRoomId = c.getString(SessionDetailQuery.ROOM_ID); starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE)); LogUtils.LOGD(TAG, "-> Title: " + c.getString(SessionDetailQuery.SESSION_TITLE)); } if (starredCount < 1) { return; } // Generates the pending intent which gets fired when the user taps on the notification. // NOTE: Use TaskStackBuilder to comply with Android's design guidelines // related to navigation from notifications. Intent baseIntent = new Intent(this, MyScheduleActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); // For a single session, tapping the notification should open the session details (b/15350787) if (starredCount == 1) { taskBuilder.addNextIntent( new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(singleSessionId))); } PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentText; int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000; if (minutesLeft < 1) { minutesLeft = 1; } if (starredCount == 1) { contentText = res.getString(R.string.session_notification_text_1, minutesLeft); } else { contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft, starredCount - 1); } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText) .setColor(getResources().getColor(R.color.theme_primary)) .setTicker(res .getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); if (minutesLeft > 5) { notifBuilder.addAction(R.drawable.ic_alarm_holo_dark, String.format(res.getString(R.string.snooze_x_min), 5), createSnoozeIntent(sessionStart, intervalEnd, 5)); } if (starredCount == 1 && SettingsUtils.isAttendeeAtVenue(this)) { notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map), createRoomMapIntent(singleSessionRoomId)); } String bigContentTitle; if (starredCount == 1 && starredSessionTitles.size() > 0) { bigContentTitle = starredSessionTitles.get(0); } else { bigContentTitle = res.getQuantityString(R.plurals.session_notification_title, starredCount, minutesLeft, starredCount); } NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(bigContentTitle); // Adds starred sessions starting at this time block to the notification. for (int i = 0; i < starredCount; i++) { richNotification.addLine(starredSessionTitles.get(i)); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LogUtils.LOGD(TAG, "Now showing notification."); nm.notify(NOTIFICATION_ID, richNotification.build()); } finally { if (c != null) { try { c.close(); } catch (Exception ignored) { } } } }
From source file:org.wso2.iot.agent.services.operation.OperationManagerCOSU.java
@Override public void setPasswordPolicy(Operation operation) throws AndroidAgentException { int attempts, length, history, specialChars; String alphanumeric, complex; boolean isAlphanumeric, isComplex; long timout;// www .j ava 2 s . co m operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); try { JSONObject policyData = new JSONObject(operation.getPayLoad().toString()); if (!policyData.isNull(getContextResources().getString(R.string.policy_password_max_failed_attempts)) && policyData.get(getContextResources() .getString(R.string.policy_password_max_failed_attempts)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_max_failed_attempts)) .toString().isEmpty()) { attempts = policyData .getInt(getContextResources().getString(R.string.policy_password_max_failed_attempts)); getDevicePolicyManager().setMaximumFailedPasswordsForWipe(getCdmDeviceAdmin(), attempts); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_min_length)) && policyData .get(getContextResources().getString(R.string.policy_password_min_length)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_min_length)).toString() .isEmpty()) { length = policyData .getInt(getContextResources().getString(R.string.policy_password_min_length)); getDevicePolicyManager().setPasswordMinimumLength(getCdmDeviceAdmin(), length); } else { getDevicePolicyManager().setPasswordMinimumLength(getCdmDeviceAdmin(), getDefaultPasswordMinLength()); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_pin_history)) && policyData .get(getContextResources().getString(R.string.policy_password_pin_history)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_pin_history)) .toString().isEmpty()) { history = policyData .getInt(getContextResources().getString(R.string.policy_password_pin_history)); getDevicePolicyManager().setPasswordHistoryLength(getCdmDeviceAdmin(), history); } else { getDevicePolicyManager().setPasswordHistoryLength(getCdmDeviceAdmin(), getDefaultPasswordLength()); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_min_complex_chars)) && policyData.get( getContextResources().getString(R.string.policy_password_min_complex_chars)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_min_complex_chars)) .toString().isEmpty()) { specialChars = policyData .getInt(getContextResources().getString(R.string.policy_password_min_complex_chars)); getDevicePolicyManager().setPasswordMinimumSymbols(getCdmDeviceAdmin(), specialChars); } else { getDevicePolicyManager().setPasswordMinimumSymbols(getCdmDeviceAdmin(), getDefaultPasswordLength()); } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_require_alphanumeric)) && policyData.get(getContextResources() .getString(R.string.policy_password_require_alphanumeric)) != null) { if (policyData.get(getContextResources() .getString(R.string.policy_password_require_alphanumeric)) instanceof String) { alphanumeric = (String) policyData .get(getContextResources().getString(R.string.policy_password_require_alphanumeric)); if (alphanumeric.equals(getContextResources().getString(R.string.shared_pref_default_status))) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC); } } else if (policyData.get(getContextResources() .getString(R.string.policy_password_require_alphanumeric)) instanceof Boolean) { isAlphanumeric = policyData.getBoolean( getContextResources().getString(R.string.policy_password_require_alphanumeric)); if (isAlphanumeric) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC); } } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_allow_simple)) && policyData .get(getContextResources().getString(R.string.policy_password_allow_simple)) != null) { if (policyData.get( getContextResources().getString(R.string.policy_password_allow_simple)) instanceof String) { complex = (String) policyData .get(getContextResources().getString(R.string.policy_password_allow_simple)); if (!complex.equals(getContextResources().getString(R.string.shared_pref_default_status))) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_COMPLEX); } } else if (policyData.get(getContextResources() .getString(R.string.policy_password_allow_simple)) instanceof Boolean) { isComplex = policyData .getBoolean(getContextResources().getString(R.string.policy_password_allow_simple)); if (!isComplex) { getDevicePolicyManager().setPasswordQuality(getCdmDeviceAdmin(), DevicePolicyManager.PASSWORD_QUALITY_COMPLEX); } } } if (!policyData.isNull(getContextResources().getString(R.string.policy_password_pin_age_in_days)) && policyData.get( getContextResources().getString(R.string.policy_password_pin_age_in_days)) != null) { if (!policyData.get(getContextResources().getString(R.string.policy_password_pin_age_in_days)) .toString().isEmpty()) { int daysOfExp = policyData .getInt(getContextResources().getString(R.string.policy_password_pin_age_in_days)); timout = daysOfExp * getDayMillisecondsMultiplier(); getDevicePolicyManager().setPasswordExpirationTimeout(getCdmDeviceAdmin(), timout); } } if (!getDevicePolicyManager().isActivePasswordSufficient()) { Intent intent = new Intent(getContext(), AlertActivity.class); intent.putExtra(getContextResources().getString(R.string.intent_extra_type), getContextResources().getString(R.string.intent_extra_password_setting)); intent.putExtra(getContextResources().getString(R.string.intent_extra_message_text), getContextResources().getString(R.string.policy_violation_password_tail)); intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK); getContext().startActivity(intent); } if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Password policy set"); } } catch (JSONException e) { operation.setStatus(getContextResources().getString(R.string.operation_value_error)); operation.setOperationResponse("Error in parsing PASSWORD_POLICY payload."); getResultBuilder().build(operation); throw new AndroidAgentException("Invalid JSON format.", e); } }
From source file:com.shafiq.mytwittle.App.java
public void restartApp(Activity currentActivity) { Intent intent = getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_CLEAR_TASK); currentActivity.overridePendingTransition(0, 0); currentActivity.startActivity(intent); }
From source file:ch.bfh.instacircle.NetworkActiveActivity.java
/** * Checks whether the current network configuration is how it is supposed to * be/* ww w . j a va 2 s.co m*/ */ public void checkNetworkState() { ConnectivityManager conn = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0); final String configuredSsid = preferences.getString("SSID", "N/A"); final String password = preferences.getString("password", "N/A"); NetworkInfo nInfo = conn.getNetworkInfo(ConnectivityManager.TYPE_WIFI); String ssid = wifi.getConnectionInfo().getSSID(); Log.d(TAG, "Currently active SSID: " + ssid); // Only check the state if this device is not an access point if (!wifiapmanager.isWifiAPEnabled(wifi)) { Log.d(TAG, "Configured SSID: " + configuredSsid); if (!(nInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED && nInfo.getState() == NetworkInfo.State.CONNECTED && ssid.equals(configuredSsid))) { if (repairInitiated == false && repairTime + 6000 < System.currentTimeMillis()) { repairInitiated = true; repairTime = System.currentTimeMillis(); // create a dialog that ask whether you want to repair the // network connection AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("InstaCircle - Network Connection Lost"); alertDialog.setMessage( "The connection to the network " + configuredSsid + " has been lost. Try to repair?"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Repair", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); adhoc.connectToNetwork(configuredSsid, password, NetworkActiveActivity.this, false); repairInitiated = false; } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Leave", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); WifiManager wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE); new AdhocWifiManager(wifiman).restoreWifiConfiguration(getBaseContext()); new WifiAPManager().disableHotspot(wifiman, getBaseContext()); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); Intent stopIntent = new Intent(NetworkActiveActivity.this, NetworkService.class); stopService(stopIntent); Intent intent = new Intent(NetworkActiveActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }); alertDialog.show(); } } else { repairInitiated = false; } } }
From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java
/** * This method is called when a daugther activity is finished * we need to analyze return code/*from w ww .j a v a 2 s .c om*/ */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult " + String.valueOf(requestCode) + " " + String.valueOf(resultCode)); if (resultCode == -1) { // Right now only PreferencesActivity returns -1 // Restart app after preferences Log.d(TAG, "Restarting"); // Get launch intent for application Intent restartIntent = getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPackageName()); restartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Finish current activity finish(); // Start launch activity startActivity(restartIntent); } }
From source file:org.egov.android.view.activity.ComplaintDetailActivity.java
/** * onResponse methods will contain the response If the response has a status * as 'success' then We have checked whether the access token is valid or * not. If the access token is invalid, redirect to login page. If access * token is valid the retrieve the//w w w .j a va 2 s.com * crn,complaintType,details,landmarkDetails,complaintStatus values from the * JSON Object and store it to the variables, then display the * crn,complaintType,details,landmarkDetails,complaintStatus values to the * corresponding UI field of complaint detail page ui. location name * coordinate is retrieved from the api response and Geocoder is used to * transforming a (latitude, longitude) coordinate into a location name and * location name is displayed to the corresponding UI. * */ @SuppressLint("DefaultLocale") @Override public void onResponse(Event<ApiResponse> event) { super.onResponse(event); String status = event.getData().getApiStatus().getStatus(); String msg = event.getData().getApiStatus().getMessage(); if (status.equalsIgnoreCase("success")) { if (isComplaintDetail) { try { isComplaintDetail = false; JSONObject jo = new JSONObject(event.getData().getResponse().toString()); complaintStatus = _getValue(jo, "status"); createdDate = _getValue(jo, "createdDate"); lastModifiedDate = _getValue(jo, "lastModifiedDate"); complaintTypeName = _getValue(jo, "complaintTypeName"); if (complaintStatus.toUpperCase().equals("COMPLETED")) { setSpinnerStatus(statusReopen); showFeedbackSpinner(); } else { setSpinnerStatus(statusDrop); } new GetComplaintComments().loadComments(); ((TextView) findViewById(R.id.crn)).setText(_getValue(jo, "crn")); ((TextView) findViewById(R.id.complaintType)).setText(complaintTypeName); ((TextView) findViewById(R.id.details)).setText(_getValue(jo, "detail")); ((TextView) findViewById(R.id.landmarkDetails)).setText(_getValue(jo, "landmarkDetails")); ((TextView) findViewById(R.id.complaintStatus)).setText(complaintStatus.toLowerCase()); String location = null; if (jo.has("lat")) { location = GeoLocation.getCurrentLocation(jo.getDouble("lat"), jo.getDouble("lng"), ComplaintDetailActivity.this); } else { if (jo.has("childLocationName")) { location = _getValue(jo, "childLocationName"); } location = (location == null ? _getValue(jo, "locationName") : (location + " - " + _getValue(jo, "locationName"))); } ((TextView) findViewById(R.id.location)).setText(location); File complaintFolder = new File(complaintFolderName); if (!complaintFolder.exists()) { new StorageManager().mkdirs(complaintFolderName); } _addDownloadJobs(jo.getInt("supportDocsSize")); if (downloadThumbImages.length() > 0) { new ImageDownloaderTask().execute(downloadThumbImages); } else { _showComplaintImages(); } } catch (JSONException e) { e.printStackTrace(); } } else { showMessage(msg); Intent intent = new Intent(this, ComplaintActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); } } else { if (msg.matches(".*Invalid access token.*")) { showMessage("Session expired"); startLoginActivity(); } else { showMessage(msg); } } }