Example usage for android.view Gravity LEFT

List of usage examples for android.view Gravity LEFT

Introduction

In this page you can find the example usage for android.view Gravity LEFT.

Prototype

int LEFT

To view the source code for android.view Gravity LEFT.

Click Source Link

Document

Push object to the left of its container, not changing its size.

Usage

From source file:mobi.monaca.framework.plugin.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*w w  w .ja  v  a  2s.  c  o  m*/
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            ImageButton back = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setImageResource(R.drawable.childbroswer_icon_arrow_left);
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setImageResource(R.drawable.childbroswer_icon_arrow_right);
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            close.setImageResource(R.drawable.childbroswer_icon_close);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            //TODO check LocalFileBootloader
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.github.obsessive.simplifyreader.ui.activity.HomeActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawer(Gravity.LEFT);
        } else {//ww w.j  a  v  a 2s  .c  o m
            mDrawerLayout.openDrawer(Gravity.LEFT);
        }
        return true;
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawer(Gravity.LEFT);
        } else {
            if ((System.currentTimeMillis() - DOUBLE_CLICK_TIME) > 2000) {
                showToast(getString(R.string.double_click_exit));
                DOUBLE_CLICK_TIME = System.currentTimeMillis();
            } else {
                getBaseApplication().exitApp();
            }
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java

public void openDrawer(int gravity) {
    if (gravity == Gravity.LEFT)
        openDrawer(mLeftDrawer);// www . j  av a2  s.  com
    else if (gravity == Gravity.RIGHT)
        openDrawer(mRightDrawer);
}

From source file:com.dhaval.mobile.plugin.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject //from w  w  w. ja  v a 2s.com
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
        showAddressBar = options.optBoolean("showAddressBar", true);
    }

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         * 
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    ctx.getContext().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(ctx.getContext(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(ctx.getContext());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(ctx.getContext());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            ImageButton back = new ImageButton(ctx.getContext());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(ctx.getContext());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(ctx.getContext());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });
            if (!showAddressBar) {
                edittext.setVisibility(EditText.INVISIBLE);
            }

            // Close button
            ImageButton close = new ImageButton(ctx.getContext());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(ctx.getContext());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:com.hippo.widget.slidingdrawerlayout.ActionBarDrawerToggle.java

private void toggle() {
    if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
        mDrawerLayout.closeDrawer(Gravity.LEFT);
    } else {//  w ww  .  ja  v a 2 s  .c om
        mDrawerLayout.openDrawer(Gravity.LEFT);
    }
}

From source file:com.aidy.bottomdrawerlayout.DrawerLayout.java

public DrawerLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = getResources().getDisplayMetrics().density;
    mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f);
    final float minVel = MIN_FLING_VELOCITY * density;

    mLeftCallback = new ViewDragCallback(Gravity.LEFT);
    mRightCallback = new ViewDragCallback(Gravity.RIGHT);

    mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback);
    mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    mLeftDragger.setMinVelocity(minVel);
    mLeftCallback.setDragger(mLeftDragger);

    mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback);
    mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
    mRightDragger.setMinVelocity(minVel);
    mRightCallback.setDragger(mRightDragger);

    // So that we can catch the back button
    setFocusableInTouchMode(true);/*from w  ww .  ja  v a 2 s.  co  m*/

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
}

From source file:com.jun.elephant.ui.main.MainActivity.java

@OnClick({ R.id.login_tv, R.id.login_success_rl, R.id.user_iv, R.id.setting_ll, R.id.login_help_ll })
@Override//w  w  w  .  j  a v  a2  s .  c  o m
public void onClick(View v) {
    super.onClick(v);
    switch (v.getId()) {
    case R.id.login_success_rl:
        mExitLoginDialog.show();
        break;

    case R.id.login_tv:
    case R.id.user_iv:
        if (getUserConstant().isLogin()) {
            startActivity(UserInfoActivity.newIntent(this, getUserConstant().getUserData().getData().getId()));
            return;
        }
        //????
        if (PermissionsChecker.lacksPermissions(this, PermissionsChecker.photosPermissions)) {
            Intent intent = new Intent(this, LoginActivity.class);
            startActivityForResult(intent, Constants.Activity.LoginActivity);
        }
        break;
    case R.id.setting_ll:
        mThemeDialog.show();
        break;
    case R.id.login_help_ll:
        OpenWebViewUtils.loginHelp(this);
        break;
    default:
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawers();
        } else {
            mDrawerLayout.openDrawer(Gravity.LEFT);
        }
        break;
    }
}

From source file:com.klinker.android.launcher.addons.view.LauncherDrawerLayout.java

public LauncherDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = getResources().getDisplayMetrics().density;
    mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f);
    final float minVel = MIN_FLING_VELOCITY * density;

    mLeftCallback = new ViewDragCallback(Gravity.LEFT);
    mRightCallback = new ViewDragCallback(Gravity.RIGHT);

    mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback);
    mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    mLeftDragger.setMinVelocity(minVel);
    mLeftCallback.setDragger(mLeftDragger);

    mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback);
    mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
    mRightDragger.setMinVelocity(minVel);
    mRightCallback.setDragger(mRightDragger);

    // So that we can catch the back button
    setFocusableInTouchMode(true);//from   w ww  .j  av a2  s .  c  o m

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
}

From source file:com.klinker.android.twitter.ui.MainActivity.java

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

    MainActivity.sendHandler = new Handler();

    context = this;
    sContext = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    DrawerActivity.settings = AppSettings.getInstance(context);

    try {//from  www  . j a  v  a 2s  .  co m
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    } catch (Exception e) {

    }

    sharedPrefs.edit().putBoolean("refresh_me", getIntent().getBooleanExtra("from_notification", false))
            .commit();

    setUpTheme();
    setUpWindow();
    setContentView(R.layout.main_activity);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    setUpDrawer(0, getResources().getString(R.string.timeline));

    MainActivity.sendLayout = (LinearLayout) findViewById(R.id.send_layout);
    MainActivity.sendHandler.postDelayed(showSend, 1000);
    MainActivity.sendButton = (ImageButton) findViewById(R.id.send_button);
    MainActivity.sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent compose = new Intent(context, ComposeActivity.class);
            startActivity(compose);
        }
    });

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.timeline));

    if (!settings.isTwitterLoggedIn) {
        Intent login = new Intent(context, LoginActivity.class);
        startActivity(login);
    } /*else if (!sharedPrefs.getBoolean("setup_v_two", false) && !PreferenceManager.getDefaultSharedPreferences(context).getBoolean("setup_v_two", false)) {
      Intent setupV2 = new Intent(context, Version2Setup.class);
      startActivity(setupV2);
      }*/

    mSectionsPagerAdapter = new TimelinePagerAdapter(getFragmentManager(), context, sharedPrefs,
            getIntent().getBooleanExtra("from_launcher", false));

    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mViewPager.setCurrentItem(mSectionsPagerAdapter.getCount() - 3);

    if (getIntent().getBooleanExtra("from_launcher", false)) {
        actionBar.setTitle(mSectionsPagerAdapter.getPageTitle(getIntent().getIntExtra("launcher_page", 0)));
    }

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (!actionBar.isShowing()) {
                actionBar.show();

                if (translucent) {
                    statusBar.setVisibility(View.VISIBLE);
                }
            }
            MainActivity.sendHandler.post(showSend);
        }

        public void onPageSelected(int position) {

            String title = "" + mSectionsPagerAdapter.getPageTitle(position);

            if (title.equals(getResources().getString(R.string.mentions))) {
                MainDrawerArrayAdapter.current = 1;
            } else if (title.equals(getResources().getString(R.string.direct_messages))) {
                MainDrawerArrayAdapter.current = 2;
            } else if (title.equals(getResources().getString(R.string.timeline))) {
                MainDrawerArrayAdapter.current = 0;
            } else {
                MainDrawerArrayAdapter.current = -1;
            }

            drawerList.invalidateViews();

            actionBar.setTitle(title);
        }
    });

    mViewPager.setOffscreenPageLimit(4);

    if (getIntent().getBooleanExtra("tutorial", false) && !sharedPrefs.getBoolean("done_tutorial", false)) {
        getIntent().putExtra("tutorial", false);
        sharedPrefs.edit().putBoolean("done_tutorial", true).commit();
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "close drawer");
                    mDrawerLayout.closeDrawer(Gravity.LEFT);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_CLOSE_DRAWER));

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "open drawer");
                    mDrawerLayout.openDrawer(Gravity.LEFT);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_OPEN_DRAWER));

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "page left");
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, true);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_PAGE_LEFT));

        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                try {
                    Log.v("tutorial_activity", "page right");
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true);
                    unregisterReceiver(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new IntentFilter(TutorialActivity.ACTION_PAGE_RIGHT));

        startActivity(new Intent(context, TutorialActivity.class));
        overridePendingTransition(0, 0);
    }

    setLauncherPage();

    if (getIntent().getBooleanExtra("from_drawer", false)) {
        mViewPager.setCurrentItem(getIntent().getIntExtra("page_to_open", 3));
    }
}

