Example usage for android.view View getViewTreeObserver

List of usage examples for android.view View getViewTreeObserver

Introduction

In this page you can find the example usage for android.view View getViewTreeObserver.

Prototype

public ViewTreeObserver getViewTreeObserver() 

Source Link

Document

Returns the ViewTreeObserver for this view's hierarchy.

Usage

From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void removeOnGlobalLayoutListener(View v, ViewTreeObserver.OnGlobalLayoutListener listener) {
    ViewTreeObserver viewTreeObserver = v.getViewTreeObserver();
    if (viewTreeObserver != null) {
        if (Build.VERSION.SDK_INT < 16) {
            viewTreeObserver.removeGlobalOnLayoutListener(listener);
        } else {/*from  ww w.j av  a 2 s.  com*/
            viewTreeObserver.removeOnGlobalLayoutListener(listener);
        }
    } else {
        Log.w(OTPApp.TAG, "Problems obtaining exact element's positions on screen, some other elements"
                + "can be misplaced");
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View mapView = super.onCreateView(inflater, container, savedInstanceState);

    View v = inflater.inflate(R.layout.fragment_map, container, false);
    FrameLayout layout = (FrameLayout) v.findViewById(R.id.map_container);

    layout.addView(mapView, 0);/*from ww w .java  2  s .c  o m*/

    mFloorControls = layout.findViewById(R.id.map_floorcontrol);

    // setup floor button handlers
    mFloorButtons[0] = (Button) v.findViewById(R.id.map_floor1);
    mFloorButtons[1] = (Button) v.findViewById(R.id.map_floor2);
    mFloorButtons[2] = (Button) v.findViewById(R.id.map_floor3);
    mFloorButtons[0].setVisibility(View.GONE);
    mFloorButtons[1].setVisibility(View.GONE);
    mFloorButtons[2].setVisibility(View.GONE);
    mFloorControls.setVisibility(View.GONE);
    for (int i = 0; i < mFloorButtons.length; i++) {
        final int j = i;
        mFloorButtons[i].setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showFloor(j);
            }
        });

    }

    // get the height and width of the view
    mapView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        @Override
        public void onGlobalLayout() {
            final View v = getView();
            mHeight = v.getHeight();
            mWidth = v.getWidth();

            // also requires width and height
            enableFloors();

            if (v.getViewTreeObserver().isAlive()) {
                // remove this layout listener
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    v.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                } else {
                    v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
            }
        }
    });

    if (mMap == null) {
        setupMap(true);
    }

    // load all markers
    LoaderManager lm = getActivity().getSupportLoaderManager();
    lm.initLoader(MarkerQuery._TOKEN, null, this);

    // load the tile overlays
    lm.initLoader(OverlayQuery._TOKEN, null, this);

    // load tracks data
    lm.initLoader(TracksQuery._TOKEN, null, this);

    return v;
}

