List of usage examples for android.app AlarmManager INTERVAL_DAY
long INTERVAL_DAY
To view the source code for android.app AlarmManager INTERVAL_DAY.
Click Source Link
From source file:com.near.chimerarevo.activities.MainActivity.java
@Override public void onDestroy() { super.onDestroy(); if (ImageLoader.getInstance().isInited()) { ImageLoader.getInstance().clearDiskCache(); ImageLoader.getInstance().clearMemoryCache(); }//from ww w .j a v a2 s . c om if (mHelper != null) mHelper.dispose(); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("news_search_pref", true)) { Intent intent = new Intent(getApplicationContext(), NewsService.class); PendingIntent pintent = PendingIntent.getService(getApplicationContext(), 0, intent, 0); AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.cancel(pintent); long delay; int sel = Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(this).getString("notification_delay_pref", "0")); switch (sel) { case 0: delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES; break; case 1: delay = AlarmManager.INTERVAL_HALF_HOUR; break; case 2: delay = AlarmManager.INTERVAL_HOUR; break; case 3: delay = 2 * AlarmManager.INTERVAL_HOUR; break; case 4: delay = 3 * AlarmManager.INTERVAL_HOUR; break; case 5: delay = 6 * AlarmManager.INTERVAL_HOUR; break; case 6: delay = AlarmManager.INTERVAL_HALF_DAY; break; case 7: delay = AlarmManager.INTERVAL_DAY; break; default: delay = AlarmManager.INTERVAL_HOUR; break; } alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent); } }
From source file:de.azapps.mirakel.reminders.ReminderAlarm.java
private static void updateAlarms(final Context ctx) { new Thread(new Runnable() { @Override//from w w w . j ava 2s.co m public void run() { Log.e(TAG, "update"); alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); // Update the Notifications at midnight final Intent intent = new Intent(ctx, ReminderAlarm.class); intent.setAction(UPDATE_NOTIFICATION); final PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final Calendar triggerCal = new GregorianCalendar(); triggerCal.set(Calendar.HOUR_OF_DAY, 0); triggerCal.set(Calendar.MINUTE, 0); triggerCal.add(Calendar.DAY_OF_MONTH, 1); alarmManager.setRepeating(AlarmManager.RTC, triggerCal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); // Alarms final List<Task> tasks = Task.getTasksWithReminders(); final Calendar now = new GregorianCalendar(); for (final Pair<Task, PendingIntent> p : activeAlarms) { final Task t = p.first; final Task newTask = Task.get(t.getId()).orNull(); if ((newTask == null) || !newTask.getReminder().isPresent() || newTask.isDone() || newTask.getReminder().get().after(new GregorianCalendar())) { cancelAlarm(ctx, t, newTask, p, p.second); } else if (newTask.getReminder().isPresent()) { if (newTask.getReminder().get().after(now) && !newTask.getRecurringReminder().isPresent()) { closeNotificationFor(ctx, t.getId()); updateAlarm(ctx, newTask); } else if (newTask.getReminder().get().after(now) && newTask.getRecurringReminder().isPresent() && (newTask.getReminder().get() .compareTo(newTask.getRecurringReminder().get() .addRecurring(newTask.getReminder()).orNull()) > 0) && !now.after(newTask.getReminder())) { updateAlarm(ctx, newTask); } else if ((t.getRecurringReminderId() != newTask.getRecurringReminderId()) || t.getRecurringReminder().isPresent()) { if (t.getRecurringReminder().isPresent() && newTask.getRecurringReminder().isPresent()) { if (!t.getRecurringReminder().get().equals(newTask.getRecurringReminder().get())) { updateAlarm(ctx, newTask); cancelAlarm(ctx, t, newTask, p, p.second); } } else if (t.getRecurringReminder().isPresent() != newTask.getRecurringReminder() .isPresent()) { updateAlarm(ctx, newTask); cancelAlarm(ctx, t, newTask, p, p.second); } } else { updateAlarm(ctx, newTask); } } } for (final Task t : tasks) { try { if (!isAlarm(t)) { Log.d(TAG, "add: " + t.getName()); Log.i(TAG, "id " + t.getId()); final PendingIntent p = updateAlarm(ctx, t); activeAlarms.add(new Pair<>(t, p)); } } catch (final NoSuchTaskException e) { Log.wtf(TAG, "Task not found", e); } } } }).start(); }
From source file:at.diamonddogs.util.CacheManager.java
/** * Turn on scheduled cache cleaning (cache will be cleaned even if app is * not running)/* w w w . j a v a 2 s . c o m*/ * * @param context a {@link Context} */ public void enableScheduledCacheCleaner(Context context) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // @formatter:off am.setInexactRepeating(AlarmManager.RTC, Utils.getScheduledDate(Calendar.SUNDAY, 3, 0, 0).getTimeInMillis(), 7 * AlarmManager.INTERVAL_DAY, getAlarmIntent(context)); // @formatter:on Log.i(TAG, "Cache cleaning alarm has been set."); }
From source file:org.xwalk.app.template.AppTemplateActivity.java
public static void set_RTC_wakeup(Context context) { Log.d(TAG, "setting RTC wakeup"); alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, UCCLauncherReceiver.class); intent.setAction(WAKEUP_SIG);/*ww w.j av a2 s. com*/ alarmIntent_Wakeup = PendingIntent.getBroadcast(context, 0, intent, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, wakeup_rtc_time_hours); calendar.set(Calendar.MINUTE, wakeup_rtc_time_minutes); // cancel old intent (if any) alarmMgr.cancel(alarmIntent_Wakeup); // set new intent // alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, // SystemClock.elapsedRealtime() + 2 * 60 * 1000, alarmIntent_Wakeup); alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent_Wakeup); }
From source file:org.xwalk.app.template.AppTemplateActivity.java
public static void set_RTC_sleep(Context context) { Log.d(TAG, "setting RTC sleep"); alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, UCCLauncherReceiver.class); intent.setAction(SLEEP_SIG);//w w w. j a v a 2s .c om alarmIntent_Sleep = PendingIntent.getBroadcast(context, 0, intent, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, sleep_rtc_time_hours); calendar.set(Calendar.MINUTE, sleep_rtc_time_minutes); // cancel old intent (if any) alarmMgr.cancel(alarmIntent_Sleep); // set new intent // alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, // SystemClock.elapsedRealtime() + 2 * 60 * 1000, alarmIntent_Sleep); alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent_Sleep); }
From source file:com.farmerbb.taskbar.service.TaskbarService.java
@SuppressLint("RtlHardcoded") private void drawTaskbar() { IconCache.getInstance(this).clearCache(); // Initialize layout params windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); U.setCachedRotation(windowManager.getDefaultDisplay().getRotation()); final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);//from ww w.j av a 2 s.co m // Determine where to show the taskbar on screen switch (U.getTaskbarPosition(this)) { case "bottom_left": layoutId = R.layout.taskbar_left; params.gravity = Gravity.BOTTOM | Gravity.LEFT; positionIsVertical = false; break; case "bottom_vertical_left": layoutId = R.layout.taskbar_vertical; params.gravity = Gravity.BOTTOM | Gravity.LEFT; positionIsVertical = true; break; case "bottom_right": layoutId = R.layout.taskbar_right; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; positionIsVertical = false; break; case "bottom_vertical_right": layoutId = R.layout.taskbar_vertical; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; positionIsVertical = true; break; case "top_left": layoutId = R.layout.taskbar_left; params.gravity = Gravity.TOP | Gravity.LEFT; positionIsVertical = false; break; case "top_vertical_left": layoutId = R.layout.taskbar_top_vertical; params.gravity = Gravity.TOP | Gravity.LEFT; positionIsVertical = true; break; case "top_right": layoutId = R.layout.taskbar_right; params.gravity = Gravity.TOP | Gravity.RIGHT; positionIsVertical = false; break; case "top_vertical_right": layoutId = R.layout.taskbar_top_vertical; params.gravity = Gravity.TOP | Gravity.RIGHT; positionIsVertical = true; break; } // Initialize views int theme = 0; SharedPreferences pref = U.getSharedPreferences(this); switch (pref.getString("theme", "light")) { case "light": theme = R.style.AppTheme; break; case "dark": theme = R.style.AppTheme_Dark; break; } boolean altButtonConfig = pref.getBoolean("alt_button_config", false); ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme); layout = (LinearLayout) LayoutInflater.from(wrapper).inflate(layoutId, null); taskbar = (LinearLayout) layout.findViewById(R.id.taskbar); scrollView = (FrameLayout) layout.findViewById(R.id.taskbar_scrollview); if (altButtonConfig) { space = (Space) layout.findViewById(R.id.space_alt); layout.findViewById(R.id.space).setVisibility(View.GONE); } else { space = (Space) layout.findViewById(R.id.space); layout.findViewById(R.id.space_alt).setVisibility(View.GONE); } space.setOnClickListener(v -> toggleTaskbar()); startButton = (ImageView) layout.findViewById(R.id.start_button); int padding; if (pref.getBoolean("app_drawer_icon", false)) { startButton.setImageDrawable(ContextCompat.getDrawable(this, R.mipmap.ic_launcher)); padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt); } else { startButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.all_apps_button_icon)); padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding); } startButton.setPadding(padding, padding, padding, padding); startButton.setOnClickListener(ocl); startButton.setOnLongClickListener(view -> { openContextMenu(); return true; }); startButton.setOnGenericMotionListener((view, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) openContextMenu(); return false; }); refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000); if (refreshInterval == 0) refreshInterval = 100; sortOrder = pref.getString("sort_order", "false"); runningAppsOnly = pref.getString("recents_amount", "past_day").equals("running_apps_only"); switch (pref.getString("recents_amount", "past_day")) { case "past_day": searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; break; case "app_start": long oneDayAgo = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY; long appStartTime = pref.getLong("time_of_service_start", System.currentTimeMillis()); long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime(); long startTime = deviceStartTime > appStartTime ? deviceStartTime : appStartTime; searchInterval = startTime > oneDayAgo ? startTime : oneDayAgo; break; } Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU"); LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent); if (altButtonConfig) { button = (Button) layout.findViewById(R.id.hide_taskbar_button_alt); layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE); } else { button = (Button) layout.findViewById(R.id.hide_taskbar_button); layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE); } try { button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf")); } catch (RuntimeException e) { /* Gracefully fail */ } updateButton(false); button.setOnClickListener(v -> toggleTaskbar()); LinearLayout buttonLayout = (LinearLayout) layout.findViewById( altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout); if (buttonLayout != null) buttonLayout.setOnClickListener(v -> toggleTaskbar()); LinearLayout buttonLayoutToHide = (LinearLayout) layout.findViewById( altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt); if (buttonLayoutToHide != null) buttonLayoutToHide.setVisibility(View.GONE); int backgroundTint = U.getBackgroundTint(this); int accentColor = U.getAccentColor(this); dashboardButton = (FrameLayout) layout.findViewById(R.id.dashboard_button); navbarButtons = (LinearLayout) layout.findViewById(R.id.navbar_buttons); dashboardEnabled = pref.getBoolean("dashboard", false); if (dashboardEnabled) { layout.findViewById(R.id.square1).setBackgroundColor(accentColor); layout.findViewById(R.id.square2).setBackgroundColor(accentColor); layout.findViewById(R.id.square3).setBackgroundColor(accentColor); layout.findViewById(R.id.square4).setBackgroundColor(accentColor); layout.findViewById(R.id.square5).setBackgroundColor(accentColor); layout.findViewById(R.id.square6).setBackgroundColor(accentColor); dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(TaskbarService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD"))); } else dashboardButton.setVisibility(View.GONE); if (pref.getBoolean("button_back", false)) { navbarButtonsEnabled = true; ImageView backButton = (ImageView) layout.findViewById(R.id.button_back); backButton.setVisibility(View.VISIBLE); backButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); } if (pref.getBoolean("button_home", false)) { navbarButtonsEnabled = true; ImageView homeButton = (ImageView) layout.findViewById(R.id.button_home); homeButton.setVisibility(View.VISIBLE); homeButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); homeButton.setOnLongClickListener(v -> { Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(voiceSearchIntent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); return true; }); homeButton.setOnGenericMotionListener((view13, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(voiceSearchIntent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); } return true; }); } if (pref.getBoolean("button_recents", false)) { navbarButtonsEnabled = true; ImageView recentsButton = (ImageView) layout.findViewById(R.id.button_recents); recentsButton.setVisibility(View.VISIBLE); recentsButton.setOnClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { recentsButton.setOnLongClickListener(v -> { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); return true; }); recentsButton.setOnGenericMotionListener((view13, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN); if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) hideTaskbar(true); } return true; }); } } if (!navbarButtonsEnabled) navbarButtons.setVisibility(View.GONE); layout.setBackgroundColor(backgroundTint); layout.findViewById(R.id.divider).setBackgroundColor(accentColor); button.setTextColor(accentColor); if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace()) showTaskbar(false); else if (!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false)) toggleTaskbar(); LocalBroadcastManager.getInstance(this).unregisterReceiver(showReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(tempShowReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(tempHideReceiver); LocalBroadcastManager.getInstance(this).registerReceiver(showReceiver, new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(tempShowReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR")); LocalBroadcastManager.getInstance(this).registerReceiver(tempHideReceiver, new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR")); startRefreshingRecents(); windowManager.addView(layout, params); isFirstStart = false; }
From source file:com.sean.takeastand.storage.ScheduleEditor.java
private void setDailyRepeatingAlarm(int UID, String time) { Intent intent = new Intent(mContext, StartScheduleReceiver.class); intent.putExtra(Constants.ALARM_UID, UID); PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, UID, intent, PendingIntent.FLAG_CANCEL_CURRENT); ((AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.RTC_WAKEUP, nextAlarmTime(time).getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); Log.i(TAG, "Set Daily Repeating alarm for " + Long.toString(nextAlarmTime(time).getTimeInMillis()) + " current time " + Long.toString(System.currentTimeMillis())); }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get preferences getSettings();/*from w w w .jav a2 s. co m*/ // Set alarm for checking completed torrents, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), NotifierService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), NotifierService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, notification_period, alarmIntent); } // Set alarm for RSS checking, if not set if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), RSSService.class), PendingIntent.FLAG_NO_CREATE) == null) { // Set Alarm for checking completed torrents alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getApplication(), RSSService.class); alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0); alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000, AlarmManager.INTERVAL_DAY, alarmIntent); } // Set Theme (It must be fore inflating or setContentView) if (dark_ui) { this.setTheme(R.style.Theme_Dark); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground)); } } else { this.setTheme(R.style.Theme_Light); if (Build.VERSION.SDK_INT >= 21) { getWindow().setNavigationBarColor(getResources().getColor(R.color.primary)); } } setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.app_bar); if (dark_ui) { toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary)); } setSupportActionBar(toolbar); // Set App title setTitle(R.string.app_shortname); // Drawer menu navigationDrawerServerItems = getResources().getStringArray(R.array.qBittorrentServers); navigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // drawerList = (ListView) findViewById(R.id.left_drawer); mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are ArrayList<ObjectDrawerItem> serverItems = new ArrayList<ObjectDrawerItem>(); ArrayList<ObjectDrawerItem> actionItems = new ArrayList<ObjectDrawerItem>(); ArrayList<ObjectDrawerItem> settingsItems = new ArrayList<ObjectDrawerItem>(); // Add server category serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_servers, getResources().getString(R.string.drawer_servers_category), DRAWER_CATEGORY, false, null)); // Server items int currentServerValue = 1; try { currentServerValue = Integer.parseInt(MainActivity.currentServer); } catch (NumberFormatException e) { } for (int i = 0; i < navigationDrawerServerItems.length; i++) { // Log.d("Debug", "MainActivity - currentServerValue - currentServerValue: " + currentServerValue); // Log.d("Debug", "MainActivity - currentServerValue - (i + 1): " + (i + 1)); // Log.d("Debug", "MainActivity - currentServerValue - (i + 1) == currentServerValue: " + ((i + 1) == currentServerValue)); serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, navigationDrawerServerItems[i], DRAWER_ITEM_SERVERS, ((i + 1) == currentServerValue), "changeCurrentServer")); } // // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 1", DRAWER_ITEM_SERVERS, true, "changeCurrentServer")); // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 2", DRAWER_ITEM_SERVERS, false, "changeCurrentServer")); // serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 3", DRAWER_ITEM_SERVERS, false, "changeCurrentServer")); // Add actions actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_all, navigationDrawerItemTitles[0], DRAWER_ITEM_ACTIONS, lastState.equals("all"), "refreshAll")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_downloading, navigationDrawerItemTitles[1], DRAWER_ITEM_ACTIONS, lastState.equals("downloading"), "refreshDownloading")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_completed, navigationDrawerItemTitles[2], DRAWER_ITEM_ACTIONS, lastState.equals("completed"), "refreshCompleted")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_paused, navigationDrawerItemTitles[3], DRAWER_ITEM_ACTIONS, lastState.equals("pause"), "refreshPaused")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_active, navigationDrawerItemTitles[4], DRAWER_ITEM_ACTIONS, lastState.equals("active"), "refreshActive")); actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_inactive, navigationDrawerItemTitles[5], DRAWER_ITEM_ACTIONS, lastState.equals("inactive"), "refreshInactive")); // Add settings actions // drawerItems.add(new ObjectDrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, false, "openOptions")); settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, false, "openSettings")); if (packageName.equals("com.lgallardo.youtorrentcontroller")) { settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_pro, navigationDrawerItemTitles[7], DRAWER_ITEM_ACTIONS, false, "getPro")); settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[8], DRAWER_ITEM_ACTIONS, false, "openHelp")); } else { settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[7], DRAWER_ITEM_ACTIONS, false, "openHelp")); } // Set adapter rAdapter = new DrawerItemRecyclerViewAdapter(getApplicationContext(), this, serverItems, actionItems, settingsItems, null); rAdapter.notifyDataSetChanged(); // Log.d("Debug", "MainActivity - oldActionPosition: "+ (Arrays.asList(actionStates).indexOf(lastState))); // drawerList.setAdapter(adapter); mRecyclerView.setAdapter(rAdapter); mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager // Set selection according to last state setSelectionAndTitle(lastState); // Set the item click listener // drawerList.setOnItemClickListener(new DrawerItemClickListener()); // Get drawer title title = drawerTitle = getTitle(); // Add the application icon control code inside MainActivity onCreate drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // New ActionBarDrawerToggle for Google Material Desing (v7) drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { /** * Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { super.onDrawerClosed(view); // getSupportActionBar().setTitle(title); } /** * Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // getSupportActionBar().setTitle(drawerTitle); // setTitle(R.string.app_shortname); } }; drawerLayout.setDrawerListener(drawerToggle); // drawerToggle.syncState(); // Finally we set the drawer toggle sync State getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); // Get options and save them as shared preferences // qBittorrentOptions qso = new qBittorrentOptions(); // qso.execute(new String[]{qbQueryString + "/preferences", "getSettings"}); // If it were awaked from an intent-filter, // Get token and cookie and then // get intent from the intent filter and Add URL torrent // Log.d("Debug", "MainActivity - 1"); new torrentTokenByIntent().execute(getIntent()); // Fragments // Check whether the activity is using the layout version with // the fragment_container FrameLayout. If so, we must add the first // fragment if (findViewById(R.id.fragment_container) != null) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // return; // } // This fragment will hold the list of torrents if (firstFragment == null) { firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment(); } // This fragment will hold the list of torrents helpTabletFragment = new HelpFragment(); // Set the second fragments container firstFragment.setSecondFragmentContainer(R.id.content_frame); // This i the second fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.list_frame, helpTabletFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.list_frame, helpTabletFragment, "firstFragment"); } if (fragmentManager.findFragmentByTag("secondFragment") == null) { fragmentTransaction.add(R.id.content_frame, secondFragment, "secondFragment"); } else { fragmentTransaction.replace(R.id.content_frame, secondFragment, "secondFragment"); } fragmentTransaction.commit(); // Second fragment will be added in ItemsFRagment's onListItemClick // method } else { // Phones handle just one fragment // Create an instance of ItemsFragments if (firstFragment == null) { firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment(); } firstFragment.setSecondFragmentContainer(R.id.one_frame); // This is the about fragment, holding a default message at the // beginning secondFragment = new AboutFragment(); // If we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. // if (savedInstanceState != null) { // // // Handle Item list empty due to Fragment stack // try { // FragmentManager fm = getFragmentManager(); // // if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.youtorrentcontroller.TorrentDetailsFragment) { // // refreshCurrent(); // // } // } // catch (Exception e) { // } // // return; // } // Add the fragment to the 'list_frame' FrameLayout FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (fragmentManager.findFragmentByTag("firstFragment") == null) { fragmentTransaction.add(R.id.one_frame, secondFragment, "firstFragment"); } else { fragmentTransaction.replace(R.id.one_frame, secondFragment, "firstFragment"); } // if torrent details was loaded reset back button stack for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) { fragmentManager.popBackStack(); } fragmentTransaction.commit(); } // Activity is visible activityIsVisible = true; // First refresh refreshCurrent(); handler = new Handler(); handler.postDelayed(m_Runnable, refresh_period); // Load banner loadBanner(); }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static long setUpdateAlarm(Context context, boolean initial) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent alarmintent = new Intent(context, AlarmReceiver.class); alarmintent.setAction(AlarmReceiver.ALARM_UPDATE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, 0, alarmintent, 0); MyApp.LogDebug(LOG_TAG, "set update alarm"); long next_fetch; long interval; Time t = new Time(); t.setToNow();// w ww. ja v a 2 s .co m long now = t.toMillis(true); if ((now >= MyApp.first_day_start) && (now < MyApp.last_day_end)) { interval = 2 * AlarmManager.INTERVAL_HOUR; next_fetch = now + interval; } else if (now >= MyApp.last_day_end) { MyApp.LogDebug(LOG_TAG, "cancel alarm post congress"); alarmManager.cancel(pendingintent); return 0; } else { interval = AlarmManager.INTERVAL_DAY; next_fetch = now + interval; } if ((now < MyApp.first_day_start) && ((now + AlarmManager.INTERVAL_DAY) >= MyApp.first_day_start)) { next_fetch = MyApp.first_day_start; interval = 2 * AlarmManager.INTERVAL_HOUR; if (!initial) { MyApp.LogDebug(LOG_TAG, "update alarm to interval " + interval + ", next in " + (next_fetch - now)); alarmManager.cancel(pendingintent); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent); } } if (initial) { MyApp.LogDebug(LOG_TAG, "set initial alarm to interval " + interval + ", next in " + (next_fetch - now)); alarmManager.cancel(pendingintent); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, next_fetch, interval, pendingintent); } return interval; }
From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java
public void setupAlarm(int hourOfDay) { //Alarm has been called ALARM_NOT_CALLED = false;/* w ww . j a va 2 s .co m*/ //Setup what the alarm has to do when it goes off. Intent alarmIntent = new Intent(SmogMapActivity.this, AirAzureDownloadService.AlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(SmogMapActivity.this, 0, alarmIntent, PendingIntent.FLAG_ONE_SHOT);//getBroadcast(context, 0, i, 0); Log.v("OnCreate", "Alarm Intent Created"); //Set the AlarmManager to wake up the system every day at 6 a.m. AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); long timeEveryDay = calendar.getTimeInMillis(); long currentTime = System.currentTimeMillis(); long oneMin = 60 * 1000; am.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeEveryDay, AlarmManager.INTERVAL_DAY, pi); if ((currentTime + oneMin) < timeEveryDay) { Log.v(LOG_TAG, "First time download and time is before 6 a.m."); Intent firstTimeDownloadIntent = new Intent(getApplicationContext(), AirAzureDownloadService.class); startService(firstTimeDownloadIntent); } }