/** Set Design of ActionBar */ @Override protected void onStart() { super.onStart(); ActionBar actionBar = this.getSupportActionBar(); actionBar.setSubtitle(R.string.app_subtitle); // add WebserverFragment when enabled in preferences if (PreferenceHelper.getWebserverEnabled(this)) { FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); mWebserverFragment = new WebserverFragment(); // replace container in view with fragment fragmentTransaction.replace(R.id.base_activity_webserver_container, mWebserverFragment); fragmentTransaction.commit(); } else { // when disabled in preferences remove fragment if existing if (mWebserverFragment != null) { FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); fragmentTransaction.remove(mWebserverFragment); fragmentTransaction.commit(); mWebserverFragment = null; } } }
/** Instantiate View and initialize fragments for this Activity */ @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.base_activity); mActivity = this; mFragmentManager = getSupportFragmentManager(); mBaseFragment = (BaseFragment) mFragmentManager.findFragmentById(R.id.base_fragment); // We use this to send broadcasts within our local process. mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); // We are going to watch for broadcasts with status updates IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_UPDATE_STATUS); filter.addAction(ACTION_BUTTONS); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (intent.getAction().equals(ACTION_UPDATE_STATUS)) { if (extras != null) { if (extras.containsKey(EXTRA_UPDATE_STATUS_TITLE) && extras.containsKey(EXTRA_UPDATE_STATUS_TEXT) && extras.containsKey(EXTRA_UPDATE_STATUS_ICON)) { String title = extras.getString(EXTRA_UPDATE_STATUS_TITLE); String text = extras.getString(EXTRA_UPDATE_STATUS_TEXT); int status = extras.getInt(EXTRA_UPDATE_STATUS_ICON); mBaseFragment.setStatus(title, text, status); } } } if (intent.getAction().equals(ACTION_BUTTONS)) { if (extras != null) { if (extras.containsKey(EXTRA_BUTTONS_DISABLED)) { boolean buttonsDisabled = extras.getBoolean(EXTRA_BUTTONS_DISABLED); mBaseFragment.setButtonsDisabled(buttonsDisabled); } } } } }; mLocalBroadcastManager.registerReceiver(mReceiver, filter); // check for root if (Utils.isAndroidRooted(mActivity)) { // set status only if not coming from an orientation change if (savedInstanceState == null) { // check if hosts file is applied if (ApplyUtils.isHostsFileCorrect(Constants.ANDROID_SYSTEM_ETC_HOSTS)) { // do background update check // do only if not disabled in preferences if (PreferenceHelper.getUpdateCheck(mActivity)) { Intent updateIntent = new Intent(mActivity, UpdateService.class); updateIntent.putExtra(UpdateService.EXTRA_BACKGROUND_EXECUTION, false); WakefulIntentService.sendWakefulWork(mActivity, updateIntent); } else { BaseActivity.updateStatusEnabled(mActivity); } } else { BaseActivity.updateStatusDisabled(mActivity); } } // schedule CheckUpdateService WakefulIntentService.scheduleAlarms(new DailyListener(), mActivity, false); } }