Example usage for android.widget RelativeLayout ALIGN_PARENT_TOP

List of usage examples for android.widget RelativeLayout ALIGN_PARENT_TOP

Introduction

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

Prototype

int ALIGN_PARENT_TOP

To view the source code for android.widget RelativeLayout ALIGN_PARENT_TOP.

Click Source Link

Document

Rule that aligns the child's top edge with its RelativeLayout parent's top edge.

Usage

From source file:net.pocketmagic.android.carousel.MainActivity.java

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

    //no keyboard unless requested by user
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // compute screen size and scaling
    Singleton.getInstance().InitGUIFrame(this);

    int padding = m_Inst.Scale(10);
    // create the interface : full screen container
    RelativeLayout panel = new RelativeLayout(this);
    panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    panel.setPadding(padding, padding, padding, padding);
    panel.setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { Color.WHITE, Color.GRAY }));
    setContentView(panel);/*from  w  w  w  . j a  v  a2s .c o  m*/

    // copy images from assets to sdcard
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma1.png", "plasma1.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma2.png", "plasma2.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma3.png", "plasma3.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma4.png", "plasma4.png", false);

    //Create carousel view documents
    ArrayList<CarouselDataItem> Docus = new ArrayList<CarouselDataItem>();
    for (int i = 0; i < 1000; i++) {
        CarouselDataItem docu;
        if (i % 4 == 0)
            docu = new CarouselDataItem("/mnt/sdcard/plasma1.png", 0, "First Image " + i);
        else if (i % 4 == 1)
            docu = new CarouselDataItem("/mnt/sdcard/plasma2.png", 0, "Second Image " + i);
        else if (i % 4 == 2)
            docu = new CarouselDataItem("/mnt/sdcard/plasma3.png", 0, "Third Image " + i);
        else
            docu = new CarouselDataItem("/mnt/sdcard/plasma4.png", 0, "4th Image " + i);
        Docus.add(docu);
    }

    // add the serach filter
    EditText etSearch = new EditText(this);
    etSearch.setHint("Search your documents");
    etSearch.setSingleLine();
    etSearch.setTextColor(Color.BLACK);
    etSearch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_menu_search, 0, 0, 0);
    AppUtils.AddView(panel, etSearch, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_TOP } }, -1,
            -1);
    etSearch.addTextChangedListener((TextWatcher) this);

    // add logo
    TextView tv = new TextView(this);
    tv.setTextColor(Color.BLACK);
    tv.setText("www.pocketmagic.net");
    AppUtils.AddView(panel, tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_BOTTOM } },
            -1, -1);

    // create the carousel
    CarouselView coverFlow = new CarouselView(this);

    // create adapter and specify device independent items size (scaling)
    // for more details see: http://www.pocketmagic.net/2013/04/how-to-scale-an-android-ui-on-multiple-screens/
    m_carouselAdapter = new CarouselViewAdapter(this, Docus, m_Inst.Scale(400), m_Inst.Scale(300));
    coverFlow.setAdapter(m_carouselAdapter);
    coverFlow.setSpacing(-1 * m_Inst.Scale(150));
    coverFlow.setSelection(Integer.MAX_VALUE / 2, true);
    coverFlow.setAnimationDuration(1000);
    coverFlow.setOnItemSelectedListener((OnItemSelectedListener) this);

    AppUtils.AddView(panel, coverFlow, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
            new int[][] { new int[] { RelativeLayout.CENTER_IN_PARENT } }, -1, -1);
}

