Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

uncle blog posted:

The page is a list of several items, with a search bar above it. If the user enters the search and starts typing, the list gets replaced by the results of the search. I want the original list to reappear when the user exits the search bar, and thought dismissing the keyboard seemed like a good point of reference.

Depends on exactly what you're using (look at the methods available on whatever component it is) but you'll probably want to use this
https://developer.android.com/reference/android/view/View.html#setOnFocusChangeListener(android.view.View.OnFocusChangeListener)
Java code:
yourSearchBar.setOnFocusChangeListener(new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (!hasFocus) {
            refreshListViewOrWhatever();
        }
    }
});
But there are a few options instead of replacing the contents of the list, like this thing. Whatever works!

Adbot
ADBOT LOVES YOU

Tunga
May 7, 2004

Grimey Drawer

uncle blog posted:

The page is a list of several items, with a search bar above it. If the user enters the search and starts typing, the list gets replaced by the results of the search. I want the original list to reappear when the user exits the search bar, and thought dismissing the keyboard seemed like a good point of reference.
For what it's worth this sounds like absolutely horrible UX. So I close the keyboard to let me see a full screen of results and all my results inexplicably disappear?

xtal
Jan 9, 2011

by Fluffdaddy
I want to make Android apps but I'm averse to Java. Will I have the most success using Scala, Clojure, Haskell or Frege?

Tunga
May 7, 2004

Grimey Drawer

xtal posted:

I want to make Android apps but I'm averse to Java. Will I have the most success using Scala, Clojure, Haskell or Frege?
I am a bad person and don't know anything much about any of those but you might also consider Kotlin which is the new funk with the guys who rave about functional everything at work.

Volmarias
Dec 31, 2002
Probation
Can't post for 2 hours!

xtal posted:

I want to make Android apps but I'm averse to Java. Will I have the most success using Scala, Clojure, Haskell or Frege?

No, you will likely not.

xtal
Jan 9, 2011

by Fluffdaddy

Volmarias posted:

No, you will likely not.

What if I wrote the Android parts in Java, but the business logic in another language? Is there anybody who had ever succeeded with a non-Java language?

speng31b
May 8, 2010

xtal posted:

What if I wrote the Android parts in Java, but the business logic in another language? Is there anybody who had ever succeeded with a non-Java language?

You're going down a dark road, friend - one with a really bad ratio of time spent worrying about tooling to time spent making apps. If you want to make Android apps, you should learn Java. When you get to know him he's not such a bad dude. Kotlin's like Java's cool younger brother who spent time traveling the world and is now back, rebuilding his career with charisma and charm - but even so, you probably won't get along with Kotlin unless you can at least demonstrate a tolerance for Java.

Spend less time worrying about what languages you like or don't, and more time making apps. Apps are cool, and if it turns out you like making them, you'll probably end up liking the tools you use to make them as well - and you'll learn about new tools along the way that you like even more. Also, it could be worse. You could be staring down the barrel of Objective C.

speng31b fucked around with this message at 22:09 on Oct 7, 2016

No Safe Word
Feb 26, 2005

The other alternative would be to use one of the cross-platform mobile frameworks that uses another language you can tolerate, but there are generally large trade-offs like:

- performance/responsiveness may suck
- your UI may lack the native look and feel
- you don't have access to all the native functionality you want

et cetera

Sereri
Sep 30, 2008

awwwrigami

You can probably use Scala, the question is just if actually want to. A quick googling says that at least there seems to be a way. Not sure if it's a good one.

speng31b
May 8, 2010

It also depends on your goal. I'd say if you want this experience building Android apps to ever translate into something that could be a marketable skill, use Java - full stop, end of discussion. Also if you want to actually build apps and not just endlessly churn on adjacent technologies.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

You could try React Native. It's pretty cool.

speng31b
May 8, 2010

Thermopyle posted:

You could try React Native. It's pretty cool.

I disagree, and I've used it pretty extensively. I gave it a fighting shot - we have a lot of JS devs in our office, and it made sense to try to build some crossover. It's just not production-ready, stable, maintainable, or fine for building a really good UX. But probably not the time for a long form rant.

xtal
Jan 9, 2011

by Fluffdaddy

Thermopyle posted:

You could try React Native. It's pretty cool.

I'm only considering Android because I'm so tired of Web apps. So, I think I will just go play with my abacus.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

