List of usage examples for java.lang ArrayIndexOutOfBoundsException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String args[]) { try {/* www .j a v a 2 s . c om*/ int c[] = { 1 }; c[42] = 99; } catch (ArrayIndexOutOfBoundsException e) { System.out.println("array index oob: " + e); e.printStackTrace(); } catch (ArithmeticException e) { System.out.println("div by 0: " + e); e.printStackTrace(); } }
From source file:se.liu.imt.SCT.SCTPostCoordTest.java
/** * @param args//from www .ja v a 2 s.co m * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws ConfigurationException * @throws IOException * @throws OWLException */ public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, ConfigurationException, OWLException { PropertyConfigurator.configure("log4j.properties"); Configuration config = null; try { String configFileName = args[0]; config = new XMLConfiguration(configFileName); } catch (ArrayIndexOutOfBoundsException e) { System.err.println("Requires configuration file argument"); System.exit(-1); } final long maxTime = 1000 * 60 * 60 * config.getInt("test_parameters.max_time"); log.debug("Starting test SNOMED CT post-coordination..."); // creating ontology manager and loading of SNOMED CT stated form OWL // file OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLDataFactory dataFactory = manager.getOWLDataFactory(); final String snomedFileName = config.getString("snomed.OWL_file"); log.debug("Loading ontology file: " + snomedFileName); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(snomedFileName)); log.debug("Loaded " + ontology.getOntologyID()); // create the reasoner final String classifierName = config.getString("classifier.name"); log.debug("Classifier name: " + classifierName); OWLReasonerFactory reasonerFactory = null; OWLReasoner reasoner = null; final String reasonerFactoryClassName = config.getString("classifier.reasoner_factory"); log.debug("Reasoner factory class: " + reasonerFactoryClassName); if (classifierName.equalsIgnoreCase("hermit")) { reasonerFactory = new org.semanticweb.HermiT.Reasoner.ReasonerFactory(); } else reasonerFactory = (OWLReasonerFactory) Class.forName(reasonerFactoryClassName).newInstance(); reasoner = reasonerFactory.createReasoner(ontology); log.debug("Created reasoner"); // SNOMED CT IRI string final String SNOMED_IRI = "http://snomed.info/id/"; // create input file reader BufferedReader in = null; FileWriter out = null; try { final String inputFileName = config.getString("test_parameters.input"); log.debug("Input file name: " + inputFileName); in = new BufferedReader(new FileReader(inputFileName)); // read past header line in.readLine(); // create output file final String outputFileName = config.getString("output.file_name_tag"); out = new FileWriter(outputFileName + "_" + classifierName + "_" + (new Date()).toString()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // get current size in terms of class axioms int currentSize = ontology.getAxiomCount(AxiomType.SUBCLASS_OF) + ontology.getAxiomCount(AxiomType.EQUIVALENT_CLASSES); final int iterations = config.getInt("test_parameters.iterations"); final int jumpSize = config.getInt("test_parameters.jump_size"); final int tries = config.getInt("test_parameters.tries"); log.debug("Iterations: " + iterations + ", Jump size: " + jumpSize + ", Tries: " + tries); long startTime = System.currentTimeMillis(); // outer loop for iterations for (int i = 0; i <= iterations; i++) { // break if 24 hours has passed if (System.currentTimeMillis() - startTime > maxTime) { log.debug("Ending because time limit has been reached"); break; } log.info("Current size: " + currentSize); long minTime = Long.MAX_VALUE; for (int j = 0; j < tries; j++) { long t1 = System.currentTimeMillis(); // Ask the reasoner to do all the necessary work now log.debug("Start classifying..."); reasoner.precomputeInferences(org.semanticweb.owlapi.reasoner.InferenceType.CLASS_HIERARCHY); reasoner.flush(); // Do special things for special reasoners if (classifierName.equalsIgnoreCase("elk")) { // nothing special } else if (classifierName.equalsIgnoreCase("snorocket")) { //SnorocketOWLReasoner r = (SnorocketOWLReasoner) reasoner; //r.synchronizeSnorocket(); } else if (classifierName.equalsIgnoreCase("fact++")) { // nothing special } else if (classifierName.equalsIgnoreCase("hermit")) { // nothing special } log.debug("Finished classifying"); long time = System.currentTimeMillis() - t1; if (time < minTime) minTime = time; log.debug("Finished try: " + (j + 1) + ", Time; " + time); } log.debug("Finished classifying, Time: " + minTime); out.write("" + currentSize + "\t" + minTime + "\n"); out.flush(); log.debug("Adding stuff..."); if (i < iterations) // add post-coordinated expressions for (int j = 0; j < jumpSize; j++) { String line = in.readLine(); if (line == null) break; String[] comp = line.split("\t"); OWLClass new_pc_concept = dataFactory.getOWLClass(IRI.create("exp" + (i * jumpSize) + j)); String baseConcept = comp[0]; String bodyStructure = comp[1]; String morphology = comp[2]; OWLClass baseConceptClass = dataFactory.getOWLClass(IRI.create(SNOMED_IRI + baseConcept)); OWLClass bodyStructureClass = dataFactory.getOWLClass(IRI.create(SNOMED_IRI + bodyStructure)); OWLClass morphologyClass = dataFactory.getOWLClass(IRI.create(SNOMED_IRI + morphology)); OWLObjectProperty roleGroupProp = dataFactory .getOWLObjectProperty(IRI.create(SNOMED_IRI + "609096000")); OWLObjectProperty findingSiteProp = dataFactory .getOWLObjectProperty(IRI.create(SNOMED_IRI + "363698007")); OWLObjectProperty morphologyProp = dataFactory .getOWLObjectProperty(IRI.create(SNOMED_IRI + "116676008")); Set<OWLClassExpression> conceptSet = new HashSet<OWLClassExpression>(); conceptSet.add(dataFactory.getOWLObjectSomeValuesFrom(findingSiteProp, bodyStructureClass)); conceptSet.add(dataFactory.getOWLObjectSomeValuesFrom(morphologyProp, morphologyClass)); OWLClassExpression expr = dataFactory.getOWLObjectIntersectionOf(baseConceptClass, dataFactory.getOWLObjectSomeValuesFrom(roleGroupProp, dataFactory.getOWLObjectIntersectionOf(conceptSet))); manager.applyChange( new AddAxiom(ontology, dataFactory.getOWLEquivalentClassesAxiom(new_pc_concept, expr))); } currentSize += jumpSize; } out.close(); log.debug("Finished test hopefully successfully"); }
From source file:org.javaweb.utils.HexUtils.java
/** * Hexdump ??ASCII?/*from w ww . j a va 2s . com*/ * * @param data * @return */ public static byte[] hexDump(byte[] data) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { HexDump.dump(data, data.length, baos, 0); } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return baos.toByteArray(); }
From source file:de.j4velin.mapsmeasure.Util.java
/** * Replaces the current points on the map with the one from the provided * file//from w w w . j a v a2s.c o m * * @param f * the file to read from * @param m * the Map activity to add the new points to * @throws IOException */ static void loadFromFile(final Uri f, final Map m) throws IOException { List<LatLng> list = new LinkedList<LatLng>(); BufferedReader in = new BufferedReader(new InputStreamReader(m.getContentResolver().openInputStream(f))); String line; String[] data; while ((line = in.readLine()) != null) { data = line.split(";"); try { list.add(new LatLng(Double.parseDouble(data[0]), Double.parseDouble(data[1]))); } catch (NumberFormatException nfe) { // should not happen when opening a valid file nfe.printStackTrace(); } catch (ArrayIndexOutOfBoundsException aiabe) { // should not happen when opening a valid file aiabe.printStackTrace(); } } in.close(); m.clear(); for (int i = 0; i < list.size(); i++) { m.addPoint(list.get(i)); } }
From source file:com.normsstuff.maps4norm.Util.java
/** * Replaces the current points on the map with the one from the provided * file// w ww. j av a 2s.c o m * * @param f the file to read from * @param m the Map activity to add the new points to * @throws IOException */ static List<LatLng> loadFromFile(final Uri f, final MyMapActivity m) throws IOException { List<LatLng> list = new LinkedList<LatLng>(); BufferedReader in = new BufferedReader(new InputStreamReader(m.getContentResolver().openInputStream(f))); String line; String[] data; while ((line = in.readLine()) != null) { data = line.split(";"); try { list.add(new LatLng(Double.parseDouble(data[0]), Double.parseDouble(data[1]))); } catch (NumberFormatException nfe) { // should not happen when opening a valid file nfe.printStackTrace(); } catch (ArrayIndexOutOfBoundsException aiabe) { // should not happen when opening a valid file aiabe.printStackTrace(); } } in.close(); return list; /* m.clearDM(); for (int i = 0; i < list.size(); i++) { m.addPoint(list.get(i)); } */ }
From source file:StatFunctions.java
public static double cov(Univariate x, Univariate y) { double sumxy = 0; int i, n = (x.size() >= y.size() ? x.size() : y.size()); try {// w w w . j av a 2 s. c o m for (i = 0; i < x.size(); i++) sumxy += (x.elementAt(i) - x.mean()) * (y.elementAt(i) - y.mean()); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("size of x != size of y"); e.printStackTrace(); } return (sumxy / (n - 1)); }
From source file:com.xperia64.timidityae.Globals.java
public static boolean initialize(final Activity a) { if (firstRun) { final File rootStorage = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/TimidityAE/"); if (!rootStorage.exists()) { rootStorage.mkdir();//w w w. j a va2s . com } File playlistDir = new File(rootStorage.getAbsolutePath() + "/playlists/"); if (!playlistDir.exists()) { playlistDir.mkdir(); } File tcfgDir = new File(rootStorage.getAbsolutePath() + "/timidity/"); if (!tcfgDir.exists()) { tcfgDir.mkdir(); } File sfDir = new File(rootStorage.getAbsolutePath() + "/soundfonts/"); if (!sfDir.exists()) { sfDir.mkdir(); } updateBuffers(updateRates()); aRate = Integer.parseInt(prefs.getString("tplusRate", Integer.toString(AudioTrack.getNativeOutputSampleRate(AudioTrack.MODE_STREAM)))); buff = Integer.parseInt(prefs.getString("tplusBuff", "192000")); // This is usually a safe number, but should probably do a test or something migrateFrom1X(rootStorage); final Editor eee = prefs.edit(); firstRun = false; eee.putBoolean("tplusFirstRun", false); eee.putString("dataDir", Environment.getExternalStorageDirectory().getAbsolutePath() + "/TimidityAE/"); if (new File(dataFolder + "/timidity/timidity.cfg").exists()) { if (manConfig = !cfgIsAuto(dataFolder + "/timidity/timidity.cfg")) { eee.putBoolean("manConfig", true); } else { eee.putBoolean("manConfig", false); ArrayList<String> soundfonts = new ArrayList<String>(); FileInputStream fstream = null; try { fstream = new FileInputStream(dataFolder + "/timidity/timidity.cfg"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); //Read File Line By Line try { br.readLine(); // skip first line } catch (IOException e) { e.printStackTrace(); } String line; try { while ((line = br.readLine()) != null) { if (line.indexOf("soundfont \"") >= 0 && line.lastIndexOf('"') >= 0) { try { String st = line.substring(line.indexOf("soundfont \"") + 11, line.lastIndexOf('"')); soundfonts.add(st); } catch (ArrayIndexOutOfBoundsException e1) { e1.printStackTrace(); } } } } catch (IOException e) { e.printStackTrace(); } try { in.close(); } catch (IOException e) { e.printStackTrace(); } try { eee.putString("tplusSoundfonts", ObjectSerializer.serialize(soundfonts)); } catch (IOException e) { e.printStackTrace(); } } eee.commit(); return true; } else { // Should probably check if 8rock11e exists no matter what eee.putBoolean("manConfig", false); AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { ProgressDialog pd; @Override protected void onPreExecute() { pd = new ProgressDialog(a); pd.setTitle(a.getResources().getString(R.string.extract)); pd.setMessage(a.getResources().getString(R.string.extract_sum)); pd.setCancelable(false); pd.setIndeterminate(true); pd.show(); } @Override protected Void doInBackground(Void... arg0) { if (extract8Rock(a) != 777) { Toast.makeText(a, "Could not extrct default soundfont", Toast.LENGTH_SHORT).show(); } return null; } @Override protected void onPostExecute(Void result) { if (pd != null) pd.dismiss(); ArrayList<String> tmpConfig = new ArrayList<String>(); tmpConfig.add(rootStorage.getAbsolutePath() + "/soundfonts/8Rock11e.sf2"); try { eee.putString("tplusSoundfonts", ObjectSerializer.serialize(tmpConfig)); } catch (IOException e) { e.printStackTrace(); } eee.commit(); writeCfg(a, rootStorage.getAbsolutePath() + "/timidity/timidity.cfg", tmpConfig); ((TimidityActivity) a).initCallback(); } }; task.execute((Void[]) null); return false; } } else { return true; } }
From source file:org.dbpedia.spotlight.lucene.index.CandidateIndexer.java
/** * Index surrogates mapping from a tab separated file. *///from w w w .j a va 2 s . c o m public void addFromCounts(File surfaceFormsDataSet, int minCount) throws IOException, IndexException { LOG.info("Indexing candidate map from " + surfaceFormsDataSet.getName() + " to " + mLucene.directory() + "..."); String separator = "\t"; Scanner tsvScanner = new Scanner(new FileInputStream(surfaceFormsDataSet), "UTF-8"); while (tsvScanner.hasNextLine()) { String[] line = tsvScanner.nextLine().split(separator); try { String countAndSf = line[0]; int count = Integer.valueOf(countAndSf.substring(0, 7).trim()); String resourceString = countAndSf.substring(8); String surfaceFormString = line[1]; if (count > minCount) add(new SurfaceForm(surfaceFormString), new DBpediaResource(resourceString), count); List<SurfaceForm> surfaceForms = AddSurfaceFormsToIndex .fromTitlesToAlternativesJ(new SurfaceForm(surfaceFormString)); add(surfaceForms, new DBpediaResource(resourceString)); } catch (ArrayIndexOutOfBoundsException e) { LOG.error("Error parsing line: " + line); e.printStackTrace(); } } LOG.info("Done."); }
From source file:org.pentaho.platform.web.hsqldb.HsqlDatabaseStarterBean.java
protected HsqlProperties getServerProperties(String[] args) { // From HSQLDB Server.java main method... String propsPath = FileUtil.getFileUtil().canonicalOrAbsolutePath("server"); //$NON-NLS-1$ HsqlProperties fileProps = ServerConfiguration.getPropertiesFromFile(ServerConstants.SC_PROTOCOL_HSQL, propsPath, ".properties"); HsqlProperties props = fileProps == null ? new HsqlProperties() : fileProps; HsqlProperties stringProps = null;/*from w ww . j a va2s . c om*/ try { stringProps = HsqlProperties.argArrayToProps(args, "server"); props.addProperties(stringProps); } catch (ArrayIndexOutOfBoundsException ex) { logger.error(Messages.getErrorString("HsqlDatabaseStarterBean.ERROR_0001_INVALID_PARAMETERS")); //$NON-NLS-1$ ex.printStackTrace(); logger.warn(Messages.getString("HsqlDatabaseStarterBean.WARN_NO_DATABASES")); //$NON-NLS-1$ return null; } return props; }
From source file:com.example.firstocr.ViewfinderView.java
@SuppressWarnings("unused") @Override/*from w w w . j ava 2 s .c om*/ public void onDraw(Canvas canvas) { Rect frame = cameraManager.getFramingRect(); if (frame == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); // Draw the exterior (i.e. outside the framing rect) darkened paint.setColor(maskColor); canvas.drawRect(0, 0, width, frame.top, paint); canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); canvas.drawRect(0, frame.bottom + 1, width, height, paint); // If we have an OCR result, overlay its information on the viewfinder. if (resultText != null) { // Only draw text/bounding boxes on viewfinder if it hasn't been resized since the OCR was requested. Point bitmapSize = resultText.getBitmapDimensions(); previewFrame = cameraManager.getFramingRectInPreview(); if (bitmapSize.x == previewFrame.width() && bitmapSize.y == previewFrame.height()) { float scaleX = frame.width() / (float) previewFrame.width(); float scaleY = frame.height() / (float) previewFrame.height(); if (DRAW_REGION_BOXES) { regionBoundingBoxes = resultText.getRegionBoundingBoxes(); for (int i = 0; i < regionBoundingBoxes.size(); i++) { paint.setAlpha(0xA0); paint.setColor(Color.MAGENTA); paint.setStyle(Style.STROKE); paint.setStrokeWidth(1); rect = regionBoundingBoxes.get(i); canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY, frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint); } } if (DRAW_TEXTLINE_BOXES) { // Draw each textline textlineBoundingBoxes = resultText.getTextlineBoundingBoxes(); paint.setAlpha(0xA0); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setStrokeWidth(1); for (int i = 0; i < textlineBoundingBoxes.size(); i++) { rect = textlineBoundingBoxes.get(i); canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY, frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint); } } if (DRAW_STRIP_BOXES) { stripBoundingBoxes = resultText.getStripBoundingBoxes(); paint.setAlpha(0xFF); paint.setColor(Color.YELLOW); paint.setStyle(Style.STROKE); paint.setStrokeWidth(1); for (int i = 0; i < stripBoundingBoxes.size(); i++) { rect = stripBoundingBoxes.get(i); canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY, frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint); } } if (DRAW_WORD_BOXES || DRAW_WORD_TEXT) { // Split the text into words wordBoundingBoxes = resultText.getWordBoundingBoxes(); // for (String w : words) { // Log.e("ViewfinderView", "word: " + w); // } //Log.d("ViewfinderView", "There are " + words.length + " words in the string array."); //Log.d("ViewfinderView", "There are " + wordBoundingBoxes.size() + " words with bounding boxes."); } if (DRAW_WORD_BOXES) { paint.setAlpha(0xFF); paint.setColor(0xFF00CCFF); paint.setStyle(Style.STROKE); paint.setStrokeWidth(1); for (int i = 0; i < wordBoundingBoxes.size(); i++) { // Draw a bounding box around the word rect = wordBoundingBoxes.get(i); canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY, frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint); } } if (DRAW_WORD_TEXT) { words = resultText.getText().replace("\n", " ").split(" "); int[] wordConfidences = resultText.getWordConfidences(); for (int i = 0; i < wordBoundingBoxes.size(); i++) { boolean isWordBlank = true; try { if (!words[i].equals("")) { isWordBlank = false; } } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); } // Only draw if word has characters if (!isWordBlank) { // Draw a white background around each word rect = wordBoundingBoxes.get(i); paint.setColor(Color.WHITE); paint.setStyle(Style.FILL); if (DRAW_TRANSPARENT_WORD_BACKGROUNDS) { // Higher confidence = more opaque, less transparent background paint.setAlpha(wordConfidences[i] * 255 / 100); } else { paint.setAlpha(255); } canvas.drawRect(frame.left + rect.left * scaleX, frame.top + rect.top * scaleY, frame.left + rect.right * scaleX, frame.top + rect.bottom * scaleY, paint); // Draw the word in black text paint.setColor(Color.BLACK); paint.setAlpha(0xFF); paint.setAntiAlias(true); paint.setTextAlign(Align.LEFT); // Adjust text size to fill rect paint.setTextSize(100); paint.setTextScaleX(1.0f); // ask the paint for the bounding rect if it were to draw this text Rect bounds = new Rect(); paint.getTextBounds(words[i], 0, words[i].length(), bounds); // get the height that would have been produced int h = bounds.bottom - bounds.top; // figure out what textSize setting would create that height of text float size = (((float) (rect.height()) / h) * 100f); // and set it into the paint paint.setTextSize(size); // Now set the scale. // do calculation with scale of 1.0 (no scale) paint.setTextScaleX(1.0f); // ask the paint for the bounding rect if it were to draw this text. paint.getTextBounds(words[i], 0, words[i].length(), bounds); // determine the width int w = bounds.right - bounds.left; // calculate the baseline to use so that the entire text is visible including the descenders int text_h = bounds.bottom - bounds.top; int baseline = bounds.bottom + ((rect.height() - text_h) / 2); // determine how much to scale the width to fit the view float xscale = ((float) (rect.width())) / w; // set the scale for the text paint paint.setTextScaleX(xscale); canvas.drawText(words[i], frame.left + rect.left * scaleX, frame.top + rect.bottom * scaleY - baseline, paint); } } } // if (DRAW_CHARACTER_BOXES || DRAW_CHARACTER_TEXT) { // characterBoundingBoxes = resultText.getCharacterBoundingBoxes(); // } // // if (DRAW_CHARACTER_BOXES) { // // Draw bounding boxes around each character // paint.setAlpha(0xA0); // paint.setColor(0xFF00FF00); // paint.setStyle(Style.STROKE); // paint.setStrokeWidth(1); // for (int c = 0; c < characterBoundingBoxes.size(); c++) { // Rect characterRect = characterBoundingBoxes.get(c); // canvas.drawRect(frame.left + characterRect.left * scaleX, // frame.top + characterRect.top * scaleY, // frame.left + characterRect.right * scaleX, // frame.top + characterRect.bottom * scaleY, paint); // } // } // // if (DRAW_CHARACTER_TEXT) { // // Draw letters individually // for (int i = 0; i < characterBoundingBoxes.size(); i++) { // Rect r = characterBoundingBoxes.get(i); // // // Draw a white background for every letter // int meanConfidence = resultText.getMeanConfidence(); // paint.setColor(Color.WHITE); // paint.setAlpha(meanConfidence * (255 / 100)); // paint.setStyle(Style.FILL); // canvas.drawRect(frame.left + r.left * scaleX, // frame.top + r.top * scaleY, // frame.left + r.right * scaleX, // frame.top + r.bottom * scaleY, paint); // // // Draw each letter, in black // paint.setColor(Color.BLACK); // paint.setAlpha(0xFF); // paint.setAntiAlias(true); // paint.setTextAlign(Align.LEFT); // String letter = ""; // try { // char c = resultText.getText().replace("\n","").replace(" ", "").charAt(i); // letter = Character.toString(c); // // if (!letter.equals("-") && !letter.equals("_")) { // // // Adjust text size to fill rect // paint.setTextSize(100); // paint.setTextScaleX(1.0f); // // // ask the paint for the bounding rect if it were to draw this text // Rect bounds = new Rect(); // paint.getTextBounds(letter, 0, letter.length(), bounds); // // // get the height that would have been produced // int h = bounds.bottom - bounds.top; // // // figure out what textSize setting would create that height of text // float size = (((float)(r.height())/h)*100f); // // // and set it into the paint // paint.setTextSize(size); // // // Draw the text as is. We don't really need to set the text scale, because the dimensions // // of the Rect should already be suited for drawing our letter. // canvas.drawText(letter, frame.left + r.left * scaleX, frame.top + r.bottom * scaleY, paint); // } // } catch (StringIndexOutOfBoundsException e) { // e.printStackTrace(); // } catch (Exception e) { // e.printStackTrace(); // } // } // } } } // Draw a two pixel solid border inside the framing rect paint.setAlpha(0); paint.setStyle(Style.FILL); paint.setColor(frameColor); canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint); canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint); canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, paint); canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, paint); // Draw the framing rect corner UI elements paint.setColor(cornerColor); canvas.drawRect(frame.left - 15, frame.top - 15, frame.left + 15, frame.top, paint); canvas.drawRect(frame.left - 15, frame.top, frame.left, frame.top + 15, paint); canvas.drawRect(frame.right - 15, frame.top - 15, frame.right + 15, frame.top, paint); canvas.drawRect(frame.right, frame.top - 15, frame.right + 15, frame.top + 15, paint); canvas.drawRect(frame.left - 15, frame.bottom, frame.left + 15, frame.bottom + 15, paint); canvas.drawRect(frame.left - 15, frame.bottom - 15, frame.left, frame.bottom, paint); canvas.drawRect(frame.right - 15, frame.bottom, frame.right + 15, frame.bottom + 15, paint); canvas.drawRect(frame.right, frame.bottom - 15, frame.right + 15, frame.bottom + 15, paint); // Request another update at the animation interval, but don't repaint the entire viewfinder mask. //postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom); }