From source file:org.noise_planet.noisecapture.CommentActivity.java

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

    View mainView = findViewById(R.id.mainLayout);
    if (mainView != null) {
        mainView.setOnTouchListener(new MainOnTouchListener(this));
    }//from   w w  w.  j  a  v a  2  s .  c om

    // Read record activity parameter
    // Use last record of no parameter provided
    this.measurementManager = new MeasurementManager(this);
    Intent intent = getIntent();
    // Read the last stored record
    List<Storage.Record> recordList = measurementManager.getRecords();
    if (intent != null && intent.hasExtra(COMMENT_RECORD_ID)) {
        record = measurementManager.getRecord(intent.getIntExtra(COMMENT_RECORD_ID, -1));
    } else {
        if (!recordList.isEmpty()) {
            record = recordList.get(0);
        } else {
            // Message for starting a record
            Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show();
            return;
        }
    }
    if (record != null) {
        View addPhoto = findViewById(R.id.btn_add_photo);
        addPhoto.setOnClickListener(new OnAddPhotoClickListener(this));
        View resultsBtn = findViewById(R.id.resultsBtn);
        resultsBtn.setOnClickListener(new OnGoToResultPage(this));
        View deleteBts = findViewById(R.id.deleteBtn);
        deleteBts.setOnClickListener(new OnDeleteMeasurement(this));
        TextView noisePartyTag = (TextView) findViewById(R.id.edit_noiseparty_tag);
        noisePartyTag.setEnabled(record.getUploadId().isEmpty());
        noisePartyTag.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter() {
            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                // [^A-Za-z0-9_]
                StringBuilder stringBuilder = new StringBuilder();
                for (int i = start; i < end; i++) {
                    char c = source.charAt(i);
                    if (Character.isLetterOrDigit(c) || c == '_') {
                        stringBuilder.append(c);
                    }
                }

                // keep original if unchanged or return swapped chars
                boolean modified = (stringBuilder.length() == end - start);
                return modified ? null : stringBuilder.toString();
            }
        } });
        if (record.getNoisePartyTag() == null) {
            // Read last stored NoiseParty id
            for (Storage.Record recordItem : recordList) {
                if (recordItem.getId() != record.getId()) {
                    if (recordItem.getNoisePartyTag() != null) {
                        noisePartyTag.setText(recordItem.getNoisePartyTag());
                    }
                    break;
                }
            }
        } else {
            noisePartyTag.setText(record.getNoisePartyTag());
        }
    }
    initDrawer(record != null ? record.getId() : null);
    SeekBar seekBar = (SeekBar) findViewById(R.id.pleasantness_slider);

    // Load stored user comment
    // Pleasantness and tags are read only if the record has been uploaded
    Map<String, Storage.TagInfo> tagToIndex = new HashMap<>(Storage.TAGS_INFO.length);
    for (Storage.TagInfo sysTag : Storage.TAGS_INFO) {
        tagToIndex.put(sysTag.name, sysTag);
    }

    View thumbnail = findViewById(R.id.image_thumbnail);
    thumbnail.setOnClickListener(new OnImageClickListener(this));
    if (record != null) {
        // Load selected tags
        for (String sysTag : measurementManager.getTags(record.getId())) {
            Storage.TagInfo tagInfo = tagToIndex.get(sysTag);
            if (tagInfo != null) {
                checkedTags.add(tagInfo.id);
            }
        }
        // Load description
        if (record.getDescription() != null) {
            TextView description = (TextView) findViewById(R.id.edit_description);
            description.setText(record.getDescription());
        }
        Integer pleasantness = record.getPleasantness();
        if (pleasantness != null) {
            seekBar.setProgress((int) (Math.round((pleasantness / 100.0) * seekBar.getMax())));
            seekBar.setThumb(
                    seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_normal_holo));
            userInputSeekBar.set(true);
        } else {
            seekBar.setThumb(
                    seekBar.getResources().getDrawable(R.drawable.seekguess_scrubber_control_disabled_holo));
        }
        photo_uri = record.getPhotoUri();
        // User can only update not uploaded data
        seekBar.setEnabled(record.getUploadId().isEmpty());
    } else {
        // Message for starting a record
        Toast.makeText(getApplicationContext(), getString(R.string.no_results), Toast.LENGTH_LONG).show();
    }
    thumbnailImageLayoutDoneObserver = new OnThumbnailImageLayoutDoneObserver(this);
    thumbnail.getViewTreeObserver().addOnGlobalLayoutListener(thumbnailImageLayoutDoneObserver);

    seekBar.setOnSeekBarChangeListener(new OnSeekBarUserInput(userInputSeekBar));
    // Fill tags grid
    Resources r = getResources();
    String[] tags = r.getStringArray(R.array.tags);
    // Append tags items
    for (Storage.TagInfo tagInfo : Storage.TAGS_INFO) {
        ViewGroup tagContainer = (ViewGroup) findViewById(tagInfo.location);
        if (tagContainer != null && tagInfo.id < tags.length) {
            addTag(tags[tagInfo.id], tagInfo.id, tagContainer,
                    tagInfo.color != -1 ? r.getColor(tagInfo.color) : -1);
        }
    }
}

From source file:de.manumaticx.crouton.Manager.java

/**
 * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
 *
 * @param crouton/*ww w. j  a va  2  s.c om*/
 *     The {@link Crouton} that should be added.
 */
