List of usage examples for android.os Bundle isEmpty
public boolean isEmpty()
From source file:mn.today.TheHubActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_the_hub); /* Set up ActionBar */ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_the_hub); setSupportActionBar(toolbar);/*from w ww . j a v a2s . c o m*/ /* Set up Navigation Drawer */ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.hub_drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); generateDrawerGreeting(navigationView); /* Set up recycler and Card View */ recyclerView = (RecyclerView) findViewById(R.id.recycler_view); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); if (savedInstanceState != null && !savedInstanceState.isEmpty()) { rvContent = savedInstanceState.getParcelableArrayList(AppConstants.RESTORED_USER_FLOWS); manager = savedInstanceState.getParcelable(AppConstants.RESTORED_DATA_MANAGER); } else { rvContent = new ArrayList<>(); manager = new AppDataManager(this); } menuState = AppConstants.MENU_ITEMS_NATIVE; // ATTENTION: This "addApi(AppIndex.API)"was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. // mGoogleApiClient = new GoogleApiClient.Builder(this) // .addApi(Drive.API) // .addScope(Drive.SCOPE_FILE) // .addConnectionCallbacks(this) // .addOnConnectionFailedListener(this) // .addApi(AppIndex.API).build(); }
From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (DEBUG_ENABLE) Log.v(APPLICATION_TAG, "onSaveInstanceState"); if (outState.isEmpty()) { outState.putBoolean("WORKAROUND_FOR_BUG_19917_KEY", true); }//from ww w . j av a 2 s .c o m }
From source file:in.ceeq.services.CommandService.java
@Override protected void onHandleIntent(Intent intent) { Utils.d("Received command..."); Bundle extras = intent.getExtras(); gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); String senderAddress = extras.getString(SENDER_ADDRESS); commandType = extras.getInt(ACTION); Utils.d("Command Type... " + commandType); switch (commandType) { case SIREN_ON: startSiren();// ww w. j a v a 2s .co m break; case SIREN_OFF: stopRinger(); break; case RINGER_ON: startRinger(); break; case RINGER_OFF: stopRinger(); break; case BACKUP: backup(); break; case ENABLE_TRACKER: Intent tracker = new Intent(this, TrackerService.class); startService(tracker); break; case WIPE: Utils.completeWipe(this); break; case LOCK: break; case GET_LOCATION_FOR_PROTECT: Intent getProtect = new Intent(this, LocationService.class); getProtect.putExtra(ACTION, RequestType.PROTECT); startService(getProtect); break; case GET_LOCATION_FOR_MESSAGE: Intent getLocation = new Intent(this, LocationService.class); getLocation.putExtra(ACTION, RequestType.MESSAGE).putExtra(SENDER_ADDRESS, senderAddress); startService(getLocation); break; case GET_LOCATION_FOR_CURRENT_DETAILS_MESSAGE: Intent getNowLocation = new Intent(this, LocationService.class); getNowLocation.putExtra(ACTION, RequestType.NOW).putExtra(SENDER_ADDRESS, senderAddress); startService(getNowLocation); break; case GET_LOCATION_FOR_BLIP: Intent getBlip = new Intent(this, LocationService.class); getBlip.putExtra(ACTION, RequestType.BLIP); startService(getBlip); break; case SEND_BLIP_TO_SERVER: break; case SEND_LOCATION_TO_SERVER: break; case SEND_CALLS_DETAILS_MESSAGE: Utils.sendMessage(this, senderAddress, Utils.CALLS_M); break; case SEND_CURRENT_DETAILS_MESSAGE: Utils.sendMessage(this, senderAddress, Utils.NOW_M); break; case SEND_CURRENT_LOCATION_MESSAGE: Utils.sendMessage(this, senderAddress, Utils.LOCATION_M); break; case SEND_NEW_LOCATION_MESSAGE: Utils.sendMessage(this, senderAddress, Utils.NEW_LOCATION_M); break; case SEND_PROTECT_MESSAGE: Utils.sendMessage(this, Utils.getStringPrefs(this, Utils.EMERGENCY_CONTACT_NUMBER), Utils.PROTECT_ME_M); case SEND_SIM_CHANGE_MESSAGE: Utils.sendMessage(this, Utils.getStringPrefs(this, Utils.EMERGENCY_CONTACT_NUMBER), Utils.SIM_CHANGE_M); Utils.lock(this); break; case SEND_PIN_FAIL_MESSAGE: Utils.sendMessage(this, senderAddress, Utils.FAIL_M); break; default: break; } if (!extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { } } CloudMessagesReceiver.completeWakefulIntent(intent); MobileMessagesReceiver.completeWakefulIntent(intent); }
From source file:org.anothermonitor.ActivityPreferences.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preferences); mPrefs = getSharedPreferences(getString(R.string.app_name) + "Prefs", MODE_PRIVATE); res = getResources();//from www . j av a 2 s .c o m navigationBarHeight = res .getDimensionPixelSize(res.getIdentifier("navigation_bar_height", "dimen", "android")); mLTabs = (LinearLayout) findViewById(R.id.LTabs); if (Build.VERSION.SDK_INT >= 19) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); sSW = res.getConfiguration().smallestScreenWidthDp; int statusBarHeight = res .getDimensionPixelSize(res.getIdentifier("status_bar_height", "dimen", "android")); if (!ViewConfiguration.get(this).hasPermanentMenuKey() && (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || sSW > 560)) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); FrameLayout nb = (FrameLayout) findViewById(R.id.LNavigationBar); nb.setVisibility(View.VISIBLE); ((FrameLayout.LayoutParams) nb.getLayoutParams()).height = navigationBarHeight; } int paddingTop = mLTabs.getPaddingTop(); int paddingBottom = mLTabs.getPaddingBottom(); int paddingLeft = mLTabs.getPaddingLeft(); int paddingRight = mLTabs.getPaddingRight(); mLTabs.setPadding(paddingLeft, paddingTop + statusBarHeight, paddingRight, paddingBottom); } findViewById(R.id.TVTabMain).setActivated(true); findViewById(R.id.TVTabMain).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mVP.setCurrentItem(0); } }); findViewById(R.id.TVTabShowRecord).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mVP.setCurrentItem(1); } }); mVP = (ViewPager) findViewById(R.id.VP); mVP.setAdapter(new MyPreferencesAdapter()); // mVP.setOffscreenPageLimit(2); mVP.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { int currentItem = 0; if (position == 1) currentItem = 2; mLTabs.getChildAt(currentItem).setActivated(true); mLTabs.getChildAt(previousSelected).setActivated(false); previousSelected = currentItem; } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int arg0) { } }); mVP.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mVP.getViewTreeObserver().removeGlobalOnLayoutListener(this); if (currentItem != -1) mVP.setCurrentItem(currentItem, false); } }); if (savedInstanceState != null && !savedInstanceState.isEmpty()) { mB = savedInstanceState; currentItem = savedInstanceState.getInt(C.currentItem); currentItem = savedInstanceState.getInt(C.currentItem); currentItem = savedInstanceState.getInt(C.currentItem); currentItem = savedInstanceState.getInt(C.currentItem); } }
From source file:com.asksven.betterbatterystats.StatsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); super.onCreate(savedInstanceState); // HockeyApp//w w w . ja va2 s . c om try { MetricsManager.register(getApplication()); } catch (Exception e) { Log.e(TAG, e.getMessage()); } //Log.i(TAG, "OnCreated called"); setContentView(R.layout.stats); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.app_name)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayUseLogoEnabled(false); // set debugging if (sharedPrefs.getBoolean("debug_logging", false)) { LogSettings.DEBUG = true; CommonLogSettings.DEBUG = true; } else { LogSettings.DEBUG = false; CommonLogSettings.DEBUG = false; } swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { doRefresh(true); } }); /////////////////////////////////////////////// // check if we have a new release /////////////////////////////////////////////// // if yes do some migration (if required) and show release notes String strLastRelease = sharedPrefs.getString("last_release", "0"); String strCurrentRelease = ""; try { PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); strCurrentRelease = Integer.toString(pinfo.versionCode); } catch (Exception e) { // nop strCurrentRelease is set to "" } // Grant permissions if they are missing and root is available if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) { if ((RootShell.getInstance().isRooted())) { // attempt to set perms using pm-comand Log.i(TAG, "attempting to grant perms with 'pm grant'"); String pkg = this.getPackageName(); RootShell.getInstance().run("pm grant " + pkg + " android.permission.BATTERY_STATS"); RootShell.getInstance().run("pm grant " + pkg + " android.permission.DUMP"); RootShell.getInstance().run("pm grant " + pkg + " android.permission.PACKAGE_USAGE_STATS"); if (SysUtils.hasBatteryStatsPermission(this)) { Log.i(TAG, "succeeded"); } else { Log.i(TAG, "failed"); } } } // Package usage stats were introduced in SDK21 so we need to make the distinction if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // show install as system app screen if root available but perms missing if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) { Intent intentSystemApp = new Intent(this, SystemAppActivity.class); this.startActivity(intentSystemApp); } } else { if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)) { Intent intentSystemApp = new Intent(this, SystemAppActivity.class); this.startActivity(intentSystemApp); } } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // first start if (strLastRelease.equals("0")) { boolean firstLaunch = !prefs.getBoolean("launched", false); if (firstLaunch) { // Save that the app has been launched SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("launched", true); editor.commit(); // start service to persist reference Intent serviceIntent = new Intent(this, WriteUnpluggedReferenceService.class); this.startService(serviceIntent); // refresh widgets Intent intentRefreshWidgets = new Intent(LargeWidgetProvider.WIDGET_UPDATE); this.sendBroadcast(intentRefreshWidgets); } SharedPreferences.Editor updater = sharedPrefs.edit(); updater.putString("last_release", strCurrentRelease); updater.commit(); } else if (!strLastRelease.equals(strCurrentRelease)) { // save the current release to properties so that the dialog won't be shown till next version SharedPreferences.Editor updater = sharedPrefs.edit(); updater.putString("last_release", strCurrentRelease); updater.commit(); // we don't need to delete refs as long as we don't change the database schema // Toast.makeText(this, getString(R.string.info_deleting_refs), Toast.LENGTH_SHORT).show(); // ReferenceStore.deleteAllRefs(this); // Intent i = new Intent(this, WriteBootReferenceService.class); // this.startService(i); // i = new Intent(this, WriteUnpluggedReferenceService.class); // this.startService(i); ChangeLog cl = new ChangeLog(this); cl.getLogDialog().show(); } /////////////////////////////////////////////// // retrieve default selections for spinners // if none were passed /////////////////////////////////////////////// m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0")); m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME); if (!ReferenceStore.hasReferenceByName(m_refFromName, this)) { m_refFromName = Reference.BOOT_REF_FILENAME; Toast.makeText(this, getString(R.string.info_fallback_to_boot), Toast.LENGTH_SHORT).show(); } if (LogSettings.DEBUG) Log.i(TAG, "onCreate state from preferences: refFrom=" + m_refFromName + " refTo=" + m_refToName); try { // recover any saved state if ((savedInstanceState != null) && (!savedInstanceState.isEmpty())) { m_iStat = (Integer) savedInstanceState.getSerializable("stat"); m_refFromName = (String) savedInstanceState.getSerializable("stattypeFrom"); m_refToName = (String) savedInstanceState.getSerializable("stattypeTo"); if (LogSettings.DEBUG) Log.i(TAG, "onCreate retrieved saved state: refFrom=" + m_refFromName + " refTo=" + m_refToName); } } catch (Exception e) { m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0")); m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME); Log.e(TAG, "Exception: " + e.getMessage()); DataStorage.LogToFile(LOGFILE, "Exception in onCreate restoring Bundle"); DataStorage.LogToFile(LOGFILE, e.getMessage()); DataStorage.LogToFile(LOGFILE, e.getStackTrace()); Toast.makeText(this, getString(R.string.info_state_recovery_error), Toast.LENGTH_SHORT).show(); } // Handle the case the Activity was called from an intent with paramaters Bundle extras = getIntent().getExtras(); if ((extras != null) && !extras.isEmpty()) { // Override if some values were passed to the intent if (extras.containsKey(StatsActivity.STAT)) m_iStat = extras.getInt(StatsActivity.STAT); if (extras.containsKey(StatsActivity.STAT_TYPE_FROM)) m_refFromName = extras.getString(StatsActivity.STAT_TYPE_FROM); if (extras.containsKey(StatsActivity.STAT_TYPE_TO)) m_refToName = extras.getString(StatsActivity.STAT_TYPE_TO); if (LogSettings.DEBUG) Log.i(TAG, "onCreate state from extra: refFrom=" + m_refFromName + " refTo=" + m_refToName); boolean bCalledFromNotification = extras.getBoolean(StatsActivity.FROM_NOTIFICATION, false); // Clear the notifications that was clicked to call the activity if (bCalledFromNotification) { NotificationManager nM = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE); nM.cancel(EventWatcherService.NOTFICATION_ID); } } // Spinner for selecting the stat Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat); ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item); spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); // android.R.layout.simple_spinner_dropdown_item); spinnerStat.setAdapter(spinnerStatAdapter); // setSelection MUST be called after setAdapter spinnerStat.setSelection(m_iStat); spinnerStat.setOnItemSelectedListener(this); /////////////////////////////////////////////// // Spinner for Selecting the Stat type /////////////////////////////////////////////// Spinner spinnerStatType = (Spinner) findViewById(R.id.spinnerStatType); m_spinnerFromAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item); m_spinnerFromAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item); spinnerStatType.setAdapter(m_spinnerFromAdapter); try { this.setListViewAdapter(); } catch (BatteryInfoUnavailableException e) { Log.e(TAG, "Exception: " + Log.getStackTraceString(e)); Snackbar.make(findViewById(android.R.id.content), R.string.info_service_connection_error, Snackbar.LENGTH_LONG).show(); // Toast.makeText(this, // getString(R.string.info_service_connection_error), // Toast.LENGTH_LONG).show(); } catch (Exception e) { //Log.e(TAG, e.getMessage(), e.fillInStackTrace()); Log.e(TAG, "Exception: " + Log.getStackTraceString(e)); Toast.makeText(this, getString(R.string.info_unknown_stat_error), Toast.LENGTH_LONG).show(); } // setSelection MUST be called after setAdapter spinnerStatType.setSelection(m_spinnerFromAdapter.getPosition(m_refFromName)); spinnerStatType.setOnItemSelectedListener(this); /////////////////////////////////////////////// // Spinner for Selecting the end sample /////////////////////////////////////////////// Spinner spinnerStatSampleEnd = (Spinner) findViewById(R.id.spinnerStatSampleEnd); m_spinnerToAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item); m_spinnerToAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item); spinnerStatSampleEnd.setVisibility(View.VISIBLE); spinnerStatSampleEnd.setAdapter(m_spinnerToAdapter); // setSelection must be called after setAdapter if ((m_refToName != null) && !m_refToName.equals("")) { int pos = m_spinnerToAdapter.getPosition(m_refToName); spinnerStatSampleEnd.setSelection(pos); } else { spinnerStatSampleEnd.setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME)); } spinnerStatSampleEnd.setOnItemSelectedListener(this); /////////////////////////////////////////////// // sorting /////////////////////////////////////////////// m_iSorting = 0; // log reference store ReferenceStore.logReferences(this); if (LogSettings.DEBUG) { Log.i(TAG, "onCreate final state: refFrom=" + m_refFromName + " refTo=" + m_refToName); Log.i(TAG, "OnCreated end"); } }