Neamar / KISS

Lightning fast, open-source, < 250kb Android launcher
https://kisslauncher.com/
GNU General Public License v3.0
2.85k stars 579 forks source link

Feature Request: Add ability to do simple math from the search bar. #481

Closed klundry closed 6 years ago

klundry commented 8 years ago

It would be great if I could just enter something like "252/6" and automatically have the solution show up without having to launch calculator and then type my math problem.

hydroid7 commented 8 years ago

I think its a good idea.

I think I would able to implement a class or a method which is able to parse a mathematical expr. and return the value, but I'm not familiar with the android API. So I would develop on the standard Oracle JDK and it would be nice if someone would integrate the method in the project.

If someone agrees with this suggestion, I would require a rude interface to start.

nmitsou commented 8 years ago

I guess you would have to create a Calculator provider and a calculator result class and place your math expression inside the provider.

ntninja commented 8 years ago

@hydroid7: You probably do not need to deal most "APIs", since you won't have to pre-load any data. If you can design something similar to https://github.com/Neamar/KISS/blob/master/app/src/main/java/fr/neamar/kiss/dataprovider/SearchProvider.java , I'd do the remaining integration stuff (dummy loader, service registration, …) for you. :smiley:

hydroid7 commented 8 years ago

Thank you, this would be very nice! :D I wrote a small Provider Interface.

public interface ProviderInterface {
    public void reload ();
    /**
     * The most important method
     */
    public ArrayList<Pojo> getResults (String query);
    /**
     * Is this method important for me?
     */
    public static String[] getSearchProviders();
}

Is this correct?

ntninja commented 8 years ago

Looks good! public static String[] getSearchProviders(); is indeed only used by the settings screen to determine which search providers to offer (= you don't need it).

hamburger1984 commented 8 years ago

I tried to use java.util.Scanner + Shunting-yard. Didn't have much time, so here's the current draft (doesn't do much except for producing tokens to be processed by Shunting-yard).

@hydroid7 if you want to, use this for your implementation. If not - never mind. :-)

hydroid7 commented 8 years ago

@hamburger1984 your implementation is a good base I think. I've started to google this and I've found a plenty of small evaluator libraries. E.g. this github example is a one-class-soulution.

hamburger1984 commented 8 years ago

@hydroid7 KISS might/will switch from MIT to a license like GPL (issue 461). Can we use the code of the project, you linked? I'm not sure about the compatiblity of such licenses.

Another point: how much functionality do we actually need? Is there a usecase for sin/tan/random/.. functions in the search field? For me it would just be simple math, like adding a few numbers or division. What do you (and others) think? (What I'm getting at: Maybe we don't need a third party library for this.)

hydroid7 commented 8 years ago

To use 3rd party library was just an idea, of course we can implement our own thing.

Math Functions: I think everything the built in stock android calculator can do, is a standard feature. In my opinion these functions are:

licaon-kter commented 8 years ago

At least add Reverse Polish notation support.

/jk :)

hamburger1984 commented 8 years ago

Usually I'm not a fan of rewriting everything. Depending on how much functionality we need, it might be easier (license) and introduce less bloat (apk size), if we write our own (or use a stripped down version of an expression evaluator). But for a first version, a 3rd party library is a good way to quickly see results and test whether an integration in the search bar would work at all.

Being on par with the stock android calculator is a good suggestion.

hydroid7 commented 8 years ago

@hamburger1984 I think it's a great idea! Let's do a fast test with a 3rd party library.

Polish notation too? I think I would prefer a matrix calculator for my linear algebra class :D

ntninja commented 8 years ago

@hamburger1984 Here is an (incomplete) list of licenses that are definitely compatible with the GPLv3: MIT/X11 License, Apache Software License 2.0, 3- and 2- clause BSD License, MPLv2, LGPLv3, LGPLv2 "or later", GPLv2 "or later", CC-BY 4.0+ (and there are any more, that are compatible or that allow for conversion to the GPL).

The gist of this is that anything, that doesn't have some "weird" special license should be compatible. Don't worry this stuff too much! :smile_cat:

hamburger1984 commented 8 years ago

