コード例 #1
0
 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);
   MainActivity mainActivity = (MainActivity) this.getActivity();
   ActionBar actionBar = (mainActivity).getSupportActionBar();
   CollapsingToolbarLayout toolbarLayout =
       (CollapsingToolbarLayout) mainActivity.findViewById(R.id.toolbar_layout);
   if (mainActivity.focusOnFragment) // focus is on Fragment
   {
     if (actionBar.getTitle() == null
         || !actionBar.getTitle().equals(this.getString(R.string.local_title)))
       toolbarLayout.setTitle(getString(R.string.local_title));
     inflater.inflate(R.menu.local, menu);
   } else menu.clear();
 }
コード例 #2
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    final MainActivity mainActivity = ((MainActivity) this.getActivity());
    super.onViewCreated(view, savedInstanceState);
    if (this.isHidden()) return;

    DrawerAdapter drawerAdapter =
        ((DrawerAdapter) ((ListView) mainActivity.findViewById(R.id.drawer_list)).getAdapter());
    if (drawerAdapter.getSelectedItem() != 1) {
      drawerAdapter.setSelectedItem(1);
      drawerAdapter.notifyDataSetChanged();
    }

    megaListView.setOnGroupClickListener(
        new ExpandableListView.OnGroupClickListener() {

          @Override
          public boolean onGroupClick(
              ExpandableListView parent, View v, int groupPosition, long id) {
            final ImageView indicator = (ImageView) v.findViewById(R.id.group_indicator);
            RotateAnimation anim;
            if (megaListView.isGroupExpanded(groupPosition)) {
              megaListView.collapseGroupWithAnimation(groupPosition);
              if (indicator != null) {
                anim =
                    new RotateAnimation(
                        180f, 360f, indicator.getWidth() / 2, indicator.getHeight() / 2);
                anim.setInterpolator(new DecelerateInterpolator(3));
                anim.setDuration(500);
                anim.setFillAfter(true);
                indicator.startAnimation(anim);
              }
            } else {
              megaListView.expandGroupWithAnimation(groupPosition);
              if (indicator != null) {
                anim =
                    new RotateAnimation(
                        0f, 180f, indicator.getWidth() / 2, indicator.getHeight() / 2);
                anim.setInterpolator(new DecelerateInterpolator(2));
                anim.setDuration(500);
                anim.setFillAfter(true);
                indicator.startAnimation(anim);
              }
            }
            return true;
          }
        });

    megaListView.setOnChildClickListener(
        new ExpandableListView.OnChildClickListener() {
          @Override
          public boolean onChildClick(
              ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            if (mSwiping) {
              mSwiping = false;
              return false;
            }
            final MainActivity mainActivity = (MainActivity) getActivity();
            megaListView.setOnChildClickListener(null); // prevents bug on double tap
            mainActivity.updateLyricsFragment(
                R.animator.slide_out_start,
                R.animator.slide_in_start,
                true,
                lyricsArray.get(groupPosition).get(childPosition));
            return true;
          }
        });

    this.isActiveFragment = true;
    new DBContentLister(this).execute();
  }