예제 #1
0
  public static boolean copyAssetToFile(String src, String tgt) {
    try {
      FileOutputStream oTGT = new FileOutputStream(tgt);
      InputStream oSRC = OMWPP.AM.open(src);

      byte[] buffer = new byte[8192];
      int iBytesRead = 0;
      while ((iBytesRead = oSRC.read(buffer)) != -1) {
        oTGT.write(buffer, 0, iBytesRead);
      }
      oTGT.close();
      oSRC.close();
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
예제 #2
0
  @Override
  public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    CONTEXT = this.getApplicationContext();
    AM = this.getAssets();

    try {
      PLACEHOLDERBMP = BitmapFactory.decodeStream(AM.open("transparent.png"));
    } catch (IOException e) {
      e.printStackTrace();
    }

    WPM = WallpaperManager.getInstance(this);
    PREFS = PreferenceManager.getDefaultSharedPreferences(OMWPP.CONTEXT);

    BMPQUERYOPTIONS = new BitmapFactory.Options();
    BMPQUERYOPTIONS.inJustDecodeBounds = true;

    BMPVALIDOPTIONS = new BitmapFactory.Options();
    BMPVALIDOPTIONS.inSampleSize = 4;

    BMPAPPLYOPTIONS = new BitmapFactory.Options();
    BMPAPPLYOPTIONS.inSampleSize = 1;
    BMPAPPLYOPTIONS.inScaled = false;
    BMPAPPLYOPTIONS.inDither = false;
    BMPAPPLYOPTIONS.inPreferredConfig = Config.ARGB_8888;

    // Initialize the four queues.
    THUMBNAILQUEUE = new ConcurrentLinkedQueue<File>();
    DOWNLOADQUEUE = new ArrayBlockingQueue<URL>(20, false);
    UNZIPQUEUE = new ArrayBlockingQueue<File>(20, false);

    SCREENWIDTH = getResources().getDisplayMetrics().widthPixels;
    SCREENHEIGHT = getResources().getDisplayMetrics().heightPixels;

    WPWIDTH = WPM.getDesiredMinimumWidth();
    WPHEIGHT = WPM.getDesiredMinimumHeight();
    if (WPWIDTH < SCREENWIDTH * 2) WPWIDTH = SCREENWIDTH * 2;
    if (WPHEIGHT < SCREENHEIGHT) WPHEIGHT = SCREENHEIGHT;
    if (OMWPP.DEBUG) Log.i("OMWPPApp", "Target Width is" + WPWIDTH);
    if (OMWPP.DEBUG) Log.i("OMWPPApp", "Target Height is " + WPHEIGHT);

    try {
      ENDMARKER_URL = new URL("http://localhost");
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (isSDPresent()) {
      // Check and/or create the wallpapers directory.
      SDROOT = new File(Environment.getExternalStorageDirectory().getPath() + "/ubuntuwps/");
      if (OMWPP.DEBUG) Log.i("OMWPPApp", "Checking/Creating " + SDROOT.getAbsoluteFile());
      SDROOT.mkdirs();
      THUMBNAILROOT = getExternalFilesDir(null);
      if (OMWPP.DEBUG) Log.i("OMWPPApp", "Checking/Creating " + THUMBNAILROOT.getAbsoluteFile());
      THUMBNAILROOT.mkdirs();
      File nomedia = new File(THUMBNAILROOT.getAbsolutePath() + "/.nomedia");
      try {
        if (!nomedia.exists()) nomedia.createNewFile();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    // First of all, let's load up the latest configuration JSON file.
    try {
      if (isSDPresent()) {
        if (OMWPP.DEBUG) Log.i("OMWPPApp", "Loading config file from TN folder");
        CONFIGJSON =
            streamToJSONObject(
                new FileInputStream(new File(THUMBNAILROOT.getPath() + "/omwpp_config.json")));
      } else {
        if (OMWPP.DEBUG) Log.i("OMWPPApp", "No config file in TN folder");
        throw new Exception();
      }
    } catch (Exception e) {
      try {
        if (OMWPP.DEBUG) Log.i("OMWPPApp", "Copying default files to Wallpaper folder");
        copyAssetToFile("omwpp_config.json", THUMBNAILROOT.getPath() + "/omwpp_config.json");
        CONFIGJSON =
            streamToJSONObject(
                new FileInputStream(new File(THUMBNAILROOT.getPath() + "/omwpp_config.json")));
        CONFIGJSON.putOpt("localpaths", new JSONArray("[\"" + SDROOT.toString() + "\"]"));
        commitJSONChanges();

        try {
          for (String sFile : OMWPP.AM.list("")) {
            copyAssetToFile(sFile, SDROOT.getPath() + "/" + sFile);
          }
        } catch (Exception ee) {
          ee.printStackTrace();
        }
      } catch (Exception ee) {
        e.printStackTrace();
      }
    }

    // Figure out when we last downloaded a new config file.
    LASTCONFIGREFRESH = OMWPP.PREFS.getLong("LASTCONFIGREFRESH", 0l);
  }