How to practically display math formula in Android - android

I researched on this for quite a while and I know this kind of questions already answered. But I couldn't find a right answer showing how to practically deal with math formula in Android app. Without including large amount (5~20MB) of files in the Android project, it seems that there is no way to parse & display math formula script like MATHML. I looked at JEuclid and MathJax that were mentioned a lot for Android but I found them in this category.
So at this point, the only way I can think of is to take each of those formula in a image file and display it on Android. But in practice, that manual process is really slow. I am sure this is not a right way.
So I have to ask this again. How to practically display math formula in your Android app?

You can not set maths formula to TextView in android. You have to use WebView in which you can display maths formulae. See mathjax for more information.
if you want to display for android then here is library you can implement in your project. mathjaxwebview

If you want to parse Tex(Inline mode and display mode) formats and ASCII math format you can use this link .I used the above math view given in this link to display formula.It worked like a charm adding to that download mathjax from official site and get fonts folder and put it in your assets folder. It will definitely work.
https://github.com/Nishant-Pathak/MathView
download math view form above link.

The libraries which are using WebView to wrap latex-rendering-js-library (e.g., this, this and this), are not working well with the RecyclerView and will make the app slow. And they are not even updating the js libraries.
Finally, I found "noties/jlatexmath-android", which is using "opencollab/jlatexmath" native Java library. It is fast and can be easily used with RecyclerView.
Sample usage of JLatexMathView:
implementation "ru.noties:jlatexmath-android:$jlatexmath_version"
// for Cyrillic symbols
implementation "ru.noties:jlatexmath-android-font-cyrillic:$jlatexmath_version"
// for Greek symbols
implementation "ru.noties:jlatexmath-android-font-greek:$jlatexmath_version"
<ru.noties.jlatexmath.JLatexMathView
android:id="#+id/j_latex_math_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dip"
android:background="#color/white"
app:jlmv_alignVertical="center"
app:jlmv_alignHorizontal="center"
app:jlmv_textSize="16sp" />
val latexText = "\$\$f(x)=(x+a)(x+b)\$\$"
binding.jLatexMathView.setLatex(latexText)
You can also use it as an extension of "noties/Markwon", a Markdown library for Android. Details can be found here.
Sample Usage of Markwon:
implementation "io.noties.markwon:core:$markwon_version"
implementation "io.noties.markwon:ext-latex:$markwon_version"
implementation "io.noties.markwon:inline-parser:$markwon_version"
<TextView
android:id="#+id/tv_markdown"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
val markwon = Markwon.builder(requireContext())
.usePlugin(MarkwonInlineParserPlugin.create())
.usePlugin(JLatexMathPlugin.create(binding.tvMarkdown.textSize) { builder ->
// ENABLE inlines
builder.inlinesEnabled(true)
})
.build()
val latexText = "Example: \$\$f(x)=(x+a)(x+b)\$\$"
markwon.setMarkdown(binding.tvMarkdown, latexText)

You can implement with MathType.
But your data for display must be in MathType format
https://docs.wiris.com/en/mathtype/mathtype_web/sdk/mobile-apps

Related

Taking Screenshots Using Qt C++ on Android

