Example usage for android.widget FrameLayout removeAllViews

List of usage examples for android.widget FrameLayout removeAllViews

Introduction

In this page you can find the example usage for android.widget FrameLayout removeAllViews.

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:com.pdftron.pdf.controls.ReflowPagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    FrameLayout frameLayout = (FrameLayout) object;

    if (DEBUG)//from   w ww . j a va  2  s .c o  m
        Log.d(TAG, "Removing page #" + (position + 1));

    frameLayout.removeAllViews();
    Integer indexI = mViewIndexes.get(position);
    if (indexI != null) {
        int index = indexI;
        ReflowWebView webView = mWebViewRepository.getWebView(index);
        webView.loadUrl("about:blank");
        mWebViewRepository.push(index);
    } else {
        if (DEBUG)
            Log.d(TAG, "calling destroyItem for second time at one position");
    }
    mViewHolders.put(position, null);
    mViewIndexes.put(position, null);

    container.removeView(frameLayout);
}

From source file:com.ehelp.home.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*w w w  .  ja  va  2  s. co m*/
    //fl.setBackgroundColor(0x666666);
    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setGravity(Gravity.TOP);
    System.out.println(position);
    if (position == 0) {
        fl.removeAllViews();
        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
        mMapView = new MapView(getActivity());
        mMapView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));
        fl.addView(mMapView);
        mBaiduMap = mMapView.getMap();
        // ??
        mBaiduMap.setMyLocationEnabled(true);
        // ??
        mLocClient = new LocationClient(getActivity());
        mLocClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true);// gps
        option.setCoorType("bd09ll"); // ??
        option.setScanSpan(1000);
        mLocClient.setLocOption(option);
        mLocClient.start();
        int count = mMapView.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = mMapView.getChildAt(i);
            if (child instanceof ZoomControls || child instanceof ImageView) {
                child.setVisibility(View.INVISIBLE);
            }
        }
        setLocation();
    } else if (position == 1) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 2, eventCache);
        queList.setAdapter(que);
        queList.setDividerHeight(20);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), recievesos_map.class);
                int eventid = events.get(index).getEventId();
                intent.putExtra(EXTRA_MESSAGE, eventid);
                startActivity(intent);
            }
        });
    } else if (position == 2) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        //queList.setBackgroundColor(0x666666);
        //queList.setAlpha(125);
        queList.setDividerHeight(20);
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 1, eventCache);
        queList.setAdapter(que);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), recieve_help_ans_map.class);
                intent.putExtra(EXTRA_MESSAGE, events.get(index));
                startActivity(intent);
            }
        });
    } else if (position == 3) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 0, eventCache);
        queList.setAdapter(que);
        queList.setDividerHeight(20);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), QuestionDetail.class);
                intent.putExtra("qusetiondatail", events.get(index));
                startActivity(intent);
            }
        });
    }
    return fl;
}

