Example usage for android.view ViewGroup removeView

List of usage examples for android.view ViewGroup removeView

Introduction

In this page you can find the example usage for android.view ViewGroup removeView.

Prototype

@Override
public void removeView(View view) 

Source Link

Document

Note: do not invoke this method from #draw(android.graphics.Canvas) , #onDraw(android.graphics.Canvas) , #dispatchDraw(android.graphics.Canvas) or any related method.

Usage

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

public void setMenu(Menu menu, MenuPresenter.Callback cb) {
    if (menu == mOptionsMenu)
        return;//from   ww w  . ja v a2 s.c  o m

    if (mOptionsMenu != null) {
        mOptionsMenu.removeMenuPresenter(mActionMenuPresenter);
        mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter);
    }

    MenuBuilder builder = (MenuBuilder) menu;
    mOptionsMenu = builder;
    if (mMenuView != null) {
        final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
        if (oldParent != null) {
            oldParent.removeView(mMenuView);
        }
    }
    if (mActionMenuPresenter == null) {
        mActionMenuPresenter = new ActionMenuPresenter(mContext);
        mActionMenuPresenter.setCallback(cb);
        mActionMenuPresenter.setId(R.id.abs__action_menu_presenter);
        mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
    }

    ActionMenuView menuView;
    final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    if (!mSplitActionBar) {
        mActionMenuPresenter.setExpandedActionViewsExclusive(
                getResources_getBoolean(getContext(), R.bool.abs__action_bar_expanded_action_views_exclusive));
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        final ViewGroup oldParent = (ViewGroup) menuView.getParent();
        if (oldParent != null && oldParent != this) {
            oldParent.removeView(menuView);
        }
        addView(menuView, layoutParams);
    } else {
        mActionMenuPresenter.setExpandedActionViewsExclusive(false);
        // Allow full screen width in split mode.
        mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
        // No limit to the item count; use whatever will fit.
        mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
        // Span the whole width
        layoutParams.width = LayoutParams.MATCH_PARENT;
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        if (mSplitView != null) {
            final ViewGroup oldParent = (ViewGroup) menuView.getParent();
            if (oldParent != null && oldParent != mSplitView) {
                oldParent.removeView(menuView);
            }
            menuView.setVisibility(getAnimatedVisibility());
            mSplitView.addView(menuView, layoutParams);
        } else {
            // We'll add this later if we missed it this time.
            menuView.setLayoutParams(layoutParams);
        }
    }
    mMenuView = menuView;
}

From source file:de.mkrtchyan.recoverytools.RecoveryTools.java

