Math Formatting in native Android? MathView library not working - java

I am creating a quiz app which includes some chemical and mathematical equations. I had a previous version that used a WebView and jqmath library to display the files. That version was very inefficient and was dead slow in old android phones (2 year old ones). I scraped that thing and started the quiz page again.
I have a TabLayout and a CardView. TabLayout is used to switch between the questions and CardView is used to display the questions. But I have the database setup in such a way that if two $$ occur in a string then use jqmath to format the string.
For eg : if the json is like this "Qno":5,"Question":"If the point represented by the complex number iz is rotated about the origin through the angle $$\u03c0\/2$$ in the counter clockwise direction then the complex number representing the new position is:","Option1":"iz","Option2":"-iz","Option3":"-z","Option4":"z","Correct":"C"
then the output is
I can take care of the $$ symbol with some java functions but I have no idea how to make the expression (pi divide by 2) appear as should be. When I used jqmath my output was something like this
How to achieve this in native android using java without affecting my existing code...??
UPDATE
As suggested in the comments I used this library. But this is not working properly. Sometimes it is rendering correctly sometimes not.
For Eg: Correct Rendering
Wrong Rendering
The TextView in the top is just a normal TextView that is showing the text that is being displayed. WebView is the set of text that is displayed below that.
What is wrong? Any help is appreciated

Related

Android Studio: Group elements together

I am fairly new to android studio and I am trying to make a car rental app for a university project.
I designed an app which has a horizontal slider containing blocks of different cars however I am unsure on how I would do this, I understand how the slider works and how to add elements to it.
I have a linear layout within the horizontal slider which will contain all of the blocks but I am unsure how to make a block of elements. Within the block it should have two buttons, an image and some text. Here is a picture of the design.
As you can see the available blocks are surrounded by a square. this is what I want, a small container which surrounds my data. Sort of like a div box in html.
Is there a way to do this?
Please just point me in the correct direction!
Many thanks!
It seems like cardviews can handle most of the grouping you want to do. I would reccomend looking into them because they incorporate a lot of material design components right out of the box.
https://developer.android.com/guide/topics/ui/layout/cardview

Android - Creating a Basketball Statistics screen

I'm currently working on an android basketball stat tracking application.
I am using the android SDK and developing it on eclipse.
I'm to the point where we are going to need a stats screen for the game that is currently active. I need to pull stats from the game that is currently running that is outputting stats into a stat table. We are using SQLite as our database to store everything.
My problem is that I know how I can pull and count the different stats, and how to output them. But I'm thinking there is an easier way to do what I'm attempting to do.
For the stat screen activity, this is what we currently have.
Don't mind the big zero in the top left, that's just a formatting issue. Don't mind the warnings either, that's because I didn't make string values for these yet.
So every single zero is its own TextView, and if a team has 20 players, that is 180 TextViews I have to populate with different numbers.
I have thought of different ways I could format the TextView ID's so I would only have to run a different code depending on the player's # for each of the 8 stats.
But in the end, I'm still using 180 different TextViews.
Is this the only way I could do something like this?
You should use a ListView with a custom View and an Adapter, refer to this
http://developer.android.com/reference/android/widget/Adapter.html
A Listview, because you can have 2 or 40 players.
a Custom View (in XML) so you can customize the fields / imageView / others
the Adapter "fills" the Custom View and put into the ListView
http://www.piwai.info/android-adapter-good-practices/

Multi-page application with corresponding pictures and text

I'm new to Java and Android. I have been trying for the past week to make an app for my phone. The app consists of 4 pages, which are diagrammed below:
Page 1: Contains a picture taking up the size of the screen. If I click on the picture it needs to go to "page 2".
Page 2: Consists of an icon on the left (say the flag for instance) followed by a text field (eg. USA). When "USA" strip is clicked it needs to go to page 3.
Page 3: Consists of text, picture and then more text from a string. This page needs to correspond to the strip clicked on in page 2 ("USA" in this example). There are also two buttons at the bottom of "page 3" and "page 4" which when pressed need to go to the corresponding page numbers.
Page 4: This page is displayed if the "More" button is pressed on "page 3".
I would like this phone to work on a minimum Android 2.2 or 2.3. All logos, pictures and string texts need to be locally available (resources folder) and not website based. I have tried all sorts of combinations of ListView's and buttons with OnClickListener's as well as toast screens. My limited knowledge of programming is frustrating.
My question is if there is a template around which will help me out with this app? Or if there are any web resources.
In Android, individual "pages" or "screens" can be implemented as Activitys. You need to extend the Activity class and add the components that you wish to display. Most of the layout can be done in an XML file. I strongly suggest that you google for a tutorial that illustrates the basics of Android programming. From there, you can start by creating an app with two pages. And then just keep adding a little bit at a time until you get the complete app that you want.
There some easy ways to do this. If you want to be backwards compatible to SDK 8 you can do this in two ways. You can use Fragments or Activities for each layout. If you implement fragments, I suggest reading http://developer.android.com/guide/components/fragments.html inside there you will about using the FragmentActivity instead of the Activity. Read this link http://developer.android.com/tools/extras/support-library.html as it will have the needed libraries to implement the Fragments in older versions of the SDK. It does looks like you looking for some navigation buttons that reside on the bottom of the layout. In order to fully implement a layout that has this view on the bottom of the screen in SDK 8, you will need to create your own View and place it on the bottom of the screen. RelativeLayout and alignParentBottom = "true" will accomplish this. There is also a way to do this using a ViewPager which will also work in the backwards compatibility requirements you have. I am sorry the amount of information I am throwing at you but I really would recommend looking into other questions posted by users on this topic. How to navigate to another page in android? for example. Good luck and everything you are looking for is able to be learned through a Google search. Maybe not all at once.