From source file:com.pdftron.pdf.controls.ReflowPagerAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    int availIndex = mWebViewRepository.pop();
    ReflowWebView webView = mWebViewRepository.getWebView(availIndex);
    if (webView == null) {
        AnalyticsHandlerAdapter.getInstance()
                .sendException(new Exception("Reflow: there is no available WebView in repository"));
        Log.e(TAG, "there is no available WebView in repository");
        return null;
    }/*from   w  ww  .j ava  2  s  .com*/
    webView.loadUrl("about:blank");

    int pagePosition = mIsRtlMode ? mPageCount - 1 - position : position;

    boolean need_load_flag = true;
    String filename = mReflowFiles.get(pagePosition);
    if (filename != null) {
        File file = new File(filename);
        if (file.exists()) {
            need_load_flag = false;
            if (DEBUG)
                Log.d(TAG, "the file at page #" + (position + 1) + " already received");
            webView.loadUrl("file:///" + filename);
            setTextZoom(webView);
        }
    }

    if (need_load_flag) {
        webView.loadUrl(mLoadingFile);
        try {
            // request for reflow output
            if (DEBUG)
                Log.d(TAG, "request for page #" + (pagePosition + 1));
            Page page = mDoc.getPage(pagePosition + 1);
            ReflowProcessor.getReflow(page, mRequestHandler, position);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    FrameLayout layout = new FrameLayout(mContext);
    FrameLayout parent = (FrameLayout) webView.getParent();
    if (parent != null) {
        // note that we share WebViews,
        // so before adding a WebView make sure it's not a child of any layout
        parent.removeAllViews();
    }
    layout.addView(webView);
    mViewHolders.put(position, layout);
    mViewIndexes.put(position, new Integer(availIndex));
    container.addView(layout);
    return layout;
}

From source file:info.tellmetime.TellmetimeActivity.java

private void resizeClock() {
    final LinearLayout mClock = (LinearLayout) findViewById(R.id.clock);

    // Set width of #mClock layout to the screen's shorter edge size, so clock is not
    // expanded in landscape mode, but has rather somewhat a square shape.
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
    lp.width = mShorterEdge;//ww  w.j  a va 2  s . c  om
    mClock.setLayoutParams(lp);

    final float mItemSize = mShorterEdge / mClock.getChildCount();
    final int mRowMargin = (int) -(mItemSize / 2.2);

    // Scale text size according to shorter edge and set spacing between rows.
    for (int i = 0; i < mClock.getChildCount(); i++) {
        LinearLayout row = (LinearLayout) mClock.getChildAt(i);

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
        params.bottomMargin = mRowMargin;
        row.setLayoutParams(params);

        for (int j = 0; j < row.getChildCount(); j++)
            ((TextView) row.getChildAt(j)).setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize);
    }
    LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams();
    params.bottomMargin = 0;
    lastRow.setLayoutParams(params);

    TextView twenty = (TextView) findViewById(R.id.twenty);
    params = (LinearLayout.LayoutParams) twenty.getLayoutParams();
    params.leftMargin = 0;
    twenty.setLayoutParams(params);

    // Inflates minutes indicators and attaches them to main view.
    FrameLayout minutesLayout = (FrameLayout) findViewById(R.id.minutes_indicators);
    minutesLayout.removeAllViews();
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final boolean isLandscape = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    inflater.inflate(isLandscape ? R.layout.minutes_land : R.layout.minutes_portrait, minutesLayout);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            isLandscape ? FrameLayout.LayoutParams.MATCH_PARENT : FrameLayout.LayoutParams.WRAP_CONTENT);
    if (!isLandscape) {
        layoutParams.addRule(RelativeLayout.BELOW, R.id.clock);
        layoutParams.topMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize / 3,
                getResources().getDisplayMetrics());
    }
    minutesLayout.setLayoutParams(layoutParams);

    ViewGroup minutesDots = (ViewGroup) findViewById(R.id.minutes_dots);
    for (int i = 0; i < minutesDots.getChildCount(); i++)
        ((TextView) minutesDots.getChildAt(i)).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mMinutesSize);
}

From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java

public void show_connectivity_error(Exception e) {
    if (e != null) {
        e.printStackTrace();/*from   w  w  w .j a  v a  2  s  . co m*/
    }
    if (getActivity() == null) {
        return;
    }
    if (e instanceof OpacErrorException) {
        AccountDataSource adatasource = new AccountDataSource(getActivity());
        adatasource.open();
        adatasource.invalidateCachedAccountData(account);
        adatasource.close();
        dialog_wrong_credentials(e.getMessage());
        return;
    }
    if (getView() != null) {
        final FrameLayout errorView = (FrameLayout) getView().findViewById(R.id.error_view);
        errorView.removeAllViews();
        View connError = getActivity().getLayoutInflater().inflate(R.layout.error_connectivity, errorView);

        if (e != null && e instanceof SSLSecurityException) {
            ((TextView) connError.findViewById(R.id.tvErrBody))
                    .setText(R.string.connection_error_detail_security);
        } else if (e != null && e instanceof NotReachableException) {
            ((TextView) connError.findViewById(R.id.tvErrBody)).setText(R.string.connection_error_detail_nre);
        }
        connError.findViewById(R.id.btRetry).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                refresh();
            }
        });
        llLoading.setVisibility(View.GONE);
        svAccount.setVisibility(View.GONE);
        connError.setVisibility(View.VISIBLE);
    }
}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

@Override
public void swapToCustomView(View customView) {
    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    View wkt = findViewById(R.id.webkit_view);
    shadow.removeAllViews();
    shadow.addView(customView, COVER_SCREEN_GRAVITY_CENTER);
    frags.setVisibility(View.GONE);
    wkt.setVisibility(View.GONE);
    shadow.setVisibility(View.VISIBLE);
    currentFragment = ScreenList.CUSTOM_VIEW;
}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

@Override
public void swapOffCustomView() {
    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    View wkt = findViewById(R.id.webkit_view);
    shadow.setVisibility(View.GONE);
    shadow.removeAllViews();
    frags.setVisibility(View.GONE);
    wkt.setVisibility(View.VISIBLE);
    wkt.invalidate();//from w w  w. j a v  a 2 s  .co m
    currentFragment = ScreenList.WEBKIT;
    levelSafeInvalidateOptionsMenu();
}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