There's already a working implementation by @pinusc in their math branch. I rebased it on current master and did some minor tweaks to it here.

Looks pretty good to me. What do you think? @pinusc is it to okay to include your code? (you didn't create a pull request, yet). @hydroid7 are you still working on this?

hydroid7 commented 8 years ago

Just finished a test version. https://github.com/hydroid7/KISS the new changes are in my repository. Sorry I can't test it because I haven't enough HDD place.

hamburger1984 commented 8 years ago

@hydroid7 I did the integration bits (see pull request).

...sooo we have 2 working implementations :+1:

pinusc commented 8 years ago

@hamburger1984, yes, I was waiting to make a pull request because I wanted to make sure it worked as intented and I didn't have enough time... It also lacked an option to disable it like the other providers. But yes, I'm okay with including it.

hydroid7 commented 8 years ago

-.-

How can I make a pull request? Am 28.06.2016 16:47 schrieb "pinusc" notifications@github.com:

@hamburger1984 https://github.com/hamburger1984, yes, I was waiting to make a pull request because I wanted to make sure it worked as intented and I didn't have enough time... It also lacked an option to disable it like the other providers. But yes, I'm okay with including it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Neamar/KISS/issues/481#issuecomment-229072255, or mute the thread https://github.com/notifications/unsubscribe/APvpiBPg_Us0pRFkOOsWaUWKwKi_zvByks5qQTQWgaJpZM4I8bLe .

hydroid7 commented 8 years ago

Made a pull request #486

hydroid7 commented 8 years ago

We can maybe introduce an other icon for the math provider, maybe π, Φ, √2 or %

blokeley commented 6 years ago

Why do you need this? The Calculator app and Google search (which supports calculations) are only 1 touch away at the moment.

It seems like unnecessary complication for a reasonably rare usage, which requires only 1 touch anyway. Doesn't it go against the axiom of Keep It Simple?

klundry commented 6 years ago

Why do we need web search from the search bar when a browser is one click away?

I disagree that using your phone as a calculator is rare. It is pretty common but probably not opened as often as a lot of other apps so it's unlikely to be in your recent apps list most of the time. Just as you can tap the search bar and type something and launch a web search, it would be very convenient to be able to type some numbers and get the sum quickly without having to find your calculator, open it then type your numbers.

Edit: I also think relying on a google search for calculations is not a good solution. What if you don't have network connection? It's just unnecessary to do a web search for simple addition and subtraction.

hamburger1984 commented 6 years ago

I was maintaining my own build for quite some time, because I was using this feature quite regularly (and like it a lot). But I'm getting tired of rebasing, merging, building and am currently on "stock" KISS ;-)

https://github.com/hamburger1984/KISS/tree/my_build

Neamar commented 6 years ago

I was thinking -- the main issue here is the size.

But I'm sure most people only use the calculator for very simple calculations. We could implement in a couple lines a simple calculator that only looks for something matching the regexp ([0-9]+)(\+|\-|\*|\/)([0-9]+) and display the results accordingly (works for instance with 2+9, 12.34 * 2 and any operation with two operands)

Might that be enough? Do we really need something more advanced?

klundry commented 6 years ago

Yes, I think very simple is good. Addition, subtraction, multiply and divide is plenty for this feature. Anything more and a dedicated calculator app is what should be used.

hasantr commented 6 years ago

Even if it is 4 operations. I am looking for this feature too.

Neamar commented 6 years ago

I've been willing to implement this, but I'm stuck with an implementation detail.

The current Providers are all Android Services. I can add a new MathProvider, but that would be one more Android service running, taking a lot of valuable memory from the device.

The Android documentation states that Services should be used sparingly: https://developer.android.com/topic/performance/memory#Services

Right now, we already have a bunch of not-so-useful Services: providers for Settings, Phone and Search don't really require a dedicated Service.

I'm trying to think about how to merge them all into a single Service that handle all those lightweight Providers. Once I have that, adding the MathProvider will be super easy.

Herbstfreud commented 6 years ago

I also the think that the four basic operations (+-*/) would be the most important ones for most users. If I'd like to use more complicated operations, there are specific apps in several app stores...

Neamar commented 6 years ago

It's finally there :) See #1023