Gibberish Generator – wirthaw – hw3
My app is a gibberish generator with two generating options. A user can either choose to create what i called element gibberish(paragraphs, text message, un ordered list, and a number of headers) or corporate gibberish which is just a bunch of generic slogans and phrases with a corporations name inserted into it. Originally I had just planned on doing the element gibberish but after i stumbled on the corporate gibberish website i had to include it.
With the element gibberish generator (second pic) there are many options a user can make. However, only some of them apply to some of the elements (headers cannot have a number of items). When an element is selected from the spinner i use the clickListener to determine which options can apply to the element and then set the other ones to setEnabaled(false). After the user hits submit i use a RESTful service get to get the results from the website, similar to in class. However, I did not need to post any parameters so everything i do is just tacked to the url like this.
url = “http://www.randomtext.me/api/gibberish” + itemKey + “/” + sbmin.getProgress() + “-” + sbmax.getProgress() + “/”;
The website then returns a JSON however the string returned is actually in HTML however android has a nice little method to help put HTML into a string. In the new activity i start i use the below method to convert the HTML string into a normal string that is shown, its much more convenient than trying to parse it myself.
gtvBody.setText(Html.fromHtml(bodyText));
In the final activity i also give the users the ability to copy the text to the clipboard or text it to someone, both of these things were actually very easy to do. To copy to clipboard all i needed was to add a clipboard manager and set the clipboards text to the body text whenever that button was pressed.
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(gtvBody.getText().toString());
To text was even easier. All i did was start a new activity with an intent that had an extra containing the body text. Android than redirects to the default messenger program and inserts the text into the body of the sms message.
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse(“sms:”));
sendIntent.putExtra(“sms_body” , gtvBody.getText().toString());
startActivity(sendIntent);
The corporate gibberish generator was done basically the same expect that website doesn’t return a JSON but an HTML page. However, luckily the HTML code has a giant comment in it that says <!– GIBBERISH STARTS HERE –> which made parsing really easy. The final view also contains a scroll view in case the text returned doesn’t fit on page.
<ScrollView android:layout_height=”wrap_content” android:layout_width=”fill_parent” android:id=”@+id/scrollView1″>
this just encases a text view and a linear layout.