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
Tunga
May 7, 2004

Grimey Drawer

Karthe posted:

What's a good way to hardcode a "no ads" mode into my app so that ads are disabled on any device from which I personally run the app?
I guess you could check the Google accounts on the device against a hardcoded whitelist.

Adbot
ADBOT LOVES YOU

A COMPUTER GUY
Aug 23, 2007

I can't spare this man - he fights.

Tunga posted:

I guess you could check the Google accounts on the device against a hardcoded whitelist.

Alternately, add your device's serial number to a string array in resources and check against that.

code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="no_ad_devices">
        <item>butts</item>
    </string-array>
</resources>

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Ulysses S. Grant posted:

Alternately, add your device's serial number to a string array in resources and check against that.

code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="no_ad_devices">
        <item>butts</item>
    </string-array>
</resources>
This seems the most simple to implement, I'll give this a try.

Boz0r
Sep 7, 2006
The Rocketship in action.
I'm trying to get a list of printers working properly, but for some reason, my refresh button doesn't work.

The refresh button triggers the getPrinters function, but when it reaches the mService.go(), mService is null. I don't understand what the problem is, as I did a very similar thing in another project.

Also, the onServiceConnected() in the ServiceConnection is never called. Why is this?

http://goo.gl/uQnt65

I hope my code is a little bit understandable.

Boz0r fucked around with this message at 12:47 on Dec 31, 2013

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
When would you use the fragment backstack instead of the regular activty backstack? What is the Android way?

Doctor w-rw-rw-
Jun 24, 2008

Jarl posted:

When would you use the fragment backstack instead of the regular activty backstack? What is the Android way?

I wouldn't use the fragment backstack because it throws away fragment state.

Infomaniac
Jul 3, 2007
Support Cartographers Without Borders
I have been using webdings and windings for some assets in my app. Now, I am getting ready to release it. Does anyone know if it is all good or am I setting myself up for a licensing problem or ip infringement case in the future? For example I use the open book webding or wingding for a category icon.
Perhaps I should remake all of the assets idk.

zeekner
Jul 14, 2007

Infomaniac posted:

I have been using webdings and windings for some assets in my app. Now, I am getting ready to release it. Does anyone know if it is all good or am I setting myself up for a licensing problem or ip infringement case in the future? For example I use the open book webding or wingding for a category icon.
Perhaps I should remake all of the assets idk.

Are you using those fonts to make PNG icons?

You can look at http://fontawesome.io/. It has most of the common symbols you would want, and the license looks pretty much perfect for your needs. I just use it to generate icons in photoshop.

e: Just install the font to your PC and copy/paste from the cheatsheet.

Infomaniac
Jul 3, 2007
Support Cartographers Without Borders
Yes, I ran them through the androind asset studio icon generator, and some of them were modified a bit after the fact. One of the reasons I used wingdings and webdings is that they are the among the available fonts in the dropdown so I figured it might be kosher/ cleared somehow through Google.

Definitely downloading fontawesome, thanks for the recommendation. :)

Infomaniac
Jul 3, 2007
Support Cartographers Without Borders
Further checking led me to a post about the webdings eula. Apparently, it is all good to create and distribute static graphic images png, gif, jpg to create printed t shirts etc... I found the actual eula and I think it's all good, but it is nice to have a backup plan.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

Doctor w-rw-rw- posted:

I wouldn't use the fragment backstack because it throws away fragment state.

But fragment has onSaveInstanceState just like activity. Besides making it possible to save the state, even if the fragment is killed while another activity is active, this, to me, also implies that a fragment on the fragment-backstack is retained in memory until killing it becomes necessary.

Am I misunderstanding this?

Doctor w-rw-rw-
Jun 24, 2008

Jarl posted:

But fragment has onSaveInstanceState just like activity. Besides making it possible to save the state, even if the fragment is killed while another activity is active, this, to me, also implies that a fragment on the fragment-backstack is retained in memory until killing it becomes necessary.

Am I misunderstanding this?

It isn't called in all situations. It's been a couple of years since I wrestled with this, but this might have been because of view pagers or fragment pager adapters not calling the state-saving methods - I don't specifically recall. Or perhaps some interaction with launching activities. In any case, I found it unreliable and broken.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
Is there a way to read a single file from a ZIP file store in the /assets/ directory? I want to use ZipFile.getEntry() to dynamically grab a specific file, but I can't figure out how to get the ZIP file in a position to do that. A lot of guides and SO articles related to this use ZipInputStream to read the contents of a given ZIP file, but that involves iterating over every single compressed file to find the one you want. The ZIP file I'm working with has almost 6700 SVG files in it, that's not feasible.

EDIT: Nevermind, I'm just going to dump the SVG files into the main OBB file and read them using Google's APKExpansionSupport library.

