Search in sources :

Example 1 with Consumer

use of com.annimon.stream.function.Consumer in project syncthing-android by syncthing.

the class MainActivity method onSaveInstanceState.

/**
 * Saves current tab index and fragment states.
 */
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    FragmentManager fm = getSupportFragmentManager();
    Consumer<Fragment> putFragment = fragment -> {
        if (fragment != null && fragment.isAdded()) {
            fm.putFragment(outState, fragment.getClass().getName(), fragment);
        }
    };
    putFragment.accept(mFolderListFragment);
    putFragment.accept(mDeviceListFragment);
    putFragment.accept(mDrawerFragment);
    outState.putInt("currentTab", mViewPager.getCurrentItem());
    outState.putBoolean(BATTERY_DIALOG_DISMISSED, mBatteryOptimizationsDialog == null || !mBatteryOptimizationsDialog.isShowing());
    outState.putBoolean(IS_SHOWING_RESTART_DIALOG, mRestartDialog != null && mRestartDialog.isShowing());
    if (mQrCodeDialog != null && mQrCodeDialog.isShowing()) {
        outState.putBoolean(IS_QRCODE_DIALOG_DISPLAYED, true);
        ImageView qrCode = mQrCodeDialog.findViewById(R.id.qrcode_image_view);
        TextView deviceID = mQrCodeDialog.findViewById(R.id.device_id);
        outState.putParcelable(QRCODE_BITMAP_KEY, ((BitmapDrawable) qrCode.getDrawable()).getBitmap());
        outState.putString(DEVICEID_KEY, deviceID.getText().toString());
    }
    Util.dismissDialogSafe(mRestartDialog, this);
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Date(java.util.Date) Util(com.nutomic.syncthingandroid.util.Util) Uri(android.net.Uri) ImageView(android.widget.ImageView) IBinder(android.os.IBinder) ActionBar(androidx.appcompat.app.ActionBar) PowerManager(android.os.PowerManager) SyncthingService(com.nutomic.syncthingandroid.service.SyncthingService) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Consumer(com.annimon.stream.function.Consumer) Fragment(androidx.fragment.app.Fragment) SyncthingApp(com.nutomic.syncthingandroid.SyncthingApp) View(android.view.View) Log(android.util.Log) RestApi(com.nutomic.syncthingandroid.service.RestApi) TabLayout(com.google.android.material.tabs.TabLayout) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Math.min(java.lang.Math.min) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) ActivityNotFoundException(android.content.ActivityNotFoundException) DeviceListFragment(com.nutomic.syncthingandroid.fragments.DeviceListFragment) Context(android.content.Context) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) AlertDialog(androidx.appcompat.app.AlertDialog) KeyEvent(android.view.KeyEvent) PermissionUtil(com.nutomic.syncthingandroid.util.PermissionUtil) FolderListFragment(com.nutomic.syncthingandroid.fragments.FolderListFragment) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) Intent(android.content.Intent) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) Constants(com.nutomic.syncthingandroid.service.Constants) SyncthingServiceBinder(com.nutomic.syncthingandroid.service.SyncthingServiceBinder) Toast(android.widget.Toast) Settings(android.provider.Settings) Build(android.os.Build) DrawerFragment(com.nutomic.syncthingandroid.fragments.DrawerFragment) DialogInterface(android.content.DialogInterface) FragmentManager(androidx.fragment.app.FragmentManager) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) GravityCompat(androidx.core.view.GravityCompat) R(com.nutomic.syncthingandroid.R) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) TimeUnit(java.util.concurrent.TimeUnit) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) Bitmap(android.graphics.Bitmap) Configuration(android.content.res.Configuration) Activity(android.app.Activity) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Fragment(androidx.fragment.app.Fragment) DeviceListFragment(com.nutomic.syncthingandroid.fragments.DeviceListFragment) FolderListFragment(com.nutomic.syncthingandroid.fragments.FolderListFragment) DrawerFragment(com.nutomic.syncthingandroid.fragments.DrawerFragment)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 IBinder (android.os.IBinder)1 PowerManager (android.os.PowerManager)1 Settings (android.provider.Settings)1 DisplayMetrics (android.util.DisplayMetrics)1