private void addCroutonToView(final Crouton crouton) {
    // don't add if it is already showing
    if (crouton.isShowing()) {
        return;
    }

    final View croutonView = crouton.getView();
    if (null == croutonView.getParent()) {
        ViewGroup.LayoutParams params = croutonView.getLayoutParams();
        if (null == params) {
            params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        // display Crouton in ViewGroup is it has been supplied
        if (null != crouton.getViewGroup()) {
            // TODO implement add to last position feature (need to align with how this will be requested for activity)
            if (crouton.getViewGroup() instanceof FrameLayout) {
                crouton.getViewGroup().addView(croutonView, params);
            } else {
                crouton.getViewGroup().addView(croutonView, 0, params);
            }
        } else {
            Activity activity = crouton.getActivity();
            if (null == activity || activity.isFinishing()) {
                return;
            }
            handleTranslucentActionBar((ViewGroup.MarginLayoutParams) params, activity);

            if (Looper.myLooper() == Looper.getMainLooper()) {
                activity.addContentView(croutonView, params);
            } else {
                final Activity mActivity = activity;
                final ViewGroup.LayoutParams mParams = params;
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mActivity.addContentView(croutonView, mParams);
                    }
                });
            }
        }
    }

    croutonView.requestLayout(); // This is needed so the animation can use the measured with/height
    ViewTreeObserver observer = croutonView.getViewTreeObserver();
    if (null != observer) {
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            @TargetApi(16)
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    croutonView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    croutonView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }

                croutonView.startAnimation(crouton.getInAnimation());
                announceForAccessibilityCompat(crouton.getActivity(), crouton.getText());
                if (Configuration.DURATION_INFINITE != crouton.getConfiguration().durationInMilliseconds) {
                    sendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                            crouton.getConfiguration().durationInMilliseconds
                                    + crouton.getInAnimation().getDuration());
                }
            }
        });
    }
}

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

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final View MenuButtonContainer = view.findViewById(R.id.dialtacts_bottom_menu_container);
    mMenuButtonCall = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_call);
    mMenuButtonCall.setOnClickListener(this);
    mMenuButtonContacts = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_contacts);
    mMenuButtonContacts.setOnClickListener(this);
    mMenuButtonSetting = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_group);
    mMenuButtonSetting.setOnClickListener(this);
    mMenuButtonDelete = (ImageButton) view.findViewById(R.id.dialtacts_bottom_menu_button_delete);

    mMenuButtonDelete.setOnClickListener(this);
    //        mFloatingActionButtonController = new FloatingActionButtonController(this,
    //                MenuButtonContainer, MenuButtonCall);

    final View floatingActionButtonContainer = view.findViewById(R.id.floating_action_button_container);
    //?/*  w w  w  . j  a v a 2s.  c  o m*/
    ImageButton floatingActionButton = (ImageButton) view.findViewById(R.id.floating_action_button);
    floatingActionButton.setOnClickListener(this);

    mFloatingActionButtonController = new FloatingActionButtonController(getActivity(),
            floatingActionButtonContainer, floatingActionButton);

    mParentLayout = (FrameLayout) view.findViewById(R.id.dialtacts_mainlayout);
    mParentLayout.setOnDragListener(new LayoutOnDragListener());
    floatingActionButtonContainer.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    final ViewTreeObserver observer = floatingActionButtonContainer.getViewTreeObserver();
                    if (!observer.isAlive()) {
                        return;
                    }
                    observer.removeOnGlobalLayoutListener(this);
                    int screenWidth = mParentLayout.getWidth();
                    mFloatingActionButtonController.setScreenWidth(screenWidth);
                    mFloatingActionButtonController.align(getFabAlignment(), false /* animate */);

                }
            });
}

From source file:org.cafemember.ui.LaunchActivity.java