IAmKale fucked around with this message at 23:15 on Jan 9, 2014

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Is there a way to read a single file from a ZIP file store in the /assets/ directory? I want to use ZipFile.getEntry() to dynamically grab a specific file, but I can't figure out how to get the ZIP file in a position to do that. A lot of guides and SO articles related to this use ZipInputStream to read the contents of a given ZIP file, but that involves iterating over every single compressed file to find the one you want. The ZIP file I'm working with has almost 6700 SVG files in it, that's not feasible.

EDIT: Nevermind, I'm just going to dump the SVG files into the main OBB file and read them using Google's APKExpansionSupport library.

Iterating over 6700 small entries in a small contiguous range of bytes is not necessarily expensive, especially not if it's done once at startup and you cache the zip entries.

In any case, assets are actually already accessed directly from within the APK, which is a compressed zip file, so you really don't gain anything by accessing a file-within-a-zip-within-a-zip. What is your rationale for zipping it up vs, say, putting it in a subdirectory of the assets folder vs. packaging it separately?

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
I have a stack A_1->A_2->A_3->B (A_1, A_2 and A_3 are all instances of the same activity A) and I want to pop back to the A_1 (root activity you will) without it being restarted it (i.e. onCreate being run), and hence with the rest of the stack finishing.

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK doesn't work, since it restarts the activity and Intent.FLAG_ACTIVITY_CLEAR_TOP doesn't work either since it also restarts the activity.

I just want it to be like if the user had used the back button until they were back at A_1.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

Doctor w-rw-rw- posted:

In any case, assets are actually already accessed directly from within the APK, which is a compressed zip file, so you really don't gain anything by accessing a file-within-a-zip-within-a-zip. What is your rationale for zipping it up vs, say, putting it in a subdirectory of the assets folder vs. packaging it separately?

I hadn't made the connection that since APK's are already compressed it doesn't matter if I dump a bunch of files into it since they'll get compressed as well. In the interest of keeping updates fairly small in size, I've decided that storing the static (in the sense that it's not updated very often) collection of drawings in the main expansion file is the way to go. And instead of ZIP files inside ZIP files, I just dumped the files themselves into the root of the OBB file since it gets compressed anyway.

Doctor w-rw-rw-
Jun 24, 2008

Jarl posted:

I have a stack A_1->A_2->A_3->B (A_1, A_2 and A_3 are all instances of the same activity A) and I want to pop back to the A_1 (root activity you will) without it being restarted it (i.e. onCreate being run), and hence with the rest of the stack finishing.

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK doesn't work, since it restarts the activity and Intent.FLAG_ACTIVITY_CLEAR_TOP doesn't work either since it also restarts the activity.

I just want it to be like if the user had used the back button until they were back at A_1.

Start the activities with an intent that includes a counter, and finish with a result code that signals the chain of activities should finish themselves until they hit the original counter of 0? Or just destructively do it as you start activities by finishing the predecessor at the same time, if I understand correctly.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

Doctor w-rw-rw- posted:

Start the activities with an intent that includes a counter, and finish with a result code that signals the chain of activities should finish themselves until they hit the original counter of 0? Or just destructively do it as you start activities by finishing the predecessor at the same time, if I understand correctly.

What I need is a HOME button (you know, the "up carret" next to the app icon in the top right) that pops the activity-instances back to the first activity-instance (not a new instance of the first activity), and if I continuously do something to make this possible, then it must NOT mess up the stack, because that mess up the regular back button which pops one activity-instance at a time.

Thus killing the predecessor as I go along is not an option, since the back button wont work as intended (i.e. it wont work as it is always expected by the user to work), AND the HOME button will not get you back to the original root activity-instance, but instead a new instance.

The chain you talk about would mean that EVERY activity and activity-call I have needs to follow this scheme with no exception.
I cannot understand why such a basic thing as "get me back to the original activity-instance on the stack" needs an extensive and/or hack solution. I mean it is right there at the bottom of the activity-stack, and if I as a user push the back button enough times I can get there. So why can't this be accomplished programmatically?

EDIT:
This might be what I need to know, but haven't tried it yet: http://developer.android.com/training/implementing-navigation/ancestral.html

Jarl fucked around with this message at 11:28 on Jan 13, 2014

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

Are you trying to pop off the entire stack to get back to the first activity, or are you trying to add the first activity to the top of the stack with the same state it had before? If it's the former you won't be interfering with the user's experience, you're effectively just pressing the back button for them

I don't know if it'll help at all but it might be worth looking at fragments, especially choosing what gets added to the stack
http://developer.android.com/guide/components/fragments.html#Transactions
You might just want to have fragment 1 get added and recreate its state

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

baka kaba posted:

Are you trying to pop off the entire stack to get back to the first activity

That is what I'm trying to do, BUT there are multiple instances on the stack of the first activity, so it should be "back to the BOTTOM activity-intance", and the activity should NOT be recreated.