From source file:com.hippo.nimingban.ui.ListActivity.java

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

    mNMBClient = NMBApplication.getNMBClient(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    mSlidingDrawerLayout = (SlidingDrawerLayout) findViewById(R.id.drawer_layout);
    mContentLayout = (ContentLayout) mSlidingDrawerLayout.findViewById(R.id.content_layout);
    mRecyclerView = mContentLayout.getRecyclerView();
    mLeftDrawer = (LeftDrawer) mSlidingDrawerLayout.findViewById(R.id.left_drawer);
    mRightDrawer = (RightDrawer) mSlidingDrawerLayout.findViewById(R.id.right_drawer);

    final GestureDetector gestureDetector = new GestureDetector(this, new SimpleGestureListener());
    gestureDetector.setOnDoubleTapListener(new SimpleDoubleTapListener() {
        @Override//from   w ww  . j  a v a 2 s  .c o  m
        public boolean onDoubleTap(MotionEvent e) {
            mPostHelper.refresh();
            return true;
        }
    });
    toolbar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            gestureDetector.onTouchEvent(event);
            return true;
        }
    });
    setSupportActionBar(toolbar);

    mDrawerToggle = new ActionBarDrawerToggle(this, mSlidingDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            if (mLeftDrawer == drawerView) {
                super.onDrawerSlide(drawerView, slideOffset);
            }
        }

        private void setMenuItemVisible(MenuItem item, boolean visible) {
            if (item != null) {
                item.setVisible(visible);
            }
        }

        @Override
        public void onDrawerClosed(View view) {
            if (mLeftDrawer == view) {
                super.onDrawerClosed(view);
            }
            if (mRightDrawer == view) {
                setMenuItemVisible(mRule, true);
                setMenuItemVisible(mCreatePost, true);
                setMenuItemVisible(mRefresh, true);
                setMenuItemVisible(mSortForumsMenu, false);
            }
        }

        @Override
        public void onDrawerOpened(View view) {
            if (mLeftDrawer == view) {
                // Analysis
                Analysis.action(ListActivity.this, "open_left_drawer");

                super.onDrawerOpened(view);
            }
            if (mRightDrawer == view) {
                // Analysis
                Analysis.action(ListActivity.this, "open_right_drawer");

                setMenuItemVisible(mRule, false);
                setMenuItemVisible(mCreatePost, false);
                setMenuItemVisible(mRefresh, false);
                setMenuItemVisible(mSortForumsMenu, true);
            }
        }
    };
    mSlidingDrawerLayout.setDrawerListener(mDrawerToggle);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
    }

    mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_left),
            Gravity.LEFT);
    mSlidingDrawerLayout.setDrawerShadow(ContextCompat.getDrawable(this, R.drawable.drawer_shadow_right),
            Gravity.RIGHT);
    mSlidingDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));

    mPostHelper = new PostHelper();
    mPostHelper.setEmptyString(getString(R.string.no_post));
    mContentLayout.setHelper(mPostHelper);
    if (Settings.getFastScroller()) {
        mContentLayout.showFastScroll();
    } else {
        mContentLayout.hideFastScroll();
    }

    mPostAdapter = new PostAdapter();
    mRecyclerView.setAdapter(mPostAdapter);
    mRecyclerView
            .setSelector(RippleSalon.generateRippleDrawable(ResourcesUtils.getAttrBoolean(this, R.attr.dark)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setOnItemClickListener(new ClickPostListener());
    mRecyclerView.hasFixedSize();
    mRecyclerView.setClipToPadding(false);

    int halfInterval = getResources().getDimensionPixelOffset(R.dimen.card_interval) / 2;
    if (getResources().getBoolean(R.bool.two_way)) {
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        mRecyclerView.addItemDecoration(new MarginItemDecoration(halfInterval));
        mRecyclerView.setPadding(halfInterval, halfInterval, halfInterval, halfInterval);
        mRecyclerView.setItemAnimator(new FloatItemAnimator(mRecyclerView));
    } else {
        mRecyclerView.addItemDecoration(new MarginItemDecoration(0, halfInterval, 0, halfInterval));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setPadding(0, halfInterval, 0, halfInterval);
    }

    mLeftDrawer.setHelper(this);

    mRightDrawer.setRightDrawerHelper(this);

    if (savedInstanceState == null) {
        int ils = Settings.getImageLoadingStrategy();
        if (ils == Settings.IMAGE_LOADING_STRATEGY_ALL || (ils == Settings.IMAGE_LOADING_STRATEGY_WIFI
                && NMBApplication.isConnectedWifi(ListActivity.this))) {
            mLeftDrawer.loadHeaderImageView();
        }
    }

    updateForums(true);

    checkForAppStart();

    Messenger.getInstance().register(Constants.MESSENGER_ID_CREATE_POST, this);
    Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this);

    // Check permission
    PermissionRequester.request(this, Manifest.permission.WRITE_EXTERNAL_STORAGE,
            getString(R.string.write_storage_permission_tip), PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);

    if (Settings.getGuideListActivity()) {
        showLeftDrawerGuide();
    }
}