Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

In this page you can find the example usage for android.app FragmentTransaction commit.

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
 * @param testPoint /*from   w w w .  j av a2s .  c o  m*/
 * @param mapType 
 * 
 */
public RMBTMapFragment showMap(String mapType, LatLng initialCenter, boolean clearFilter, int viewId,
        boolean popBackStack) {
    if (popBackStack) {
        popBackStackFull();
    }

    FragmentTransaction ft;

    setCurrentMapType(mapType);

    if (clearFilter) {
        final List<MapListSection> mapFilterListSelectionList = getMapFilterListSelectionList();
        if (mapFilterListSelectionList != null) {
            for (final MapListSection section : mapFilterListSelectionList) {
                for (final MapListEntry entry : section.getMapListEntryList())
                    entry.setChecked(entry.isDefault());
            }
            updateMapFilter();
        }
    }

    final RMBTMapFragment fragment = new RMBTMapFragment();

    final Bundle bundle = new Bundle();
    bundle.putParcelable("initialCenter", initialCenter);

    if (viewId >= 0) {
        bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_ALL_GESTURES, false);
        bundle.putBoolean(RMBTMapFragment.OPTION_SHOW_INFO_TOAST, false);
        bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_CONTROL_BUTTONS, false);
        bundle.putBoolean(RMBTMapFragment.OPTION_ENABLE_OVERLAY, false);
        fragment.setArguments(bundle);
        ft = fm.beginTransaction();
        //replace the given viewgroup, but do not add to backstack
        ft.replace(viewId, fragment, AppConstants.PAGE_TITLE_MINI_MAP);
        //ft.addToBackStack(AppConstants.PAGE_TITLE_MINI_MAP);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();
    } else {
        System.out.println("SHOW MAP");
        fragment.setArguments(bundle);
        ft = fm.beginTransaction();
        ft.replace(R.id.fragment_content, fragment, AppConstants.PAGE_TITLE_MAP);
        ft.addToBackStack(AppConstants.PAGE_TITLE_MAP);
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.commit();
        refreshActionBar(AppConstants.PAGE_TITLE_MAP);
    }

    return fragment;
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showDetailFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.DETAIL);
    this.updateChildViewVisibility(ViewFragmentType.DETAIL);
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.DETAIL, fragmentTransaction);
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    // Try and use the default.
    if (fileName == null) {
        WebLogger.getLogger(getAppName()).d(TAG, "[showDetailFragment] fileName not found in Intent");
        SQLiteDatabase db = null;/*from  w ww .  j ava2s. c  om*/
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getDetailViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    String rowId = IntentUtil.retrieveRowIdFromBundle(this.getIntent().getExtras());
    // Try to retrieve one that already exists.
    DetailViewFragment detailViewFragment = (DetailViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.DETAIL_FRAGMENT);
    if (detailViewFragment == null || createNew) {
        if (detailViewFragment != null) {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] removing old detail view fragment");
            fragmentTransaction.remove(detailViewFragment);
        } else {
            WebLogger.getLogger(getAppName()).d(TAG,
                    "[showDetailViewFragment] no existing detail view fragment found");
        }
        detailViewFragment = this.createDetailViewFragment(fileName, rowId);

        fragmentTransaction.add(R.id.activity_table_display_activity_one_pane_content, detailViewFragment,
                Constants.FragmentTags.DETAIL_FRAGMENT);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG,
                "[showDetailViewFragment] existing detail view fragment found");
        fragmentTransaction.show(detailViewFragment);
    }

    fragmentTransaction.commit();
}

From source file:com.android.dialer.DialtactsActivity.java

/**
 * Shows the search fragment// www  .  jav a 2  s  .co m
 */
