Search in sources :

Example 56 with FragmentManager

use of androidx.fragment.app.FragmentManager 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)

Example 57 with FragmentManager

use of androidx.fragment.app.FragmentManager in project Applozic-Android-SDK by AppLozic.

the class MainActivity method onNavigationDrawerItemSelected.

@Override
public void onNavigationDrawerItemSelected(int position) {
    if (position == 1) {
        Intent intent = new Intent(this, ConversationActivity.class);
        if (ApplozicClient.getInstance(this).isContextBasedChat()) {
            intent.putExtra(ConversationUIService.CONTEXT_BASED_CHAT, true);
        }
        startActivity(intent);
        return;
    }
    /*
        if (position == 1) {
            ConversationFragment conversationFragment = new ConversationFragment();
            Contact contact = new Contact(this, "mobicomkit");
            mTitle = getString(R.string.user_id);
            addFragment(this, conversationFragment, "conversationFragment");
            conversationFragment.loadConversation(contact);
            return;

        }*/
    if (position == 0) {
        mTitle = getString(R.string.ecommerce);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.container, EcommerceFragment.newInstance("", "")).commit();
        return;
    }
    if (position == 2) {
        Applozic.logoutUser(this, new AlLogoutHandler() {

            @Override
            public void onSuccess(Context context) {
                Toast.makeText(getBaseContext(), getBaseContext().getString(R.string.log_out_successful), Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
                finish();
            }

            @Override
            public void onFailure(Exception exception) {
                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
                alertDialog.setTitle(getString(R.string.text_alert));
                alertDialog.setMessage(exception.toString());
                alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok_alert), new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                if (!isFinishing()) {
                    alertDialog.show();
                }
            }
        });
    }
    if (position == 3) {
        Map<String, String> messageMetaData = new HashMap<>();
        messageMetaData.put(Message.MetaDataType.KEY.getValue(), Message.MetaDataType.HIDDEN.getValue());
        Message message = new Message();
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(MainActivity.this);
        message.setContactIds("android");
        message.setTo("android");
        message.setContentType(Message.ContentType.CUSTOM.getValue());
        message.setMessage("this is meta data hidden");
        message.setMetadata(messageMetaData);
        message.setStoreOnDevice(Boolean.TRUE);
        message.setRead(Boolean.TRUE);
        message.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
        message.setSendToDevice(Boolean.FALSE);
        message.setType(Message.MessageType.MT_OUTBOX.getValue());
        message.setDeviceKeyString(userPreferences.getDeviceKeyString());
        message.setSource(Message.Source.MT_MOBILE_APP.getValue());
        new MobiComConversationService(MainActivity.this).sendMessage(message);
    }
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, PlaceholderFragment.newInstance(position + 1)).commit();
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) Message(com.applozic.mobicomkit.api.conversation.Message) DialogInterface(android.content.DialogInterface) HashMap(java.util.HashMap) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Intent(android.content.Intent) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) FragmentManager(androidx.fragment.app.FragmentManager) AlLogoutHandler(com.applozic.mobicomkit.listners.AlLogoutHandler)

Example 58 with FragmentManager

use of androidx.fragment.app.FragmentManager in project prebid-mobile-android by prebid.

the class PrebidServerSettingsViewholder method openPrebidServerDialog.

private void openPrebidServerDialog() {
    FragmentManager fragmentManager = ((AppCompatActivity) itemView.getContext()).getSupportFragmentManager();
    PrebidServerDialog dialog = PrebidServerDialog.newInstance();
    dialog.show(fragmentManager, PrebidServerDialog.TAG);
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) PrebidServerDialog(org.prebid.mobile.drprebid.ui.dialog.PrebidServerDialog)

Example 59 with FragmentManager

use of androidx.fragment.app.FragmentManager in project prebid-mobile-android by prebid.

the class PrebidServerSettingsViewholder method openInputDialog.

private void openInputDialog(String title, int type, int format, boolean shouldShowQrScanner) {
    FragmentManager fragmentManager = ((AppCompatActivity) itemView.getContext()).getSupportFragmentManager();
    InputDialog dialog = InputDialog.newInstance(title, type, format, shouldShowQrScanner);
    dialog.show(fragmentManager, InputDialog.TAG);
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) InputDialog(org.prebid.mobile.drprebid.ui.dialog.InputDialog) AppCompatActivity(androidx.appcompat.app.AppCompatActivity)

Example 60 with FragmentManager

use of androidx.fragment.app.FragmentManager in project Applozic-Android-SDK by AppLozic.

the class ContactSelectionActivity method addFragment.

public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd, String fragmentTag) {
    FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.layout_child_activity, fragmentToAdd, fragmentTag);
    if (supportFragmentManager.getBackStackEntryCount() > 1) {
        supportFragmentManager.popBackStack();
    }
    fragmentTransaction.addToBackStack(fragmentTag);
    fragmentTransaction.commitAllowingStateLoss();
    supportFragmentManager.executePendingTransactions();
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction)

Aggregations

FragmentManager (androidx.fragment.app.FragmentManager)163 FragmentTransaction (androidx.fragment.app.FragmentTransaction)55 Fragment (androidx.fragment.app.Fragment)42 Bundle (android.os.Bundle)28 Test (org.junit.Test)15 Intent (android.content.Intent)13 FragmentActivity (androidx.fragment.app.FragmentActivity)10 Activity (android.app.Activity)6 View (android.view.View)6 DialogFragment (androidx.fragment.app.DialogFragment)6 TaskRetainerFragment (com.owncloud.android.ui.fragment.TaskRetainerFragment)5 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)3 LayoutInflater (android.view.LayoutInflater)3 MenuInflater (android.view.MenuInflater)3 Window (android.view.Window)3 TextView (android.widget.TextView)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3