Android Open Source - BT4Android-trunk B T4 Android






From Project

Back to project page BT4Android-trunk.

License

The source code is released under:

Apache License

If you think the Android project BT4Android-trunk 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.love.apps.BT4U;
/*from w w w  . j a v  a  2 s.c  o m*/
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;

import com.Leadbolt.AdController;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
import com.parse.GetCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;



public class BT4Android extends SherlockFragmentActivity {

  TabHost mTabHost;
  ViewPager  mViewPager;
  TabsAdapter mTabsAdapter;
  private int loaded = 0;
  private RelativeLayout layout = null;
  private Activity act = null;
  public static final String PREFS_NAME = "MyPrefsFile";

  public static GoogleAnalyticsTracker tracker;
  
  static GoogleAnalyticsTracker getTracker()
  {
    return tracker;
  }
  private     AdController myController;

  @Override
        /*On create is used to set up initial fragments and tabs as well 
       set up minor things such as favorites and analytics*/
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Favorites.checkForOldFavorites(this);
    
    setupGoogleAnalytics();
    setContentView(R.layout.fragment_tabs_pager);
    mTabHost = (TabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mViewPager = (ViewPager)findViewById(R.id.pager);
    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);
    mTabsAdapter.addTab(mTabHost.newTabSpec("routes").setIndicator("Routes"),
        Routes.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("favorites").setIndicator("Favorites"),
        Favorites.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("updates").setIndicator("BT Updates"),
        Updates.class, null);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String tab = sharedPref.getString("tab", "0");
    mTabHost.setCurrentTab(Integer.parseInt(tab));

    for(int j=0 ; j < mTabHost.getTabWidget().getChildCount() ; j++) 
    {
      TextView tv = (TextView) mTabHost.getTabWidget().getChildAt(j).findViewById(android.R.id.title);
      tv.setTextColor(0xff990000);
    }         if (savedInstanceState != null) {
      mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }

    Parse.initialize(this, "2yYQs2ODsrljCxsgvb1062l927eINrYFp968bD3B", "Jmpr3qkovqnfEYJimfK6nRX6aSUDjRrJbisXArK9"); 
    ParseQuery q = new ParseQuery("BT4UHttpRequestUrls");
    q.getInBackground("DJAl8sVMSV", new GetCallback() {
      
      @Override
      public void done(ParseObject BT4AndroidUrls, ParseException arg1) {
        // TODO Auto-generated method stub
        if( arg1 == null )
        {
          System.out.println("Got Parse OBJECT");
          System.out.println(BT4AndroidUrls.getString("RouteRequestUrl"));
        
        }
        else
          arg1.printStackTrace();
        
      }
    });
  }
  
  /*set up all required info for google analytics*/
  private void setupGoogleAnalytics() {
    tracker = GoogleAnalyticsTracker.getInstance();
    tracker.startNewSession("UA-34219177-1", 10, this);
    tracker.trackPageView("/bt4android");
    tracker.dispatch();    
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("tab", mTabHost.getCurrentTabTag());
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String tab = sharedPref.getString("tab", "0");
    mTabHost.setCurrentTab(Integer.parseInt(tab));

  }

  /**
   * This is a helper class that implements the management of tabs and all
   * details of connecting a ViewPager with associated TabHost.  It relies on a
   * trick.  Normally a tab host has a simple API for supplying a View or
   * Intent that each tab will show.  This is not sufficient for switching
   * between pages.  So instead we make the content part of the tab host
   * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy
   * view to show as the tab content.  It listens to changes in tabs, and takes
   * care of switch to the correct paged in the ViewPager whenever the selected
   * tab changes.
   */
  public static class TabsAdapter extends FragmentPagerAdapter
  implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
    private final Context mContext;
    private final TabHost mTabHost;
    private final ViewPager mViewPager;
    private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();

    static final class TabInfo {
      private final String tag;
      private final Class<?> clss;
      private final Bundle args;

      TabInfo(String _tag, Class<?> _class, Bundle _args) {
        tag = _tag;
        clss = _class;
        args = _args;
      }
    }

    static class DummyTabFactory implements TabHost.TabContentFactory {
      private final Context mContext;

      public DummyTabFactory(Context context) {
        mContext = context;
      }

      public View createTabContent(String tag) {
        View v = new View(mContext);
        v.setMinimumWidth(0);
        v.setMinimumHeight(0);
        return v;
      }
    }

    public TabsAdapter(FragmentActivity activity, TabHost tabHost, ViewPager pager) {
      super(activity.getSupportFragmentManager());
      mContext = activity;
      mTabHost = tabHost;
      mViewPager = pager;
      mTabHost.setOnTabChangedListener(this);
      mViewPager.setAdapter(this);
      mViewPager.setOnPageChangeListener(this);
    }

    public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
      tabSpec.setContent(new DummyTabFactory(mContext));
      String tag = tabSpec.getTag();

      TabInfo info = new TabInfo(tag, clss, args);
      mTabs.add(info);
      mTabHost.addTab(tabSpec);
      notifyDataSetChanged();
    }

    @Override
    public int getCount() {
      return mTabs.size();
    }

    @Override
    public Fragment getItem(int position) {
      TabInfo info = mTabs.get(position);
      return Fragment.instantiate(mContext, info.clss.getName(), info.args);
    }

    public void onTabChanged(String tabId) {
      int position = mTabHost.getCurrentTab();
      Log.i("TABS", position + " ");
      mViewPager.setCurrentItem(position);
      if(position == 1) {
        BT4Android.getTracker().trackPageView("/favorites");
        BT4Android.getTracker().dispatch();
        Favorites favs = Favorites.getFavorites();
        if(favs == null)
          return;
        
        favs.updateFavorites(mContext);
      }
      else if(position==0)
      {
        BT4Android.getTracker().trackPageView("/routes");
        BT4Android.getTracker().dispatch();
        Routes.checkMenu();
      }
      
    }

    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    public void onPageSelected(int position) {
      // Unfortunately when TabHost changes the current tab, it kindly
      // also takes care of putting focus on it when not in touch mode.
      // The jerk.
      // This hack tries to prevent this from pulling focus out of our
      // ViewPager.
      TabWidget widget = mTabHost.getTabWidget();
      int oldFocusability = widget.getDescendantFocusability();
      widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
      mTabHost.setCurrentTab(position);
      widget.setDescendantFocusability(oldFocusability);
    }

    public void onPageScrollStateChanged(int state) {
    }
  }
  
  @Override
    protected void onDestroy() {
     
    //stop showing ad
    if(myController!=null)
    myController.destroyAd();
      // Stop the tracker when it is no longer needed.
      tracker.stopSession();
      super.onDestroy();
    }  

}