From source file:com.xalops.spotifystreamer.fragments.SearchListFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *//* w  w  w .j a va  2 s. co m*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();
    FrameLayout root = new FrameLayout(context);

    //QUICK Inflate from XML file

    //inflater.inflate(R.layout.search_list_detail, root);
    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    RelativeLayout rlayout = new RelativeLayout(context);

    EditText et = new EditText(getActivity());
    et.setId(INTERNAL_SEARCH_FIELD_ID);
    et.setSingleLine(true);
    et.setInputType(InputType.TYPE_CLASS_TEXT);
    et.setImeOptions(EditorInfo.IME_ACTION_DONE);
    RelativeLayout.LayoutParams etRLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    etRLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    etRLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);
    RelativeLayout.LayoutParams lframeRLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    lframeRLayoutParams.addRule(RelativeLayout.BELOW, INTERNAL_SEARCH_FIELD_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    rlayout.addView(et, etRLayoutParams);
    rlayout.addView(lframe, lframeRLayoutParams);
    root.addView(rlayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:mobisocial.musubi.ui.FeedIdentityGrid.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //TODO: this begs for being in util, huh.  i wonder where else it is used.
    //check that we aren't going to send a message using the local authority
    //to our friends.  This is similar to the initial hidden state of the 
    //person picker on the feed list
    mDatabaseSource = App.getDatabaseSource(this);
    mIdentitiesManager = new IdentitiesManager(mDatabaseSource);
    mFeedManager = new FeedManager(mDatabaseSource);
    if (mIdentitiesManager.getOwnedIdentities().size() < 2) {
        Toast.makeText(this, "You must connect an account in Musubi to be able to share with your contacts",
                Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, FeedListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);/*from   ww  w .  j  av  a  2  s  . c  o  m*/
        return;
    }

    setTitle("Share");
    RelativeLayout window = new RelativeLayout(this);
    LayoutParams fill = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    window.setLayoutParams(fill);

    // Identity multi-select
    mIdentitySelector = new MultiIdentitySelector(this);
    mIdentitySelector.setOnIdentitiesUpdatedListener(mIdentitiesUpdatedListener);
    mIdentitySelector.setOnRequestAddIdentityListener(mOnRequestAddIdentityListener);
    RelativeLayout.LayoutParams selectorParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    selectorParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    mIdentitySelector.setLayoutParams(selectorParams);
    mIdentitySelector.setId(R.id.people);

    // Feed list
    mFeedListView = new ListView(this);
    RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
    listParams.addRule(RelativeLayout.BELOW, R.id.people);
    listParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    mFeedListView.setLayoutParams(listParams);
    mFeedListView.setOnItemClickListener(mFeedClickListener);
    // Must be called before setAdapter():
    //mFeedListView.addHeaderView(mHeaderView);

    // Bind to content view
    window.addView(mIdentitySelector);
    window.addView(mFeedListView);
    setContentView(window, fill);

    getSupportLoaderManager().initLoader(LOAD_FEEDS, null, this);
}

From source file:net.homelinux.penecoptero.android.citybikes.donation.app.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from  w  w  w  .  j  a v  a 2s .  c o  m
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mapView = (MapView) findViewById(R.id.mapview);
    mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer);
    infoLayer = (InfoLayer) findViewById(R.id.info_layer);
    scale = getResources().getDisplayMetrics().density;
    //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!");
    infoLayerPopulator = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == InfoLayer.POPULATE) {
                infoLayer.inflateStation(stations.getCurrent());

            }
            if (msg.what == CityBikes.BOOKMARK_CHANGE) {
                int id = msg.arg1;
                boolean bookmarked;
                if (msg.arg2 == 0) {
                    bookmarked = false;
                } else {
                    bookmarked = true;
                }
                StationOverlay station = stations.getById(id);
                try {
                    BookmarkManager bm = new BookmarkManager(getApplicationContext());
                    bm.setBookmarked(station.getStation(), !bookmarked);
                } catch (Exception e) {
                    Log.i("CityBikes", "Error bookmarking station");
                    e.printStackTrace();
                }

                if (!view_all) {
                    view_near();
                }
                mapView.postInvalidate();
            }
        }
    };

    infoLayer.setHandler(infoLayerPopulator);
    RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

    modeButton = (ToggleButton) findViewById(R.id.mode_button);

    modeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            changeMode(!getBike);
        }

    });

    applyMapViewLongPressListener(mapView);

    settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);

    List<Overlay> mapOverlays = mapView.getOverlays();

    locator = new Locator(this, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == Locator.LOCATION_CHANGED) {
                GeoPoint point = new GeoPoint(msg.arg1, msg.arg2);
                hOverlay.moveCenter(point);
                mapView.getController().animateTo(point);
                mDbHelper.setCenter(point);
                // Location has changed
                try {
                    mDbHelper.updateDistances(point);
                    infoLayer.update();
                    if (!view_all) {
                        view_near();
                    }
                } catch (Exception e) {

                }
                ;
            }
        }
    });

    hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) {
                try {
                    if (!view_all) {
                        view_near();
                    }
                    mapView.postInvalidate();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });

    stations = new StationOverlayList(mapOverlays, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1));
            if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) {
                // One station has been touched
                stations.setCurrent(msg.arg1, getBike);
                infoLayer.inflateStation(stations.getCurrent());
                //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1));
            }
        }
    });

    stations.addOverlay(hOverlay);

    mNDBAdapter = new NetworksDBAdapter(getApplicationContext());

    mDbHelper = new StationsDBAdapter(this, mapView, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationsDBAdapter.FETCH:
                break;
            case StationsDBAdapter.UPDATE_MAP:
                progressDialog.dismiss();
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("reload_network", false);
                editor.commit();
            case StationsDBAdapter.UPDATE_DATABASE:
                StationOverlay current = stations.getCurrent();
                if (current == null) {
                    infoLayer.inflateMessage(getString(R.string.no_bikes_around));
                }
                if (current != null) {
                    current.setSelected(true, getBike);
                    infoLayer.inflateStation(current);
                    if (view_all)
                        view_all();
                    else
                        view_near();
                } else {

                }
                mapView.invalidate();
                infoLayer.update();
                ////Log.i("openBicing", "Database updated");
                break;
            case StationsDBAdapter.NETWORK_ERROR:
                ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated());
                Toast toast = Toast.makeText(getApplicationContext(),
                        getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(),
                        Toast.LENGTH_LONG);
                toast.show();
                break;
            }
        }
    }, stations);

    mDbHelper.setCenter(locator.getCurrentGeoPoint());

    mSlidingDrawer.setHandler(new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationSlidingDrawer.ITEMCLICKED:
                StationOverlay clicked = (StationOverlay) msg.obj;
                stations.setCurrent(msg.arg1, getBike);
                Message tmp = new Message();
                tmp.what = InfoLayer.POPULATE;
                tmp.arg1 = msg.arg1;
                infoLayerPopulator.dispatchMessage(tmp);
                mapView.getController().animateTo(clicked.getCenter());
            }
        }
    });

    if (savedInstanceState != null) {
        locator.unlockCenter();
        hOverlay.setRadius(savedInstanceState.getInt("homeRadius"));
        this.view_all = savedInstanceState.getBoolean("view_all");
    } else {
        updateHome();
    }

    try {
        mDbHelper.loadStations();
        if (savedInstanceState == null) {
            String strUpdated = mDbHelper.getLastUpdated();

            Boolean dirty = settings.getBoolean("reload_network", false);

            if (strUpdated == null || dirty) {
                this.fillData(view_all);
            } else {
                Toast toast = Toast.makeText(this.getApplicationContext(),
                        "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG);
                toast.show();
                Calendar cal = Calendar.getInstance();
                long now = cal.getTime().getTime();
                if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5)
                    this.fillData(view_all);
            }
        }

    } catch (Exception e) {
        ////Log.i("openBicing", "SHIT ... SUCKS");
    }
    ;

    if (view_all)
        view_all();
    else
        view_near();
    ////Log.i("openBicing", "CREATE!");
}

