Android Open Source - utexas-utilities Phone Delegate






From Project

Back to project page utexas-utilities.

License

The source code is released under:

Apache License

If you think the Android project utexas-utilities listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mapsaurus.paneslayout;
//from  w ww. j  a va2 s.co  m
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.view.View;

import com.actionbarsherlock.view.MenuItem;

import java.lang.ref.WeakReference;

public class PhoneDelegate extends ActivityDelegate implements OnBackStackChangedListener {

  private SlidingPaneLayout spl;
  
  public PhoneDelegate(PanesActivity a) {
    super(a);
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    if (findViewById(R.id.content_frame) == null)
      setContentView(R.layout.phone_layout);
    
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    
    int menuOffset = getResources().getDimensionPixelSize(R.dimen.menu_offset);
    
    spl = (SlidingPaneLayout) findViewById(R.id.slidingpane_layout);
    spl.setShadowResource(R.drawable.shadow_left);
    spl.setParallaxDistance(menuOffset);
    spl.setCoveredFadeColor(Color.parseColor("#88000000"));
    spl.setSliderFadeColor(Color.parseColor("#00000000"));
    spl.setPanelSlideListener(new PanelSlideListener() {
      
      @Override
      public void onPanelSlide(View panel, float offset) {
        
      }
      
      @Override
      public void onPanelOpened(View panel) {
        
      }
      
      @Override
      public void onPanelClosed(View panel) {
        
      }
    });
    
    FragmentManager fm = getSupportFragmentManager();
    fm.addOnBackStackChangedListener(this);
  }

  /* *********************************************************************
   * Interactions with menu/back/etc
   * ********************************************************************* */

  @Override
  public boolean onBackPressed() {
    FragmentManager fm = getSupportFragmentManager();

    if (!spl.isOpen()) {
      if (fm.getBackStackEntryCount() > 0) {
        return false;
      } else {
        spl.openPane();
        return true;
      }
    } else {
      getActivity().finish();
      return true;
    }
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
      if (!spl.isOpen())
        spl.openPane();
      else
        onBackPressed();
      return true;
    }
    return false;
  }
  
  @Override
  public void onBackStackChanged() {

  }

  /* *********************************************************************
   * Adding, removing, getting fragments
   * ********************************************************************* */

  /**
   * Save the menu fragment. The reason to do this is because sometimes when
   * we need to retrieve a fragment, that fragment has not yet been added.
   */
  private WeakReference<Fragment> wMenuFragment = new WeakReference<Fragment>(null);

  @Override
  public void addFragment(Fragment prevFragment, Fragment newFragment) {
    boolean addToBackStack = false;
    if (prevFragment == getMenuFragment() || prevFragment == null) {
      clearFragments();
    } else {
      addToBackStack = true;
    }

    if (spl.isOpen()) spl.closePane();

    if (newFragment != null) {
      FragmentManager fm = getSupportFragmentManager();
      FragmentTransaction ft = fm.beginTransaction();
      ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
          android.R.anim.fade_in, android.R.anim.fade_out);
      ft.replace(R.id.content_frame, newFragment);
      if (addToBackStack) ft.addToBackStack(newFragment.toString());
      ft.commit();
    }
  }

  @Override
  public void clearFragments() {
    FragmentManager fm = getSupportFragmentManager();
    for(int i = 0; i < fm.getBackStackEntryCount(); i ++)    
      fm.popBackStack();
  }

  @Override
  public void setMenuFragment(Fragment f) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.menu_frame, f);
    ft.commit();

    wMenuFragment = new WeakReference<Fragment>(f);
  }

  @Override
  public Fragment getMenuFragment() {
    Fragment f = wMenuFragment.get();
    if (f == null) {
      f = getSupportFragmentManager().findFragmentById(R.id.menu_frame);
      wMenuFragment = new WeakReference<Fragment>(f);
    }
    return f;
  }

  @Override
  public Fragment getTopFragment() {
    return getSupportFragmentManager().findFragmentById(R.id.content_frame);
  }

  @Override
  public void showMenu() {
    spl.openPane();
  }
  
  @Override
  public void showContent() {
    spl.closePane();
  }

}




Java Source Code List

