Search in sources :

Example 1 with PreferencesMigrator

use of ca.rmen.android.networkmonitor.app.prefs.PreferencesMigrator in project network-monitor by caarmen.

the class NetMonService method scheduleTests.

/**
 * Start scheduling tests, using the scheduler class chosen by the user in the advanced settings.
 */
private void scheduleTests() {
    Log.v(TAG, "scheduleTests");
    NetMonPreferences prefs = NetMonPreferences.getInstance(this);
    PreferencesMigrator prefsMigrator = new PreferencesMigrator(this);
    prefsMigrator.migratePreferences();
    Class<?> schedulerClass = prefs.getSchedulerClass();
    Log.v(TAG, "Will use scheduler " + schedulerClass);
    // noinspection TryWithIdenticalCatches
    try {
        if (mScheduler == null || !mScheduler.getClass().getName().equals(schedulerClass.getName())) {
            Log.v(TAG, "Creating new scheduler " + schedulerClass);
            if (mScheduler != null)
                mScheduler.onDestroy();
            mScheduler = (Scheduler) schedulerClass.newInstance();
            mScheduler.onCreate(this);
            mScheduler.schedule(mTask, prefs.getUpdateInterval());
        } else {
            Log.v(TAG, "Rescheduling scheduler " + mScheduler);
            int interval = prefs.getUpdateInterval();
            mScheduler.setInterval(interval);
        }
    } catch (InstantiationException e) {
        Log.e(TAG, "setScheduler Could not create scheduler " + schedulerClass + ": " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        Log.e(TAG, "setScheduler Could not create scheduler " + schedulerClass + ": " + e.getMessage(), e);
    }
}
Also used : NetMonPreferences(ca.rmen.android.networkmonitor.app.prefs.NetMonPreferences) PreferencesMigrator(ca.rmen.android.networkmonitor.app.prefs.PreferencesMigrator)

Aggregations

NetMonPreferences (ca.rmen.android.networkmonitor.app.prefs.NetMonPreferences)1 PreferencesMigrator (ca.rmen.android.networkmonitor.app.prefs.PreferencesMigrator)1