public void optimizeLayout() throws NullPointerException {

    try {/* w w w .j  av  a  2s  .  c om*/
        if (mDevice.isRecoverySupported() || mDevice.isKernelSupported()) {
            /** If device is supported start setting up layout */
            if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
                /** Setting layout for flashing over external App for example File Browser */
                setContentView(R.layout.flash_as);
                RelativeLayout FlashAsLayout = (RelativeLayout) findViewById(R.layout.flash_as);
                String path;
                if ((path = getIntent().getData().getPath()) != null) {
                    final File IMG = new File(path);
                    if (IMG.exists()) {
                        TextView tvFlashAs = (TextView) findViewById(R.id.tvFlashAs);
                        tvFlashAs.setText(String.format(getString(R.string.flash_as), IMG.getName()));
                    } else {
                        exit();
                    }
                    RadioButton optAsRecovery = (RadioButton) findViewById(R.id.optAsRecovery);
                    RadioButton optAsKernel = (RadioButton) findViewById(R.id.optAsKernel);

                    if (!mDevice.isRecoverySupported()) {
                        FlashAsLayout.removeView(optAsRecovery);
                        optAsKernel.setChecked(true);
                    }
                    if (!mDevice.isKernelSupported()) {
                        FlashAsLayout.removeView((optAsKernel));
                    }
                } else {
                    exit();
                }
            } else {
                setContentView(R.layout.recovery_tools);

                mRecoveryToolsLayout = (DrawerLayout) findViewById(R.id.RecoveryToolsLayout);
                mSwipeUpdater = (SwipeRefreshLayout) findViewById(R.id.swipe_updater);
                mSwipeUpdater.setColorScheme(R.color.custom_green, android.R.color.black, R.color.custom_green,
                        android.R.color.darker_gray);
                mSwipeUpdater.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        Downloader updater = new Downloader(mContext, "http://dslnexus.de/Android/", "img_sums",
                                RecoveryCollectionFile, new Runnable() {
                                    @Override
                                    public void run() {
                                        mDevice = new Device(mContext);
                                    }
                                });
                        updater.setOverrideFile(true);
                        updater.setRetry(true);
                        updater.setHidden(true);
                        Toast.makeText(mContext, "Refreshing recovery list", Toast.LENGTH_SHORT).show();
                        updater.setAfterDownload(new Runnable() {
                            @Override
                            public void run() {
                                mSwipeUpdater.setRefreshing(false);
                                Toast.makeText(mContext, "Update finished", Toast.LENGTH_SHORT).show();
                                mDevice.loadRecoveryList();
                            }
                        });
                        updater.execute();
                    }
                });
                LayoutInflater layoutInflater = getLayoutInflater();

                DrawerLayout mMenuDrawer = (DrawerLayout) layoutInflater.inflate(R.layout.menu_drawer,
                        mRecoveryToolsLayout, true);
                DrawerLayout mBackupDrawer = (DrawerLayout) layoutInflater.inflate(R.layout.backup_drawer,
                        mRecoveryToolsLayout, true);
                mRecoveryToolsLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
                ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(mActivity, mRecoveryToolsLayout,
                        R.drawable.ic_drawer, R.string.settings, R.string.app_name);
                mRecoveryToolsLayout.setDrawerListener(mDrawerToggle);
                mDrawerToggle.syncState();
                mDrawerToggle.setDrawerIndicatorEnabled(true);
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setHomeButtonEnabled(true);

                String Styles[] = getResources().getStringArray(R.array.styles);
                if (mMenuDrawer != null) {
                    Spinner spStyle = (Spinner) mMenuDrawer.findViewById(R.id.spStyle);
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mActivity,
                            R.layout.custom_list_item, Styles);
                    adapter.setDropDownViewResource(R.layout.custom_list_item);

                    spStyle.setAdapter(adapter);
                    spStyle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            switch (position) {
                            case 1:
                                Common.setIntegerPref(mContext, PREF_NAME, PREF_STYLE,
                                        APPCOMPAT_LIGHT_DARK_BAR);
                                restartActivity();
                                break;
                            case 2:
                                Common.setIntegerPref(mContext, PREF_NAME, PREF_STYLE, APPCOMPAT_LIGHT);
                                restartActivity();
                                break;
                            case 3:
                                Common.setIntegerPref(mContext, PREF_NAME, PREF_STYLE, APPCOMPAT_DARK);
                                restartActivity();
                                break;
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {

                        }
                    });
                    CheckBox cbShowAds = (CheckBox) mMenuDrawer.findViewById(R.id.cbShowAds);
                    CheckBox cbLog = (CheckBox) mMenuDrawer.findViewById(R.id.cbLog);

                    cbShowAds.setChecked(Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS));
                    cbLog.setChecked(Common.getBooleanPref(mContext, Shell.PREF_NAME, Shell.PREF_LOG));
                    if (cbLog.isChecked()) {
                        findViewById(R.id.bShowLogs).setVisibility(View.VISIBLE);
                    } else {
                        findViewById(R.id.bShowLogs).setVisibility(View.INVISIBLE);
                    }
                    cbShowAds.setChecked(Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS));

                }

                final TextView RecoveryVersion = (TextView) findViewById(R.id.tvVersion);
                RecoveryVersion.setText(mDevice.getRecoveryVersion() + "\n" + mDevice.getKernelVersion());
                loadBackupDrawer();

                AdView adView = (AdView) findViewById(R.id.adView);
                ViewGroup MainParent = (ViewGroup) adView.getParent();
                /** Removing ads if user has turned off */
                if (!Common.getBooleanPref(mContext, PREF_NAME, PREF_KEY_ADS)) {
                    if (adView != null && MainParent != null) {
                        MainParent.removeView(adView);
                    }
                }

                if (MainParent != null) {
                    if (!mDevice.isKernelSupported()) {
                        /** If Kernel flashing is not supported remove flash options */
                        MainParent.removeView(findViewById(R.id.bFlashKernel));
                    }
                    if (!mDevice.isRecoverySupported()) {
                        /** If Recovery flashing is not supported remove flash options */
                        MainParent.removeView(findViewById(R.id.bFlashRecovery));
                    }
                }

                if (mBackupDrawer != null) {
                    ViewGroup BackupDrawerParent = (ViewGroup) mBackupDrawer.getParent();
                    if (mDevice.isRecoveryOverRecovery()) {
                        BackupDrawerParent.removeView(mBackupDrawer);
                    } else {
                        View createKernelBackup = findViewById(R.id.bCreateKernelBackup);
                        View kernelBackups = findViewById(R.id.lvKernelBackups);
                        View createRecoveryBackup = findViewById(R.id.bCreateRecoveryBackup);
                        View recoveryBackups = findViewById(R.id.lvRecoveryBackups);
                        if (!mDevice.isKernelSupported()) {
                            /** If Kernel flashing is not supported remove backup views */
                            ((ViewGroup) createKernelBackup.getParent()).removeView(createKernelBackup);
                            ((ViewGroup) kernelBackups.getParent()).removeView(kernelBackups);
                        }
                        if (!mDevice.isRecoverySupported()) {
                            /** If Recovery flashing is not supported remove backup views */
                            ((ViewGroup) createRecoveryBackup.getParent()).removeView(createRecoveryBackup);
                            ((ViewGroup) recoveryBackups.getParent()).removeView(recoveryBackups);
                        }
                    }
                }
            }
        }

    } catch (NullPointerException e) {
        throw new NullPointerException("Error while setting up Layout " + e.getMessage());
    }
}