private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
    if (mStateSaved || getFragmentManager().isDestroyed()) {
        // Weird race condition where fragment is doing work after the activity is destroyed
        // due to talkback being on (b/10209937). Just return since we can't do any
        // constructive here.
        return;
    }

    if (DEBUG) {
        Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
    }

    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (mInDialpadSearch && mSmartDialSearchFragment != null) {
        transaction.remove(mSmartDialSearchFragment);
    } else if (mInRegularSearch && mRegularSearchFragment != null) {
        transaction.remove(mRegularSearchFragment);
    }

    final String tag;
    if (smartDialSearch) {
        tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
    } else {
        tag = TAG_REGULAR_SEARCH_FRAGMENT;
    }
    mInDialpadSearch = smartDialSearch;
    mInRegularSearch = !smartDialSearch;

    mFloatingActionButtonController.scaleOut();

    SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
    if (animate) {
        transaction.setCustomAnimations(android.R.animator.fade_in, 0);
    } else {
        transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
    }
    if (fragment == null) {
        if (smartDialSearch) {
            fragment = new SmartDialSearchFragment();
        } else {
            fragment = ObjectFactory.newRegularSearchFragment();
            fragment.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // Show the FAB when the user touches the lists fragment and the soft
                    // keyboard is hidden.
                    hideDialpadFragment(true, false);
                    showFabInSearchUi();
                    return false;
                }
            });
        }
        transaction.add(R.id.dialtacts_frame, fragment, tag);
    } else {
        transaction.show(fragment);
    }
    // DialtactsActivity will provide the options menu
    fragment.setHasOptionsMenu(false);
    fragment.setShowEmptyListForNullQuery(true);
    if (!smartDialSearch) {
        fragment.setQueryString(query, false /* delaySelection */);
    }
    transaction.commit();

    if (animate) {
        mListsFragment.getView().animate().alpha(0).withLayer();
    }
    mListsFragment.setUserVisibleHint(false);

    if (smartDialSearch) {
        Logger.logScreenView(ScreenEvent.SMART_DIAL_SEARCH, this);
    } else {
        Logger.logScreenView(ScreenEvent.REGULAR_SEARCH, this);
    }
}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread.setDefaultUncaughtExceptionHandler(new UnhandledExceptionHandler(this));

    // Set window styles for fullscreen-window size. Needs to be done before
    // adding content.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON | LayoutParams.FLAG_DISMISS_KEYGUARD
            | LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_TURN_SCREEN_ON);
    getWindow().getDecorView()//from  w w w . j a  va  2s .c o  m
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    setContentView(R.layout.activity_call);

    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(WebsocketService.ACTION_BYE);
    mIntentFilter.addAction(WebsocketService.ACTION_USER_ENTERED);
    mIntentFilter.addAction(WebsocketService.ACTION_USER_LEFT);
    mIntentFilter.addAction(WebsocketService.ACTION_SCREENSHARE);
    mIntentFilter.addAction(CustomPhoneStateListener.ACTION_HOLD_ON);
    mIntentFilter.addAction(CustomPhoneStateListener.ACTION_HOLD_OFF);
    mIntentFilter.addAction(WebsocketService.ACTION_CHAT_MESSAGE);
    mIntentFilter.addAction(WebsocketService.ACTION_FILE_MESSAGE);
    registerReceiver(mReceiver, mIntentFilter);

    // Get setting keys.
    PreferenceManager.setDefaultValues(this, R.xml.webrtc_preferences, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    keyprefVideoCallEnabled = getString(R.string.pref_videocall_key);
    keyprefScreencapture = getString(R.string.pref_screencapture_key);
    keyprefCamera2 = getString(R.string.pref_camera2_key);
    keyprefResolution = getString(R.string.pref_resolution_key);
    keyprefFps = getString(R.string.pref_fps_key);
    keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key);
    keyprefVideoBitrateType = getString(R.string.pref_maxvideobitrate_key);
    keyprefVideoBitrateValue = getString(R.string.pref_maxvideobitratevalue_key);
    keyprefVideoCodec = getString(R.string.pref_videocodec_key);
    keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
    keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key);
    keyprefFlexfec = getString(R.string.pref_flexfec_key);
    keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
    keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
    keyprefAudioCodec = getString(R.string.pref_audiocodec_key);
    keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key);
    keyprefAecDump = getString(R.string.pref_aecdump_key);
    keyprefOpenSLES = getString(R.string.pref_opensles_key);
    keyprefDisableBuiltInAec = getString(R.string.pref_disable_built_in_aec_key);
    keyprefDisableBuiltInAgc = getString(R.string.pref_disable_built_in_agc_key);
    keyprefDisableBuiltInNs = getString(R.string.pref_disable_built_in_ns_key);
    keyprefEnableLevelControl = getString(R.string.pref_enable_level_control_key);
    keyprefDisplayHud = getString(R.string.pref_displayhud_key);
    keyprefTracing = getString(R.string.pref_tracing_key);
    keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
    keyprefEnableDataChannel = getString(R.string.pref_enable_datachannel_key);
    keyprefOrdered = getString(R.string.pref_ordered_key);
    keyprefMaxRetransmitTimeMs = getString(R.string.pref_max_retransmit_time_ms_key);
    keyprefMaxRetransmits = getString(R.string.pref_max_retransmits_key);
    keyprefDataProtocol = getString(R.string.pref_data_protocol_key);
    keyprefNegotiated = getString(R.string.pref_negotiated_key);
    keyprefDataId = getString(R.string.pref_data_id_key);

    readPrefs();

    final Intent intent = getIntent();

    if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_ICE_CANDIDATE)) {
        finish(); // don't start the activity on this intent
    } else if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_DESCRIPTION)) {
        SerializableSessionDescription sdp = (SerializableSessionDescription) intent
                .getSerializableExtra(WebsocketService.EXTRA_REMOTE_DESCRIPTION);
        mVideoCallEnabled = sdp.description.contains("m=video");
    }

    iceConnected = false;
    signalingParameters = new SignalingParameters(WebsocketService.getIceServers(), initiator, "", "", "", null,
            null);
    scalingType = ScalingType.SCALE_ASPECT_FILL;

    // Create UI controls.

    localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
    screenshareRender = (SurfaceViewRenderer) findViewById(R.id.screenshare_video_view);
    remoteRenderScreen = (SurfaceViewRenderer) findViewById(R.id.remote_video_view);

    remoteRenderScreen2 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view2);
    remoteRenderScreen3 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view3);
    remoteRenderScreen4 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view4);
    remoteVideoLabel = (TextView) findViewById(R.id.remote_video_label);
    remoteVideoLabel2 = (TextView) findViewById(R.id.remote_video_label2);
    remoteVideoLabel3 = (TextView) findViewById(R.id.remote_video_label3);
    remoteVideoLabel4 = (TextView) findViewById(R.id.remote_video_label4);
    remoteUserImage = (ImageView) findViewById(R.id.remote_user_image1);
    remoteUserImage2 = (ImageView) findViewById(R.id.remote_user_image2);
    remoteUserImage3 = (ImageView) findViewById(R.id.remote_user_image3);
    remoteUserImage4 = (ImageView) findViewById(R.id.remote_user_image4);
    remoteUserHoldStatus = (ImageView) findViewById(R.id.remote_user_hold_status);
    remoteUserHoldStatus2 = (ImageView) findViewById(R.id.remote_user_hold_status2);
    remoteUserHoldStatus3 = (ImageView) findViewById(R.id.remote_user_hold_status3);
    remoteUserHoldStatus4 = (ImageView) findViewById(R.id.remote_user_hold_status4);
    localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layout);
    screenshareRenderLayout = (PercentFrameLayout) findViewById(R.id.screenshare_video_layout);
    remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_layout);
    remoteRenderLayout2 = (PercentFrameLayout) findViewById(R.id.remote_video_layout2);
    remoteRenderLayout3 = (PercentFrameLayout) findViewById(R.id.remote_video_layout3);
    remoteRenderLayout4 = (PercentFrameLayout) findViewById(R.id.remote_video_layout4);
    initiateCallFragment = new InitiateCallFragment();
    callListFragment = new CallListFragment();
    callFragment = new CallFragment();
    hudFragment = new HudFragment();
    chatFragment = new ChatFragment();

    screenshareRemoteView = new RemoteConnectionViews("screenshare", screenshareRenderLayout, screenshareRender,
            null, null, null);

    remoteViewsInUseList.add(new RemoteConnectionViews("remote 1", remoteRenderLayout, remoteRenderScreen,
            remoteUserImage, remoteVideoLabel, remoteUserHoldStatus)); // first one is always in use
    remoteViewsList.add(new RemoteConnectionViews("remote 2", remoteRenderLayout2, remoteRenderScreen2,
            remoteUserImage2, remoteVideoLabel2, remoteUserHoldStatus2));
    remoteViewsList.add(new RemoteConnectionViews("remote 3", remoteRenderLayout3, remoteRenderScreen3,
            remoteUserImage3, remoteVideoLabel3, remoteUserHoldStatus3));
    remoteViewsList.add(new RemoteConnectionViews("remote 4", remoteRenderLayout4, remoteRenderScreen4,
            remoteUserImage4, remoteVideoLabel4, remoteUserHoldStatus4));

    // Show/hide call control fragment on view click.
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleCallControlFragmentVisibility();
        }
    };

    View.OnClickListener screenshareListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            maximizeScreenshare = !maximizeScreenshare;
            updateVideoView();
        }
    };

    localRender.setOnClickListener(listener);
    screenshareRender.setOnClickListener(screenshareListener);
    remoteRenderScreen.setOnClickListener(listener);
    remoteRenderScreen2.setOnClickListener(listener);
    remoteRenderScreen3.setOnClickListener(listener);
    remoteRenderScreen4.setOnClickListener(listener);
    remoteRenderers.add(remoteRenderScreen);

    // Create video renderers.
    if (rootEglBase == null) {
        rootEglBase = EglBase.create();
    }
    localRender.init(rootEglBase.getEglBaseContext(), null);
    screenshareRender.init(rootEglBase.getEglBaseContext(), null);
    String saveRemoteVideoToFile = intent.getStringExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE);

    // When saveRemoteVideoToFile is set we save the video from the remote to a file.
    if (saveRemoteVideoToFile != null) {
        int videoOutWidth = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WIDTH, 0);
        int videoOutHeight = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT, 0);
        try {
            videoFileRenderer = new VideoFileRenderer(saveRemoteVideoToFile, videoOutWidth, videoOutHeight,
                    rootEglBase.getEglBaseContext());
            remoteRenderers.add(videoFileRenderer);
        } catch (IOException e) {
            throw new RuntimeException("Failed to open video file for output: " + saveRemoteVideoToFile, e);
        }
    }
    remoteRenderScreen.init(rootEglBase.getEglBaseContext(), null);
    remoteRenderScreen2.init(rootEglBase.getEglBaseContext(), null);
    remoteRenderScreen3.init(rootEglBase.getEglBaseContext(), null);
    remoteRenderScreen4.init(rootEglBase.getEglBaseContext(), null);

    localRender.setZOrderMediaOverlay(true);
    localRender.setEnableHardwareScaler(true /* enabled */);

    screenshareRender.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    screenshareRenderLayout.setVisibility(View.GONE);
    screenshareRender.setVisibility(View.GONE);

    if (intent.getAction().equals(ACTION_RESUME_CALL)) {
        iceConnected = true;
    }

    updateVideoView();

    // If capturing format is not specified for screencapture, use screen resolution.
    if (screencaptureEnabled && mVideoWidth == 0 && mVideoHeight == 0) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            windowManager.getDefaultDisplay().getRealMetrics(displayMetrics);
        }
        mVideoWidth = displayMetrics.widthPixels;
        mVideoHeight = displayMetrics.heightPixels;
    }
    DataChannelParameters dataChannelParameters = null;
    if (mDataChannelEnabled) {
        dataChannelParameters = new DataChannelParameters(mOrdered, mMaxRetrMs, mMaxRetr, mProtocol,
                mNegotiated, mId);
    }
    peerConnectionParameters = new PeerConnectionParameters(mVideoCallEnabled, false, false, mVideoWidth,
            mVideoHeight, mCameraFps, mVideoStartBitrate, mVideoCodec, mHwCodecEnabled, mFlexfecEnabled,
            mAudioStartBitrate, mAudioCodec, mNoAudioProcessing, mAecDump, mUseOpenSLES, mDisableBuiltInAEC,
            mDisableBuiltInAGC, mDisableBuiltInNS, mEnableLevelControl, dataChannelParameters);
    commandLineRun = intent.getBooleanExtra(EXTRA_CMDLINE, false);
    runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0);

    Log.d(TAG, "VIDEO_FILE: '" + intent.getStringExtra(EXTRA_VIDEO_FILE_AS_CAMERA) + "'");

    // Create connection client. Use DirectRTCClient if room name is an IP otherwise use the
    // standard WebSocketRTCClient.
    //if (loopback || !DirectRTCClient.IP_PATTERN.matcher(roomId).matches()) {
    //   appRtcClient = new WebSocketRTCClient(this);
    // } else {
    //   Log.i(TAG, "Using DirectRTCClient because room name looks like an IP.");
    //   appRtcClient = new DirectRTCClient(this);
    // }
    // Create connection parameters.
    //roomConnectionParameters = new RoomConnectionParameters(roomUri.toString(), roomId, loopback);

    // Create CPU monitor
    //cpuMonitor = new CpuMonitor(this);
    //hudFragment.setCpuMonitor(cpuMonitor);
    Bundle extras = intent.getExtras();
    extras.putBoolean(CallActivity.EXTRA_VIDEO_CALL, mVideoCallEnabled);

    // Send intent arguments to fragments.
    chatFragment.setArguments(getIntent().getExtras());
    initiateCallFragment.setArguments(extras);
    callFragment.setArguments(extras);
    callListFragment.setArguments(extras);
    hudFragment.setArguments(intent.getExtras());
    // Activate call and HUD fragments and start the call.
    remoteUserImage.setVisibility(View.INVISIBLE);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    if (intent.getAction().equals(ACTION_RESUME_CALL)) {
        ft.add(R.id.call_fragment_container, callFragment);
    } else {
        ft.add(R.id.call_fragment_container, initiateCallFragment);
    }
    ft.add(R.id.hud_fragment_container, hudFragment);
    ft.commit();

    // For command line execution run connection for <runTimeMs> and exit.
    if (commandLineRun && runTimeMs > 0) {
        (new Handler()).postDelayed(new Runnable() {
            @Override
            public void run() {
                disconnect();
            }
        }, runTimeMs);
    }

    if (!intent.getAction().equals(ACTION_RESUME_CALL)) {
        peerConnectionClient = PeerConnectionClient.getInstance();

        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        options.disableNetworkMonitor = true;
        peerConnectionClient.setPeerConnectionFactoryOptions(options);

        if (mForceTurn) {
            peerConnectionParameters.forceTurn = true;
        }

        peerConnectionClient.createPeerConnectionFactory(CallActivity.this, peerConnectionParameters,
                CallActivity.this);

        peerConnectionClient.setDataChannelCallback(this);

        ThumbnailsCacheManager.ThumbnailsCacheManagerInit(this);
        handleIntent(intent);

        if (screencaptureEnabled) {
            /*MediaProjectionManager mediaProjectionManager =
                (MediaProjectionManager) getApplication().getSystemService(
                    Context.MEDIA_PROJECTION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
              startActivityForResult(
                  mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
            }*/
        } else {
            startCall();
        }
    } else {
        mPeerId = intent.getStringExtra(EXTRA_PEER_ID);
        iceConnected = true;
        if (peerConnectionClient != null) {
            peerConnectionClient.updateActivity(this, this);
            peerConnectionClient.updateLocalRenderer(localRender);
            peerConnectionClient.updateRemoteRenderers(remoteRenderers);
        }
    }

    AddRunningIntent();
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

