Example usage for android.widget RelativeLayout bringToFront

List of usage examples for android.widget RelativeLayout bringToFront

Introduction

In this page you can find the example usage for android.widget RelativeLayout bringToFront.

Prototype

public void bringToFront() 

Source Link

Document

Change the view's z order in the tree, so it's on top of other sibling views.

Usage

From source file:com.almalence.opencam.ui.AlmalenceStore.java

public void showStore() {
    LayoutInflater inflater = LayoutInflater.from(MainScreen.getInstance());
    List<RelativeLayout> pages = new ArrayList<RelativeLayout>();

    // <!-- -+-
    final boolean unlocked = false;
    //-+- -->//w w w  . ja v a 2s. c  o m
    /* <!-- +++
    final boolean unlocked = true; 
     +++ --> */

    // page 1
    RelativeLayout page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    initStoreList();

    RelativeLayout store = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_store, null);
    final ImageView imgStoreNext = (ImageView) store.findViewById(R.id.storeWhatsNew);
    GridView gridview = (GridView) store.findViewById(R.id.storeGrid);
    gridview.setAdapter(storeAdapter);

    if (!unlocked) {
        page.addView(store);
        pages.add(page);
    }

    // page 2
    page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    RelativeLayout features = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_features, null);
    final ImageView imgFeaturesPrev = (ImageView) features.findViewById(R.id.storeWhatsNew);
    imgFeaturesPrev.setVisibility(View.INVISIBLE);
    WebView wv = (WebView) features.findViewById(R.id.text_features);
    wv.loadUrl("file:///android_asset/www/features.html");

    page.addView(features);
    pages.add(page);

    SamplePagerAdapter pagerAdapter = new SamplePagerAdapter(pages);
    final ViewPager viewPager = new ViewPager(MainScreen.getInstance());
    viewPager.setAdapter(pagerAdapter);
    if (!unlocked)
        viewPager.setCurrentItem(0);
    else
        viewPager.setCurrentItem(1);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            switch (position) {
            case 0:
                // 0
                imgStoreNext.setVisibility(View.VISIBLE);
                // 1
                imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            case 1:
                // 0
                imgStoreNext.setVisibility(View.INVISIBLE);
                // 1
                if (!unlocked)
                    imgFeaturesPrev.setVisibility(View.VISIBLE);
                else
                    imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            default:
                break;
            }
        }
    });

    imgStoreNext.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(1);
        }
    });

    imgFeaturesPrev.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(0);
        }
    });

    guiView.findViewById(R.id.buttonGallery).setEnabled(false);
    guiView.findViewById(R.id.buttonShutter).setEnabled(false);
    guiView.findViewById(R.id.buttonSelectMode).setEnabled(false);

    PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
            ApplicationInterface.MSG_CONTROL_LOCKED);

    MainScreen.getGUIManager().lockControls = true;

    // <!-- -+-
    if (MainScreen.getInstance().showPromoRedeemed) {
        Toast.makeText(MainScreen.getInstance(),
                "The promo code has been successfully redeemed. All PRO-Features are unlocked",
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemed = false;
    }
    if (MainScreen.getInstance().showPromoRedeemedJulius) {
        Toast.makeText(MainScreen.getInstance(),
                MainScreen.getInstance().getResources().getString(R.string.promoRedeemedJulius),
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemedJulius = false;
    }
    //-+- -->

    final RelativeLayout pagerLayout = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayout));
    pagerLayout.addView(viewPager);

    final RelativeLayout pagerLayoutMain = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayoutMain));
    pagerLayoutMain.setVisibility(View.VISIBLE);
    pagerLayoutMain.bringToFront();

    // We need this timer, to show store on top, after we return from google
    // play.
    // In MainScreen there is timer, which brings main buttons on top,
    // after MainScreen activity resumed.
    // So this timer "blocks" timer from MainScreen if we want to show
    // store.
    new CountDownTimer(600, 10) {
        public void onTick(long millisUntilFinished) {
            pagerLayoutMain.bringToFront();
        }

        public void onFinish() {
            pagerLayoutMain.bringToFront();
        }
    }.start();
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Show the alert//  w  w w. j a  va2 s .  co m
 *
 * @param context                 application-specific resources
 * @param configuration           describes all device configuration information
 * @param text                    message to be displayed
 * @param forceClearPreviousAlert true will clear previous alert else keep it
 */
@SuppressLint("NewApi")
private static void showAlertOnScreen(final Activity context, final Configuration configuration,
        final String text, boolean forceClearPreviousAlert) {

    final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content));
    boolean currentlyDisplayed = false;
    int viewId = R.id.alert_view_top;
    final TextView textView;
    boolean alertAlreadyExists = false;

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    // Retrieving the view
    RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId);

    if (forceClearPreviousAlert) {
        mainView.removeView(relativeLayout);
        relativeLayout = null;
    }

    // Creating the view
    if (relativeLayout == null) {

        // Main layout
        relativeLayout = new RelativeLayout(context);
        relativeLayout.setId(viewId);
        relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight()));
        relativeLayout.setGravity(Gravity.CENTER);

        // Textview
        textView = new TextView(context);
        textView.setId(R.id.alert_view_text);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(
                new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        relativeLayout.addView(textView);

        setIcon(context, configuration, relativeLayout, textView);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            relativeLayout.setY(-configuration.getHeight());
        } else {
            relativeLayout.setY(mainView.getHeight());
        }

        // Adding the view to the global layout
        mainView.addView(relativeLayout, 0);
        relativeLayout.bringToFront();
        relativeLayout.requestLayout();
        relativeLayout.invalidate();
    }
    // View already exists
    else {
        alertAlreadyExists = true;
        textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            if (relativeLayout.getY() == 0) {
                currentlyDisplayed = true;
            }
        } else {
            if (relativeLayout.getY() < mainView.getHeight()) {
                currentlyDisplayed = true;
            }
        }

        // The view is currently shown to the user
        if (currentlyDisplayed) {

            // If the message is not the same, we hide the current message and display the new one
            if (!StringUtils.equals(text, textView.getText())) {
                // Anim out the current message
                ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout);

                final RelativeLayout relativeLayoutFinal = relativeLayout;

                if (viewPropertyAnimator != null) {
                    // Anim in the new message after the animation out has finished
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    } else {
                        viewPropertyAnimator.withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    }
                } else {
                    setIcon(context, configuration, relativeLayoutFinal, textView);
                    animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                }
            }
        }
    }

    final RelativeLayout relativeLayoutFinal = relativeLayout;

    // Close the alert by clicking the layout
    if (configuration.isCloseable()) {
        relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                animOut(configuration, mainView, relativeLayoutFinal);
                v.performClick();
                return true;
            }
        });
    }

    if (!currentlyDisplayed) {
        // Set the icon in case the alert already exists but it's not currently displayed
        if (alertAlreadyExists) {
            setIcon(context, configuration, relativeLayoutFinal, textView);
        }

        // We anim in the alert
        animIn(configuration, relativeLayoutFinal, textView, mainView, text);
    }
}