thanks for checking my question out!
I'm currently working on a project using Qt C++, which is designed to be multi-platform. I'm a bit of a newcoming to it, so I've been asked to set up the ability to take screenshots from within the menu structure, and I'm having issues with the Android version of the companion app.
As a quick overview, it's a bit of software that send the content of a host PC's screen to our app, and I've been able to take screenshots on the Windows version just fine, using QScreen and QPixmap, like so:
overlaywindow.cpp
{
QPixmap screenSnapData = screenGrab->currentBackground();
}
screenGrabber.cpp
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
}
Unfortunately, Android seems to reject QScreen, and with most suggestions from past Google searches suggesting the now-deprecated QPixmap::grab(), I've gotten a little stuck.
What luck I have had is within the code for the menu itself, and QWidget, but that isn't without issue, of course!
QFile doubleCheckFile("/storage/emulated/0/Pictures/Testing/checking.png");
doubleCheckFile.open(QIODevice::ReadWrite);
QPixmap checkingPixmap = QWidget::grab();
checkingPixmap.save(&doubleCheckFile);
doubleCheckFile.close();
This code does take a screenshot, but only of the button strip currently implemented, and not for the whole screen. I've also taken a 'screenshot' of just a white box with the screen's dimensions by using:
QDesktopWidget dw;
QWidget *screen=dw.screen();
QPixmap checkingPixmap = screen->grab();
Would anyone know of whether there was an alternative to using QScreen to take a screenshot in Android, or whether there's a specific way to get it working as compared to Windows? Or would QWidget be the right track? Any help's greatly appreciated!
as i can read in Qt doc : In your screenGrabber.cpp :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
replace with :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( 0 ); // as 0 is the id of main screen
If you want to take a screenshot of your own widget, you can use the method QWidget::render (Qt Doc):
QPixmap pixmap(widget->size());
widget->render(&pixmap);
If you want to take a screenshot of another app/widget than your app, you should use the Android API...

How to display source code "prettily" in android app

everyone.
[What I'd like to do]
To display source code "prettily" in android app. Like this.
At least if there are indents, it's fine.
[Why?]
Because I'm developing an android app where users can see Views and its source code at the same time.
[Issue]
Showing source codes on TextView looks ugly. A lot of escape characters needed for <> and the text layout collapsed. Googling and searching on Stackoverflow didn't give me any useful information.
Any help would be appreciated. Thanks!
(update 2015/11/23)
These link might be useful when you use WebView to display source codes.
- How can I display HTML source code within a HTML website? [duplicate]
- How to display source code with indent in a web page? HTML? CSS?
Displaying the text in a WebView is a great idea as you can now use javascript APIs like Google's Code Prettify
I believe SO uses it ;)
The comments in prettify.js are authoritative but the lexer should
work on a number of languages including C and friends, Java, Python,
Bash, SQL, HTML, XML, CSS, Javascript, Makefiles, and Rust.
It works passably on Ruby, PHP, VB, and Awk and a decent subset of
Perl and Ruby, but, because of commenting conventions, doesn't work on
Smalltalk, OCaml, etc. without a language extension.
Other languages are supported via extensions:
Apollo; Basic; Clojure; CSS; Dart; Erlang; Go; Haskell; Lasso; Lisp,
Scheme; Llvm; Logtalk; Lua; Matlab; MLs: F#, Ocaml,SML; Mumps;
Nemerle; Pascal; Protocol buffers; R, S; RD; Rust; Scala; SQL; Swift;
TCL; Latek; Visual Basic; VHDL; Wiki; XQ; YAML
I think this question is a tricky one. I tried to google myself and only find this library
https://android-arsenal.com/details/1/2049
which supports different text appearence. Hope this will help you out.

Which animation/view is used for Recent apps/History in android 5.0(Lollipop)?

I need to do animation like it is there in Recent App section in Android 5.0.
Like shown in the image below. Any hint or link or even the Animation type used here would be helpful.
Take a look here: https://github.com/vikramkakkar/DeckView
There is also an example here. You can also find about RecentsView here:
https://github.com/android/platform_frameworks_base/blob/59701b9ba5c453e327bc0e6873a9f6ff87a10391/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
I have never done this, but I can point you in the right direction to use StackView. It was added in API level 11 (Android 3.0)
I have found some examples
http://www.broculos.net/2011/12/android-101-how-to-create-stackview.html
http://www.informit.com/articles/article.aspx?p=2078060&seqNum=3
http://www.thaicreate.com/mobile/android-stackview.html
Also this library looks decent
https://github.com/blipinsk/FlippableStackView
Take a look here: https://github.com/ZieIony/MaterialRecents I personally tried it and it looks promising.
You can always look at the official Android source code.
Check the method startRecentsActivity() under packages/SystemUI from the official Android source code.
It's not a very easy-to-read code, but it's definitely the best and most reliable source if you really want to mimic the official Android Lollipop animations.
i have created a github repo with my class i hope it helps,
it's is the start i hope it helps
Stack Cards Android
it makes the same as your image
you can set the difference between cards, scale from card to card,
animation duration, number of cards of course
usage easy just include the class &
// **Paramters definitions** :
// Activity owningActivity, RelativeLayout container, int cardHeightDP, int cardDiffDP,float cardScale, int animationDuration)
StackCards stackCards = new StackCards(yourActivity.this, cardsContainer, 100, 50, (float) 0.2, 500);
//(Number of Cards, The Layout of the Card)
stackCards.initCards(7, R.layout.stack_card);

