Office Hours — Today, July 14

Yesterday, July 13

Jul 14
8:50 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:05 AM
Johnny
has entered the room
Mark M.
hello, Johnny!
how can I help you today?
Johnny
Hi Mark
Currently in my activity layout I have the toolbar at the top, frameLayout for a fragment in the middle then an adView at the bottom.
View paste (12 more lines)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/toolbar"
        android:id="@+id/toolbar"/>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
...
How would I only show the adView when there is an Ad loaded? So if it fails I don't want the adView there.
Mark M.
hmmmm...
I have not tried setting visibility to GONE on a widget that is used as an anchor by something else in a RelativeLayout
so, while I would try that first, it may not work
Johnny
Yeah that crashes when I do that
Mark M.
OK
9:10 AM
Johnny
Do I have to switch over to LinearLayout?
Mark M.
that was what I was going to recommend trying next
when you make the adView GONE, the recalculated weight should give all the space to the FrameLayout
Johnny
Hmm yeah guess I got no choice. Thanks :)
Mark M.
if you were desperate to stick with the RelativeLayout, you would need to change the RelativeLayout.LayoutParams for the FrameLayout, before you made the adView GONE
basically, you'd change the FrameLayout to anchor at the bottom of the screen, as the adView does
then, with no other anchoring rules dependent upon adView, I would expect that making it be GONE (or removing it via removeChild()) would work
Johnny
Ah that makes sense. I'll try that also
9:15 AM
Johnny
I have another problem I am hoping that you could help me with
Mark M.
go right ahead -- it's a quiet chat room today
Johnny
I'm currently using the material theme at the moment
View paste (1 more line)
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="AppTheme.Base"/>

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>

        <item name="android:textColorPrimary">@color/text_primary</item>
        <item name="android:textColor">@color/text_secondary</item>

        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
...
Mark M.
no, you are using Theme.AppCompat.Light.NoActionBar
Johnny
Oh, should I have it there for pre-lollipop compatibility?
Mark M.
I am not sure what "it" is
you use Theme.AppCompat-based themes if you are using appcompat-v7
inheriting from AppCompatActivity or ActionBarActivity, etc.
9:20 AM
Tejas
has entered the room
Mark M.
hello, Tejas!
Johnny
sorry, so I should be using something else for the parent?
Tejas
Hi Mark. Good morning.
Mark M.
Johnny: if you are not using appcompat-v7, using Theme.AppCompat-based themes will not work AFAIK
Theme.Material only works on API Level 21+, so if your minSdkVersion is lower than that, you would need to either use something else consistently (e.g., Theme.Holo) or use Theme.Material only on the newer devices
Johnny
Ah right, yeah I got min 15, and I have app-compat-v7
Mark M.
this sample app from the book demonstrates an app that uses Theme.Holo-based themes on Android 4.x devices and Theme.Material-based themes on Android 5.x devices: https://github.com/commonsguy/cw-omnibus/tree/m...
then you should stick with Theme.AppCompat-based themes
Johnny
Thank you
Mark M.
unless you like crashing :-)
Johnny
haha
Mark M.
let me take a question from Tejas, and I will be back with you in a bit
Tejas: your turn! do you have a question?
Tejas
Hi Mark. I need to flag a stack overflow question here. Can I give you a link?
Mark M.
sure, though you're welcome to use the Stack Overflow "bump" feature in the Warescription account for that sort of thing too
Tejas
Okay. Was not aware of that. Here the link http://stackoverflow.com/questions/30610216/and...
Mark M.
mostly, via "bump", there is no need to wait for office hours
9:25 AM
Mark M.
OK, give me a moment...
Tejas
Sure.
Mark M.
in your case, I'd solve the issue in another way
the fact that you get 30% after 40% is not a problem
the fact that you *pay attention* to 30% after having paid attention to 40% is the problem
so, have each event bus event include not only the percentage, but the time of the event
and if you get an event that is older than the last-seen event, discard it
Tejas
Okay. Perfect. I will do that. That's it from me.
Mark M.
this way, you are independent of event bus characteristics
Tejas
Thank you.
Mark M.
happy to help
Johnny: back to you! do you have another question?
Tejas
has left the room
Johnny
yep, so with the theme above I declared it in the manifest - android:theme="@style/AppTheme
But I was wondering how my preferenceFragment can have a different theme/style
9:30 AM
Johnny
because the text in the numberPicker is white
Mark M.
it's more that you would need to figure out what to add to your theme to say "hey, number picker text should be this other color"
or, since presumably this is your own custom Preference subclass, hack something in there
(leastways, I don't recall a NumberPickerPreference in the Android SDK...)
Johnny
Opps, yeah I actually extended DialogPreference
NumberPickerPreference extends DialogPreference
How can I separate or declare a new theme for my preference activity/fragment?
Mark M.
so, you could either hard-code the coloring that you want as part of NumberPickerPreference, or add your own checks for theme attributes to allow you to set the colors in the theme
you can't declare a theme for a fragment
you're welcome to create another theme and have your PreferenceActivity use that theme via its manifest
9:35 AM
Johnny
View paste
In my manifest I have <application android:theme="@style/AppTheme" ... />
So both my main activity and preference activity adopts this theme. But when I tried to declare a separate theme inside <activity ... /> for my preference activity it crashes
I'll re-try though
Mark M.
what is the nature of the crash?
Johnny
ok sorry, it's working now
Must have been something else that was causing the crash before
9:40 AM
Mark M.
either that, or you were working on it yesterday, and the code was having a bad Monday :-)
Johnny
lol got to love Android programming. Half the time my console doesn't show the crash report
Mark M.
yeah, Android Studio's LogCat display has its issues, if that's what you are using
Johnny
I was also wondering what's your opinion on ORMs?
Mark M.
haven't played with any ORMs yet
Johnny
yep I meant logcat
Ah ok. Reason I asked was because of all the boilerplate setting up content providers each time
9:45 AM
Johnny
Do you also know what's the difference between the SharePreference and Preference. I tried researching but I couldn't find much.
Mark M.
Preference is a UI thing
SharedPreferences are a data thing
it's roughly analogous to the difference between a NumberPicker and a SQLite database
Johnny
View paste
What do you mean by UI thing?
I realised in my older app I used Preference for setting up user preferences, but just now I've set up use preferences with shared preferences
9:50 AM
Mark M.
"What do you mean by UI thing?" -- pretty much what I said. Preference objects are used by PreferenceScreens as part of PreferenceFragments (and, previously, PreferenceActivities)
they present a specific SharedPreference value to the user and, usually, allow the user to update that value
just as a NumberPicker might present a specific database value to the user and, usually, allow the user to update that value
now, in truth, a Preference like DialogPreference is a bit closer to a controller than a view, in MVC semantics
Johnny
Ah right.. understand. Thank you so much for all your help Mark!
Mark M.
you are very welcome
Johnny
Enjoy the rest of your day. Bye :)
Johnny
has left the room
10:00 AM
Mark M.
turned off guest access

Yesterday, July 13

 

Office Hours

People in this transcript

  • Johnny
  • Mark Murphy
  • Tejas