Android Open Source - LASA-Schedules Main Activity






From Project

Back to project page LASA-Schedules.

License

The source code is released under:

GNU General Public License

If you think the Android project LASA-Schedules 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.asdar.lasaschedules;
// w w w .j  ava 2s  .  c  om
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.parse.ParseAnalytics;
import com.parse.ParseInstallation;
import com.parse.PushService;
public class MainActivity extends ActionBarActivity  {
    String[] mDrawerArray;
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;
    private CharSequence mTitle;
    private AlarmManager alarmMgr;
    private PendingIntent alarmIntent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Define Toolbar
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mDrawerArray = getResources().getStringArray(R.array.drawer_array);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        // Set the adapter for the list view
        mDrawerList.setAdapter(new ArrayAdapter<String>(this,
                R.layout.drawer_list_item, mDrawerArray));
        // Set the list's click listener
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(false);
        // 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.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);
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getSupportActionBar().setTitle(R.string.app_name);
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        if (savedInstanceState == null){
            selectItem(0);
        }
        SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(this);
        if (s.getBoolean("updates",true)){
            PushService.subscribe(getApplicationContext(), "updates", MainActivity.class, R.drawable.ic_stat_notification);
        }
        else{
            PushService.unsubscribe(this, "updates");
        }
        ParseInstallation.getCurrentInstallation().saveInBackground();
        ParseAnalytics.trackAppOpened(getIntent());
        alarmMgr = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplicationContext(), AlarmRespondIntentService.class);
        alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intent, 0);
        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1,
                AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent);
    }
    private void selectItem(int position) {
        // update the main content by replacing fragments
        FragmentManager fragmentManager = getSupportFragmentManager();
        if (position == 0){
            Fragment fragment = new HomeFragment();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        }
        if (position == 1) {
            StaticScheduleFragment fragment = new StaticScheduleFragment();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        }
        if (position == 2){
            SettingsFragment fragment = new SettingsFragment();
            fragmentManager.beginTransaction().replace(R.id.content_frame,fragment).commit();

        }
        if (position == 3){
            String url = "http://lasa2017.com/schedules/";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
        // update selected item and title, then close the drawer
        if (position != 3){
            mDrawerList.setItemChecked(position, true);
            setTitle(getResources().getStringArray(R.array.drawer_array)[position]);
        }
        mDrawerLayout.closeDrawer(mDrawerList);
    }
    public void setTitle(CharSequence title) {
        mTitle = title;
        getSupportActionBar().setTitle(mTitle);
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        //int id = item.getItemId();
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    /* The click listner for ListView in the navigation drawer */
    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    }
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

}




Java Source Code List

com.asdar.lasaschedules.AboutDialog.java
com.asdar.lasaschedules.AlarmClearIntent.java
com.asdar.lasaschedules.AlarmRespondIntentService.java
com.asdar.lasaschedules.HomeFragment.java
com.asdar.lasaschedules.MainActivity.java
com.asdar.lasaschedules.NotificationServiceReciever.java
com.asdar.lasaschedules.NotificationService.java
com.asdar.lasaschedules.Resources.java
com.asdar.lasaschedules.RobotoTextView.java
com.asdar.lasaschedules.ScheduleAdapter.java
com.asdar.lasaschedules.ScheduleElement.java
com.asdar.lasaschedules.ScheduleFragment.java
com.asdar.lasaschedules.Schedule.java
com.asdar.lasaschedules.SettingsActivity.java
com.asdar.lasaschedules.SettingsFragment.java
com.asdar.lasaschedules.StaticResources.java
com.asdar.lasaschedules.StaticScheduleFragment.java
com.asdar.lasaschedules.StaticSchedules.java
com.asdar.lasaschedules.TodayActivity.java