From source file:cn.org.eshow.framwork.activity.AbActivity.java

/**
 * ?????./*from   w  ww  .  j  a  v  a 2  s . co  m*/
 *
 * @param overlay the new title bar overlay
 */
public void setTitleBarOverlay(boolean overlay) {
    ab_base.removeAllViews();
    if (overlay) {
        RelativeLayout.LayoutParams layoutParamsFW1 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParamsFW1.addRule(RelativeLayout.ABOVE, mAbBottomBar.getId());
        ab_base.addView(contentLayout, layoutParamsFW1);
        RelativeLayout.LayoutParams layoutParamsFW2 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParamsFW2.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
        ab_base.addView(mAbTitleBar, layoutParamsFW2);

        RelativeLayout.LayoutParams layoutParamsFW3 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParamsFW3.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        ab_base.addView(mAbBottomBar, layoutParamsFW3);

    } else {
        ab_base.addView(mAbTitleBar,
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        RelativeLayout.LayoutParams layoutParamsFW2 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParamsFW2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        ab_base.addView(mAbBottomBar, layoutParamsFW2);

        RelativeLayout.LayoutParams layoutParamsFW1 = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParamsFW1.addRule(RelativeLayout.BELOW, mAbTitleBar.getId());
        layoutParamsFW1.addRule(RelativeLayout.ABOVE, mAbBottomBar.getId());
        ab_base.addView(contentLayout, layoutParamsFW1);
    }
}

From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from w  w  w  .j a  v  a  2  s . co m
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    mapView = (MapView) findViewById(R.id.mapview);
    mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer);
    infoLayer = (InfoLayer) findViewById(R.id.info_layer);
    scale = getResources().getDisplayMetrics().density;
    //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!");
    infoLayerPopulator = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == InfoLayer.POPULATE) {
                infoLayer.inflateStation(stations.getCurrent());

            }
            if (msg.what == CityBikes.BOOKMARK_CHANGE) {
                int id = msg.arg1;
                boolean bookmarked;
                if (msg.arg2 == 0) {
                    bookmarked = false;
                } else {
                    bookmarked = true;
                }
                StationOverlay station = stations.getById(id);
                try {
                    BookmarkManager bm = new BookmarkManager(getApplicationContext());
                    bm.setBookmarked(station.getStation(), !bookmarked);
                } catch (Exception e) {
                    Log.i("CityBikes", "Error bookmarking station");
                    e.printStackTrace();
                }

                if (!view_all) {
                    view_near();
                }
                mapView.postInvalidate();
            }
        }
    };

    infoLayer.setHandler(infoLayerPopulator);
    RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams);

    modeButton = (ToggleButton) findViewById(R.id.mode_button);

    modeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            changeMode(!getBike);
        }

    });

    applyMapViewLongPressListener(mapView);

    settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0);

    List<Overlay> mapOverlays = mapView.getOverlays();

    locator = new Locator(this, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == Locator.LOCATION_CHANGED) {
                GeoPoint point = new GeoPoint(msg.arg1, msg.arg2);
                hOverlay.moveCenter(point);
                mapView.getController().animateTo(point);
                mDbHelper.setCenter(point);
                // Location has changed
                try {
                    mDbHelper.updateDistances(point);
                    infoLayer.update();
                    if (!view_all) {
                        view_near();
                    }
                } catch (Exception e) {

                }
                ;
            }
        }
    });

    hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) {
                try {
                    if (!view_all) {
                        view_near();
                    }
                    mapView.postInvalidate();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    });

    stations = new StationOverlayList(mapOverlays, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1));
            if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) {
                // One station has been touched
                stations.setCurrent(msg.arg1, getBike);
                infoLayer.inflateStation(stations.getCurrent());
                //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1));
            }
        }
    });

    stations.addOverlay(hOverlay);

    mNDBAdapter = new NetworksDBAdapter(getApplicationContext());

    mDbHelper = new StationsDBAdapter(this, mapView, new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationsDBAdapter.FETCH:
                break;
            case StationsDBAdapter.UPDATE_MAP:
                progressDialog.dismiss();
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("reload_network", false);
                editor.commit();
            case StationsDBAdapter.UPDATE_DATABASE:
                StationOverlay current = stations.getCurrent();
                if (current == null) {
                    infoLayer.inflateMessage(getString(R.string.no_bikes_around));
                }
                if (current != null) {
                    infoLayer.inflateStation(current);
                    if (view_all)
                        view_all();
                    else
                        view_near();
                } else {

                }
                mapView.invalidate();
                infoLayer.update();
                ////Log.i("openBicing", "Database updated");
                break;
            case StationsDBAdapter.NETWORK_ERROR:
                ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated());
                Toast toast = Toast.makeText(getApplicationContext(),
                        getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(),
                        Toast.LENGTH_LONG);
                toast.show();
                break;
            }
        }
    }, stations);

    mDbHelper.setCenter(locator.getCurrentGeoPoint());

    mSlidingDrawer.setHandler(new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case StationSlidingDrawer.ITEMCLICKED:
                StationOverlay clicked = (StationOverlay) msg.obj;
                stations.setCurrent(msg.arg1, getBike);
                Message tmp = new Message();
                tmp.what = InfoLayer.POPULATE;
                tmp.arg1 = msg.arg1;
                infoLayerPopulator.dispatchMessage(tmp);
                mapView.getController().animateTo(clicked.getCenter());
            }
        }
    });

    if (savedInstanceState != null) {
        locator.unlockCenter();
        hOverlay.setRadius(savedInstanceState.getInt("homeRadius"));
        this.view_all = savedInstanceState.getBoolean("view_all");
    } else {
        updateHome();
    }

    try {
        mDbHelper.loadStations();
        if (savedInstanceState == null) {
            String strUpdated = mDbHelper.getLastUpdated();

            Boolean dirty = settings.getBoolean("reload_network", false);

            if (strUpdated == null || dirty) {
                this.fillData(view_all);
            } else {
                Toast toast = Toast.makeText(this.getApplicationContext(),
                        "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG);
                toast.show();
                Calendar cal = Calendar.getInstance();
                long now = cal.getTime().getTime();
                if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5)
                    this.fillData(view_all);
            }
        }

    } catch (Exception e) {
        ////Log.i("openBicing", "SHIT ... SUCKS");
    }
    ;

    if (view_all)
        view_all();
    else
        view_near();
    ////Log.i("openBicing", "CREATE!");
}