Java Source Code List

android.support.v4.app._ActionBarSherlockTrojanHorse.java
com.actionbarsherlock.ActionBarSherlock.java
com.actionbarsherlock.app.ActionBar.java
com.actionbarsherlock.app.SherlockActivity.java
com.actionbarsherlock.app.SherlockDialogFragment.java
com.actionbarsherlock.app.SherlockExpandableListActivity.java
com.actionbarsherlock.app.SherlockFragmentActivity.java
com.actionbarsherlock.app.SherlockFragment.java
com.actionbarsherlock.app.SherlockListActivity.java
com.actionbarsherlock.app.SherlockListFragment.java
com.actionbarsherlock.app.SherlockPreferenceActivity.java
com.actionbarsherlock.internal.ActionBarSherlockCompat.java
com.actionbarsherlock.internal.ActionBarSherlockNative.java
com.actionbarsherlock.internal.ResourcesCompat.java
com.actionbarsherlock.internal.app.ActionBarImpl.java
com.actionbarsherlock.internal.app.ActionBarWrapper.java
com.actionbarsherlock.internal.nineoldandroids.animation.AnimatorListenerAdapter.java
com.actionbarsherlock.internal.nineoldandroids.animation.AnimatorSet.java
com.actionbarsherlock.internal.nineoldandroids.animation.Animator.java
com.actionbarsherlock.internal.nineoldandroids.animation.FloatEvaluator.java
com.actionbarsherlock.internal.nineoldandroids.animation.FloatKeyframeSet.java
com.actionbarsherlock.internal.nineoldandroids.animation.IntEvaluator.java
com.actionbarsherlock.internal.nineoldandroids.animation.IntKeyframeSet.java
com.actionbarsherlock.internal.nineoldandroids.animation.KeyframeSet.java
com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.java
com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator.java
com.actionbarsherlock.internal.nineoldandroids.animation.PropertyValuesHolder.java
com.actionbarsherlock.internal.nineoldandroids.animation.TypeEvaluator.java
com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.java
com.actionbarsherlock.internal.nineoldandroids.view.NineViewGroup.java
com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy.java
com.actionbarsherlock.internal.nineoldandroids.widget.NineFrameLayout.java
com.actionbarsherlock.internal.nineoldandroids.widget.NineHorizontalScrollView.java
com.actionbarsherlock.internal.nineoldandroids.widget.NineLinearLayout.java
com.actionbarsherlock.internal.view.ActionProviderWrapper.java
com.actionbarsherlock.internal.view.StandaloneActionMode.java
com.actionbarsherlock.internal.view.View_HasStateListenerSupport.java
com.actionbarsherlock.internal.view.View_OnAttachStateChangeListener.java
com.actionbarsherlock.internal.view.menu.ActionMenuItemView.java
com.actionbarsherlock.internal.view.menu.ActionMenuItem.java
com.actionbarsherlock.internal.view.menu.ActionMenuPresenter.java
com.actionbarsherlock.internal.view.menu.ActionMenuView.java
com.actionbarsherlock.internal.view.menu.ActionMenu.java
com.actionbarsherlock.internal.view.menu.BaseMenuPresenter.java
com.actionbarsherlock.internal.view.menu.ListMenuItemView.java
com.actionbarsherlock.internal.view.menu.MenuBuilder.java
com.actionbarsherlock.internal.view.menu.MenuItemImpl.java
com.actionbarsherlock.internal.view.menu.MenuItemWrapper.java
com.actionbarsherlock.internal.view.menu.MenuPopupHelper.java
com.actionbarsherlock.internal.view.menu.MenuPresenter.java
com.actionbarsherlock.internal.view.menu.MenuView.java
com.actionbarsherlock.internal.view.menu.MenuWrapper.java
com.actionbarsherlock.internal.view.menu.SubMenuBuilder.java
com.actionbarsherlock.internal.view.menu.SubMenuWrapper.java
com.actionbarsherlock.internal.widget.AbsActionBarView.java
com.actionbarsherlock.internal.widget.ActionBarContainer.java
com.actionbarsherlock.internal.widget.ActionBarContextView.java
com.actionbarsherlock.internal.widget.ActionBarView.java
com.actionbarsherlock.internal.widget.CapitalizingButton.java
com.actionbarsherlock.internal.widget.CapitalizingTextView.java
com.actionbarsherlock.internal.widget.FakeDialogPhoneWindow.java
com.actionbarsherlock.internal.widget.IcsAbsSpinner.java
com.actionbarsherlock.internal.widget.IcsAdapterView.java
com.actionbarsherlock.internal.widget.IcsLinearLayout.java
com.actionbarsherlock.internal.widget.IcsListPopupWindow.java
com.actionbarsherlock.internal.widget.IcsProgressBar.java
com.actionbarsherlock.internal.widget.IcsSpinner.java
com.actionbarsherlock.internal.widget.IcsView.java
com.actionbarsherlock.internal.widget.ScrollingTabContainerView.java
com.actionbarsherlock.view.ActionMode.java
com.actionbarsherlock.view.ActionProvider.java
com.actionbarsherlock.view.CollapsibleActionView.java
com.actionbarsherlock.view.MenuInflater.java
com.actionbarsherlock.view.MenuItem.java
com.actionbarsherlock.view.Menu.java
com.actionbarsherlock.view.SubMenu.java
com.actionbarsherlock.view.Window.java
com.actionbarsherlock.widget.ActivityChooserModel.java
com.actionbarsherlock.widget.ActivityChooserView.java
com.actionbarsherlock.widget.ShareActionProvider.java
com.love.apps.BT4U.Arrival.java
com.love.apps.BT4U.ArrivalsAdapter.java
com.love.apps.BT4U.BT4Android.java
com.love.apps.BT4U.Favorites.java
com.love.apps.BT4U.FileRead.java
com.love.apps.BT4U.Routes.java
com.love.apps.BT4U.SettingsActivity.java
com.love.apps.BT4U.Updates.java
com.love.apps.BT4U.webservice.BT4U.java
com.love.apps.BT4U.webservice.BusStop.java
com.love.apps.BT4U.webservice.Bus.java
com.love.apps.BT4U.webservice.RouteBuilder.java
com.love.apps.BT4U.webservice.Route.java
com.love.apps.BT4U.webservice.ScheduledDeparture.java
com.love.apps.BT4U.webservice.ScheduledStop.java
com.love.apps.BT4U.aboutMe.java
com.love.qsort.DSutil.java
com.love.qsort.MyQsort.java