@Override
protected void onDestroy() {
    PhotoViewer.getInstance().destroyPhotoViewer();
    SecretPhotoViewer.getInstance().destroyPhotoViewer();
    StickerPreviewViewer.getInstance().destroy();
    try {//  ww  w .j a v  a 2  s.c o m
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    try {
        if (onGlobalLayoutListener != null) {
            final View view = getWindow().getDecorView().getRootView();
            if (Build.VERSION.SDK_INT < 16) {
                view.getViewTreeObserver().removeGlobalOnLayoutListener(onGlobalLayoutListener);
            } else {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    super.onDestroy();
    onFinish();
}

From source file:fr.free.nrw.commons.media.MediaDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    detailProvider = (fr.free.nrw.commons.media.MediaDetailPagerFragment.MediaDetailProvider) getActivity();

    if (savedInstanceState != null) {
        editable = savedInstanceState.getBoolean("editable");
        index = savedInstanceState.getInt("index");
        initialListTop = savedInstanceState.getInt("listTop");
    } else {/*from ww  w.  j a  v  a  2s  .  co  m*/
        editable = getArguments().getBoolean("editable");
        index = getArguments().getInt("index");
        initialListTop = 0;
    }
    categoryNames = new ArrayList<String>();
    categoryNames.add(getString(R.string.detail_panel_cats_loading));

    final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);

    image = (ImageView) view.findViewById(R.id.mediaDetailImage);
    loadingProgress = (ProgressBar) view.findViewById(R.id.mediaDetailImageLoading);
    loadingFailed = (ImageView) view.findViewById(R.id.mediaDetailImageFailed);
    scrollView = (ScrollView) view.findViewById(R.id.mediaDetailScrollView);

    // Detail consists of a list view with main pane in header view, plus category list.
    spacer = (fr.free.nrw.commons.media.MediaDetailSpacer) view.findViewById(R.id.mediaDetailSpacer);
    title = (TextView) view.findViewById(R.id.mediaDetailTitle);
    desc = (TextView) view.findViewById(R.id.mediaDetailDesc);
    license = (TextView) view.findViewById(R.id.mediaDetailLicense);
    categoryContainer = (LinearLayout) view.findViewById(R.id.mediaDetailCategoryContainer);

    licenseList = new LicenseList(getActivity());

    Media media = detailProvider.getMediaAtPosition(index);
    if (media == null) {
        // Ask the detail provider to ping us when we're ready
        Log.d("Commons", "MediaDetailFragment not yet ready to display details; registering observer");
        dataObserver = new DataSetObserver() {
            public void onChanged() {
                Log.d("Commons", "MediaDetailFragment ready to display delayed details!");
                detailProvider.unregisterDataSetObserver(dataObserver);
                dataObserver = null;
                displayMediaDetails(detailProvider.getMediaAtPosition(index));
            }
        };
        detailProvider.registerDataSetObserver(dataObserver);
    } else {
        Log.d("Commons", "MediaDetailFragment ready to display details");
        displayMediaDetails(media);
    }

    // Progressively darken the image in the background when we scroll detail pane up
    scrollListener = new ViewTreeObserver.OnScrollChangedListener() {
        public void onScrollChanged() {
            updateTheDarkness();
        }
    };
    view.getViewTreeObserver().addOnScrollChangedListener(scrollListener);

    // Layout layoutListener to size the spacer item relative to the available space.
    // There may be a .... better way to do this.
    layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        private int currentHeight = -1;

        public void onGlobalLayout() {
            int viewHeight = view.getHeight();
            //int textHeight = title.getLineHeight();
            int paddingDp = 112;
            float paddingPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingDp,
                    getResources().getDisplayMetrics());
            int newHeight = viewHeight - Math.round(paddingPx);

            if (newHeight != currentHeight) {
                currentHeight = newHeight;
                ViewGroup.LayoutParams params = spacer.getLayoutParams();
                params.height = newHeight;
                spacer.setLayoutParams(params);

                scrollView.scrollTo(0, initialListTop);
            }

        }
    };
    view.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
    return view;
}

From source file:de.grobox.transportr.locations.LocationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getArguments();/*from  ww w  .  j a v  a2s . c om*/
    if (args == null)
        throw new IllegalStateException();
    location = (WrapLocation) args.getSerializable(WRAP_LOCATION);
    if (location == null)
        throw new IllegalArgumentException("No location");

    View v = inflater.inflate(R.layout.fragment_location, container, false);
    getComponent().inject(this);

    if (getActivity() == null)
        throw new IllegalStateException();
    viewModel = ViewModelProviders.of(getActivity(), viewModelFactory).get(MapViewModel.class);
    viewModel.nearbyStationsFound().observe(this, found -> onNearbyStationsLoaded());

    // Location
    locationIcon = v.findViewById(R.id.locationIcon);
    locationName = v.findViewById(R.id.locationName);
    locationIcon.setOnClickListener(view -> onLocationClicked());
    locationName.setOnClickListener(view -> onLocationClicked());

    // Lines
    linesLayout = v.findViewById(R.id.linesLayout);
    linesLayout.setVisibility(GONE);
    linesLayout.setAdapter(adapter);
    linesLayout.setLayoutManager(new LinearLayoutManager(getContext(), HORIZONTAL, false));
    linesLayout.setOnClickListener(view -> onLocationClicked());

    // Location Info
    locationInfo = v.findViewById(R.id.locationInfo);
    showLocation();

    if (location.getLocation().type == COORD) {
        ReverseGeocoder geocoder = new ReverseGeocoder(getActivity(), this);
        geocoder.findLocation(location.getLocation());
    }

    // Departures
    Button departuresButton = v.findViewById(R.id.departuresButton);
    if (location.hasId()) {
        departuresButton.setOnClickListener(view -> {
            Intent intent = new Intent(getContext(), DeparturesActivity.class);
            intent.putExtra(WRAP_LOCATION, location);
            startActivity(intent);
        });
    } else {
        departuresButton.setVisibility(GONE);
    }

    // Nearby Stations
    nearbyStationsButton = v.findViewById(R.id.nearbyStationsButton);
    nearbyStationsProgress = v.findViewById(R.id.nearbyStationsProgress);
    nearbyStationsButton.setOnClickListener(view -> {
        nearbyStationsButton.setVisibility(INVISIBLE);
        nearbyStationsProgress.setVisibility(VISIBLE);
        IntentUtils.findNearbyStations(getContext(), location);
    });

    // Share Location
    Button shareButton = v.findViewById(R.id.shareButton);
    shareButton.setOnClickListener(view -> startGeoIntent(getActivity(), location));

    // Overflow Button
    ImageButton overflowButton = v.findViewById(R.id.overflowButton);
    overflowButton.setOnClickListener(view -> new LocationPopupMenu(getContext(), view, location).show());

    v.getViewTreeObserver().addOnGlobalLayoutListener(this);

    return v;
}