From source file:com.spoiledmilk.ibikecph.navigation.SMRouteNavigationActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.route_navigation_activity);
    LayoutInflater inflater = LayoutInflater.from(this);
    reportProblemsView = (RelativeLayout) inflater.inflate(R.layout.report_problems_view, null);
    textReport = (TextView) reportProblemsView.findViewById(R.id.textReport);

    instructionsViewMaxContainer = (RelativeLayout) findViewById(R.id.instructionsViewMaxContainer);
    paramsForInstMaxContainer = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    paramsForInstMaxContainer.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    paramsForInstMaxContainer.addRule(RelativeLayout.CENTER_HORIZONTAL);
    paramsForInstMaxContainer.topMargin = 0;
    instructionsViewMaxContainer.setLayoutParams(paramsForInstMaxContainer);

    routeFinishedContainer = (RelativeLayout) findViewById(R.id.routeFinishedContainer);
    imgClose = (ImageButton) findViewById(R.id.imgClose);
    imgClose.setOnClickListener(new OnClickListener() {
        @Override/*from   w w w.ja  v  a  2s . co m*/
        public void onClick(View arg0) {
            Bundle conData = new Bundle();
            conData.putInt("overlaysShown", getOverlaysShown());
            Intent intent = new Intent();
            intent.putExtras(conData);
            setResult(MapActivity.RESULT_RETURN_FROM_NAVIGATION, intent);
            setResult(MapActivity.RESULT_RETURN_FROM_NAVIGATION);
            finish();
            overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
        }

    });
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    textGoodRide = (TextView) findViewById(R.id.textGoodRide);
    textRecalculating = (TextView) findViewById(R.id.textRecalculating);
    textBicycle = (TextView) findViewById(R.id.textBicycle);
    textCargo = (TextView) findViewById(R.id.textCargo);
    textGreen = (TextView) findViewById(R.id.textGreen);
    FrameLayout.LayoutParams rootParams = new FrameLayout.LayoutParams((int) (9 * Util.getScreenWidth() / 5),
            FrameLayout.LayoutParams.MATCH_PARENT);
    findViewById(R.id.root_layout).setLayoutParams(rootParams);
    this.maxSlide = (int) (4 * Util.getScreenWidth() / 5);
    Util.init(getWindowManager());
    leftContainer = (RelativeLayout) findViewById(R.id.leftContainer);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) Util.getScreenWidth() * 4 / 5,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    leftContainer.setLayoutParams(params);
    parentContainer = (RelativeLayout) findViewById(R.id.parent_container);
    params = new RelativeLayout.LayoutParams((int) Util.getScreenWidth(),
            RelativeLayout.LayoutParams.MATCH_PARENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    parentContainer.setLayoutParams(params);
    imgCargoSlider = (ImageView) findViewById(R.id.imgCargoSlider);
    imgCargoSlider.setOnTouchListener(new OnTouchListener() {
        // Swipe the view horizontally
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return onSliderTouch(v, event);
        }

    });

    darkenedView = findViewById(R.id.darkenedView);
    darkenedView.setBackgroundColor(Color.BLACK);
    viewDistance = (RelativeLayout) findViewById(R.id.viewDistance);
    textTime = (TextView) findViewById(R.id.textTime);

    mapDisabledView = findViewById(R.id.mapDisabledView);
    mapDisabledView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // used to disable the map touching when sliden
            return onSliderTouch(v, event);
        }

    });

    paramsInstructionsMaxNormal.topMargin = (int) (Util.getScreenHeight() - Util.dp2px(146));
    paramsInstructionsMaxNormal.bottomMargin = -(int) ((Util.getScreenHeight()));
    paramsInstructionsMaxMaximized.topMargin = INSTRUCTIONS_TOP_MARGIN;
    paramsInstructionsMaxMinimized.topMargin = (int) (Util.getScreenHeight() - Util.getScreenHeight() / 10);
    paramsInstructionsMaxMinimized.bottomMargin = -(int) ((Util.getScreenHeight()));

    overviewLayout = (RelativeLayout) findViewById(R.id.overviewLayout);

    btnStart = (Button) overviewLayout.findViewById(R.id.btnStart);
    btnStart.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewDistance.setVisibility(View.VISIBLE);
            btnStart.setEnabled(false);
            hideOverview();
            textTime.setText(mapFragment.getEstimatedArrivalTime());
            mapFragment.startRouting();
            IbikeApplication.getTracker().sendEvent("Route", "Overview", mapFragment.destination, (long) 0);
            // instructionsView.setVisibility(View.VISIBLE);
            setInstructionViewState(InstrcutionViewState.Normal);
            RelativeLayout.LayoutParams paramsBtnTrack = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            paramsBtnTrack.setMargins(Util.dp2px(10), Util.dp2px(10), Util.dp2px(10), Util.dp2px(10));
            paramsBtnTrack.alignWithParent = true;
            paramsBtnTrack.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            paramsBtnTrack.addRule(RelativeLayout.ABOVE, instructionsView.getId());
            btnTrack.setLayoutParams(paramsBtnTrack);
            startTrackingUser();
        }
    });

    btnClose = ((ImageButton) findViewById(R.id.btnClose));
    btnClose.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showStopDlg();
        }
    });

    // Darken the button on touch :
    btnClose.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent me) {
            if (me.getAction() == MotionEvent.ACTION_DOWN) {
                btnClose.setColorFilter(Color.argb(150, 155, 155, 155));
                return false;
            } else if (me.getAction() == MotionEvent.ACTION_UP || me.getAction() == MotionEvent.ACTION_CANCEL) {
                btnClose.setColorFilter(Color.argb(0, 155, 155, 155));
                return false;
            }
            return false;
        }

    });

    // increased touch area for the normal pull handle
    pullTouchNormal = findViewById(R.id.pullTouchNormal);
    pullTouchNormal.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            isPulledFromNormal = true;
            return onPullHandleTouch(null, event);
        }
    });

    // increased touch area for the max pull handle
    pullTouchMax = findViewById(R.id.pullTouchMax);
    pullTouchMax.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            isPulledFromNormal = false;
            yFix = Util.dp2px(16);
            return onPullHandleTouch(null, event);
        }
    });

    mapTopDisabledView = findViewById(R.id.mapTopDisabledView);
    mapTopDisabledView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            isPulledFromNormal = false;
            yFix = Util.dp2px(42);
            // return onPullHandleTouch(null, event);
            return true;
        }
    });

    instructionsView = (RelativeLayout) findViewById(R.id.instructionsView);
    instructionsView.setBackgroundColor(Color.BLACK);
    pullHandle = (ImageButton) instructionsView.findViewById(R.id.imgPullHandle);
    pullHandle.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            isPulledFromNormal = true;
            return onPullHandleTouch(null, event);
        }

    });

    instructionsViewMin = (LinearLayout) findViewById(R.id.instructionsViewMin);
    pullHandleMin = (ImageButton) instructionsViewMin.findViewById(R.id.imgPullHandleMin);
    pullHandleMin.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            return onPullHandleTouch(arg0, arg1);
        }

    });

    instructionsViewMax = (RelativeLayout) findViewById(R.id.instructionsViewMax);
    params = new RelativeLayout.LayoutParams((int) Util.getScreenWidth(),
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    instructionsView.setLayoutParams(params);
    params = new RelativeLayout.LayoutParams((int) Util.getScreenWidth(),
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    findViewById(R.id.overviewLayout).setLayoutParams(params);
    pullHandleMax = (ImageButton) instructionsViewMax.findViewById(R.id.imgPullHandleMax);
    pullHandleMax.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            isPulledFromNormal = false;
            return onPullHandleTouch(arg0, arg1);
        }

    });

    instructionList = (ListView) instructionsViewMax.findViewById(R.id.listView);
    instructionList.addFooterView(reportProblemsView);
    setInstructionViewState(InstrcutionViewState.Invisible);

    FragmentManager fm = this.getSupportFragmentManager();
    mapFragment = getMapFragment();
    fm.beginTransaction().add(R.id.map_container, mapFragment).commit();

    viewPager = (ViewPager) instructionsView.findViewById(R.id.viewPager);
    // viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            if (!instructionsUpdated || (mapFragment.isRecalculation && !mapFragment.getTrackingMode())) {
                SMTurnInstruction turn = mapFragment.route.getTurnInstructions().get(position);
                if (turn.drivingDirection == SMTurnInstruction.TurnDirection.ReachedYourDestination
                        || turn.drivingDirection == SMTurnInstruction.TurnDirection.ReachingDestination) {
                    mapFragment.animateTo(mapFragment.route.getEndLocation());
                } else {
                    mapFragment.animateTo(turn.getLocation());
                }
                stopTrackingUser();
            }
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageScrollStateChanged(int arg0) {

        }
    });

    pagerAdapter = getPagerAdapter();
    viewPager.setAdapter(pagerAdapter);
    viewPager.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // used to disable viewPager swiping when the left menu is
            // opened
            return slidden;
        }
    });

    btnTrack = (ImageButton) findViewById(R.id.btnTrack);
    btnTrack.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mapFragment.getTrackingMode()) {
                startTrackingUser();
            } else {
                mapFragment.switchTracking();
                changeTrackingIcon();
            }
        }

    });

    textReport.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            launchReportIssuesActivity();
        }

    });

    textReport2 = (TextView) findViewById(R.id.textReport2);
    textReport2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            launchReportIssuesActivity();
        }

    });
    textDestAddress = (TextView) findViewById(R.id.textDestAddress);
    textDestAddress.setTypeface(IbikeApplication.getNormalFont());
    Config.OSRM_SERVER = Config.OSRM_SERVER_FAST;

    if (savedInstanceState != null) {
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(SMRouteNavigationActivity.this, getSplashActivityClass());
                intent.putExtra("timeout", 0);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish();
            }
        }, 400);
    }

    instructionsViewMax.setLayoutParams(paramsInstructionsMaxNormal);

    RelativeLayout.LayoutParams paramsBtnTrack = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    paramsBtnTrack.setMargins(Util.dp2px(10), Util.dp2px(10), Util.dp2px(10), Util.dp2px(10));
    paramsBtnTrack.alignWithParent = true;
    paramsBtnTrack.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    paramsBtnTrack.addRule(RelativeLayout.ABOVE, overviewLayout.getId());
    btnTrack.setLayoutParams(paramsBtnTrack);

    instructionsView.measure(0, 0);
    instructionsViewHeight = instructionsView.getMeasuredHeight();

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