public void showMapFragment(boolean createNew) {
    this.setCurrentFragmentType(ViewFragmentType.MAP);
    this.updateChildViewVisibility(ViewFragmentType.MAP);
    // Set the list view file name.
    String fileName = IntentUtil.retrieveFileNameFromBundle(this.getIntent().getExtras());
    if (fileName == null) {
        SQLiteDatabase db = null;/*from  w ww  .  j a v  a2 s .c om*/
        try {
            db = DatabaseFactory.get().getDatabase(this, getAppName());
            fileName = TableUtil.get().getMapListViewFilename(db, getTableId());
        } finally {
            if (db != null) {
                db.close();
            }
        }
    }
    FragmentManager fragmentManager = this.getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    this.hideAllOtherViewFragments(ViewFragmentType.MAP, fragmentTransaction);
    MapListViewFragment mapListViewFragment = (MapListViewFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_LIST);
    TableMapInnerFragment innerMapFragment = (TableMapInnerFragment) fragmentManager
            .findFragmentByTag(Constants.FragmentTags.MAP_INNER_MAP);
    if (mapListViewFragment == null || (fileName != null && !fileName.equals(mapListViewFragment.getFileName()))
            || createNew) {
        if (mapListViewFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old map list fragment");
            fragmentTransaction.remove(mapListViewFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new map list fragment");
        mapListViewFragment = this.createMapListViewFragment(fileName);
        fragmentTransaction.add(R.id.map_view_list, mapListViewFragment, Constants.FragmentTags.MAP_LIST);
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing map list fragment found");
        fragmentTransaction.show(mapListViewFragment);
    }
    if (innerMapFragment == null || createNew) {
        if (innerMapFragment != null) {
            // remove the old fragment
            WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] removing old inner map fragment");
            fragmentTransaction.remove(innerMapFragment);
        }
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] creating new inner map fragment");
        innerMapFragment = this.createInnerMapFragment();
        fragmentTransaction.add(R.id.map_view_inner_map, innerMapFragment,
                Constants.FragmentTags.MAP_INNER_MAP);
        innerMapFragment.listener = this;
    } else {
        WebLogger.getLogger(getAppName()).d(TAG, "[showMapFragment] existing inner map fragment found");
        innerMapFragment.listener = this;
        fragmentTransaction.show(innerMapFragment);
    }
    fragmentTransaction.commit();
}

