Search in sources :

Example 1 with HomeFragment

use of im.tny.segvault.disturbances.ui.fragment.top.HomeFragment in project underlx by underlx.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Object conn = getLastCustomNonConfigurationInstance();
    if (conn != null && ((LocServiceConnection) conn).getBinder() != null) {
        // have the service connection survive through activity configuration changes
        // (e.g. screen orientation changes)
        mConnection = (LocServiceConnection) conn;
        locService = mConnection.getBinder().getService();
        locBound = true;
    } else if (!locBound) {
        startService(new Intent(this, MainService.class));
        getApplicationContext().bindService(new Intent(getApplicationContext(), MainService.class), mConnection, Context.BIND_AUTO_CREATE);
    }
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    if (savedInstanceState == null) {
        // show initial fragment
        Fragment newFragment = null;
        if (getIntent() != null) {
            String id = getIntent().getStringExtra(EXTRA_INITIAL_FRAGMENT);
            if (id != null) {
                newFragment = getNewFragment(pageStringToResourceId(id));
                planRouteTo = getIntent().getStringExtra(EXTRA_PLAN_ROUTE_TO_STATION);
            }
            if (getIntent().getBooleanExtra(EXTRA_FROM_INTRO, false)) {
                showTargetPrompt();
            }
        }
        if (newFragment == null) {
            newFragment = new HomeFragment();
        }
        replaceFragment(newFragment, false);
    }
    IntentFilter filter = new IntentFilter();
    filter.addAction(MainService.ACTION_UPDATE_TOPOLOGY_PROGRESS);
    filter.addAction(MainService.ACTION_UPDATE_TOPOLOGY_FINISHED);
    filter.addAction(MainService.ACTION_TOPOLOGY_UPDATE_AVAILABLE);
    filter.addAction(MainService.ACTION_CACHE_EXTRAS_PROGRESS);
    filter.addAction(MainService.ACTION_CACHE_EXTRAS_FINISHED);
    filter.addAction(FeedbackUtil.ACTION_FEEDBACK_PROVIDED);
    bm = LocalBroadcastManager.getInstance(this);
    bm.registerReceiver(mBroadcastReceiver, filter);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            SharedPreferences sharedPref = getSharedPreferences("settings", MODE_PRIVATE);
            boolean isFirstStart = sharedPref.getBoolean("fuse_first_run", true);
            if (isFirstStart) {
                // intro will request permission for us
                final Intent i = new Intent(MainActivity.this, IntroActivity.class);
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        startActivity(i);
                        finish();
                    }
                });
            } else {
                boolean locationEnabled = sharedPref.getBoolean(PreferenceNames.LocationEnable, true);
                if (locationEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                requestPermissions(new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION);
                            }
                        }
                    });
                }
            }
        }
    });
    // Start the thread
    t.start();
}
Also used : IntentFilter(android.content.IntentFilter) IntroActivity(im.tny.segvault.disturbances.ui.intro.IntroActivity) SharedPreferences(android.content.SharedPreferences) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) DisturbanceFragment(im.tny.segvault.disturbances.ui.fragment.top.DisturbanceFragment) DialogFragment(android.support.v4.app.DialogFragment) HelpFragment(im.tny.segvault.disturbances.ui.fragment.top.HelpFragment) TopFragment(im.tny.segvault.disturbances.ui.fragment.TopFragment) Fragment(android.support.v4.app.Fragment) UnconfirmedTripsFragment(im.tny.segvault.disturbances.ui.fragment.UnconfirmedTripsFragment) RouteFragment(im.tny.segvault.disturbances.ui.fragment.top.RouteFragment) AnnouncementFragment(im.tny.segvault.disturbances.ui.fragment.top.AnnouncementFragment) AboutFragment(im.tny.segvault.disturbances.ui.fragment.top.AboutFragment) MapFragment(im.tny.segvault.disturbances.ui.fragment.top.MapFragment) HomeStatsFragment(im.tny.segvault.disturbances.ui.fragment.HomeStatsFragment) HomeLinesFragment(im.tny.segvault.disturbances.ui.fragment.HomeLinesFragment) GeneralPreferenceFragment(im.tny.segvault.disturbances.ui.fragment.top.GeneralPreferenceFragment) HtmlDialogFragment(im.tny.segvault.disturbances.ui.fragment.HtmlDialogFragment) HomeFragment(im.tny.segvault.disturbances.ui.fragment.top.HomeFragment) TripFragment(im.tny.segvault.disturbances.ui.fragment.TripFragment) TripHistoryFragment(im.tny.segvault.disturbances.ui.fragment.top.TripHistoryFragment) NotifPreferenceFragment(im.tny.segvault.disturbances.ui.fragment.top.NotifPreferenceFragment) HomeFragment(im.tny.segvault.disturbances.ui.fragment.top.HomeFragment) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 DialogFragment (android.support.v4.app.DialogFragment)1 Fragment (android.support.v4.app.Fragment)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1 HomeLinesFragment (im.tny.segvault.disturbances.ui.fragment.HomeLinesFragment)1 HomeStatsFragment (im.tny.segvault.disturbances.ui.fragment.HomeStatsFragment)1 HtmlDialogFragment (im.tny.segvault.disturbances.ui.fragment.HtmlDialogFragment)1 TopFragment (im.tny.segvault.disturbances.ui.fragment.TopFragment)1 TripFragment (im.tny.segvault.disturbances.ui.fragment.TripFragment)1 UnconfirmedTripsFragment (im.tny.segvault.disturbances.ui.fragment.UnconfirmedTripsFragment)1 AboutFragment (im.tny.segvault.disturbances.ui.fragment.top.AboutFragment)1 AnnouncementFragment (im.tny.segvault.disturbances.ui.fragment.top.AnnouncementFragment)1 DisturbanceFragment (im.tny.segvault.disturbances.ui.fragment.top.DisturbanceFragment)1 GeneralPreferenceFragment (im.tny.segvault.disturbances.ui.fragment.top.GeneralPreferenceFragment)1 HelpFragment (im.tny.segvault.disturbances.ui.fragment.top.HelpFragment)1 HomeFragment (im.tny.segvault.disturbances.ui.fragment.top.HomeFragment)1