From source file:com.noriginmedia.exoplayer.VideoPlayerFragment.java

private void resizeVideo(Configuration config, boolean fullscreen, int screenWidth, int screenHeight,
        boolean isPortrait, boolean softkeys) {
    if (mView == null || mPlayerView == null)
        return;/*from w  w w .  ja  v a 2 s . c o  m*/

    int displayWidth = screenWidth;
    int displayHeight = screenHeight;
    int videoWidth = 0;
    int videoHeight = 0;
    int left = 0;
    int top = 0;

    videoWidth = displayWidth;
    videoHeight = displayHeight;

    Log.d(LOG_TAG, "_-_ resizingVideo... vH:" + videoHeight + " vW:" + videoWidth + " mLastH:"
            + mLastVideoHeight + " mLastW:" + mLastVideoWidth);
    int vTop, vLeft;

    if (videoWidth > 0 && videoHeight > 0 && !fullscreen) {
        if (displayHeight - videoHeight > 0) {
            vTop = top + (displayHeight - videoHeight) / 2;
        } else {
            vTop = top;
        }

        if (displayWidth - videoWidth > 0) {
            vLeft = left + (displayWidth - videoWidth) / 2;
        } else {
            vLeft = left;
        }
    } else {
        vTop = 0;
        vLeft = 0;
    }

    if (mLastVideoWidth != videoWidth || mLastVideoHeight != videoHeight || vTop != mLastTop
            || vLeft != mLastLeft) {
        RelativeLayout.LayoutParams paramsV;

        if (videoWidth > 0 && videoHeight > 0) {
            paramsV = new RelativeLayout.LayoutParams(videoWidth, videoHeight);
            paramsV.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            paramsV.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

        } else {
            paramsV = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
                    RelativeLayout.LayoutParams.FILL_PARENT);
            paramsV.addRule(RelativeLayout.CENTER_IN_PARENT);
        }
        mLastTop = paramsV.topMargin = vTop;
        mLastLeft = paramsV.leftMargin = vLeft;
        Log.d(LOG_TAG, "_-_ resizedVideo tm:" + paramsV.topMargin + " tl: " + paramsV.leftMargin + " w:"
                + paramsV.width + " h:" + paramsV.height + " fullscreen:" + fullscreen);

        mPlayerView.setLayoutParams(paramsV);
        mView.requestLayout();

        mLastVideoHeight = videoHeight;
        mLastVideoWidth = videoWidth;
    }

    boolean fullView = (displayWidth >= screenWidth && displayHeight >= screenHeight);
}

