Example usage for android.widget LinearLayout getViewTreeObserver

List of usage examples for android.widget LinearLayout getViewTreeObserver

Introduction

In this page you can find the example usage for android.widget LinearLayout getViewTreeObserver.

Prototype

public ViewTreeObserver getViewTreeObserver() 

Source Link

Document

Returns the ViewTreeObserver for this view's hierarchy.

Usage

From source file:org.ohmage.reminders.types.location.LocTrigMapsActivity.java

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

    setContentView(R.layout.trigger_loc_maps);

    // Get the category id from the intent
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        Log.e(TAG, "Maps: Intent extras is null");

        finish();// w  w  w  . j a va 2s . co m
        return;
    }

    mCategId = extras.getInt(LocTrigDB.KEY_ID);
    Log.v(TAG, "Maps: category id = " + mCategId);

    TouchableSupportMapFragment mapFragment = (TouchableSupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.triggers_map);
    mMap = mapFragment.getMap();
    mMap.setMyLocationEnabled(true);

    // Set the info window so it has an add button
    mMap.setInfoWindowAdapter(
            new LocTrigInfoAdapter((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)));

    // Set the on Long click handler. This takes care of adding a pin,
    // deleting a pin and entering radius update mode
    mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

        @Override
        public void onMapLongClick(LatLng point) {

            // First check to see if there is a marker close enough that the
            // user is trying to remove
            if (removeLocation(point))
                return;

            // Then check to see if we are in the radius of the marker to
            // start an update
            if (testMarkerRadiusUpdate(point)) {
                onRadiusUpdateStart();
                return;
            }

            // The default action for a long press is to add a new temporary
            // marker
            onAddTemporaryMarker(point);
        }
    });

    // When the user taps the map, reset all temporary pins
    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {

        @Override
        public void onMapClick(LatLng point) {
            resetMapPins();
        }
    });

    // When a marker is clicked, focus the marker so the radius can be
    // edited
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (!marker.equals(mAddMarker)) {
                onRadiusUpdateFocus(marker);
                return true;
            }
            return false;
        }
    });

    // When the info window is clicked, interpret as adding a point
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            onAddLocation();
        }
    });

    // Watch for touches to handle resizing of the radius
    mapFragment.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(MotionEvent event) {

            if (mRadiusUpdate) {
                // Update the radius movement if we are in the middle of a
                // radius update

                if (MotionEvent.ACTION_MOVE == event.getAction()) {
                    // Continue the radius update since we got a move touch
                    // event
                    Point p = new Point((int) event.getX(), (int) event.getY());
                    onRadiusUpdate(p);
                    return true;
                } else {
                    // End the radius update since we got a touch movement
                    // which wasn't move
                    onRadiusUpdateStop();
                }
            }
            return false;
        }
    });

    // Handle done button and exit this activity
    Button bDone = (Button) findViewById(R.id.button_maps_done);
    bDone.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    mDb = new LocTrigDB(this);
    mDb.open();

    final Builder bounds = new LatLngBounds.Builder();

    // Add locations to the map
    Cursor c = mDb.getLocations(mCategId);
    while (c.moveToNext()) {
        MarkerInfo info = new MarkerInfo();
        int latE6 = c.getInt(c.getColumnIndexOrThrow(LocTrigDB.KEY_LAT));
        int longE6 = c.getInt(c.getColumnIndexOrThrow(LocTrigDB.KEY_LONG));
        info.radius = c.getFloat(c.getColumnIndexOrThrow(LocTrigDB.KEY_RADIUS));
        info.id = c.getLong(c.getColumnIndexOrThrow(LocTrigDB.KEY_ID));
        LatLng position = new LatLng(latE6 / 1E6, longE6 / 1E6);

        Marker marker = mMap.addMarker(new MarkerOptions().position(position));
        bounds.include(marker.getPosition());
        markerInfos.put(marker, info);
    }

    // We need to wait for the map to be layed out before we can animate to
    // show all the points
    final LinearLayout map = (LinearLayout) findViewById(R.id.trigger_maps_container);
    if (map.getViewTreeObserver().isAlive()) {
        map.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                map.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                Location myLocation = Utilities.getCurrentLocation(LocTrigMapsActivity.this);
                if (myLocation != null) {
                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
                            new LatLng(myLocation.getLatitude(), myLocation.getLongitude()), 16));
                }

                if (!markerInfos.isEmpty()) {
                    mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(),
                            getResources().getDimensionPixelSize(R.dimen.map_marker_gutter)));
                }
            }
        });
    }

    // Display appropriate title text
    updateTitleText();

    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            showHelpDialog();
        }
    };

    if (!shouldSkipToolTip()) {
        // Show the tool tip after a small delay
        new Handler().postDelayed(runnable, TOOL_TIP_DELAY);
    }
}

