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();
}
Aggregations