From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from   w ww  .  j a  v a2s.com
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View mainView = inflater.inflate(R.layout.main, container, false);

    if (mainView != null) {
        ViewTreeObserver vto = mainView.getViewTreeObserver();

        if (vto != null) {
            vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                @Override
                public void onGlobalLayout() {
                    MainFragment.removeOnGlobalLayoutListener(mainView, this);
                    int locationTbEndLocation[] = new int[2];
                    mTbEndLocation.getLocationInWindow(locationTbEndLocation);
                    int locationItinerarySelectionSpinner[] = new int[2];
                    mItinerarySelectionSpinner.getLocationInWindow(locationItinerarySelectionSpinner);
                    int locationBtnHandle[] = new int[2];
                    mBtnHandle.getLocationInWindow(locationBtnHandle);
                    DisplayMetrics metrics = MainFragment.this.getResources().getDisplayMetrics();
                    int windowHeight = metrics.heightPixels;
                    int paddingMargin = MainFragment.this.getResources()
                            .getInteger(R.integer.map_padding_margin);
                    if (mMap != null) {
                        mMap.setPadding(locationBtnHandle[0] + mBtnHandle.getWidth() / 2 + paddingMargin,
                                locationTbEndLocation[1] + mTbEndLocation.getHeight() / 2 + paddingMargin, 0,
                                windowHeight - locationItinerarySelectionSpinner[1] + paddingMargin);
                    }
                }
            });
        } else {
            Log.w(OTPApp.TAG, "Not possible to obtain exact element's positions on screen, some other"
                    + "elements can be misplaced");
        }

        mTbStartLocation = (EditText) mainView.findViewById(R.id.tbStartLocation);
        mTbEndLocation = (EditText) mainView.findViewById(R.id.tbEndLocation);

        mBtnPlanTrip = (ImageButton) mainView.findViewById(R.id.btnPlanTrip);
        mDdlOptimization = (ListView) mainView.findViewById(R.id.spinOptimization);
        mDdlTravelMode = (ListView) mainView.findViewById(R.id.spinTravelMode);

        mBikeTriangleParameters = new RangeSeekBar<Double>(OTPApp.BIKE_PARAMETERS_MIN_VALUE,
                OTPApp.BIKE_PARAMETERS_MAX_VALUE, this.getActivity().getApplicationContext(), R.color.sysRed,
                R.color.sysGreen, R.color.sysBlue, R.drawable.seek_thumb_normal, R.drawable.seek_thumb_pressed);

        // add RangeSeekBar to pre-defined layout
        mBikeTriangleParametersLayout = (ViewGroup) mainView.findViewById(R.id.bikeParametersLayout);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.BELOW, R.id.bikeParametersTags);

        mBikeTriangleParametersLayout.addView(mBikeTriangleParameters, params);

        mBtnMyLocation = (ImageButton) mainView.findViewById(R.id.btnMyLocation);

        mBtnDateDialog = (ImageButton) mainView.findViewById(R.id.btnDateDialog);

        mBtnDisplayDirection = (ImageButton) mainView.findViewById(R.id.btnDisplayDirection);

        mNavigationDrawerLeftPane = (ViewGroup) mainView.findViewById(R.id.navigationDrawerLeftPane);
        mPanelDisplayDirection = mainView.findViewById(R.id.panelDisplayDirection);

        mBtnHandle = (ImageButton) mainView.findViewById(R.id.btnHandle);
        mDrawerLayout = (DrawerLayout) mainView.findViewById(R.id.drawerLayout);

        mTbStartLocation.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        mTbEndLocation.setImeOptions(EditorInfo.IME_ACTION_DONE);
        mTbEndLocation.requestFocus();

        mItinerarySelectionSpinner = (Spinner) mainView.findViewById(R.id.itinerarySelection);

        Log.v(OTPApp.TAG, "finish onStart()");

        if (Build.VERSION.SDK_INT > 11) {
            LayoutTransition l = new LayoutTransition();
            ViewGroup mainButtons = (ViewGroup) mainView.findViewById(R.id.content_frame);
            mainButtons.setLayoutTransition(l);
        }

        return mainView;
    } else {
        Log.e(OTPApp.TAG, "Not possible to obtain main view, UI won't be correctly created");
        return null;
    }
}