From source file:mobisocial.musubi.ui.fragments.FeedViewFragment.java

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

    WizardStepHandler.accomplishTask(mActivity, WizardStepHandler.TASK_OPEN_FEED);
    mSendTextButton = (Button) view.findViewById(R.id.send_text);
    mSendTextButton.setOnClickListener(mSendStatus);
    mSendTextButton.setEnabled(false);//from  w w  w  .  j a  va2  s  . co m

    mStatusText = (EditText) view.findViewById(R.id.status_text);
    mStatusText.setOnEditorActionListener(FeedViewFragment.this);
    mStatusText.addTextChangedListener(FeedViewFragment.this);

    view.findViewById(R.id.pick_app).setOnClickListener(mPickApp);

    mInputBar = (View) view.findViewById(R.id.input_bar);
    mInputBar.setBackgroundColor(Color.WHITE);

    mListView = getListView();
    mListView.setFastScrollEnabled(true);
    mListView.setOnItemClickListener(mItemClickListener);
    mListView.setOnItemLongClickListener(mItemLongClickListener);
    mListView.setOnScrollListener(this);
    mListView.setFocusable(true);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(0,
            RelativeLayout.LayoutParams.FILL_PARENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    ((MusubiBaseActivity) getActivity()).setOnKeyListener(this);
}