How to find a WebView element in Android using Calabash using TextContent

I have a webview in an ios app that basically has no id or class. (I know, right?)
But it does have a textContent field that I would like to use to select elements.
This is the element I want to find:
{"rect"=>
{"center_x"=>307.5,
"left"=>295,
"bottom"=>136,
"right"=>320,
"top"=>93,
"width"=>25,
"height"=>43,
"center_y"=>178.5},
"nodeName"=>"LI",
"id"=>"",
"textContent"=>"!!! I WANT TO FIND IT BY THIS !!!",
"center"=>{"X"=>307.5, "Y"=>178.5},
"nodeType"=>"ELEMENT_NODE",
"webView"=>
"<UIWebView: 0xe2e1400; frame = (0 0; 320 504); clipsToBounds = YES; autoresize = W+H
"class"=>"arrow",
"html"=>"<div class=\"arrow\"></div>"}
So I was able to find this using css pseudo-selectors alá
query("webView css:'el:first-child'")
I can find it by using the hashes in the results array alá
query("webView css:'li'").select {|element| element["textContent"] == "!!! I WANT TO FIND IT BY THIS !!!}
And I can refactor it a bit to use a regex alá
query("webView css:'li'").select {|element| element["textContent"] =~ /I WANT/}
But all this feels really dirty. Very un-Calabashy. Is there a better way to write this?
I have not tried your exact setup. But I do often use queries with the LIKE comparison on label.
Would that solve your problem?
ex.
element_exists("label {text LIKE 'I WANT TO FIND'}")
I wound up going with this:
query("webView css:'TITLE'{textContent CONTAINS ’I WANT’}")
It tends to work more consistently with these particular webviews (given a lack of accessibility labels in the code).

How to import a SpriteFont into MonoGame

I'm porting a simple tetris-like XNA app to Android, using Mono For Android and MonoGame; I have followed the suggested steps in this link and so far, everything compiles well, and no relevant warnings fire up. However, upon loading the contents, a null parameter exception breaks the program at the point below in my program:
protected override void LoadContent() {
// ...
_font = Content.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>("SpriteFont1");
// ...
}
The content root directory is set in the game constructor class:
public Game2 (){
Content.RootDirectory = "Content";
Content.RootDirectory = "Assets/Content"; // TEST.
//...}
And I have tried several combinations, all to no avail.
I have also tried setting the xnb files as Content as well as Android Assets in the Build Action property; having the linked, copied always, copied only if newer... etc.
Either way, my problem is that I don't really understand WHY and HOW should I do this. I'm rather new to the platform and to XNA as well, so this may very well be a newbie question, but the truth is after several hours banging my head and fists against the monitor/keyboard I feel stuck and need your help.
I have a library that supports variable-width fonts (generated by BMFont) on MonoGame. Unfortunately it is a renderer and so has other code around it. However, the basic idea is very simple. You can take a look at the loader here and the mesh builder (given a string) here. This builder supports fonts that spread characters across multiple pages, too.
Hope this helps!
MonoGame (2.5.1) throws NotImplementedException in ContentManager.Load for SpriteFont type. Have the same not resolved problem. I'm trying not to use DrawString.
For loading textures in Win32 application I use:
Content.RootDirectory = #"../../Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");
You even must not add it to solution.
For Andoind (MonoDroid) application you must add "Content" folder to your solution and set "Andtoid Asset" in "Sample.png" properties.
Content.RootDirectory = "Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");
See also:
http://monogame.codeplex.com/discussions/360468
http://monogame.codeplex.com/discussions/267900

Categories

Resources