From source file:com.android.calendar.AllInOneActivity.java

private void initFragments(long timeMillis, int viewType, Bundle icicle) {
    if (DEBUG) {//from   ww w .  j ava 2 s . co m
        Log.d(TAG, "Initializing to " + timeMillis + " for view " + viewType);
    }
    FragmentTransaction ft = getFragmentManager().beginTransaction();

    if (mShowCalendarControls) {
        Fragment miniMonthFrag = new MonthByWeekFragment(timeMillis, true);
        ft.replace(R.id.mini_month, miniMonthFrag);
        mController.registerEventHandler(R.id.mini_month, (EventHandler) miniMonthFrag);

        Fragment selectCalendarsFrag = new SelectVisibleCalendarsFragment();
        ft.replace(R.id.calendar_list, selectCalendarsFrag);
        mController.registerEventHandler(R.id.calendar_list, (EventHandler) selectCalendarsFrag);
    }
    if (!mShowCalendarControls || viewType == ViewType.EDIT) {
        mMiniMonth.setVisibility(View.GONE);
        mCalendarsList.setVisibility(View.GONE);
    }

    EventInfo info = null;
    if (viewType == ViewType.EDIT) {
        mPreviousView = GeneralPreferences.getSharedPreferences(this).getInt(GeneralPreferences.KEY_START_VIEW,
                GeneralPreferences.DEFAULT_START_VIEW);

        long eventId = -1;
        Intent intent = getIntent();
        Uri data = intent.getData();
        if (data != null) {
            try {
                eventId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
                if (DEBUG) {
                    Log.d(TAG, "Create new event");
                }
            }
        } else if (icicle != null && icicle.containsKey(BUNDLE_KEY_EVENT_ID)) {
            eventId = icicle.getLong(BUNDLE_KEY_EVENT_ID);
        }

        long begin = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1);
        long end = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1);
        info = new EventInfo();
        if (end != -1) {
            info.endTime = new Time();
            info.endTime.set(end);
        }
        if (begin != -1) {
            info.startTime = new Time();
            info.startTime.set(begin);
        }
        info.id = eventId;
        // We set the viewtype so if the user presses back when they are
        // done editing the controller knows we were in the Edit Event
        // screen. Likewise for eventId
        mController.setViewType(viewType);
        mController.setEventId(eventId);
    } else {
        mPreviousView = viewType;
    }

    setMainPane(ft, R.id.main_pane, viewType, timeMillis, true);
    ft.commit(); // this needs to be after setMainPane()

    Time t = new Time(mTimeZone);
    t.set(timeMillis);
    if (viewType == ViewType.AGENDA && icicle != null) {
        mController.sendEvent(this, EventType.GO_TO, t, null, icicle.getLong(BUNDLE_KEY_EVENT_ID, -1),
                viewType);
    } else if (viewType != ViewType.EDIT) {
        mController.sendEvent(this, EventType.GO_TO, t, null, -1, viewType);
    }
}

