Android Open Source - ADNHome Launcher






From Project

Back to project page ADNHome.

License

The source code is released under:

Copyright (c) 2013, David Krauser All rights reserved. Redistribution and use in source and binary forms, with or without modification, are not permitted. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT ...

If you think the Android project ADNHome 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.davidkrauser.adnhome;
/*from   w  ww .  j a va 2 s . c  o m*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;

public class Launcher extends FragmentActivity {

  public static ADNModel sADNModel;
  private LauncherPagerAdapter mLauncherPagerAdapter;
  private ViewPager mViewPager;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.launcher);

    sADNModel = new ADNModel();

    mLauncherPagerAdapter = new LauncherPagerAdapter(
        getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.launcher_pager);
    mViewPager.setAdapter(mLauncherPagerAdapter);
    mViewPager.setCurrentItem(1);
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
      if (mViewPager.getCurrentItem() == 0
          && ((StreamFragment) ((LauncherPagerAdapter) mViewPager
              .getAdapter()).getItem(0)).onKeyDown(keyCode)) {
        return true;
      } else {
        mViewPager.setCurrentItem(1);
        return true;
      }
    }

    if (keyCode == KeyEvent.KEYCODE_HOME) {
      mViewPager.setCurrentItem(1);
      return true;
    }

    return super.onKeyDown(keyCode, event);
  }

  private class LauncherPagerAdapter extends FragmentPagerAdapter {

    public LauncherPagerAdapter(FragmentManager fm) {
      super(fm);
    }

    @Override
    public Fragment getItem(int position) {
      Fragment fragment = null;

      switch (position) {
      case 0:
        fragment = new StreamFragment();
        break;
      case 1:
        fragment = new ApplicationListFragment();
        break;
      case 2:
        fragment = new MessagesFragment();
        break;
      default:
        break;
      }

      return fragment;
    }

    @Override
    public int getCount() {
      // Show 2 total pages.
      return 2;
    }
  }
}




Java Source Code List

com.davidkrauser.adnhome.ADNModel.java
com.davidkrauser.adnhome.ApplicationListFragment.java
com.davidkrauser.adnhome.Launcher.java
com.davidkrauser.adnhome.MessagesFragment.java
com.davidkrauser.adnhome.StreamFragment.java