Example usage for android.content Context ACTIVITY_SERVICE

List of usage examples for android.content Context ACTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context ACTIVITY_SERVICE.

Prototype

String ACTIVITY_SERVICE

To view the source code for android.content Context ACTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Usage

From source file:org.uguess.android.sysinfo.SiragonManager.java

/**
 * @return [total, idle, free]//  w w  w . ja va2s. c  o m
 */
static long[] getMemState(Context ctx) {
    BufferedReader reader = null;

    try {
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(F_MEM_INFO))), 1024);

        String line;
        String totalMsg = null;
        String freeMsg = null;

        while ((line = reader.readLine()) != null) {
            if (line.startsWith("MemTotal")) //$NON-NLS-1$
            {
                totalMsg = line;
            } else if (line.startsWith("MemFree")) //$NON-NLS-1$
            {
                freeMsg = line;
            }

            if (totalMsg != null && freeMsg != null) {
                break;
            }
        }

        long[] mem = new long[3];

        mem[0] = extractMemCount(totalMsg);
        mem[1] = extractMemCount(freeMsg);

        ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
        MemoryInfo mi = new MemoryInfo();
        am.getMemoryInfo(mi);
        mem[2] = mi.availMem;

        return mem;
    } catch (Exception e) {
        Log.e(SiragonManager.class.getName(), e.getLocalizedMessage(), e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException ie) {
                Log.e(SiragonManager.class.getName(), ie.getLocalizedMessage(), ie);
            }
        }
    }

    return null;
}

From source file:org.csploit.android.core.System.java

public static boolean isServiceRunning(String name) {
    ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);

    //noinspection ConstantConditions
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (name.equals(service.service.getClassName()))
            return true;
    }//from ww  w  .  j a  v  a  2 s.co m

    return false;
}

From source file:com.landenlabs.all_devtool.ConsoleFragment.java

private void snapConsole() {
    try {//from w  w w  .ja v  a 2s.c  om
        MemoryInfo mi = new MemoryInfo();
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Context.ACTIVITY_SERVICE);
        activityManager.getMemoryInfo(mi);

        consoleState.lastFreeze = new Date();
        consoleState.usingMemory = Debug.getNativeHeapSize();
        consoleState.freeMemory = mi.availMem;
        if (Build.VERSION.SDK_INT >= 16) {
            consoleState.totalMemory = mi.totalMem;
        }

        consoleState.netRxBytes = TrafficStats.getTotalRxBytes();
        consoleState.netRxPacks = TrafficStats.getTotalRxPackets();
        consoleState.netTxBytes = TrafficStats.getTotalTxBytes();
        consoleState.netTxPacks = TrafficStats.getTotalRxPackets();

        ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
        consoleState.processCnt = actMgr.getRunningAppProcesses().size();
        consoleState.batteryLevel = calculateBatteryLevel(getActivity());
    } catch (Exception ex) {
    }
}

From source file:org.durka.hallmonitor.CoreStateManager.java

/**
 * Is the service running./*from w w  w.j  ava2  s  .c o m*/
 * 
 * @param ctx
 *            Application context.
 * @return Is the cover closed.
 */
public boolean getServiceRunning(@SuppressWarnings("rawtypes") Class svc) {

    Log.d(LOG_TAG, "Is service running called.");

    ActivityManager manager = (ActivityManager) mAppContext.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (svc.getName().equals(service.service.getClassName())) {
            // the service is running
            Log.d(LOG_TAG, "The " + svc.getName() + " is running.");
            return true;
        }
    }
    // the service must not be running
    Log.d(LOG_TAG, "The " + svc.getName() + " service is NOT running.");
    return false;
}

From source file:system.info.reader.java