baka kaba posted:

If it's the former you won't be interfering with the user's experience, you're effectively just pressing the back button for them

Exactly, which is why I expected it to be supported.

EDIT:
http://developer.android.com/training/implementing-navigation/ancestral.html sadly this wont be a solution since it under the hood does one of the things I've already tried.

code:
Intent intent = new Intent(this, ParentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
One problem with this is that if there are MORE instances of ParentActivity, then it only pops down to the first of them. This might be solved by when creating an instance of parentactivity use a boolean extra that indicates that it is not the original and then use that to keep popping to ParentActivity. Still it will recreate the activity, and I don't want that.

Jarl fucked around with this message at 11:29 on Jan 13, 2014

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
I have solved it by doing:

code:
Intent homeIntent = new Intent(this, FooActivity.class);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(homeIntent); 
and in FooActivity

code:
    protected void onNewIntent(Intent intent) {
        if (home == false) {
            finish();
            Intent homeIntent = new Intent(this, FooActivity_.class);
            homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(homeIntent);
        }
    }
home = false by default and home = true through an extra when spawning the instances. This solution means that other activities does not need to worry about whether or not there are multiple instances of the activity used for home.

MrZig
Aug 13, 2005
I exist onl because of Parias'
LEGENDARY GENEROSITY.
I want to use the stock 'pop' touch sound in my app from KitKat. Is it possibly without rooting and copying the actual sound file into my resources? I know you can access the factory ring tone via RingtoneManager, but what about the 'pop' touch sound?

Suran37
Feb 28, 2009
Using the following image I want to be able to overlay other images onto the slots in the upper-half of the image (and eventually the lower-half). I was thinking maybe a GridLayout, but I'm not sure if it's the best option since I'm not real experienced with android.

Currently, I just have the image set as the background, but I can change that if needed.



Any tips would be appreciated.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
Is there any way to exit an Android application in the oncreate method in a class that extends Application? System.exit(0) does not work.

I need it when a check fail, that only need to be run once when the application starts. A hack would be to set a static boolean and check it in my home activity's oncreate method, where I can then call finish, but then the check wont be made again until the user manually shutdown the application and restarts it. Another way would be to put the check itself in the home activty, but the activty is used in multiple instances, and isn't always just the home activity, so it would clutter the code. Still if it is the only way, then it is the only way.

EDIT:
Have decided to put the check in the activity, where it is run if it is the home activity instance.

Jarl fucked around with this message at 12:26 on Jan 24, 2014

Infomaniac
Jul 3, 2007
Support Cartographers Without Borders
Developer console really messed up today, blocking any updates for one of my apks. Frustrating because I completed a rewrite of my apps description and am unable to update. Fingers crossed that every thing gets worked through the system. Upside the chat support was very fast with a response for me.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
Anybody who knows why on earth there only is a horizontal viewpager? There are hacks on the net and selfmade vertical viewpagers, but this is such a fundamental thing that it obviously should be natively supported. Is it possibly a design philosophy by Google?

zeekner
Jul 14, 2007

Jarl posted:

Anybody who knows why on earth there only is a horizontal viewpager? There are hacks on the net and selfmade vertical viewpagers, but this is such a fundamental thing that it obviously should be natively supported. Is it possibly a design philosophy by Google?

They don't have a horizontal listview either. :doom:

There are a lot of obvious view elements that should exist but don't, it's pretty frustrating. You might be able to hack jump-by-page functionality into listview, but that doesn't sound fun at all.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

Uncomfortable Gaze posted:

They don't have a horizontal listview either. :doom:

There are a lot of obvious view elements that should exist but don't, it's pretty frustrating. You might be able to hack jump-by-page functionality into listview, but that doesn't sound fun at all.

The worst part is not even that is is annoying to make/hack these things. Instead it is that it's very likely it will suddenly break with Android 4.5 or something. Also the improvements/fixes made to the ordinary ViewPager is not automatically put into your own homemade VerticalViewPager. *sigh* Come on Google.

Tunga
May 7, 2004

Grimey Drawer
What's your use case? A vertical ViewPager sounds like a fairly horrible piece of UX, which is probably why it doesn't exist by standard.

(Reminds me of a question I came across recently on SO which was basically "how do I make swiping scroll the other way" and all the answers were "oh god why would you do this?")

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

Tunga posted:

What's your use case? A vertical ViewPager sounds like a fairly horrible piece of UX, which is probably why it doesn't exist by standard.

(Reminds me of a question I came across recently on SO which was basically "how do I make swiping scroll the other way" and all the answers were "oh god why would you do this?")

Imagine a number of "span"-pages which you traverse horizontally. Each "span"-page consists of pages you can traverse vertically. This can all be done.
Now however you also want thumbnails to all these pages that you can call up. Each "span"-page's thumbnails (one for each page) fit in a VerticalViewPager, which in turn is in a HorizontalViewPager. Now you can horizonally swipe through the thumbnails for each "span"-page, while you also can swipe vertically in a "span"-page's thumbnails with swipes. When you touch a thumbnail, that becomes the current page.

EDIT:

Each # is a thumbnail. You can only see 3,5 x 2 thumbnails at a time.
In column 8 you might want to swipe down to number 4. The other "span"-pages wont scroll along.

code:
#############
##    ##  #
#      #
       #
       #
It works beautifully. Would just wish there was a a VerticalViewPager in the Android API.

Jarl fucked around with this message at 20:27 on Feb 6, 2014

Tunga
May 7, 2004

Grimey Drawer
Right, but that's a description of a vertical ViewPager. What are you actually trying to use it for? I assume the thumbnails link to something? Why can't I just flick-scroll down through each column and tap on the thing that I want to view rather than having to swipe swipe swipe once per thing? Look at something like Currents or Newsstand. I might be missing something specific about why your content should work that way.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

Tunga posted:

Right, but that's a description of a vertical ViewPager. What are you actually trying to use it for? I assume the thumbnails link to something? Why can't I just flick-scroll down through each column and tap on the thing that I want to view rather than having to swipe swipe swipe once per thing? Look at something like Currents or Newsstand. I might be missing something specific about why your content should work that way.

I'm no designer and hence did not decide this. I suppose you could use a flick-scroller without a side bar with how far down you are (sans side bar would be necessary).

EDIT:
On the other hand by that logic why even use a horizontal ViewPager?

EDIT2:
The pages are pages in a digital-magazine, so I think the reason is that it doesn't fit with how an article in a magazine should be consumed. Still, when you use thumbnails to jump to a page, it shouldn't matter that you might see too much too fast. You are already jumping into it and thus skipping something. Again, not the designer so I'm just guessing.

Jarl fucked around with this message at 21:07 on Feb 6, 2014

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
Okay having looked at it again the pages are navigated with horizontal- and vertical-viewpager, and that is a good thing (you swipe through pages). However the thumbnails are navigated likewise, and that is a bad thing, but the reason was that ordinary scroll would load all the pictures from the get go and with 100 pages that used to much RAM.

Tunga
May 7, 2004

Grimey Drawer
As far as I understand, if you put them in a ListView it will recycle the views as you scroll.

Load the images then rather than all at the start.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

Tunga posted:

As far as I understand, if you put them in a ListView it will recycle the views as you scroll.

Load the images then rather than all at the start.

Only the thumbnails shown and those right next to the shown should be loaded. So they should be loaded and removed dynamically. Do you think that would be the case?

nardvark
Feb 4, 2014

Tunga posted:

As far as I understand, if you put them in a ListView it will recycle the views as you scroll.

Load the images then rather than all at the start.

This is what ListView and Adapters are designed to do.

They're a pain in the butt to work with, but they're effective for reducing memory consumption and loading jank in long lists of Views. They will organize caching and reloading of View content above and below what's currently displayed.

Writing a ListView Adapter for your custom ViewGroup is probably the way to go.

Unexpected
Jan 5, 2010

You're gonna need
a bigger boat.
I have a newbie question (sorry). If I wanted to write a simple app that would work on both Android and iOS, do I create it on one platform (e.g. XCode on Mac) and then "rewrite" it for Java (as an example) or is there an application that would handle conversion "automatically". I know literally nothing about Android (and Java), so apologies if what I'm asking is retarded.

Tunga
May 7, 2004

Grimey Drawer
There are cross-platform frameworks such as Xamarin but otherwise you have to rewrite it.

Try use the appropriate UX patterns for each platform unless you hate your users.

Doctor w-rw-rw-
Jun 24, 2008

Unexpected posted:

I have a newbie question (sorry). If I wanted to write a simple app that would work on both Android and iOS, do I create it on one platform (e.g. XCode on Mac) and then "rewrite" it for Java (as an example) or is there an application that would handle conversion "automatically". I know literally nothing about Android (and Java), so apologies if what I'm asking is retarded.

Xamarin is the only environment with a realistic approach to writing native apps for each platform using the same language (without resorting to C/C++). The other environments typically offer you variations on a HTML/JS/CSS kind of environment, but it'll generally be very difficult even for moderately experienced developers to make a quality app that feels native on both.

Having developed extensively for both Android and iOS. I can't recommend strongly enough that you should _not_ start on Android for a first platform if the choice is between Android and iOS. iOS is easier to get started on, more profitable, and more fun. Completely worth the price of admission.

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
As an android developer transitioning to iOS, I can't stress enough that each platform has it's own design patterns and idioms, and it's both easy and annoying for your users to spot a crappy port.

If you can, write for each, not both.

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