From source file:com.github.yggie.pulltorefresh.PullListFragment.java

/**
 * Called to do initial creation of the fragment. Creates all the Views in code
 *
 * @param inflater The LayoutInflater/*from  ww w  .ja v  a2 s .c om*/
 * @param container The parent container
 * @param savedInstanceState The saved pullState
 * @return The inflated view
 */

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    // setup the list view
    listView = new CustomListView(this);
    listView.setId(ID_LIST_VIEW);
    final RelativeLayout.LayoutParams listViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    listViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    listViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    listView.setLayoutParams(listViewParams);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            onListItemClick((ListView) adapterView, view, position, id);
        }
    });

    // setup the empty view
    final TextView textView = new TextView(context);
    textView.setLayoutParams(listViewParams);
    textView.setGravity(Gravity.CENTER);
    textView.setText("Nothing to show");
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18.0f);
    emptyView = textView;
    emptyView.setId(ID_EMPTY_VIEW);

    // setup top pulled view
    final RelativeLayout.LayoutParams topViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    topViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    topViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    final FrameLayout topFrameLayout = new FrameLayout(context);
    topFrameLayout.setLayoutParams(topViewParams);
    // setup the default child of the FrameLayout
    topManager = new DefaultPulledView(this, true);
    topFrameLayout.addView(topManager);
    topPulledView = topFrameLayout;
    topPulledView.setId(ID_TOP_VIEW);

    // setup bottom pulled view
    final RelativeLayout.LayoutParams bottomViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bottomViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    bottomViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    final FrameLayout bottomFrameLayout = new FrameLayout(context);
    bottomFrameLayout.setLayoutParams(bottomViewParams);
    // setup the default child in the FrameLayout
    bottomManager = new DefaultPulledView(this, false);
    bottomFrameLayout.addView(bottomManager);
    bottomPulledView = bottomFrameLayout;
    bottomPulledView.setId(ID_BOTTOM_VIEW);

    layout = new PullToRefreshLayout(this);
    layout.addView(topPulledView);
    layout.addView(bottomPulledView);
    layout.addView(listView);
    layout.addView(emptyView);
    layout.setId(ID_LAYOUT);

    listShown = false;
    listView.setVisibility(View.GONE);
    emptyView.setVisibility(View.VISIBLE);

    // applies the XML attributes, if exists
    if (attrs != null) {
        final TypedArray a = getActivity().obtainStyledAttributes(attrs, R.styleable.PullListFragment);
        if (a != null) {
            parseXmlAttributes(a);
            a.recycle();
        }
        attrs = null;
    }

    return layout;
}