public String refresh() {
    //wifi/*from  w w  w .jav  a  2 s  . c  o  m*/
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if ((wifiInfo != null) && (wifiInfo.getMacAddress() != null))
        Properties.setInfo((String) propertyItems[4], wifiInfo.getMacAddress());
    else
        Properties.setInfo((String) propertyItems[4], "not avaiable");

    //String tmpsdcard = runCmd("df", "");
    //if (tmpsdcard != null) result += tmpsdcard + "\n\n";

    //setMap("dpi", dpi);

    //location
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    List ll = lm.getProviders(true);
    Boolean foundLoc = false;
    for (int i = 0; i < ll.size(); i++) {
        Location lo = lm.getLastKnownLocation((String) ll.get(i));
        if (lo != null) {
            Properties.setInfo((String) propertyItems[3], lo.getLatitude() + ":" + lo.getLongitude());
            foundLoc = true;
            break;
        }
    }
    if (!foundLoc)
        Properties.setInfo((String) propertyItems[3], getString(R.string.locationHint));

    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List serviceList = am.getRunningServices(10000);
    serviceInfo = "";
    for (int i = 0; i < serviceList.size(); i++) {
        RunningServiceInfo rs = (RunningServiceInfo) serviceList.get(i);
        serviceInfo += rs.service.flattenToShortString() + "\n";
    }
    //result += getString(R.string.nService) + serviceList.size() + "\n";//service number

    psInfo = "";
    List appList = am.getRunningAppProcesses();
    for (int i = 0; i < appList.size(); i++) {
        RunningAppProcessInfo as = (RunningAppProcessInfo) appList.get(i);
        psInfo += as.processName + "\n";
    }
    //result += getString(R.string.nProcess) + appList.size() + "\n";//process number

    taskInfo = "";
    List taskList = am.getRunningTasks(10000);
    for (int i = 0; i < taskList.size(); i++) {
        RunningTaskInfo ts = (RunningTaskInfo) taskList.get(i);
        taskInfo += ts.baseActivity.flattenToShortString() + "\n";
    }
    //result += getString(R.string.nTask) + taskList.size() + "\n\n";//task number

    //result += getString(R.string.nProcess) + runCmd("ps", "") + "\n";//process number

    //setMap(getString(R.string.nApk), nApk);

    //send message to let view redraw.
    Message msg = mRedrawHandler.obtainMessage();
    mRedrawHandler.sendMessage(msg);
    //properListItemAdapter.notifyDataSetChanged();//no use?

    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(400);
    return "";
}

From source file:org.uguess.android.sysinfo.ProcessManager.java