From source file:com.xplink.android.carchecklist.CarCheckListActivity.java

public void menuToggle(int motionin, int motionout, int fragment) {

    /*/* ww  w.j a  v  a 2  s .c o m*/
     * final Dialog settingdialog = new Dialog(CarCheckListActivity.this,
     * R.style.backgrounddialog); settingdialog.dismiss();
     */

    new Dialog(CarCheckListActivity.this, R.style.backgrounddialog).dismiss();

    headsetting.setVisibility(ImageView.VISIBLE);
    TranslateAnimation slideoutheadsetting = new TranslateAnimation(0, 0, 0, -468);
    slideoutheadsetting.setDuration(500);
    slideoutheadsetting.setFillAfter(true);
    headsetting.startAnimation(slideoutheadsetting);

    int prefer = getSharedPreferences("mysettings", MODE_PRIVATE).getInt("already", 1);
    if (prefer == 1) {
        getSharedPreferences("mysettings", MODE_PRIVATE).edit().putInt("already", 0).commit();

        FragmentTransaction ft = getFragmentManager().beginTransaction().setCustomAnimations(motionin,
                motionout);
        FragmentManager fm = getFragmentManager();
        Fragment fmTarget = fm.findFragmentById(fragment);
        ft.show(fmTarget);
        ft.commit();
    } else {
        getSharedPreferences("mysettings", MODE_PRIVATE).edit().putInt("already", 1).commit();
        FragmentTransaction ft = getFragmentManager().beginTransaction().setCustomAnimations(motionin,
                motionout);
        FragmentManager fm = getFragmentManager();
        final Fragment fmTarget = fm.findFragmentById(fragment);
        ft.hide(fmTarget);
        ft.commit();
    }
}

