madcyph3r / AdvancedMaterialDrawer

A Gmail-like Material Drawer implementation
Apache License 2.0
198 stars 55 forks source link

Using large amount (50+) of head items with listener and static background. #27

Open JaisonBrooks opened 9 years ago

JaisonBrooks commented 9 years ago

Hey madcyph3r,

First off great lib! its freaking awesome!!!

I'd like to use this lib in a project where i have an array of custom objects and am using this array to build the head items. Sometimes i may have up to 50+ custom objects in the array and need a head item for each one. I'd like to have a static background between them. Or a way to load the background initially for the first item then only on head item change. (I ran into memory issues when setting the same background (~12kb jpg) to 50+ header items).

I need to be able to load the custom object from the array based on the position of the head item that was clicked (either by avatar clicked or from extra menu).

I'd attempted to use bits and pieces from the header item types 5 item with extra menu and i can successfully build 50+ header items with a transparent xml background and a onheaditemchange listener. However this listener seems to only be being called when i click the avatars and not when clicking from the extra menu (not sure why).

Any advise or explanation on how to go about this would be greatly appreciated. Also do you have in the pipeline a demo with large amounts of head items or something similar to my query? thanks for your time.

madcyph3r commented 9 years ago

I will add a method, to set a static background and test the result.

madcyph3r commented 9 years ago

See the latest git version. I have add an option, to set a static background. I will release the next version, if i have found the sliding tab bug.

JaisonBrooks commented 9 years ago

Thanks for adding a static method!! I downloaded the latest apk from the github link and your 100+ static background seems to be failing on my end.

04-19 21:28:10.726 E/AndroidRuntime(32054): java.lang.OutOfMemoryError: Failed to allocate a 3111708 byte allocation with 2044872 free bytes and 1996KB until OOM

Any ideas?

JaisonBrooks commented 9 years ago

Here is the full logs

04-19 21:30:44.496 E/AndroidRuntime(833): Process: de.madcyph3r.MaterialDrawer, PID: 833 04-19 21:30:44.496 E/AndroidRuntime(833): java.lang.OutOfMemoryError: Failed to allocate a 3111708 byte allocation with 2034696 free bytes and 1987KB until OOM 04-19 21:30:44.496 E/AndroidRuntime(833): at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:467) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:497) 04-19 21:30:44.496 E/AndroidRuntime(833): at de.madcyph3r.example.example.headItemTypes.HeadItem100StaticBackgroundActivity.getHeadItem(HeadItem100StaticBackgroundActivity.java:66) 04-19 21:30:44.496 E/AndroidRuntime(833): at de.madcyph3r.example.example.headItemTypes.HeadItem100StaticBackgroundActivity.init(HeadItem100StaticBackgroundActivity.java:46) 04-19 21:30:44.496 E/AndroidRuntime(833): at de.madcyph3r.materialnavigationdrawer.MaterialNavigationDrawer.onCreate(MaterialNavigationDrawer.java:218) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.app.Activity.performCreate(Activity.java:5938) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.app.ActivityThread.access$900(ActivityThread.java:147) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.os.Handler.dispatchMessage(Handler.java:102) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.os.Looper.loop(Looper.java:135) 04-19 21:30:44.496 E/AndroidRuntime(833): at android.app.ActivityThread.main(ActivityThread.java:5254) 04-19 21:30:44.496 E/AndroidRuntime(833): at java.lang.reflect.Method.invoke(Native Method) 04-19 21:30:44.496 E/AndroidRuntime(833): at java.lang.reflect.Method.invoke(Method.java:372) 04-19 21:30:44.496 E/AndroidRuntime(833): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898) 04-19 21:30:44.496 E/AndroidRuntime(833): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

madcyph3r commented 9 years ago

Do you use images for the headItem avatar?

JaisonBrooks commented 9 years ago

I've been using TextDrawable's as the avatar heads, and this stack trace is from the sample app.

madcyph3r commented 9 years ago

Ok, then i must implement lazy load for the icons.