void handleAction(final ProcessItem rap, int action) {
    Activity ctx = getActivity();//from   www .  j a v a 2  s . co  m

    switch (action) {
    case ACTION_END:

        if (!ignoreList.contains(rap.procInfo.processName) && !rap.sys) {
            ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);

            String self = ctx.getPackageName();

            if (self.equals(rap.procInfo.processName)) {
                Util.killSelf(handler, ctx, am, self);
            } else {
                endProcess(am, rap.procInfo.pkgList, self);

                handler.removeCallbacks(task);
                handler.post(task);
            }
        }

        break;
    case ACTION_END_OTHERS:

        endAllExcept(rap.procInfo.processName);

        break;
    case ACTION_SWITCH:

        String pkgName = rap.procInfo.processName;

        if (!pkgName.equals(ctx.getPackageName())) {
            Intent it = new Intent("android.intent.action.MAIN"); //$NON-NLS-1$
            it.addCategory(Intent.CATEGORY_LAUNCHER);

            List<ResolveInfo> acts = ctx.getPackageManager().queryIntentActivities(it, 0);

            if (acts != null) {
                boolean started = false;

                for (int i = 0, size = acts.size(); i < size; i++) {
                    ResolveInfo ri = acts.get(i);

                    if (pkgName.equals(ri.activityInfo.packageName)) {
                        it.setClassName(ri.activityInfo.packageName, ri.activityInfo.name);

                        it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                                .addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);

                        try {
                            startActivity(it);

                            started = true;
                        } catch (Exception e) {
                            Log.e(ProcessManager.class.getName(), "Cannot start activity: " + pkgName, //$NON-NLS-1$
                                    e);
                        }

                        break;
                    }
                }

                if (!started) {
                    Util.shortToast(ctx, R.string.error_switch_task);
                }
            }
        }

        break;
    case ACTION_IGNORE:

        if (!ignoreList.contains(rap.procInfo.processName) && !rap.sys) {
            ignoreList.add(rap.procInfo.processName);

            setIgnoreList(ignoreList);

            if (IGNORE_ACTION_HIDDEN == Util.getIntOption(ctx, PSTORE_PROCESSMANAGER, PREF_KEY_IGNORE_ACTION,
                    IGNORE_ACTION_HIDDEN)) {
                handler.removeCallbacks(task);
                handler.post(task);
            }
        }

        break;
    case ACTION_DETAILS:

        String[] status = readProcStatus(rap.procInfo.pid);

        StringBuffer sb = new StringBuffer().append("<small>") //$NON-NLS-1$
                .append(getString(R.string.proc_name)).append(": ") //$NON-NLS-1$
                .append(rap.procInfo.processName).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.pid)).append(": ") //$NON-NLS-1$
                .append(rap.procInfo.pid).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.uid)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[1]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.gid)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[2]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.state)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[0]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.threads)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[3]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.importance)).append(": ") //$NON-NLS-1$
                .append(rap.procInfo.importance).append("<br>LRU: ") //$NON-NLS-1$
                .append(rap.procInfo.lru).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.pkg_name)).append(": "); //$NON-NLS-1$

        if (rap.procInfo.pkgList != null) {
            int i = 0;

            for (String pkg : rap.procInfo.pkgList) {
                if (pkg != null) {
                    if (i > 0) {
                        sb.append(", "); //$NON-NLS-1$
                    }
                    sb.append(pkg);
                    i++;
                }
            }
        }

        sb.append("</small>"); //$NON-NLS-1$

        new AlertDialog.Builder(ctx).setTitle(rap.label == null ? rap.procInfo.processName : rap.label)
                .setNeutralButton(R.string.close, null).setMessage(Html.fromHtml(sb.toString())).create()
                .show();

        break;
    case ACTION_MENU:

        final boolean protect = ignoreList.contains(rap.procInfo.processName) || rap.sys;

        OnClickListener listener = new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                // bypass the 'showMenu' action offset
                int action = which + 1;

                if (!protect || (action != ACTION_END && action != ACTION_IGNORE)) {
                    handleAction(rap, action);
                }
            }
        };

        new AlertDialog.Builder(
                ctx).setTitle(R.string.actions)
                        .setItems(
                                new CharSequence[] { getString(R.string.switch_to),
                                        protect ? Html.fromHtml("<font color=\"#848484\">" //$NON-NLS-1$
                                                + getString(R.string.end_task) + "</font>") //$NON-NLS-1$
                                                : getString(R.string.end_task),
                                        getString(R.string.end_others),
                                        protect ? Html.fromHtml("<font color=\"#848484\">" //$NON-NLS-1$
                                                + getString(R.string.ignore) + "</font>") //$NON-NLS-1$
                                                : getString(R.string.ignore),
                                        getString(R.string.details) },
                                listener)
                        .create().show();

        break;
    }
}

From source file:net.wespot.pim.view.InqCommunicateFragment.java

public boolean isPimRunning() {
    ActivityManager activityManager = (ActivityManager) ARL.getContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE);
    boolean isActivityFound = false;

    if (services.get(0).topActivity.getPackageName().toString()
            .equalsIgnoreCase(ARL.getContext().getPackageName().toString())) {
        return true;
    } else {/*from   www . j av  a  2s .co m*/
        return false;
    }
}

From source file:com.keithandthegirl.ui.activity.EpisodesFragment.java