From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java

@Override
public void onResume() {
    super.onResume();
    activityIsVisible = true;/*w  w w  . j a v a 2s .  c  o m*/

    // Handle Item list empty due to Fragment stack
    try {

        FragmentManager fm = getFragmentManager();
        FragmentTransaction fragmentTransaction = fm.beginTransaction();

        if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.one_frame
                && fm.findFragmentById(
                        R.id.one_frame) instanceof com.lgallardo.youtorrentcontroller.ItemstFragment) {

            com.lgallardo.youtorrentcontroller.ItemstFragment fragment = (com.lgallardo.youtorrentcontroller.ItemstFragment) fm
                    .findFragmentById(R.id.one_frame);

            if (fragment.getListView().getCount() == 0) {

                // Create the about fragment
                aboutFragment = new AboutFragment();

                fragmentTransaction.replace(R.id.one_frame, aboutFragment, "firstFragment");

                fragmentTransaction.commit();

                // Se titile
                //                    setTitle(navigationDrawerItemTitles[drawerList.getCheckedItemPosition()]);
                setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]);

                // Close Contextual Action Bar
                if (firstFragment != null && firstFragment.mActionMode != null) {
                    firstFragment.mActionMode.finish();
                }

                // Refresh current list
                refreshCurrent();
            }

        }
        if (fm.getBackStackEntryCount() == 0 && firstFragment.getSecondFragmentContainer() == R.id.content_frame
                && (fm.findFragmentByTag("secondFragment") instanceof AboutFragment)) {

            // Create the about fragment
            aboutFragment = new AboutFragment();

            fragmentTransaction.replace(R.id.content_frame, aboutFragment, "secondFragment");

            fragmentTransaction.commit();

            // Set title
            setTitle(navigationDrawerItemTitles[DrawerItemRecyclerViewAdapter.actionPosition]);

            // Close Contextual Action Bar
            if (firstFragment != null && firstFragment.mActionMode != null) {
                firstFragment.mActionMode.finish();
            }

            // Refresh current list
            refreshCurrent();

        }
    } catch (Exception e) {

    }
}

From source file:de.sourcestream.movieDB.controller.SearchList.java

public void onSuggestionClick(int id, String mediaType, String title) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    boolean result;
    Bundle args;/*from w w  w . j  av  a 2  s  .  c o m*/
    switch (mediaType) {
    case "movie":
        activity.setRestoreMovieDetailsAdapterState(true);
        activity.setRestoreMovieDetailsState(false);
        if (movieDetails != null && lastVisitedId == id && movieDetails.getTimeOut() == 0) {
            // Old movie details retrieve info and re-init component else crash
            movieDetails.onSaveInstanceState(new Bundle());
            Bundle bundle = new Bundle();
            bundle.putInt("id", id);
            Bundle save = movieDetails.getSave();
            movieDetails = new MovieDetails();
            movieDetails.setTimeOut(0);
            movieDetails.setSave(save);
            movieDetails.setArguments(bundle);
        } else
            movieDetails = new MovieDetails();

        args = new Bundle();
        args.putInt("id", id);
        movieDetails.setArguments(args);

        movieDetails.setTitle(title);
        transaction.replace(R.id.frame_container, movieDetails);
        result = true;
        break;

    case "person":
        activity.setRestoreMovieDetailsAdapterState(true);
        activity.setRestoreMovieDetailsState(false);
        if (castDetails != null && lastVisitedId == id && castDetails.getTimeOut() == 0) {
            // Old movie details retrieve info and re-init component else crash
            castDetails.onSaveInstanceState(new Bundle());
            Bundle bundle = new Bundle();
            bundle.putInt("id", id);
            Bundle save = castDetails.getSave();
            castDetails = new CastDetails();
            castDetails.setTimeOut(0);
            castDetails.setSave(save);
            castDetails.setArguments(bundle);
        } else
            castDetails = new CastDetails();

        args = new Bundle();
        args.putInt("id", id);
        castDetails.setArguments(args);

        castDetails.setTitle(title);
        transaction.replace(R.id.frame_container, castDetails);
        result = true;
        break;

    case "tv":
        activity.setRestoreMovieDetailsAdapterState(true);
        activity.setRestoreMovieDetailsState(false);
        if (tvDetails != null && lastVisitedId == id && tvDetails.getTimeOut() == 0) {
            // Old movie details retrieve info and re-init component else crash
            tvDetails.onSaveInstanceState(new Bundle());
            Bundle bundle = new Bundle();
            bundle.putInt("id", id);
            Bundle save = tvDetails.getSave();
            tvDetails = new TVDetails();
            tvDetails.setTimeOut(0);
            tvDetails.setSave(save);
            tvDetails.setArguments(bundle);
        } else
            tvDetails = new TVDetails();

        args = new Bundle();
        args.putInt("id", id);
        tvDetails.setArguments(args);

        tvDetails.setTitle(title);
        transaction.replace(R.id.frame_container, tvDetails);
        result = true;
        break;

    default:
        result = false;
        break;
    }

    lastVisitedId = id;

    if (result) {
        // add the current transaction to the back stack:
        transaction.addToBackStack("movieList");
        transaction.commit();
        // collapse the search View
        ((MainActivity) getActivity()).collapseSearchView();
    }

}

