Search in sources :

Example 1 with EnableInternetDialogFragment

use of edu.berkeley.cs.amplab.carat.android.fragments.EnableInternetDialogFragment in project carat by amplab.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CaratApplication.setMain(this);
    tracker = Tracker.getInstance();
    // track user clicks (taps)
    tracker.trackUser("caratstarted");
    if (!CaratApplication.isInternetAvailable()) {
        EnableInternetDialogFragment dialog = new EnableInternetDialogFragment();
        dialog.show(getSupportFragmentManager(), "dialog");
    }
    /*
		 * Activity.getWindow.requestFeature() should get invoked only before
		 * setContentView(), otherwise it will cause an app crash The progress
		 * bar doesn't get displayed when there is no update in progress
		 */
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    // Log.d(TAG, "about to set the layout");
    setContentView(R.layout.activity_main);
    ActionBar actionBar = getSupportActionBar();
    setTitleNormal();
    // read and load the preferences specified in our xml preference file
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    // Log.d(TAG, "about to initialize fragments");
    preInittializeFragments();
    // Log.d(TAG, "done with fragment initialization");
    /*
		 * Before using the field "fullVersion", first invoke setTitleNormal()
		 * or setFullVersion() to set this field
		 */
    mDrawerItems = getResources().getStringArray(R.array.drawer_items);
    List<Item> items = new ArrayList<Item>();
    //		items.add(new NavDrawerListHeader("Main"));
    items.add(new ListItem(mDrawerItems[0]));
    items.add(new ListItem(mDrawerItems[1]));
    items.add(new ListItem(mDrawerItems[2]));
    items.add(new ListItem(mDrawerItems[3]));
    items.add(new ListItem(mDrawerItems[4]));
    items.add(new NavDrawerListHeader(""));
    items.add(new ListItem(mDrawerItems[5]));
    items.add(new ListItem(mDrawerItems[6]));
    TextArrayAdapter adapter = new TextArrayAdapter(this, items);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(adapter);
    //		mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerItems));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close) {

        /* "close drawer" description for accessibility */
        public void onDrawerClosed(View view) {
        //getSupportActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mTitle);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    // Enable ActionBar app icon to behave as action to toggle navigation drawer
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    if (savedInstanceState == null) {
        selectItem(0);
    }
    setTitleNormal();
// Uncomment the following to enable listening on local port 8080:
/*
		 * try {
		 *  HelloServer h = new HelloServer();
		 * } catch (IOException e) {
		 *  e.printStackTrace(); 
		 * }
		 */
}
Also used : MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) EnableInternetDialogFragment(edu.berkeley.cs.amplab.carat.android.fragments.EnableInternetDialogFragment) ActionBar(android.support.v7.app.ActionBar)

Aggregations

ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)1 ActionBar (android.support.v7.app.ActionBar)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 EnableInternetDialogFragment (edu.berkeley.cs.amplab.carat.android.fragments.EnableInternetDialogFragment)1 ArrayList (java.util.ArrayList)1