@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { if (soundFragment != null && soundFragment.isVisible()) { sendBroadcast(new Intent(ScriptActivity.ACTION_SOUNDS_LIST_INIT)); } if (lookFragment != null && lookFragment.isVisible()) { sendBroadcast(new Intent(ScriptActivity.ACTION_LOOKS_LIST_INIT)); } } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { FragmentManager fragmentManager = getSupportFragmentManager(); for (String tag : FormulaEditorListFragment.TAGS) { FormulaEditorListFragment fragment = (FormulaEditorListFragment) fragmentManager.findFragmentByTag(tag); if (fragment != null && fragment.isVisible()) { return fragment.onKey(null, keyCode, event); } } FormulaEditorVariableListFragment formulaEditorVariableListFragment = (FormulaEditorVariableListFragment) getSupportFragmentManager() .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG); if (formulaEditorVariableListFragment != null && formulaEditorVariableListFragment.isVisible()) { return formulaEditorVariableListFragment.onKey(null, keyCode, event); } FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSupportFragmentManager() .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG); if (formulaEditor != null && formulaEditor.isVisible()) { scriptFragment.getAdapter().updateProjectBrickList(); return formulaEditor.onKey(null, keyCode, event); } if (soundFragment != null && soundFragment.isVisible() && soundFragment.onKey(null, keyCode, event)) { return true; } if (lookFragment != null && lookFragment.isVisible() && lookFragment.onKey(null, keyCode, event)) { return true; } int backStackEntryCount = fragmentManager.getBackStackEntryCount(); for (int i = backStackEntryCount; i > 0; --i) { String backStackEntryName = fragmentManager.getBackStackEntryAt(i - 1).getName(); if (backStackEntryName != null && (backStackEntryName.equals(LookFragment.TAG) || backStackEntryName.equals(SoundFragment.TAG))) { fragmentManager.popBackStack(); } else { break; } } if (keyCode == KeyEvent.KEYCODE_BACK && currentFragmentPosition == FRAGMENT_SCRIPTS) { DragAndDropListView listView = scriptFragment.getListView(); if (listView.isCurrentlyDragging()) { listView.resetDraggingScreen(); BrickAdapter adapter = scriptFragment.getAdapter(); adapter.removeDraggedBrick(); return true; } } return super.onKeyDown(keyCode, event); }