private boolean isDownloadInProgress() {
    ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.keithandthegirl.services.download.DownloadService".equals(service.service.getClassName())) {
            return true;
        }//from  w w  w  .j  av  a  2s.co  m
    }

    return false;
}

From source file:piuk.blockchain.android.WalletApplication.java

private boolean isBitcoinJServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        //         if (BlockchainServiceImpl.class.getName().equals(service.service.getClassName())) {
        //            return true;
        //         }
    }/*from  w w  w .  j ava2  s . c  o m*/
    return false;
}

From source file:nl.hnogames.domoticz.Preference.Preference.java

private void setPreferences() {
    final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference(
            "enableMultiServers");
    android.preference.Preference ServerSettings = findPreference("server_settings");
    android.preference.Preference PermissionsSettings = findPreference("permissionssettings");
    android.preference.Preference NotificationLogged = findPreference("notification_show_logs");
    android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config");
    android.preference.Preference resetApplication = findPreference("reset_settings");
    android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage");
    final android.preference.Preference registrationId = findPreference("notification_registration_id");
    android.preference.Preference GeoSettings = findPreference("geo_settings");
    android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference(
            "enableWearItems");
    android.preference.Preference NFCPreference = findPreference("nfc_settings");
    android.preference.Preference QRCodePreference = findPreference("qrcode_settings");
    android.preference.Preference SpeechPreference = findPreference("speech_settings");
    android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference(
            "enableNFC");
    android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference(
            "enableQRCode");
    android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference(
            "enableSpeech");
    android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference(
            "talkBack");
    MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference(
            "alwayson");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference(
            "settingsscreen");
    android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference(
            "premium_category");
    android.preference.Preference premiumPreference = findPreference("premium_settings");
    NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "suppressNotifications");
    NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "alarmNotifications");
    android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference(
            "darkTheme");
    android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings");
    android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference(
            "enableSecurity");

    if (!BuildConfig.DEBUG) {
        PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference(
                "androidautocategory");
        PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference(
                "notificationscreen");
        oNotificationScreen.removePreference(oAndroidAutoCategory);
    }//from w w  w.  ja va2 s. com

    List<String> notifications = mSharedPrefs.getReceivedNotifications();
    if (notifications == null || notifications.size() <= 0) {
        notificationsMultiSelectListPreference.setEnabled(false);
        alarmMultiSelectListPreference.setEnabled(false);
    } else {
        notificationsMultiSelectListPreference.setEnabled(true);
        alarmMultiSelectListPreference.setEnabled(true);
    }

    PermissionsSettings
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    permissionHelper.openSettingsScreen();
                    return true;
                }
            });

    drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
            try {
                final HashSet selectedDrawerItems = (HashSet) newValue;
                if (selectedDrawerItems.size() < 1) {
                    showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer));
                    return false;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }
    });

    ThemePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_theme));
                        return false;
                    } else {
                        ((SettingsActivity) getActivity()).reloadSettings();
                        return true;
                    }
                }
            });

    MultiServerPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.multi_server));
                        return false;
                    }
                    return true;
                }
            });

    ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (!MultiServerPreference.isChecked()) {
                Intent intent = new Intent(mContext, ServerSettingsActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(mContext, ServerListSettingsActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    FingerPrintSettingsPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                    return true;
                }
            });

    fetchServerConfig
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() {
                        @Override
                        public void onReceiveConfig(ConfigInfo settings) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_success));
                        }

                        @Override
                        public void onError(Exception error) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_failed));
                        }
                    }, null);
                    return true;
                }
            });

    displayLanguage
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    showRestartMessage();
                    return true;
                }
            });

    registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!PermissionsUtil.canAccessDeviceState(mContext)) {
                    permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS);
                } else {
                    pushGCMRegistrationIds();
                }
            } else {
                pushGCMRegistrationIds();
            }
            return true;
        }
    });

    GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.geofence));
                return false;
            } else {
                Intent intent = new Intent(mContext, GeoSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    EnableNFCPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_nfc));
                        return false;
                    }

                    if (NfcAdapter.getDefaultAdapter(mContext) == null) {
                        showSnackbar(mContext.getString(R.string.nfc_not_supported));
                        return false;
                    }
                    return true;
                }
            });

    EnableQRCodePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    }

                    return true;
                }
            });

    EnableSpeechPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    }
                    return true;
                }
            });

    EnableTalkBackPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_talk_back));
                        return false;
                    }
                    return true;
                }
            });

    NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.category_nfc));
                return false;
            } else {
                Intent intent = new Intent(mContext, NFCSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    QRCodePreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, QRCodeSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    SpeechPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, SpeechSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    WearPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_wear));
                        return false;
                    }
                    return true;
                }
            });

    AlwaysOnPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.always_on_title));
                        return false;
                    }
                    return true;
                }
            });

    NotificationLogged
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    //show dialog
                    List<String> logs = mSharedPrefs.getLoggedNotifications();
                    if (logs != null && logs.size() > 0) {
                        Collections.reverse(logs);
                        new MaterialDialog.Builder(mContext)
                                .title(mContext.getString(R.string.notification_show_title))
                                .items((CharSequence[]) logs.toArray(new String[0])).show();
                    } else
                        UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing),
                                Toast.LENGTH_LONG);
                    return true;
                }
            });

    //noinspection PointlessBooleanExpression
    if (!BuildConfig.LITE_VERSION) {
        preferenceScreen.removePreference(premiumCategory);
    } else {
        premiumPreference
                .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(android.preference.Preference preference) {
                        String packageID = mContext.getPackageName() + ".premium";
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + packageID)));
                        } catch (android.content.ActivityNotFoundException ignored) {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("https://play.google.com/store/apps/details?id=" + packageID)));
                        }

                        return true;
                    }
                });
    }

    resetApplication
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        new MaterialDialog.Builder(mContext).title(R.string.category_Reset)
                                .content(R.string.are_you_sure).positiveText(R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @SuppressLint("NewApi")
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE))
                                                .clearApplicationUserData();
                                    }
                                }).show();
                    } else {
                        startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
                    }
                    return true;
                }
            });

    FingerPrintPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @SuppressLint("NewApi")
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object o) {
                    if (mSharedPrefs.isStartupSecurityEnabled())
                        return true;
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_startup_security));
                        return false;
                    } else {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                            UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported),
                                    Toast.LENGTH_LONG);
                            return false;
                        }
                        if (!PermissionsUtil.canAccessFingerprint(mContext)) {
                            permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS);
                        } else {
                            FingerprintManager fingerprintManager = (FingerprintManager) mContext
                                    .getSystemService(Context.FINGERPRINT_SERVICE);
                            if (ActivityCompat.checkSelfPermission(mContext,
                                    Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                                return false;
                            }
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                if (!fingerprintManager.isHardwareDetected()) {
                                    return false;
                                } else if (!fingerprintManager.hasEnrolledFingerprints()) {
                                    UsefulBits.showSimpleToast(mContext,
                                            getString(R.string.fingerprint_not_setup_in_android),
                                            Toast.LENGTH_LONG);
                                    return false;
                                } else {
                                    new MaterialDialog.Builder(mContext)
                                            .title(R.string.category_startup_security)
                                            .content(R.string.fingerprint_sure).positiveText(R.string.ok)
                                            .negativeText(R.string.cancel)
                                            .onPositive(new MaterialDialog.SingleButtonCallback() {
                                                @Override
                                                public void onClick(@NonNull MaterialDialog dialog,
                                                        @NonNull DialogAction which) {
                                                    mSharedPrefs.setStartupSecurityEnabled(true);
                                                    ((SettingsActivity) getActivity()).reloadSettings();
                                                }
                                            }).show();

                                    return false;
                                }
                            }
                        }
                    }
                    return false;
                }
            });
}