From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get preferences
    getSettings();/*from  www  . j  av a 2 s  .c  o m*/

    // Set alarm for checking completed torrents, if not set
    if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), NotifierService.class),
            PendingIntent.FLAG_NO_CREATE) == null) {

        // Set Alarm for checking completed torrents
        alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplication(), NotifierService.class);
        alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0);

        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
                notification_period, alarmIntent);
    }

    // Set alarm for RSS checking, if not set
    if (PendingIntent.getBroadcast(getApplication(), 0, new Intent(getApplication(), RSSService.class),
            PendingIntent.FLAG_NO_CREATE) == null) {

        // Set Alarm for checking completed torrents
        alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplication(), RSSService.class);
        alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0);

        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
                AlarmManager.INTERVAL_DAY, alarmIntent);
    }

    // Set Theme (It must be fore inflating or setContentView)
    if (dark_ui) {
        this.setTheme(R.style.Theme_Dark);

        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setNavigationBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground));
            getWindow().setStatusBarColor(getResources().getColor(R.color.Theme_Dark_toolbarBackground));
        }
    } else {
        this.setTheme(R.style.Theme_Light);

        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setNavigationBarColor(getResources().getColor(R.color.primary));
        }

    }

    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.app_bar);

    if (dark_ui) {
        toolbar.setBackgroundColor(getResources().getColor(R.color.Theme_Dark_primary));
    }

    setSupportActionBar(toolbar);

    // Set App title
    setTitle(R.string.app_shortname);

    // Drawer menu
    navigationDrawerServerItems = getResources().getStringArray(R.array.qBittorrentServers);
    navigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    //        drawerList = (ListView) findViewById(R.id.left_drawer);

    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View
    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are

    ArrayList<ObjectDrawerItem> serverItems = new ArrayList<ObjectDrawerItem>();
    ArrayList<ObjectDrawerItem> actionItems = new ArrayList<ObjectDrawerItem>();
    ArrayList<ObjectDrawerItem> settingsItems = new ArrayList<ObjectDrawerItem>();

    // Add server category
    serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_servers,
            getResources().getString(R.string.drawer_servers_category), DRAWER_CATEGORY, false, null));

    // Server items
    int currentServerValue = 1;

    try {
        currentServerValue = Integer.parseInt(MainActivity.currentServer);
    } catch (NumberFormatException e) {

    }

    for (int i = 0; i < navigationDrawerServerItems.length; i++) {
        //            Log.d("Debug", "MainActivity - currentServerValue - currentServerValue: " + currentServerValue);
        //            Log.d("Debug", "MainActivity - currentServerValue - (i + 1): " + (i + 1));
        //            Log.d("Debug", "MainActivity - currentServerValue - (i + 1) == currentServerValue: " + ((i + 1) == currentServerValue));

        serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, navigationDrawerServerItems[i],
                DRAWER_ITEM_SERVERS, ((i + 1) == currentServerValue), "changeCurrentServer"));

    }

    //
    //        serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 1", DRAWER_ITEM_SERVERS, true, "changeCurrentServer"));
    //        serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 2", DRAWER_ITEM_SERVERS, false, "changeCurrentServer"));
    //        serverItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_subitem, "Server 3", DRAWER_ITEM_SERVERS, false, "changeCurrentServer"));

    // Add actions
    actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_all, navigationDrawerItemTitles[0],
            DRAWER_ITEM_ACTIONS, lastState.equals("all"), "refreshAll"));
    actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_downloading, navigationDrawerItemTitles[1],
            DRAWER_ITEM_ACTIONS, lastState.equals("downloading"), "refreshDownloading"));
    actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_completed, navigationDrawerItemTitles[2],
            DRAWER_ITEM_ACTIONS, lastState.equals("completed"), "refreshCompleted"));
    actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_paused, navigationDrawerItemTitles[3],
            DRAWER_ITEM_ACTIONS, lastState.equals("pause"), "refreshPaused"));
    actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_active, navigationDrawerItemTitles[4],
            DRAWER_ITEM_ACTIONS, lastState.equals("active"), "refreshActive"));
    actionItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_inactive, navigationDrawerItemTitles[5],
            DRAWER_ITEM_ACTIONS, lastState.equals("inactive"), "refreshInactive"));

    // Add settings actions
    //        drawerItems.add(new ObjectDrawerItem(R.drawable.ic_action_options, navigationDrawerItemTitles[6], DRAWER_ITEM_ACTIONS, false, "openOptions"));
    settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_settings, navigationDrawerItemTitles[6],
            DRAWER_ITEM_ACTIONS, false, "openSettings"));
    if (packageName.equals("com.lgallardo.youtorrentcontroller")) {
        settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_pro, navigationDrawerItemTitles[7],
                DRAWER_ITEM_ACTIONS, false, "getPro"));
        settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[8],
                DRAWER_ITEM_ACTIONS, false, "openHelp"));
    } else {
        settingsItems.add(new ObjectDrawerItem(R.drawable.ic_drawer_help, navigationDrawerItemTitles[7],
                DRAWER_ITEM_ACTIONS, false, "openHelp"));
    }

    // Set adapter

    rAdapter = new DrawerItemRecyclerViewAdapter(getApplicationContext(), this, serverItems, actionItems,
            settingsItems, null);
    rAdapter.notifyDataSetChanged();

    //        Log.d("Debug", "MainActivity - oldActionPosition: "+ (Arrays.asList(actionStates).indexOf(lastState)));

    //        drawerList.setAdapter(adapter);
    mRecyclerView.setAdapter(rAdapter);

    mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager
    mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager

    // Set selection according to last state
    setSelectionAndTitle(lastState);

    // Set the item click listener
    //        drawerList.setOnItemClickListener(new DrawerItemClickListener());

    // Get drawer title
    title = drawerTitle = getTitle();

    // Add the application icon control code inside MainActivity onCreate

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // New ActionBarDrawerToggle for Google Material Desing (v7)
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open,
            R.string.drawer_close) {

        /**
         * Called when a drawer has settled in a completely closed state.
         */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            // getSupportActionBar().setTitle(title);
        }

        /**
         * Called when a drawer has settled in a completely open state.
         */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // getSupportActionBar().setTitle(drawerTitle);
            // setTitle(R.string.app_shortname);
        }
    };

    drawerLayout.setDrawerListener(drawerToggle);
    //        drawerToggle.syncState();               // Finally we set the drawer toggle sync State

    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    getSupportActionBar().setHomeButtonEnabled(false);

    // Get options and save them as shared preferences
    //        qBittorrentOptions qso = new qBittorrentOptions();
    //        qso.execute(new String[]{qbQueryString + "/preferences", "getSettings"});

    // If it were awaked from an intent-filter,
    // Get token and cookie and then
    // get intent from the intent filter and Add URL torrent
    //        Log.d("Debug", "MainActivity - 1");
    new torrentTokenByIntent().execute(getIntent());

    // Fragments

    // Check whether the activity is using the layout version with
    // the fragment_container FrameLayout. If so, we must add the first
    // fragment
    if (findViewById(R.id.fragment_container) != null) {

        // However, if we're being restored from a previous state,
        // then we don't need to do anything and should return or else
        // we could end up with overlapping fragments.
        // if (savedInstanceState != null) {
        // return;
        // }

        // This fragment will hold the list of torrents
        if (firstFragment == null) {
            firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment();
        }

        // This fragment will hold the list of torrents
        helpTabletFragment = new HelpFragment();

        // Set the second fragments container
        firstFragment.setSecondFragmentContainer(R.id.content_frame);

        // This i the second fragment, holding a default message at the
        // beginning
        secondFragment = new AboutFragment();

        // Add the fragment to the 'list_frame' FrameLayout
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        if (fragmentManager.findFragmentByTag("firstFragment") == null) {
            fragmentTransaction.add(R.id.list_frame, helpTabletFragment, "firstFragment");
        } else {
            fragmentTransaction.replace(R.id.list_frame, helpTabletFragment, "firstFragment");
        }

        if (fragmentManager.findFragmentByTag("secondFragment") == null) {
            fragmentTransaction.add(R.id.content_frame, secondFragment, "secondFragment");
        } else {
            fragmentTransaction.replace(R.id.content_frame, secondFragment, "secondFragment");
        }

        fragmentTransaction.commit();

        // Second fragment will be added in ItemsFRagment's onListItemClick
        // method

    } else {

        // Phones handle just one fragment

        // Create an instance of ItemsFragments
        if (firstFragment == null) {
            firstFragment = new com.lgallardo.youtorrentcontroller.ItemstFragment();
        }
        firstFragment.setSecondFragmentContainer(R.id.one_frame);

        // This is the about fragment, holding a default message at the
        // beginning
        secondFragment = new AboutFragment();

        // If we're being restored from a previous state,
        // then we don't need to do anything and should return or else
        // we could end up with overlapping fragments.
        //            if (savedInstanceState != null) {
        //
        //                // Handle Item list empty due to Fragment stack
        //                try {
        //                    FragmentManager fm = getFragmentManager();
        //
        //                    if (fm.getBackStackEntryCount() == 1 && fm.findFragmentById(R.id.one_frame) instanceof com.lgallardo.youtorrentcontroller.TorrentDetailsFragment) {
        //
        //                        refreshCurrent();
        //
        //                    }
        //                }
        //                catch (Exception e) {
        //                }
        //
        //                return;
        //            }

        // Add the fragment to the 'list_frame' FrameLayout
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        if (fragmentManager.findFragmentByTag("firstFragment") == null) {
            fragmentTransaction.add(R.id.one_frame, secondFragment, "firstFragment");
        } else {
            fragmentTransaction.replace(R.id.one_frame, secondFragment, "firstFragment");
        }

        // if torrent details was loaded reset back button stack
        for (int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) {
            fragmentManager.popBackStack();
        }

        fragmentTransaction.commit();
    }

    // Activity is visible
    activityIsVisible = true;

    // First refresh
    refreshCurrent();

    handler = new Handler();
    handler.postDelayed(m_Runnable, refresh_period);

    // Load banner
    loadBanner();

}