From source file:com.tmall.ultraviewpager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO/*  ww  w.j a  v  a2  s. c o m*/
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    if (item instanceof RecyclerView.ViewHolder)
        childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int realPosition = position;
    //TODO/*from w  w w. j  a va 2s .  c o m*/
    if (enableLoop && adapter.getCount() != 0) {
        realPosition = position % adapter.getCount();
    }

    Object item = adapter.instantiateItem(container, realPosition);
    //TODO
    View childView = null;
    if (item instanceof View)
        childView = (View) item;
    //        if (item instanceof RecyclerView.ViewHolder)
    //            childView = ((RecyclerView.ViewHolder) item).itemView;

    ViewPager viewPager = (ViewPager) container;
    int childCount = viewPager.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = viewPager.getChildAt(i);
        if (isViewFromObject(child, item)) {
            viewArray.put(realPosition, child);
            break;
        }
    }

    if (isEnableMultiScr()) {
        if (scrWidth == 0) {
            scrWidth = container.getResources().getDisplayMetrics().widthPixels;
        }
        RelativeLayout relativeLayout = new RelativeLayout(container.getContext());

        if (childView.getLayoutParams() != null) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    (int) (scrWidth * multiScrRatio), ViewGroup.LayoutParams.MATCH_PARENT);

            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            childView.setLayoutParams(layoutParams);
        }

        container.removeView(childView);
        relativeLayout.addView(childView);

        container.addView(relativeLayout);
        return relativeLayout;
    }

    return item;
}

From source file:ti.modules.titanium.ui.widget.abslistview.TiAbsListView.java