public void swapToFragmentView(ScreenList newFragment) {
    WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newFragment.toString());
    FragmentManager mgr = getFragmentManager();
    Fragment f;//w w  w. j  av a 2 s.co m
    if (newFragment == ScreenList.MAIN_SCREEN) {
        throw new IllegalStateException("unexpected reference to generic main screen");
    } else if (newFragment == ScreenList.CUSTOM_VIEW) {
        WebLogger.getLogger(getAppName()).w(t,
                "swapToFragmentView: changing navigation to move to WebKit (was custom view)");
        f = mgr.findFragmentById(WebViewFragment.ID);
        if (f == null) {
            f = new WebViewFragment();
        }
        newFragment = ScreenList.WEBKIT;
    } else if (newFragment == ScreenList.FORM_CHOOSER) {
        f = mgr.findFragmentById(FormChooserListFragment.ID);
        if (f == null) {
            f = new FormChooserListFragment();
        }
    } else if (newFragment == ScreenList.INITIALIZATION_DIALOG) {
        if (currentFragment == ScreenList.INITIALIZATION_DIALOG) {
            WebLogger.getLogger(getAppName()).e(t, "Unexpected: currentFragment == INITIALIZATION_DIALOG");
            return;
        } else {
            f = mgr.findFragmentById(InitializationFragment.ID);
            if (f == null) {
                f = new InitializationFragment();
            }
            ((InitializationFragment) f).setFragmentToShowNext(
                    (currentFragment == null) ? ScreenList.FORM_CHOOSER.name() : currentFragment.name());
        }
    } else if (newFragment == ScreenList.FORM_DELETER) {
        f = mgr.findFragmentById(FormDeleteListFragment.ID);
        if (f == null) {
            f = new FormDeleteListFragment();
        }
    } else if (newFragment == ScreenList.FORM_DOWNLOADER) {
        f = mgr.findFragmentById(FormDownloadListFragment.ID);
        if (f == null) {
            f = new FormDownloadListFragment();
        }
    } else if (newFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER) {
        f = mgr.findFragmentById(InstanceUploaderTableChooserListFragment.ID);
        if (f == null) {
            f = new InstanceUploaderTableChooserListFragment();
        }
    } else if (newFragment == ScreenList.INSTANCE_UPLOADER) {
        f = mgr.findFragmentById(InstanceUploaderListFragment.ID);
        if (f == null) {
            f = new InstanceUploaderListFragment();
        }
        ((InstanceUploaderListFragment) f).changeUploadTableId();
    } else if (newFragment == ScreenList.WEBKIT) {
        f = mgr.findFragmentById(WebViewFragment.ID);
        if (f == null) {
            f = new WebViewFragment();
        }
    } else if (newFragment == ScreenList.ABOUT_MENU) {
        f = mgr.findFragmentById(AboutMenuFragment.ID);
        if (f == null) {
            f = new AboutMenuFragment();
        }

    } else {
        throw new IllegalStateException("Unrecognized ScreenList type");
    }

    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    View wkt = findViewById(R.id.webkit_view);
    shadow.setVisibility(View.GONE);
    shadow.removeAllViews();
    if (newFragment == ScreenList.WEBKIT) {
        frags.setVisibility(View.GONE);
        wkt.setVisibility(View.VISIBLE);
        wkt.invalidate();
    } else {
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.VISIBLE);
    }

    currentFragment = newFragment;
    BackStackEntry entry = null;
    for (int i = 0; i < mgr.getBackStackEntryCount(); ++i) {
        BackStackEntry e = mgr.getBackStackEntryAt(i);
        if (e.getName().equals(currentFragment.name())) {
            entry = e;
            break;
        }
    }
    if (entry != null) {
        // flush backward, including the screen want to go back to
        mgr.popBackStackImmediate(currentFragment.name(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    // add transaction to show the screen we want
    FragmentTransaction trans = mgr.beginTransaction();
    trans.replace(R.id.main_content, f);
    trans.addToBackStack(currentFragment.name());
    trans.commit();

    // and see if we should re-initialize...
    if ((currentFragment != ScreenList.INITIALIZATION_DIALOG)
            && Survey.getInstance().shouldRunInitializationTask(getAppName())) {
        WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView -- calling clearRunInitializationTask");
        // and immediately clear the should-run flag...
        Survey.getInstance().clearRunInitializationTask(getAppName());
        // OK we should swap to the InitializationFragment view
        swapToFragmentView(ScreenList.INITIALIZATION_DIALOG);
    } else {
        levelSafeInvalidateOptionsMenu();
    }
}

From source file:org.path.episample.android.activities.MainMenuActivity.java

public void swapToFragmentView(ScreenList newFragment) {
    WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView: " + newFragment.toString());

    String get = PropertiesSingleton.getProperty("survey",
            AdminPreferencesActivity.KEY_TURN_ON_OFF_WIFI_AUTOMATICALLY);
    if (!(get != null && get.equalsIgnoreCase("false"))) {
        if (mWifiManager.isWifiEnabled() && mWifiManager.getWifiState() != WifiManager.WIFI_STATE_DISABLED) {
            mWifiManager.setWifiEnabled(false);
        }//w w  w .  j a v a 2 s. co  m
    }

    FragmentManager mgr = getFragmentManager();
    Fragment f;
    if (newFragment == ScreenList.MAIN_SCREEN) {
        throw new IllegalStateException("unexpected reference to generic main screen");
    } else if (newFragment == ScreenList.CUSTOM_VIEW) {
        WebLogger.getLogger(getAppName()).w(t,
                "swapToFragmentView: changing navigation to move to WebKit (was custom view)");
        f = mgr.findFragmentById(WebViewFragment.ID);
        if (f == null) {
            f = new WebViewFragment();
        }
        newFragment = ScreenList.WEBKIT;
    } else if (newFragment == ScreenList.MAIN_MENU) {
        f = mgr.findFragmentById(MainMenuFragment.ID);
        if (f == null) {
            f = new MainMenuFragment();
        }
    } else if (newFragment == ScreenList.COLLECT_MODULE) {
        f = mgr.findFragmentById(CollectFragment.ID);
        if (f == null) {
            f = new CollectFragment();
        }
    } else if (newFragment == ScreenList.SEND_RECEIVE_WIFI_DIRECT_MODULE) {
        f = mgr.findFragmentById(SendReceiveFragment.ID);
        if (f == null) {
            f = new SendReceiveFragment();
        }
    } /*else if (newFragment == ScreenList.SEND_RECEIVE_BLUETOOTH_MODULE) {
       f = mgr.findFragmentById(SendReceiveFragmentBT.ID);
       if (f == null) {
          f = new SendReceiveFragmentBT();
       }
      }*/ else if (newFragment == ScreenList.SELECT_MODULE) {
        f = mgr.findFragmentById(SelectFragment.ID);
        if (f == null) {
            f = new SelectFragment();
        }
    } else if (newFragment == ScreenList.NAVIGATE_MODULE) {
        f = mgr.findFragmentById(NavigateFragment.ID);
        if (f == null) {
            f = new NavigateFragment();
        }
    } else if (newFragment == ScreenList.RESTORE_MODULE) {
        f = mgr.findFragmentById(RestoreFragment.ID);
        if (f == null) {
            f = new RestoreFragment();
        }
    } else if (newFragment == ScreenList.EDIT_CENSUS_MODULE) {
        f = mgr.findFragmentById(EditCensusFragment.ID);
        if (f == null) {
            f = new EditCensusFragment();
        }
    } else if (newFragment == ScreenList.REMOVE_CENSUS_MODULE) {
        f = mgr.findFragmentById(RemoveCensusFragment.ID);
        if (f == null) {
            f = new RemoveCensusFragment();
        }
    } else if (newFragment == ScreenList.INVALIDATE_CENSUS_MODULE) {
        f = mgr.findFragmentById(InvalidateCensusFragment.ID);
        if (f == null) {
            f = new InvalidateCensusFragment();
        }
    } else if (newFragment == ScreenList.FORM_CHOOSER) {
        f = mgr.findFragmentById(FormChooserListFragment.ID);
        if (f == null) {
            f = new FormChooserListFragment();
        }
    } else if (newFragment == ScreenList.INITIALIZATION_DIALOG) {
        if (currentFragment == ScreenList.INITIALIZATION_DIALOG) {
            WebLogger.getLogger(getAppName()).e(t, "Unexpected: currentFragment == INITIALIZATION_DIALOG");
            return;
        } else {
            f = mgr.findFragmentById(InitializationFragment.ID);
            if (f == null) {
                f = new InitializationFragment();
            }
            ((InitializationFragment) f).setFragmentToShowNext(
                    (currentFragment == null) ? ScreenList.FORM_CHOOSER.name() : currentFragment.name());
        }
    } else if (newFragment == ScreenList.FORM_DELETER) {
        f = mgr.findFragmentById(FormDeleteListFragment.ID);
        if (f == null) {
            f = new FormDeleteListFragment();
        }
    } else if (newFragment == ScreenList.FORM_DOWNLOADER) {
        f = mgr.findFragmentById(FormDownloadListFragment.ID);
        if (f == null) {
            f = new FormDownloadListFragment();
        }
    } else if (newFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER) {
        f = mgr.findFragmentById(InstanceUploaderTableChooserListFragment.ID);
        if (f == null) {
            f = new InstanceUploaderTableChooserListFragment();
        }
    } else if (newFragment == ScreenList.INSTANCE_UPLOADER) {
        f = mgr.findFragmentById(InstanceUploaderListFragment.ID);
        if (f == null) {
            f = new InstanceUploaderListFragment();
        }
        ((InstanceUploaderListFragment) f).changeUploadTableId();
    } else if (newFragment == ScreenList.WEBKIT) {
        f = mgr.findFragmentById(WebViewFragment.ID);
        if (f == null) {
            f = new WebViewFragment();
        }
    } else if (newFragment == ScreenList.ABOUT_MENU) {
        f = mgr.findFragmentById(AboutMenuFragment.ID);
        if (f == null) {
            f = new AboutMenuFragment();
        }

    } else {
        throw new IllegalStateException("Unrecognized ScreenList type");
    }

    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    View wkt = findViewById(R.id.webkit_view);
    shadow.setVisibility(View.GONE);
    shadow.removeAllViews();
    if (newFragment == ScreenList.WEBKIT) {
        frags.setVisibility(View.GONE);
        wkt.setVisibility(View.VISIBLE);
        wkt.invalidate();
    } else {
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.VISIBLE);
    }

    currentFragment = newFragment;
    BackStackEntry entry = null;
    for (int i = 0; i < mgr.getBackStackEntryCount(); ++i) {
        BackStackEntry e = mgr.getBackStackEntryAt(i);
        if (e.getName().equals(currentFragment.name())) {
            entry = e;
            break;
        }
    }
    if (entry != null) {
        // flush backward, including the screen want to go back to
        mgr.popBackStackImmediate(currentFragment.name(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }

    // add transaction to show the screen we want
    FragmentTransaction trans = mgr.beginTransaction();
    trans.replace(R.id.main_content, f);
    trans.addToBackStack(currentFragment.name());
    trans.commit();

    // and see if we should re-initialize...
    if ((currentFragment != ScreenList.INITIALIZATION_DIALOG)
            && Survey.getInstance().shouldRunInitializationTask(getAppName())) {
        WebLogger.getLogger(getAppName()).i(t, "swapToFragmentView -- calling clearRunInitializationTask");
        // and immediately clear the should-run flag...
        Survey.getInstance().clearRunInitializationTask(getAppName());
        // OK we should swap to the InitializationFragment view
        swapToFragmentView(ScreenList.INITIALIZATION_DIALOG);
    } else {
        levelSafeInvalidateOptionsMenu();
    }
}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

@SuppressLint("InlinedApi")
@Override//  ww w.  j a v a  2s .  c  o m
protected void onStart() {
    super.onStart();

    // ensure the DbShimService is started
    Intent intent = new Intent(this, DbShimService.class);
    this.startService(intent);

    this.bindService(intent, mConnection,
            Context.BIND_AUTO_CREATE | ((Build.VERSION.SDK_INT >= 14) ? Context.BIND_ADJUST_WITH_ACTIVITY : 0));

    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    ODKWebView wkt = (ODKWebView) findViewById(R.id.webkit_view);

    if (currentFragment == ScreenList.FORM_CHOOSER || currentFragment == ScreenList.FORM_DOWNLOADER
            || currentFragment == ScreenList.FORM_DELETER
            || currentFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER
            || currentFragment == ScreenList.INSTANCE_UPLOADER
            || currentFragment == ScreenList.INITIALIZATION_DIALOG) {
        shadow.setVisibility(View.GONE);
        shadow.removeAllViews();
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.VISIBLE);
    } else if (currentFragment == ScreenList.WEBKIT) {
        shadow.setVisibility(View.GONE);
        shadow.removeAllViews();
        wkt.setVisibility(View.VISIBLE);
        wkt.invalidate();
        frags.setVisibility(View.GONE);
    } else if (currentFragment == ScreenList.CUSTOM_VIEW) {
        shadow.setVisibility(View.VISIBLE);
        // shadow.removeAllViews();
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.GONE);
    }

    FragmentManager mgr = getFragmentManager();
    if (mgr.getBackStackEntryCount() == 0) {
        swapToFragmentView(currentFragment);
    }
}