private int createProgram(final String vertexSource, final String fragmentSource) { final int vertexShader = this.loadShader(GLES20.GL_VERTEX_SHADER, vertexSource); if (vertexShader == 0) { return 0; } final int pixelShader = this.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); if (pixelShader == 0) { return 0; } int program = GLES20.glCreateProgram(); if (program != 0) { GLES20.glAttachShader(program, vertexShader); this.checkGlError("glAttachShader"); GLES20.glAttachShader(program, pixelShader); this.checkGlError("glAttachShader"); GLES20.glLinkProgram(program); final int[] linkStatus = {0}; GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0); if (linkStatus[0] != 1) { Log.e("DistortionRenderer", "Could not link program: "); Log.e("DistortionRenderer", GLES20.glGetProgramInfoLog(program)); GLES20.glDeleteProgram(program); program = 0; } } return program; }
public int[] readProgress() { int progress[] = new int[2]; try { DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(resume_file))); progress[0] = in.readInt(); progress[1] = in.readInt(); in.close(); } catch (FileNotFoundException e) { Log.e(TAG, "readProgress file not found."); } catch (IOException e) { Log.e(TAG, e.getMessage()); } return progress; }
public synchronized void writeProgress(int current_file, int total_files) { try { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(resume_file, false))); out.writeInt(current_file); out.writeInt(total_files); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); Log.e(TAG, "writeProgress resume.txt not found."); } catch (IOException ex) { Log.e(TAG, "Unable to create resume.txt."); } }
private int loadShader(final int shaderType, final String source) { int shader = GLES20.glCreateShader(shaderType); if (shader != 0) { GLES20.glShaderSource(shader, source); GLES20.glCompileShader(shader); final int[] compiled = {0}; GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == 0) { Log.e( "DistortionRenderer", new StringBuilder(37) .append("Could not compile shader ") .append(shaderType) .append(":") .toString()); Log.e("DistortionRenderer", GLES20.glGetShaderInfoLog(shader)); GLES20.glDeleteShader(shader); shader = 0; } } return shader; }
private void checkGlError(final String op) { final int error; if ((error = GLES20.glGetError()) != 0) { final String s = "DistortionRenderer"; final String value = String.valueOf(String.valueOf(op)); Log.e( s, new StringBuilder(21 + value.length()) .append(value) .append(": glError ") .append(error) .toString()); final String value2 = String.valueOf(String.valueOf(op)); throw new RuntimeException( new StringBuilder(21 + value2.length()) .append(value2) .append(": glError ") .append(error) .toString()); } }
@Override public void onComplete(String response, Object state) { try { Log.i(TAG, response); json = Util.parseJson(response); // photos are in the form of a json array child = json.getJSONArray("data"); int total = child.length(); // contains links to photos links = new ArrayList<String>(total); // adds link to each photo to our list after replacing the "https" from url // DownloadManager does not support https in gingerbread for (int i = 0; i < total; i++) { photo_json = child.getJSONObject(i); if (dl_high_res_pics) { JSONArray image_set = photo_json.getJSONArray("images"); // highest resolution picture has the index zero in the images jsonarray JSONObject highest_res_pic = image_set.getJSONObject(0); String http_replaced = highest_res_pic.getString("source").replaceFirst("https", "http"); links.add(i, http_replaced); } else { // source property of the json object points to the photo's link String http_replaced = photo_json.getString("source").replaceFirst("https", "http"); links.add(i, http_replaced); } } download_photos.this.runOnUiThread( new Runnable() { public void run() { // mytask = new DownloadImageTask(); // mytask.execute(links); // start downloading using asynctask // new DownloadImageTask().execute(links); // downloadThread.setPath(path); // downloadThread.setWholeTasks(links.size()); if (resume_file.exists()) { initial_value = readProgress()[0]; final_value = links.size(); // case if the task is already completed if (initial_value == final_value) { completed = true; resume_pause.setVisibility(View.GONE); progress_download.setMax(final_value); progress_download.setProgress(0); // bug in progress bar progress_download.setProgress(initial_value); progress_text.setText("Completed."); mtext.setText( getText(R.string.download_textview_message_1) + " " + path.toString() + ". "); } // case if some of the photos are already downloaded else { progress_download.setMax(links.size()); // progress_download.setProgress(0); //bug in progress bar progress_download.setProgress(initial_value); // N.B if i= initial_value -1, then one image will be downloaded again. so to // save cost we start with i = initial_value for (int i = initial_value; i < links.size(); i++) { mtext.setText( getText(R.string.download_textview_message_1) + " " + path.toString() + ". "); // downloadThread.setRunningTask(i + 1); downloadThread.enqueueDownload( new DownloadTask( links.get(i), path, i + 1, final_value, download_photos.this)); } } } // case if the task is entirely new task else { for (int i = 0; i < links.size(); i++) { mtext.setText( getText(R.string.download_textview_message_1) + " " + path.toString() + ". "); // downloadThread.setRunningTask(i + 1); downloadThread.enqueueDownload( new DownloadTask( links.get(i), path, i + 1, links.size(), download_photos.this)); } } } }); } catch (JSONException ex) { Log.e(TAG, "JSONEXception : " + ex.getMessage()); } }