Exemplo n.º 1
0
 private String readUpdateStatus(File statusFile) {
   String status = "";
   try {
     BufferedReader reader = new BufferedReader(new FileReader(statusFile));
     status = reader.readLine();
     reader.close();
   } catch (Exception e) {
     Log.i(LOG_FILE_NAME, "error reading update status", e);
   }
   return status;
 }
Exemplo n.º 2
0
 void removeFiles() throws IOException {
   BufferedReader reader = new BufferedReader(new FileReader(new File(sGREDir, "removed-files")));
   try {
     for (String removedFileName = reader.readLine();
         removedFileName != null;
         removedFileName = reader.readLine()) {
       File removedFile = new File(sGREDir, removedFileName);
       if (removedFile.exists()) removedFile.delete();
     }
   } finally {
     reader.close();
   }
 }
Exemplo n.º 3
0
    @Override
    protected String doInBackground(String... params) {
      Context context = getApplicationContext();
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

      String serviceUrlString = prefs.getString("connection.url", null);
      if (serviceUrlString != null) {
        if (!serviceUrlString.endsWith("/")) serviceUrlString += "/";

        Command command = new Command();
        command.actionName = params[0];

        Gson gson = new Gson();
        String commandContent = gson.toJson(command);

        HttpPost executePost = new HttpPost(serviceUrlString + "action/execute");
        BasicHttpEntity httpEntity = new BasicHttpEntity();
        httpEntity.setContentType("application/json");
        try {
          httpEntity.setContent(new ByteArrayInputStream(commandContent.getBytes("UTF-8")));
        } catch (UnsupportedEncodingException e) {
          throw new RuntimeException(e);
        }

        executePost.setEntity(httpEntity);
        HttpClient client = new DefaultHttpClient();

        try {
          HttpResponse executeResult = client.execute(executePost);
          if (executeResult.getStatusLine().getStatusCode() == HTTP_STATUS_OK) {
            InputStream content = executeResult.getEntity().getContent();

            // Get the response
            BufferedReader rd = new BufferedReader(new InputStreamReader(content));
            StringBuilder contentBuilder = new StringBuilder();

            String line;
            while ((line = rd.readLine()) != null) {
              contentBuilder.append(line).append("\n");
            }

            Result result = gson.fromJson(contentBuilder.toString(), Result.class);
            return result.message;
          }
        } catch (IOException e) {
          return null;
        }
      }
      return null;
    }
Exemplo n.º 4
0
 public String getClasses() {
   String name = "";
   try {
     URL site = new URL("http://www.marksonvisuals.com/sitapp/cc.php");
     URLConnection yc = site.openConnection();
     BufferedReader out = new BufferedReader(new InputStreamReader(yc.getInputStream()));
     String inputLine;
     while ((inputLine = out.readLine()) != null) {
       name += inputLine + "\n";
     }
     out.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return name.trim();
 }
Exemplo n.º 5
0
    @Override
    protected String doInBackground(Void... params) {
      Context context = getApplicationContext();
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

      String serviceUrlString = prefs.getString("connection.url", null);
      if (serviceUrlString != null) {
        if (!serviceUrlString.endsWith("/")) serviceUrlString += "/";

        HttpPost statusPost = new HttpPost(serviceUrlString + "action/status");
        HttpClient client = new DefaultHttpClient();

        try {
          HttpResponse statusResult = client.execute(statusPost);
          if (statusResult.getStatusLine().getStatusCode() == HTTP_STATUS_OK) {
            InputStream content = statusResult.getEntity().getContent();

            // Get the response
            BufferedReader rd = new BufferedReader(new InputStreamReader(content));
            StringBuilder contentBuilder = new StringBuilder();

            String line;
            while ((line = rd.readLine()) != null) {
              contentBuilder.append(line).append("\n");
            }
            Gson gson = new Gson();

            Result result = gson.fromJson(contentBuilder.toString(), Result.class);
            return result.message;
          }
        } catch (IOException e) {
          return null;
        }
      }
      return null;
    }
Exemplo n.º 6
0
    @Override
    protected List<Action> doInBackground(Void... params) {
      Context context = getApplicationContext();
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

      String serviceUrlString = prefs.getString("connection.url", null);
      if (serviceUrlString != null) {
        if (!serviceUrlString.endsWith("/")) serviceUrlString += "/";
        HttpGet listGet = new HttpGet(serviceUrlString + "action/list");
        HttpClient client = new DefaultHttpClient();
        try {
          HttpResponse listResponse = client.execute(listGet);
          if (listResponse.getStatusLine().getStatusCode() == HTTP_STATUS_OK) {
            InputStream content = listResponse.getEntity().getContent();

            // Get the response
            BufferedReader rd = new BufferedReader(new InputStreamReader(content));
            StringBuilder contentBuilder = new StringBuilder();

            String line;
            while ((line = rd.readLine()) != null) {
              contentBuilder.append(line).append("\n");
            }

            Type listType = new TypeToken<ArrayList<Action>>() {}.getType();

            Gson gson = new Gson();

            return gson.fromJson(contentBuilder.toString(), listType);
          }
        } catch (IOException e) {
          return null;
        }
      }
      return null;
    }
Exemplo n.º 7
0
  public void nextLevel() {
    boolean loaded = false;
    final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard);
    this.level++;

    AssetManager am = getResources().getAssets();

    try {
      List<String> allTutoLevels =
          new LinkedList<String>(Arrays.asList(am.list("levels/tutorial")));

      // if(addMsg){
      //    allTutoLevels.addAll(Arrays.asList(am.list("msg")));
      // }

      Log.d(TAG, allTutoLevels.toString());

      for (String name : allTutoLevels) {
        if (name.startsWith(this.level + ".")) {
          BufferedReader br =
              new BufferedReader(new InputStreamReader(am.open("levels/tutorial/" + name)));
          String line;
          String levelJSON = "";

          while ((line = br.readLine()) != null) {
            levelJSON += line + "\n";
          }

          br.close();

          game.initGame(
              levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
          loaded = true;
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    if (!loaded) {
      Random r = new Random();

      List<String> allLevels = new ArrayList<>();

      try {
        allLevels = Arrays.asList(am.list("levels"));
      } catch (IOException e) {
      }

      if (r.nextBoolean() && !allLevels.isEmpty() && allLevels.size() != allDoneLevels.size()) {
        try {
          int nLevel;
          do {
            nLevel = r.nextInt(allLevels.size());
          } while (allDoneLevels.contains(allLevels.get(nLevel)));

          String name = allLevels.get(nLevel);
          BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/" + name)));

          String line;
          String levelJSON = "";

          while ((line = br.readLine()) != null) {
            levelJSON += line + "\n";
          }

          br.close();

          allDoneLevels.add(name);

          game.initGame(
              levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
        } catch (IOException e) {
          this.game.initGame(
              level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
        }
      } else {
        this.game.initGame(
            level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60);
      }
    }

    // am.close();

    boardView.setGame(this.game);
    boardView.invalidate();
    boardView.getHowdyShadeView().invalidate();

    Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show();

    Log.i(
        TAG,
        "Max tiles : "
            + (boardView.getMeasuredWidth() / 60) * (boardView.getMeasuredHeight() / 60));
  }