Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Developing better debug_components

4 954 vues

Publié le

This slides explains 2 tips about how to develop better debug components with Android application.

Publié dans : Ingénierie
  • Is Your Ex With a Woman? Don't lose your Ex boyfriend! This weird trick will get him back! ■■■ http://ishbv.com/exback123/pdf
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Developing better debug_components

  1. 1. Developing Better Debug Components Mercari, Inc. Tomoaki Imai 07/30/2015 @shibuya.apk
  2. 2. Hi I’m Tomo Android Developer Joined Mercari, Inc. Mar,2014 Focusing on US app development twitter: @tomoaki_imai github: tomoima525
  3. 3. How debugging goes at Mercari
  4. 4. Debug View Configure settings that affect the whole app • Api domain configuration • Debug logout • Open specific dialogs & screens directly
  5. 5. Debug Menu Debugging functions that you want to use at each screens Things you don’t always need to see at Debug View
  6. 6. Debug Menu Functions • Auto Inputs • Device Info • Activity Info • Heap size • Screen dpi • GCM ID • Refresh master data etc.
  7. 7. 2 tips for debug functions • Get the debug-related source code out of the production • Control a visibility of the debug menu
  8. 8. 2 tips for debug functions • Get the debug-related source code out of the production • Control a visibility of the debug menu
  9. 9. Modularize debug functions
  10. 10. public class DebugView { public static void init(Context context, LinearLayout layout){ // Do nothing } } Modularize debug functions public class DebugView { public static void init(Context context, LinearLayout layout) { new DebugView(context, layout); } private DebugView(Context context, LinearLayout layout) { LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View debugView = layoutInflater.inflate(R.layout.layout_debug, null); // Set debug views ... layout.addView(debugView); } } /src/release/…/DebugView.java /src/debug/…/DebugView.java
  11. 11. // Any Activity or Fragment where you want to set DebugView. // ex) SettingFragment.java @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_setting, container, false); // … LinearLayout layout = (LinearLayout) view.findViewById(R.id.debug_view); DebugView.init(getBaseActivity(),layout); return view; } Modularize debug functions
  12. 12. 2 tips for debug functions • Get the debug-related source code out of the production • Control a visibility of the debug menu
  13. 13. Control visibility of debug menu
  14. 14. Control visibility of debug menu public class MenuModule { private final static int GROUP_ID = Integer.MAX_VALUE; public void onCreateOptionsMenu(Menu menu){ if(!LocalStorageUtil.getBoolean(S.is_debug_menu_visible)) return; // Set group id so that we can control visibility! menu.add(GROUP_ID, 100, 0, "Input"); //... Add menus } public void setVisibility(Menu menu, boolean isVisible){ for(int i = 0, length = menu.size(); i < length; i++ ){ MenuItem menuItem = menu.getItem(i); if(menuItem.getGroupId() == GROUP_ID){ menuItem.setVisible(isVisible); //Set visibility } } } }
  15. 15. public class BaseActivity { mMenuModule = new MenuModule(this); // Called only once @Override public boolean onCreateOptionsMenu(Menu menu) { mMenuModule.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu); } // Called every time menu is shown @Override public boolean onPrepareOptionsMenu(Menu menu) { mMenuModule.setVisibility(menu, LocalStorageUtil.getBoolean(S.is_debug_menu_visible, false)); return super.onPrepareOptionsMenu(menu); } } Control visibility of debug menu
  16. 16. public class DebugView { private void changeDebugMenu(boolean isDebugMenuVisible){ // Save the state in Shared preference LocalStorageUtil.putBoolean(S.is_debug_menu_visible, isDebugMenuVisible); debugMenuButton .setText(isDebugMenuVisible ? R.string.on : R.string.off); debugMenuButton .setBackgroundResource(isDebugMenuVisible ? R.drawable.indicator_on :R.drawable.indicator_off); // Update menu MyApplication .getContext().getCurrentActivity().invalidateOptionsMenu(); } } Control visibility of debug menu
  17. 17. Wrap up • Modularise debug components and get rid of them out from production • Control the visibility of debug menu to avoid effects on usability

×