com.google.maps.android.ui.MyIconGenerator.java
com.mapsaurus.paneslayout.ActivityDelegate.java
com.mapsaurus.paneslayout.FragmentLauncher.java
com.mapsaurus.paneslayout.MenuItemWrapper.java
com.mapsaurus.paneslayout.MySlidingPaneLayout.java
com.mapsaurus.paneslayout.PanesActivity.java
com.mapsaurus.paneslayout.PanesLayout.java
com.mapsaurus.paneslayout.PanesSizer.java
com.mapsaurus.paneslayout.PhoneDelegate.java
com.mapsaurus.paneslayout.SimpleScrollView.java
com.mapsaurus.paneslayout.TabletDelegate.java
com.nasageek.utexasutilities.AsyncTask.java
com.nasageek.utexasutilities.AttachmentDownloadService.java
com.nasageek.utexasutilities.AuthCookie.java
com.nasageek.utexasutilities.BlackboardDashboardXmlParser.java
com.nasageek.utexasutilities.BuildingDatabase.java
com.nasageek.utexasutilities.BuildingProvider.java
com.nasageek.utexasutilities.BuildingSaxHandler.java
com.nasageek.utexasutilities.ChangeLog.java
com.nasageek.utexasutilities.ChangeableContextTask.java
com.nasageek.utexasutilities.CourseMapSaxHandler.java
com.nasageek.utexasutilities.FixedListPreference.java
com.nasageek.utexasutilities.LoginWebViewClient.java
com.nasageek.utexasutilities.MarkerManager.java
com.nasageek.utexasutilities.MyPair.java
com.nasageek.utexasutilities.MyScrollView.java
com.nasageek.utexasutilities.PlacemarkSaxHandler.java
com.nasageek.utexasutilities.PnaAuthCookie.java
com.nasageek.utexasutilities.RouteSaxHandler.java
com.nasageek.utexasutilities.SecurePreferences.java
com.nasageek.utexasutilities.TempLoginException.java
com.nasageek.utexasutilities.UTilitiesApplication.java
com.nasageek.utexasutilities.UtdAuthCookie.java
com.nasageek.utexasutilities.Utility.java
com.nasageek.utexasutilities.WrappedViewPager.java
com.nasageek.utexasutilities.WrappingSlidingDrawer.java
com.nasageek.utexasutilities.activities.AboutMeActivity.java
com.nasageek.utexasutilities.activities.BalanceActivity.java
com.nasageek.utexasutilities.activities.BlackboardPanesActivity.java
com.nasageek.utexasutilities.activities.CampusMapActivity.java
com.nasageek.utexasutilities.activities.DataUsageActivity.java
com.nasageek.utexasutilities.activities.LoginActivity.java
com.nasageek.utexasutilities.activities.MenuActivity.java
com.nasageek.utexasutilities.activities.NutritionInfoActivity.java
com.nasageek.utexasutilities.activities.Preferences.java
com.nasageek.utexasutilities.activities.ScheduleActivity.java
com.nasageek.utexasutilities.activities.UTilitiesActivity.java
com.nasageek.utexasutilities.adapters.BBClassAdapter.java
com.nasageek.utexasutilities.adapters.CourseMapAdapter.java
com.nasageek.utexasutilities.adapters.MultiPanePagerAdapter.java
com.nasageek.utexasutilities.adapters.MyFragmentPagerAdapter.java
com.nasageek.utexasutilities.adapters.ScheduleClassAdapter.java
com.nasageek.utexasutilities.adapters.TransactionAdapter.java
com.nasageek.utexasutilities.fragments.ActionModeFragment.java
com.nasageek.utexasutilities.fragments.BlackboardAnnouncementsFragment.java
com.nasageek.utexasutilities.fragments.BlackboardCourseListFragment.java
com.nasageek.utexasutilities.fragments.BlackboardCourseMapFragment.java
com.nasageek.utexasutilities.fragments.BlackboardDashboardFragment.java
com.nasageek.utexasutilities.fragments.BlackboardDownloadableItemFragment.java
com.nasageek.utexasutilities.fragments.BlackboardExternalItemFragment.java
com.nasageek.utexasutilities.fragments.BlackboardFragment.java
com.nasageek.utexasutilities.fragments.BlackboardGradesFragment.java
com.nasageek.utexasutilities.fragments.BlackboardPagerFragment.java
com.nasageek.utexasutilities.fragments.CourseScheduleFragment.java
com.nasageek.utexasutilities.fragments.DatePickerFragment.java
com.nasageek.utexasutilities.fragments.DoubleDatePickerDialogFragment.java
com.nasageek.utexasutilities.fragments.ExamScheduleFragment.java
com.nasageek.utexasutilities.fragments.MenuFragment.java
com.nasageek.utexasutilities.fragments.NutritionInfoFragment.java
com.nasageek.utexasutilities.fragments.PickCalendarDialogFragment.java
com.nasageek.utexasutilities.fragments.TransactionsFragment.java
com.nasageek.utexasutilities.model.BBClass.java
com.nasageek.utexasutilities.model.Building.java
com.nasageek.utexasutilities.model.Classtime.java
com.nasageek.utexasutilities.model.CourseMapItem.java
com.nasageek.utexasutilities.model.FeedItem.java
com.nasageek.utexasutilities.model.Placemark.java
com.nasageek.utexasutilities.model.Transaction.java
com.nasageek.utexasutilities.model.UTClass.java
com.viewpagerindicator.MyTabPageIndicator.java