From source file:info.papdt.blacklight.ui.statuses.TimeLineFragment.java

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

    mActionBar = ((ToolbarActivity) getActivity()).getSupportActionBar();
    mToolbar = ((ToolbarActivity) getActivity()).getToolbar();
    initTitle();/*from ww  w . java 2 s .  c o m*/
    mSettings = Settings.getInstance(getActivity().getApplicationContext());

    final View v = inflater.inflate(R.layout.home_timeline, null);

    // Initialize views
    mList = Utility.findViewById(v, R.id.home_timeline);
    mShadow = Utility.findViewById(v, R.id.action_shadow);

    mCache = bindApiCache();
    mCache.loadFromCache();

    mList.setDrawingCacheEnabled(true);
    mList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    mList.setPersistentDrawingCache(
            ViewGroup.PERSISTENT_ANIMATION_CACHE | ViewGroup.PERSISTENT_SCROLLING_CACHE);

    mManager = new LinearLayoutManager(getActivity());
    mList.setLayoutManager(mManager);

    // Swipe To Refresh
    bindSwipeToRefresh((ViewGroup) v);

    if (mCache.mMessages.getSize() == 0) {
        new Refresher().execute(true);
    }

    // Adapter
    mAdapter = new WeiboAdapter(getActivity(), mList, mCache.mMessages, mBindOrig, mShowCommentStatus);

    // Content Margin
    if (getActivity() instanceof MainActivity && mAllowHidingActionBar) {
        View header = new View(getActivity());
        RecyclerView.LayoutParams p = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT,
                Utility.getDecorPaddingTop(getActivity()));
        header.setLayoutParams(p);
        mAdapter.setHeaderView(header);
        mSwipeRefresh.setProgressViewOffset(false, 0,
                (int) ((p.height + Utility.dp2px(getActivity(), 20)) * 1.2));
    }

    mList.setAdapter(mAdapter);

    // Listener
    if (getActivity() instanceof MainActivity) {
        mAdapter.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView view, int dx, int dy) {
                int deltaY = -dy;
                boolean shouldShow = deltaY > 0;
                if (shouldShow != mFABShowing) {
                    if (shouldShow) {
                        showFAB();
                    } else {
                        hideFAB();
                    }
                }

                if (mAllowHidingActionBar) {
                    if ((mTranslationY > -mActionBarHeight && deltaY < 0)
                            || (mTranslationY < 0 && deltaY > 0)) {

                        mTranslationY += deltaY;
                    }

                    if (mTranslationY < -mActionBarHeight) {
                        mTranslationY = -mActionBarHeight;
                    } else if (mTranslationY > 0) {
                        mTranslationY = 0;
                    }

                    updateTranslation();
                }

                mFABShowing = shouldShow;
                mLastY = dy;
            }
        });
    }

    mAdapter.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView v, int dx, int dy) {
            if (!mRefreshing && mManager.findLastVisibleItemPosition() >= mAdapter.getItemCount() - 5) {
                new Refresher().execute(false);
            }
        }
    });

    mShadow.bringToFront();

    v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (getActivity() instanceof MainActivity && mAllowHidingActionBar) {
                mActionBarHeight = mToolbar.getHeight();
                mShadow.setTranslationY(mActionBarHeight);
                RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) mAdapter.getHeaderView()
                        .getLayoutParams();
                lp.height = mActionBarHeight;
                mAdapter.getHeaderView().setLayoutParams(lp);
                mSwipeRefresh.setProgressViewOffset(false, 0, (int) (mActionBarHeight * 1.2));
                mSwipeRefresh.invalidate();
                v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });

    return v;
}