/**
  * Initialize unread number by querying system settings provider.
  *
  * @param context
  */
 private void initUnreadNumberFromSystem() {
   final ContentResolver cr = mContext.getContentResolver();
   final int shortcutsNum = sUnreadSupportShortcutsNum;
   UnreadSupportShortcut shortcut = null;
   for (int i = 0; i < shortcutsNum; i++) {
     shortcut = UNREAD_SUPPORT_SHORTCUTS.get(i);
     try {
       shortcut.mUnreadNum = android.provider.Settings.System.getInt(cr, shortcut.mKey);
       if (LauncherLog.DEBUG_UNREAD) {
         LauncherLog.d(
             TAG,
             "initUnreadNumberFromSystem: key = "
                 + shortcut.mKey
                 + ", unreadNum = "
                 + shortcut.mUnreadNum);
       }
     } catch (android.provider.Settings.SettingNotFoundException e) {
       LauncherLog.e(
           TAG,
           "initUnreadNumberFromSystem SettingNotFoundException key = "
               + shortcut.mKey
               + ", e = "
               + e.getMessage());
     }
   }
   if (LauncherLog.DEBUG_UNREAD) {
     LauncherLog.d(TAG, "initUnreadNumberFromSystem end:" + getUnreadSupportShortcutInfo());
   }
 }
Exemple #2
0
 /**
  * Get GPS location mode
  *
  * @param context Context
  * @return location mode from Settings.Secure
  */
 public static int getLocationMode(Context context) { // TODO : display dialog
   try {
     return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
   } catch (Settings.SettingNotFoundException e) {
     e.printStackTrace();
   }
   return 0;
 }
  /** to get the state of isAutoBrightness */
  public static boolean isAutoBrightness(Activity activity) {
    ContentResolver aContentResolver = activity.getContentResolver();
    boolean automicBrightness = false;
    try {

      automicBrightness =
          Settings.System.getInt(aContentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE)
              == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
    } catch (Settings.SettingNotFoundException e) {
      e.printStackTrace();
    }
    return automicBrightness;
  }
  /**
   * Check whether notification listener accessibility service is enabled for the specified context
   * and the specified service class name
   *
   * <p>solution taken from http://stackoverflow.com/a/5106419/527759
   *
   * @param context
   * @param serviceClass
   * @return
   */
  public static boolean isServiceEnabled(Context context, Class<?> serviceClass) {
    int accessibilityEnabled = 0;
    final String ACCESSIBILITY_SERVICE_NAME =
        context.getPackageName() + "/" + serviceClass.getName();
    boolean accessibilityFound = false;
    try {
      accessibilityEnabled =
          Settings.Secure.getInt(
              context.getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
      Timber.d("isServiceEnabled: ACCESSIBILITY: " + accessibilityEnabled);
    } catch (Settings.SettingNotFoundException e) {
      Timber.d(
          "isServiceEnabled: Error finding setting, default accessibility to not found: "
              + e.getMessage());
    }

    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
      Timber.d("isServiceEnabled: ***ACCESSIBILIY IS ENABLED***: ");

      String settingValue =
          Settings.Secure.getString(
              context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
      Timber.d("Setting: " + settingValue);
      if (settingValue != null) {
        TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
        splitter.setString(settingValue);
        while (splitter.hasNext()) {
          String accessabilityService = splitter.next();
          Timber.d("isServiceEnabled: Setting: " + accessabilityService);
          if (accessabilityService.equalsIgnoreCase(ACCESSIBILITY_SERVICE_NAME)) {
            Timber.d(
                "isServiceEnabled: We've found the correct setting - accessibility is switched on!");
            return true;
          }
        }
      }

      Timber.d("isServiceEnabled: ***END***");
    } else {
      Timber.d("isServiceEnabled: ***ACCESSIBILIY IS DISABLED***");
    }
    return accessibilityFound;
  }
  public static boolean IsAutoBrightness(Context context) {

    boolean IsAutoBrightness = false;

    try {

      IsAutoBrightness =
          Settings.System.getInt(
                  context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE)
              == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;

    } catch (Settings.SettingNotFoundException e) {

      e.printStackTrace();
    }

    return IsAutoBrightness;
  }
Exemple #6
0
  /**
   * Check if Accessibility Service is enabled.
   *
   * @param mContext
   * @return <code>true</code> if Accessibility Service is ON, otherwise <code>false</code>
   */
  public static boolean isAccessibilitySettingsOn(Context mContext) {
    int accessibilityEnabled = 0;

    final String service =
        mContext.getPackageName() + "/com.mytest.accessibility.MyAccessibilityService";

    boolean accessibilityFound = false;
    try {
      accessibilityEnabled =
          Settings.Secure.getInt(
              mContext.getApplicationContext().getContentResolver(),
              Settings.Secure.ACCESSIBILITY_ENABLED);
      Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
    } catch (Settings.SettingNotFoundException e) {
      Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
      Log.v(TAG, "***ACCESSIBILIY IS ENABLED*** -----------------");
      String settingValue =
          Settings.Secure.getString(
              mContext.getApplicationContext().getContentResolver(),
              Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
      if (settingValue != null) {
        TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
        splitter.setString(settingValue);
        while (splitter.hasNext()) {
          String accessabilityService = splitter.next();

          Log.v(TAG, "-------------- > accessabilityService :: " + accessabilityService);
          if (accessabilityService.equalsIgnoreCase(service)) {
            Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
            return true;
          }
        }
      }
    } else {
      Log.v(TAG, "***ACCESSIBILIY IS DISABLED***");
    }

    return accessibilityFound;
  }
  public static boolean isLocationEnabled(Context context) {
    int locationMode = 0;
    String locationProviders;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      try {
        locationMode =
            Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);

      } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
      }

      return locationMode != Settings.Secure.LOCATION_MODE_OFF;

    } else {
      locationProviders =
          Settings.Secure.getString(
              context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
      return !TextUtils.isEmpty(locationProviders);
    }
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Crate notification
    int rotationState = RotationSwitchAppConstant.ROTATION_STATE_ON;
    try {
      if (Settings.System.getInt(this.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION)
          == 1) {
        rotationState = RotationSwitchAppConstant.ROTATION_STATE_ON;
      } else {
        rotationState = RotationSwitchAppConstant.ROTATION_STATE_OFF;
      }
    } catch (Settings.SettingNotFoundException e) {
      Log.e(TAG, "###  Settings: ACCELEROMETER_ROTATION not found.");
      e.printStackTrace();
    }

    mNotification = RotationSwitchAppHelper.generateNotification(this, rotationState);

    mNotiManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Button btnStart = (Button) findViewById(R.id.btn_start_notification);
    btnStart.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View view) {
            mNotiManager.notify(RotationSwitchAppConstant.ROTATION_SWITCH_NOTI_ID, mNotification);
            Intent intent = new Intent();
            intent.setClass(RotationSwitchActivity.this, RotationSwitchService.class);
            startService(intent);
            Toast toast =
                Toast.makeText(
                    getApplicationContext(), "Switch is added to status bar", Toast.LENGTH_LONG);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
          }
        });

    Button btnFinish = (Button) findViewById(R.id.btn_finish_notification);
    btnFinish.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View view) {
            mNotiManager.cancel(RotationSwitchAppConstant.ROTATION_SWITCH_NOTI_ID);
            Intent intent = new Intent();
            intent.setClass(RotationSwitchActivity.this, RotationSwitchService.class);
            stopService(intent);
            Toast toast =
                Toast.makeText(
                    getApplicationContext(),
                    "Switch is removed from status bar",
                    Toast.LENGTH_LONG);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
          }
        });
  }