From source file:info.johannblake.shutterstockdemo.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContext = this;
    mAppTerminating = false;/* w  ww .  j ava 2 s .  co  m*/

    // Create a cache to store downloaded images.
    CacheSupport.createCache(mContext);

    restoreAppState();

    NavigationDrawerFragment navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);

    // Set up the drawer.
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationDrawerFragment.setUp(R.id.navigation_drawer, mDrawerLayout);

    if (!INCLUDE_NAV_DRAWER)
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    toolbar.inflateMenu(R.menu.options_menu);

    mMenuItemSearch = toolbar.getMenu().findItem(R.id.search);
    mSearchView = (SearchView) mMenuItemSearch.getActionView();

    mSearchView.setOnQueryTextListener(queryTextListener);

    // Note: Calling mSearchView.setQuery doesn't set the SearchView's input field
    // probably because the SearchView's layout is inflated each time the search
    // icon is tapped. To set the input field, it has to be done after the
    // button has been tapped. Presumably, the SearchView's layout is inflated at that
    // moment.
    mSearchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSearchView.setQuery(mQuery, false);
        }
    });

    if (INCLUDE_NAV_DRAWER) {
        // Display the hamburger icon.
        toolbar.setNavigationIcon(R.drawable.ic_hamburger);
    }

    // Handle the user tapping on the hamburger icon.
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (INCLUDE_NAV_DRAWER)
                mDrawerLayout.openDrawer(Gravity.START);
        }
    });

    // Move the toolbar up/down as the user scrolls the recyclerview.
    final LinearLayout llHeader = (LinearLayout) findViewById(R.id.llHeader);

    llHeader.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final CustomRecyclerView rvImages = (CustomRecyclerView) findViewById(R.id.rvImages);
            rvImages.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);

            rvImages.setY(llHeader.getHeight());
            mJBHeaderScroll = new JBHeaderScroll(llHeader, 0);
            mJBHeaderScroll.registerScroller(rvImages, new JBHeaderScroll.IJBHeaderScroll() {
                @Override
                public void onResize(float top) {
                    ViewGroup.LayoutParams rlLayoutParams = new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    rvImages.setLayoutParams(rlLayoutParams);
                    rvImages.setY(top);
                    llHeader.bringToFront();
                }

                @Override
                public int onHeaderBeforeAnimation(boolean scrollingUp, float scrollDelta) {
                    return JBHeaderScroll.ANIMATE_HEADER_USE_DEFAULT;
                }

                @Override
                public void onHeaderAfterAnimation(boolean animatedUp, float scrollDelta) {
                }
            });

            rvImages.setJBHeaderRef(mJBHeaderScroll);
            llHeader.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
}

From source file:com.sdspikes.fireworks.FireworksActivity.java

private void displayInitialState() {
    switchToScreen(R.id.screen_game);//from  ww  w.java2  s . c  om
    GameState.HandNode currentNode = mTurnData.state.hands.get(mMyId);
    FragmentManager fm = getFragmentManager();
    fragments = new HashMap<>();

    if (fm.findFragmentById(R.id.my_hand) == null) {
        if (currentNode != null) {
            addHandFragment(fm, currentNode, mMyId, mIdToName.get(mMyId), R.id.my_hand);
        } else {
            Log.d(TAG, mMyId);
        }
    }

    if (fm.findFragmentById(R.id.other_hands) == null) {
        while (true) {
            String currentId = currentNode.nextPlayerId;
            if (currentId.equals(mMyId)) {
                break;
            }
            currentNode = mTurnData.state.hands.get(currentId);
            addHandFragment(fm, currentNode, currentId, mIdToName.get(currentId), R.id.other_hands);
        }
    }

    LinearLayout played = (LinearLayout) findViewById(R.id.played_pile);

    played.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            LinearLayout played = (LinearLayout) findViewById(R.id.played_pile);
            mDiscardWidthR2 = played.getMeasuredWidth();

            if (mDiscardWidthR2 != 0) {
                int usableWidth = mDiscardWidthR2 - findViewById(R.id.played_label).getMeasuredWidth();
                mDiscardWidthR1 = mDiscardWidthR2 - findViewById(R.id.discarded_label).getMeasuredWidth();
                for (int i = 1; i < played.getChildCount(); i++) {
                    ViewGroup.LayoutParams params = played.getChildAt(i).getLayoutParams();
                    params.width = usableWidth / 5;
                    played.getChildAt(i).setLayoutParams(params);
                }
                played.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                LinearLayout chooseAttribute = (LinearLayout) findViewById(R.id.chooseAttribute);
                for (int i = 1; i <= 5; i++) {
                    chooseAttribute.addView(makeAttributeTextView(i, null));
                }
                for (GameState.CardColor color : GameState.CardColor.values()) {
                    chooseAttribute.addView(makeAttributeTextView(-1, color));
                }

                // In case all the data is ready already and was just waiting on this.
                updateDisplay();
            }
        }
    });

    createInitialLog();
    ((TextView) findViewById(R.id.log)).setMovementMethod(new ScrollingMovementMethod());
}