How to show special characters in Android?

I am developing a native app which consists of some mathematical formulas.
Formulas will be like.........
I want to display such formulas in my application, but i don't how to use these special characters in Android. I want to display each formula individually in a list view...... If i am copying formula & if i am setting text to text view means it is showing like
txtv.setText("\\cos^2\\theta + \\sin^2\\theta = 1\\! ");
and getting output in the same pattern. So, can anyone help me how to use these mathematical special characters in Android..
Sorry, there are not a lot of different solutions..
There are no 'magical answer", here are some different ways to achieve what you want.
1) Using a webview with some Javascript
2) using a server to produce a picture of the formula.
3) Using a 9.png file embededd in your app with the square root symbol and display it as textview background
4) Drawing a canvas with all your text and symbols
5) using Hexadecimal code: http://htmlhelp.com/reference/html40/entities/symbols.html
http://tlt.its.psu.edu/suggestions/international/bylanguage/mathchart.html
6) Maybe other ideas, but definitely no way to achieve a 300 formula listview in a easiest way.
This one seem quite good and works in Android without any issue: http://mathscribe.com/author/jqmath.html
Edit:
You can run this inside a WebView, you don't need any webapp.

Printing data to a pre printed form/stationery

We have a requirement where we already have pre printed stationery and want user to put data in a HTML form and be able to print data on that form. Alignment/text size etc are very important since the pre-printed stationery already has boxes for each character. What could be a good way to achieve this in java? I have thinking of using jasper reports. Any other options? May be overlay image with text or something?
Also we might need to capability to print on plain paper in which case the boxes needs to be printed by our application and the form should match after the printed with the already printed blank stationery containing data.
Do we have some open source framework to do such stuff?
Jaspersoft reports -- http://sourceforge.net/projects/jasperreports/
You will then create XML templates, then you will be able to produce a report in PDF, HTML, CSV, XLS, TXT, RTF, and more. It has all the necessary options to customize the report. Used it before and recommend it.
You will create the templates with iReport then write the code for the engine to pass the data in different possible ways.
check http://www.jaspersoft.com/jasperreports
Edit:
You can have background images and overlay the boxes over it and set a limit on the max character size ... and many more
It is very powerful and gives you plenty of options
Here is one of iReport's tutorial for a background image http://ireport-tutorial.blogspot.com/2008/12/background-image-in-ireport.html
The big problem when printing form content that has been filled in electronically, is aligning it correctly on the pre-printed form. You may get content to align for one printer, but when you use another it is completely misaligned.
Fly Software have a form design product called InForm Designer that gets around the problem nicely by allowing users to specify and save vertical and horizontal offsets for printers. This ensures filled in form content is always aligned. I've tried it and it works perfectly. Take a look for yourself here...
http://www.flysoftware.com/products/inform_designer/overview.asp
It might be worth implementing a printer offset similar to InForm's in your own application (if possible).
Some things to think about.
First in terms of the web page, do you want use the stationery as the form layout?
Does it have to be exact?
Combed boxes (one for each character)
Do you want to show it like that on the web page, or deal with the combing later.
How are you going to deal with say a combed 6 digit number. Is this right aligned. What if they enter 7 digits. Same for text. what if it won't fit.
Font choices, we had a lot of fun with W...
How aligned do you want the character within the box, what font limitations does that imply, some of the auto magic software we looked at did crap like change the size of each character.
Combed editing is a nightmare, we display combed, but raise an edit surface the size of the full box on selection.
Another thing that might drive you barking mad, you find find small differences in the size and layout of the boxes, so they look okay from a distance but a column of boxes sort of shifts about by a pixel. Some of testing guys had to lend us their electron microscopes, so we could see how many ink molecules we were out by. :(
Expect to spend a lot of time in the UI side of things, and remember printed stationery changes, so giving yourself some sort of meta description of the form to start with will save you loads of trouble later on.

Categories

Resources