public static View layoutHeaderOrFooterView(TiViewProxy viewProxy, View convertView) {
    TiUIView tiView = viewProxy.getOrCreateView();
    View outerView = null;// www.  ja v a2 s  . c o m
    ViewGroup parentView = null;
    if (tiView != null) {
        outerView = tiView.getOuterView();
        parentView = (ViewGroup) outerView.getParent();
    }
    if ((parentView != null && parentView.getId() == HEADER_FOOTER_WRAP_ID)
            && (convertView == null || convertView == parentView)) {
        return parentView;
    } else {

        TiCompositeLayout wrapper = null;
        if (convertView instanceof TiCompositeLayout && convertView.getId() == HEADER_FOOTER_WRAP_ID) {
            wrapper = (TiCompositeLayout) convertView;
            wrapper.removeAllViews();
        } else {
            wrapper = new TiCompositeLayout(viewProxy.getActivity(), LayoutArrangement.DEFAULT, null);
            //add a wrapper so layout params such as height, width takes in effect.
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(
                    AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
            wrapper.setLayoutParams(params);
            wrapper.setInternalTouchPassThrough(true);
        }
        if (parentView != null) {
            parentView.removeView(outerView);
        }
        //           TiUIHelper.removeViewFromSuperView(viewProxy);

        if (outerView != null && tiView != null) {
            TiCompositeLayout.LayoutParams headerParams = tiView.getLayoutParams();
            //If height is not dip, explicitly set it to SIZE
            if (!headerParams.fixedSizeHeight()) {
                headerParams.sizeOrFillHeightEnabled = true;
                headerParams.autoFillsHeight = false;
            }
            if (headerParams.optionWidth == null && !viewProxy.hasProperty(TiC.PROPERTY_WIDTH)) {
                headerParams.sizeOrFillWidthEnabled = true;
                headerParams.autoFillsWidth = true;
            }
            wrapper.addView(outerView, tiView.getLayoutParams());
        }
        wrapper.setId(HEADER_FOOTER_WRAP_ID);
        wrapper.setTag(HEADER_FOOTER_WRAP_ID);
        return wrapper;
    }
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

private void removePromptView() {
    if (mPromptView != null) {
        final ViewParent parent = mPromptView.getParent();
        if (parent instanceof ViewGroup) {
            final ViewGroup group = (ViewGroup) parent;
            group.removeView(mPromptView);
        }/*from w ww.  j  a  v a2 s  .com*/
    }
}

From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java

/**
 *  Activity /*from  w  ww .  j  a  va 2s .co  m*/
 *
 * @param activity
 */
public void attachToActivity(Activity activity) {
    mActivity = activity;

    setSliderFadeColor(Color.TRANSPARENT);

    mShadowView = new View(activity);
    setIsNeedShowShadow(mIsNeedShowShadow);
    addView(mShadowView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    mContentView = decorView.getChildAt(0);
    decorView.removeView(mContentView);
    decorView.addView(this);
    addView(mContentView, 1, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}

From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java

private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext()).inflate(getMenuItemLayoutId(), this,
            false);//from  w ww  .  j a va2  s  .  c o  m

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);

        if (miniFabTitleTextColorArray != null) {
            titleView.setTextColor(ContextCompat.getColorStateList(getContext(),
                    miniFabTitleTextColorArray[menuItem.getOrder()]));
        }
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);

    if (miniFabBackgroundTintArray != null) {
        miniFab.setBackgroundTintList(
                ContextCompat.getColorStateList(getContext(), miniFabBackgroundTintArray[menuItem.getOrder()]));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}

From source file:org.thecongers.mcluster.MainActivity.java

public void updateLayout() {
    if (sharedPrefs.getString("prefInfoView", "0").contains("0")) {
        View otherLayout = findViewById(R.id.layoutInfoTPMS);
        if (otherLayout != null) {
            ViewGroup parent = (ViewGroup) otherLayout.getParent();
            parent.removeView(otherLayout);
        }/*from   w w w . ja v a 2  s. c o m*/

        View tempsLayout = findViewById(R.id.layoutInfoTemps);
        if (tempsLayout != null) {
            ViewGroup parent = (ViewGroup) tempsLayout.getParent();
            parent.removeView(tempsLayout);
        }

        LinearLayout infoOtherLayout = (LinearLayout) findViewById(R.id.layoutInfoOther);
        if (infoOtherLayout == null) {
            LinearLayout infoLayout = (LinearLayout) findViewById(R.id.layoutInfo);
            View infoView = getLayoutInflater().inflate(R.layout.activity_main_info, infoLayout, false);
            infoLayout.addView(infoView);

        }

        txtInfo = (TextView) findViewById(R.id.textViewInfo);
        txtInfo.setGravity(Gravity.CENTER | Gravity.BOTTOM);
        txtInfo.setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);
        // Update Colors
        if ((!itsDark) && (!sharedPrefs.getBoolean("prefNightMode", false))) {
            txtInfo.setTextColor(getResources().getColor(android.R.color.black));
        } else {
            txtInfo.setTextColor(getResources().getColor(android.R.color.white));
        }
        txtInfo.setText("- RPM");
    } else if (sharedPrefs.getString("prefInfoView", "0").contains("1")) {
        View otherLayout = findViewById(R.id.layoutInfoTPMS);
        if (otherLayout != null) {
            ViewGroup parent = (ViewGroup) otherLayout.getParent();
            parent.removeView(otherLayout);
        }

        View tempsLayout = findViewById(R.id.layoutInfoTemps);
        if (tempsLayout != null) {
            ViewGroup parent = (ViewGroup) tempsLayout.getParent();
            parent.removeView(tempsLayout);
        }

        LinearLayout infoOtherLayout = (LinearLayout) findViewById(R.id.layoutInfoOther);
        if (infoOtherLayout == null) {
            LinearLayout infoLayout = (LinearLayout) findViewById(R.id.layoutInfo);
            View infoView = getLayoutInflater().inflate(R.layout.activity_main_info, infoLayout, false);
            infoLayout.addView(infoView);

        }

        txtInfo = (TextView) findViewById(org.thecongers.mcluster.R.id.textViewInfo);
        txtInfo.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL);
        txtInfo.setTextSize(TypedValue.COMPLEX_UNIT_SP, 120);
        // Update Colors
        if ((!itsDark) && (!sharedPrefs.getBoolean("prefNightMode", false))) {
            txtInfo.setTextColor(getResources().getColor(android.R.color.black));
        } else {
            txtInfo.setTextColor(getResources().getColor(android.R.color.white));
        }
        txtInfo.setText("-");
    } else if (sharedPrefs.getString("prefInfoView", "0").contains("2")) {
        View otherLayout = findViewById(R.id.layoutInfoOther);
        if (otherLayout != null) {
            ViewGroup parent = (ViewGroup) otherLayout.getParent();
            parent.removeView(otherLayout);
        }

        View tempsLayout = findViewById(R.id.layoutInfoTemps);
        if (tempsLayout != null) {
            ViewGroup parent = (ViewGroup) tempsLayout.getParent();
            parent.removeView(tempsLayout);
        }

        LinearLayout infoTPMSLayout = (LinearLayout) findViewById(R.id.layoutInfoTPMS);
        if (infoTPMSLayout == null) {
            LinearLayout myLayout = (LinearLayout) findViewById(R.id.layoutInfo);
            View infoView = getLayoutInflater().inflate(R.layout.activity_main_tpms, myLayout, false);
            myLayout.addView(infoView);
        }

        String pressureUnit = "psi";
        double frontPressure = frontPressurePSI;
        double rearPressure = rearPressurePSI;
        String pressureFormat = sharedPrefs.getString("prefpressuref", "0");
        if (pressureFormat.contains("1")) {
            // KPa
            frontPressure = frontPressurePSI * 6.894757293168361;
            rearPressure = rearPressurePSI * 6.894757293168361;
            pressureUnit = "KPa";
        } else if (pressureFormat.contains("2")) {
            // Kg-f
            frontPressure = frontPressurePSI * 0.070306957965539;
            rearPressure = rearPressurePSI * 0.070306957965539;
            pressureUnit = "Kg-f";
        } else if (pressureFormat.contains("3")) {
            // Bar
            frontPressure = frontPressurePSI * 0.0689475729;
            rearPressure = rearPressurePSI * 0.0689475729;
            pressureUnit = "Bar";
        }
        int formattedFrontPressure = (int) (frontPressure + 0.5d);
        int formattedRearPressure = (int) (rearPressure + 0.5d);
        txtFrontTPMS = (TextView) findViewById(R.id.textViewFrontTPMS);
        txtFrontTPMS.setTextSize(TypedValue.COMPLEX_UNIT_SP, 50);
        txtFrontTPMS.setText(formattedFrontPressure + " " + pressureUnit);
        txtRearTPMS = (TextView) findViewById(R.id.textViewRearTPMS);
        txtRearTPMS.setTextSize(TypedValue.COMPLEX_UNIT_SP, 50);
        txtRearTPMS.setText(formattedRearPressure + " " + pressureUnit);
        // Update Colors
        if ((!itsDark) && (!sharedPrefs.getBoolean("prefNightMode", false))) {
            txtFrontTPMS.setTextColor(getResources().getColor(android.R.color.black));
            txtRearTPMS.setTextColor(getResources().getColor(android.R.color.black));
        } else {
            txtFrontTPMS.setTextColor(getResources().getColor(android.R.color.white));
            txtRearTPMS.setTextColor(getResources().getColor(android.R.color.white));
        }
    } else if (sharedPrefs.getString("prefInfoView", "0").contains("3")) {
        View otherLayout = findViewById(R.id.layoutInfoOther);
        if (otherLayout != null) {
            ViewGroup parent = (ViewGroup) otherLayout.getParent();
            parent.removeView(otherLayout);
        }

        View tpmsLayout = findViewById(R.id.layoutInfoTPMS);
        if (tpmsLayout != null) {
            ViewGroup parent = (ViewGroup) tpmsLayout.getParent();
            parent.removeView(tpmsLayout);
        }

        LinearLayout infoTPMSLayout = (LinearLayout) findViewById(R.id.layoutInfoTemps);
        if (infoTPMSLayout == null) {
            LinearLayout myLayout = (LinearLayout) findViewById(R.id.layoutInfo);
            View infoView = getLayoutInflater().inflate(R.layout.activity_main_temps, myLayout, false);
            myLayout.addView(infoView);
        }

        String temperatureUnit = "C";
        double engineTemp = engineTempC;
        double airTemp = airTempC;
        String temperatureFormat = sharedPrefs.getString("prefTempF", "0");
        if (temperatureFormat.contains("1")) {
            // F
            engineTemp = (int) Math.round((9.0 / 5.0) * engineTemp + 32.0);
            airTemp = (int) Math.round((9.0 / 5.0) * airTemp + 32.0);
            temperatureUnit = "F";
        }
        txtEngineTemp = (TextView) findViewById(R.id.textViewEngineTemp);
        txtEngineTemp.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        txtEngineTemp.setText(engineTemp + " " + temperatureUnit);
        txtAirTemp = (TextView) findViewById(R.id.textViewAirTemp);
        txtAirTemp.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
        txtAirTemp.setText(airTemp + " " + temperatureUnit);
        // Update Colors
        if ((!itsDark) && (!sharedPrefs.getBoolean("prefNightMode", false))) {
            txtEngineTemp.setTextColor(getResources().getColor(android.R.color.black));
            txtAirTemp.setTextColor(getResources().getColor(android.R.color.black));
        } else {
            txtEngineTemp.setTextColor(getResources().getColor(android.R.color.white));
            txtAirTemp.setTextColor(getResources().getColor(android.R.color.white));
        }
    }
}