From source file:com.tct.mail.compose.ComposeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //TS: zheng.zou 2015-12-03 EMAIL BUGFIX_1030520 ADD_S
    if (mHasNoPermission) {
        return;/*from w w  w .j  av a 2  s  .c o m*/
    }
    //TS: zheng.zou 2015-12-03 EMAIL BUGFIX_1030520 ADD_E
    //AM: peng-zhang 2015-02-27 EMAIL BUGFIX_955421 MOD_S
    if (savedInstanceState != null) {
        bcc_text = savedInstanceState.getString("BCC_SAVE");
        Changed = savedInstanceState.getBoolean("BCC_CHANGED");
        // TS: junwei-xu 2015-06-30 EMAIL BUGFIX-1030195 ADD_S
        mPriorityFlag = savedInstanceState.getInt(KEY_PRIORITY_SAVED_STATE);
        // TS: junwei-xu 2015-06-30 EMAIL BUGFIX-1030195 ADD_E
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_S
        mTextChanged = savedInstanceState.getBoolean(KEY_SAVED_STATE_TEXT_CHANGED);
        mAttachmentsChanged = savedInstanceState.getBoolean(KEY_SAVED_STATE_ATTACHMENT_CHANGED);
        mReplyFromChanged = savedInstanceState.getBoolean(KEY_SAVED_STATE_REPLY_FROM_CHANGED);
        mProrityChanged = savedInstanceState.getBoolean(KEY_SAVED_STATE_PRIORITY_CHANGED);
        // TS: junwei-xu 2015-07-17 EMAIL BUGFIX-1029180 ADD_E
        //TS: yanhua.chen 2015-7-29 EMAIL BUGFIX_1053132 ADD_S
        attLargeWarning = savedInstanceState.getBoolean(KEY_SAVED_STATE_ATTLARGEWARNING_CHANGED);
        //TS: yanhua.chen 2015-7-29 EMAIL BUGFIX_1053132 ADD_E
        //TS: yanhua.chen 2015-9-1 EMAIL CD_551912 ADD_S
        //mIsClickIcon = savedInstanceState.getBoolean(KEY_SAVED_STATE_ISCLICKICON_CHANGED);//[BUGFIX]-MOD by SCDTABLET.shujing.jin@tcl.com,05/06/2016,2013535
        mChangeAccount = savedInstanceState.getBoolean(KEY_SAVED_STATE_CHANGEACCOUNT_CHANGED);
        mEditDraft = savedInstanceState.getBoolean(KEY_SAVED_STATE_EDITDRAFT_CHANGED);
        //TS: yanhua.chen 2015-9-1 EMAIL CD_551912 ADD_E
    }
    //AM: peng-zhang 2015-02-27 EMAIL BUGFIX_955421 MOD_E
    setContentView(R.layout.compose);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Hide the app icon.
        actionBar.setIcon(null);
        actionBar.setDisplayUseLogoEnabled(false);
    }

    mInnerSavedState = (savedInstanceState != null) ? savedInstanceState.getBundle(KEY_INNER_SAVED_STATE)
            : null;

    //[FEATURE]-Add-BEGIN by TSNJ,Zhenhua.Fan,06/11/2014,FR-622609
    if (EmailApplication.isOrangeImapFeatureOn()) {
        Intent i = getIntent();
        if (i != null && i.getBooleanExtra(EXTRA_FROM_DRAFT_VIEW, false)) {
            isFromView = true;
        }
    }
    //[FEATURE]-Add-END by TSNJ,Zhenhua.Fan
    checkValidAccounts();
    // TS: jian.xu 2015-06-05 EMAIL BUGFIX-1006499 ADD_S
    LinearLayout tmp = (LinearLayout) findViewById(R.id.content);
    tmp.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();
            //get the cutrent visibale disrict.
            ComposeActivity.this.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
            //get the screen height
            int screenHeight = ComposeActivity.this.getWindow().getDecorView().getRootView().getHeight();

            Rect textRect = new Rect();
            int keyboardHeight = screenHeight - r.bottom;
            // the number 100 means that the keyboard is showing.
            if (keyboardHeight > 100) {
                android.os.Message msg = mHandler.obtainMessage(SET_LISTPOPUPWINDOW_HEIGHT);
                mHandler.sendMessage(msg);
            }
        }
    });
    // TS: jian.xu 2015-06-05 EMAIL BUGFIX-1006499 ADD_E
}