Ejemplo n.º 1
0
 private void optionSwitchTheme() {
   String sTheme = XRestriction.getSetting(null, this, XRestriction.cSettingTheme, null, false);
   int themeId = (sTheme == null ? android.R.style.Theme_Holo_Light : Integer.parseInt(sTheme));
   if (themeId == android.R.style.Theme_Holo_Light)
     XRestriction.setSetting(
         null, this, XRestriction.cSettingTheme, Integer.toString(android.R.style.Theme_Holo));
   else
     XRestriction.setSetting(
         null,
         this,
         XRestriction.cSettingTheme,
         Integer.toString(android.R.style.Theme_Holo_Light));
   this.recreate();
 }
Ejemplo n.º 2
0
    @Override
    protected String doInBackground(File... params) {
      mFile = params[0];
      try {
        // Read XML
        FileInputStream fis = new FileInputStream(mFile);
        InputStreamReader isr = new InputStreamReader(fis);
        char[] inputBuffer = new char[fis.available()];
        isr.read(inputBuffer);
        String xml = new String(inputBuffer);
        isr.close();
        fis.close();

        // Prepare XML document
        InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document dom = db.parse(is);
        dom.getDocumentElement().normalize();

        // Process settings
        publishProgress(getString(R.string.menu_settings));
        NodeList sItems = dom.getElementsByTagName("Setting");
        for (int i = 0; i < sItems.getLength(); i++) {
          // Process package restriction
          Node entry = sItems.item(i);
          NamedNodeMap attrs = entry.getAttributes();
          String setting = attrs.getNamedItem("Name").getNodeValue();
          String value = attrs.getNamedItem("Value").getNodeValue();
          XRestriction.setSetting(null, ActivityMain.this, setting, value);
        }

        // Process restrictions
        Map<String, Map<String, List<String>>> mapPackage =
            new HashMap<String, Map<String, List<String>>>();
        NodeList rItems = dom.getElementsByTagName("Package");
        for (int i = 0; i < rItems.getLength(); i++) {
          // Process package restriction
          Node entry = rItems.item(i);
          NamedNodeMap attrs = entry.getAttributes();
          String packageName = attrs.getNamedItem("Name").getNodeValue();
          String restrictionName = attrs.getNamedItem("Restriction").getNodeValue();
          String methodName =
              (attrs.getNamedItem("Method") == null
                  ? null
                  : attrs.getNamedItem("Method").getNodeValue());

          // Map package restriction
          if (!mapPackage.containsKey(packageName))
            mapPackage.put(packageName, new HashMap<String, List<String>>());
          if (!mapPackage.get(packageName).containsKey(restrictionName))
            mapPackage.get(packageName).put(restrictionName, new ArrayList<String>());
          if (methodName != null) mapPackage.get(packageName).get(restrictionName).add(methodName);
        }

        // Process result
        for (String packageName : mapPackage.keySet()) {
          try {
            publishProgress(packageName);

            // Get uid
            int uid = getPackageManager().getPackageInfo(packageName, 0).applicationInfo.uid;

            // Reset existing restrictions
            XRestriction.deleteRestrictions(ActivityMain.this, uid);

            // Set imported restrictions
            for (String restrictionName : mapPackage.get(packageName).keySet()) {
              XRestriction.setRestricted(null, ActivityMain.this, uid, restrictionName, null, true);
              for (String methodName : mapPackage.get(packageName).get(restrictionName))
                XRestriction.setRestricted(
                    null, ActivityMain.this, uid, restrictionName, methodName, false);
            }
          } catch (NameNotFoundException ex) {
            XUtil.log(null, Log.WARN, "Not found package=" + packageName);
          }
        }

        // Display message
        return getString(R.string.msg_done);
      } catch (Throwable ex) {
        XUtil.bug(null, ex);
        return ex.toString();
      }
    }