xtal posted:

I'm only considering Android because I'm so tired of Web apps. So, I think I will just go play with my abacus.

Why do you hate Java so bad? You can even use lambdas now!

You could still have a play with it, it's not a huge investment to try it out and tinker with butts.apk

xtal
Jan 9, 2011

by Fluffdaddy

baka kaba posted:

Why do you hate Java so bad? You can even use lambdas now!

You could still have a play with it, it's not a huge investment to try it out and tinker with butts.apk

it's a can of worms but I just don't enjoy imperative programming anymore. I've written my last for loop. I know you can write functional in Java, I've been writing functional in Ruby and JavaScript for years, but it's a second rate experience, that's why I don't dig the Web.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

speng31b posted:

I disagree, and I've used it pretty extensively. I gave it a fighting shot - we have a lot of JS devs in our office, and it made sense to try to build some crossover. It's just not production-ready, stable, maintainable, or fine for building a really good UX. But probably not the time for a long form rant.

Interesting. I've only built some toy apps with it, but I haven't really heard people talking about it like you.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

xtal posted:

it's a can of worms but I just don't enjoy imperative programming anymore. I've written my last for loop. I know you can write functional in Java, I've been writing functional in Ruby and JavaScript for years, but it's a second rate experience, that's why I don't dig the Web.

You tried out Elm? All your web dreams come true maybe

speng31b
May 8, 2010

Thermopyle posted:

Interesting. I've only built some toy apps with it, but I haven't really heard people talking about it like you.

I got to the point of opening some PRs to fix some issues I was having, at which point the maintainers commented that they have "internal" implementations they don't (and won't) release which didn't have the same problems, and would probably implement a take on those fixes instead at some indefinite time in the future. I stopped. I still think it's a cool concept, but it's a toy. To use it in production, I'd need to fork it and maintain extensively, since the "good stuff" isn't always available to the open source part. I couldn't sleep at night taking ownership of a product built on that. There are too many good options out there which are way more trustworthy and come without serious pitfalls.

speng31b fucked around with this message at 01:53 on Oct 8, 2016

xtal
Jan 9, 2011

by Fluffdaddy

baka kaba posted:

You tried out Elm? All your web dreams come true maybe

Yeah Elm is great

Vesi
Jan 12, 2005

pikachu looking at?
Kotlin is good, and the java/android sdk interoperability is really seamless. Feels like a better version of Swift

brap
Aug 23, 2004

Grimey Drawer

Vesi posted:

Kotlin is good, and the java/android sdk interoperability is really seamless. Feels like a worse version of Swift with a crashy debugger

This was my experience. I basically liked using it but at the time I was doing it (last winter probably) it was not fun to debug.

kitten smoothie
Dec 29, 2001

My team switched to Kotlin for all new work starting a couple months ago. It's been a joy to work with.

Tunga
May 7, 2004

Grimey Drawer

kitten smoothie posted:

My team switched to Kotlin for all new work starting a couple months ago. It's been a joy to work with.
My team lead is convinced it's "the latest fad" and won't let us touch it, which I do understand, I really just want an excuse to use something different from Java for once!

speng31b
May 8, 2010

Tunga posted:

My team lead is convinced it's "the latest fad" and won't let us touch it, which I do understand, I really just want an excuse to use something different from Java for once!

Link them to Jake Wharton's long form rebuttal of "Kotlin is a fad/we can't support it." I'll dig it up later and link it. Basically Jetbrains is a highly credible maintainer and it will never be "a fad" unless you think Java (but better) is a fad.

The opinion of your team lead is a common ignorant take on it, but should be easily corrected with a bit of actual good faith research.

speng31b fucked around with this message at 23:43 on Oct 9, 2016

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Does no one use groovy anymore? Last time I did java development my co-workers were really into that. It did seem less painful than writing Java. How does kotlin compare with groovy?

speng31b
May 8, 2010

peepsalot posted:

Does no one use groovy anymore? Last time I did java development my co-workers were really into that. It did seem less painful than writing Java. How does kotlin compare with groovy?

We use Groovy for tooling - Gradle - because we're forced to. I've never heard of any of the more credible sources in the community endorse it as an application language. Personally it's not my cup of tea and I'd say among JVM languages that are Android compatible it's not held in particularly high esteem.

kitten smoothie
Dec 29, 2001

speng31b posted:

We use Groovy for tooling - Gradle - because we're forced to. I've never heard of any of the more credible sources in the community endorse it as an application language. Personally it's not my cup of tea and I'd say among JVM languages that are Android compatible it's not held in particularly high esteem.

Yeah, if nothing else it seems people are wanting to go into the other direction, with Gradle buildscripts written in Kotlin

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Groovy is one of the worst languages I've ever used. It's like someone thought that the problem with Ruby was that it just didn't have enough magic or cute little tricks.

Tunga
May 7, 2004

Grimey Drawer

speng31b posted:

Link them to Jake Wharton's long form rebuttal of "Kotlin is a fad/we can't support it." I'll dig it up later and link it. Basically Jetbrains is a highly credible maintainer and it will never be "a fad" unless you think Java (but better) is a fad.
Is this a blog post or a video? I found a video but can't check right now if that's the right thing. Link would be great if you can find it.

speng31b
May 8, 2010

Tunga posted:

Is this a blog post or a video? I found a video but can't check right now if that's the right thing. Link would be great if you can find it.

It's a blog post, but it's proving trickier to find than I thought it would be. I'll post it as soon as I can find it, it's a good read.

Tunga
May 7, 2004

Grimey Drawer

speng31b posted:

It's a blog post, but it's proving trickier to find than I thought it would be. I'll post it as soon as I can find it, it's a good read.
I'm guessing this?

https://docs.google.com/document/d/1ReS3ep-hjxWA8kZi0YqDbEhCqTt29hG8P44aA9W0DM8/edit

speng31b
May 8, 2010


Yep that's it.

uncle blog
Nov 18, 2012

I have a picture of a minus sign in my app. When a user clicks it, I want a field to drop down with the text "Remove object", that is clickable. Is there an easy wat to implement this?

Sereri
Sep 30, 2008

awwwrigami

uncle blog posted:

I have a picture of a minus sign in my app. When a user clicks it, I want a field to drop down with the text "Remove object", that is clickable. Is there an easy wat to implement this?

I'm guessing you want a PopupMenu ?

uncle blog
Nov 18, 2012

Seems like a good guess, thanks!

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop
I'm not sure if this is an android or java question, but here goes:

I've got two nasty constraints to deal with - a polling-only interface, and devices with flaky real time clocks.

The ones that run faster than real-time eventually check the network time and jump back, sometimes a few minutes. My Timer().schedule(task, 100ms) doesn't seem to fire until it the system clock goes past where it was before.

Obvious question answered first: Yes, I'm making sure to post the results to the UI thread. I forgot that once and my app promptly crashed.

All that the timer does is toss a 'requestUpdate' command in the transmit queue. Some of the UI buttons toss commands in the queue too, and those keep working as expected. It's a PITA to diagnose due to the specific hardware this runs on, and I don't have the update service working on an emulator.

Is there a way to request monotonic intervals on android through sleep and time changes?

Edit: To clarify, I don't want to fire during sleep, just a fairly consistent period while the device is running that doesn't hang when the time changes or the device sleeps. All the answers out there are "never change the wall time."

Harik fucked around with this message at 21:10 on Oct 20, 2016

Vesi
Jan 12, 2005

pikachu looking at?
how about skipping java and using clock_gettime() with CLOCK_MONOTONIC?

linux is one of the easier platforms to get monotonic time with

speng31b
May 8, 2010

Vesi posted:

how about skipping java and using clock_gettime() with CLOCK_MONOTONIC?

linux is one of the easier platforms to get monotonic time with

Yes you can use monotonic time to help with unreliable system time, no you don't "skip Java" to get monotonic time. Read the docs:

https://developer.android.com/reference/android/os/SystemClock.html

Elapsed real-time is guaranteed to be monotonic. Trying to skip Java and use raw *nix functionality in android apps is a great way to end up with unstable unportable code.

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop
I don't particularly want to write a replacement for Timer.schedule() using SystemClock.sleep() and .uptimeMillis().

Timer.schedule() is based on Object.wait(millis), and I thought that was monotonic. Going over the page again it's not clear that it is. It looks like android.os.Handler.postDelayed() is monotonic, and it's trivial to switch to that. Is that the right answer?

Adbot
ADBOT LOVES YOU

speng31b
May 8, 2010

postDelayed and/or postAtTime with uptimeMillis are probably what you want, yep.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply