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:com.anysoftkeyboard.ui.settings.MainSettingsActivity.java

public void openDrawer() {
    mDrawerRootLayout.openDrawer(Gravity.LEFT);
}

From source file:com.facebook.react.flat.RCTText.java

@ReactProp(name = ViewProps.TEXT_ALIGN)
public void setTextAlign(@Nullable String textAlign) {
    if (textAlign == null || "auto".equals(textAlign)) {
        mAlignment = Gravity.NO_GRAVITY;
    } else if ("left".equals(textAlign)) {
        // left and right may yield potentially different results (relative to non-nodes) in cases
        // when supportsRTL="true" in the manifest.
        mAlignment = Gravity.LEFT;
    } else if ("right".equals(textAlign)) {
        mAlignment = Gravity.RIGHT;//from   w  w  w  .  j a v a 2 s .  co  m
    } else if ("center".equals(textAlign)) {
        mAlignment = Gravity.CENTER;
    } else {
        throw new JSApplicationIllegalArgumentException("Invalid textAlign: " + textAlign);
    }

    notifyChanged(false);
}

From source file:com.elekso.potfix.MainActivity.java

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

    PowerManager pm = (PowerManager) getApplicationContext()
            .getSystemService(getApplicationContext().POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, " POTFIX holding wake lock");
    wl.acquire();/*from   ww w. j  av  a 2 s  . com*/
    Globals.getInstance().setFlexiblemap(true);

    //
    //
    //        new Thread(new Runnable(){
    //            @Override
    //            public void run() {
    //                try {
    //                    LALpotfixservicePortBinding service = new LALpotfixservicePortBinding();
    //                    try {
    //                        globaldata_test=service.CheckWS("mandar");
    //
    //                    } catch (Exception e) {
    //                        e.printStackTrace();
    //                    }
    //                } catch (Exception ex) {
    //                    ex.printStackTrace();
    //                }
    //            }
    //        }).start();

    String login = "";

    //  Config.getInstance(getBaseContext(),getCacheDir()).setProfile("df","asd");
    login = Config.getInstance(getBaseContext(), getCacheDir()).getProfileName();
    if (login == null || login.isEmpty()) {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
        return;
    }
    //remove
    //  Stetho.initializeWithDefaults(this);

    // Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Drawer
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    tusername = (TextView) drawer.findViewById(R.id.tvusername);
    //        tuseremail =(TextView) findViewById(R.id.tvuseremail);
    //
    //        if(login!=null)
    //            tusername.setText("jhjhjhjh");
    //   if(Config.getInstance().getProfileEmail()!=null)
    //tuseremail.setText(Config.getInstance().getProfileEmail());

    // FAB
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setRippleColor(Color.parseColor("#78D6F3"));
    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC")));
    fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (currentFragment) {
            case 1: //profile
                Snackbar.make(view, "Updating Information", Snackbar.LENGTH_LONG).setAction("Action", null)
                        .show();
                Fragment frg = new ProfileFragment();
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.frame_containerone, frg);
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.commit();
                break;
            case 2: //map

                if (Globals.getInstance().getFlexiblemap()) {
                    Snackbar.make(view, "Free to Scroll", Snackbar.LENGTH_LONG).setAction("Action", null)
                            .show();
                    Globals.getInstance().setFlexiblemap(false);
                    fab.setRippleColor(Color.parseColor("#FFE082"));
                    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFB300")));
                    fab.setImageResource(R.drawable.ic_gps_off_white_24dp);
                } else {
                    Snackbar.make(view, "Follow Potfix", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                    Globals.getInstance().setFlexiblemap(true);
                    fab.setRippleColor(Color.parseColor("#78D6F3"));
                    fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC")));
                    fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp);
                }
                break;
            case 3: //share
                //Snackbar.make(view, "Some sharing action", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                String[] TO = { "aziz@potfix.com" };
                String[] CC = { "" };
                Intent emailIntent = new Intent(Intent.ACTION_SEND);

                emailIntent.setData(Uri.parse("mailto:"));
                emailIntent.setType("text/plain");
                emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
                emailIntent.putExtra(Intent.EXTRA_CC, CC);
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Potfix Communication");
                emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message...");

                try {
                    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                    finish();
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT)
                            .show();
                }
                break;
            case 4: //legal
                Snackbar.make(view, "Software License", Snackbar.LENGTH_LONG).setAction("Action", null).show();
                drawer.openDrawer(Gravity.LEFT);
                break;
            }

        }
    });

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    startService(new Intent(getBaseContext(), BackgroundService.class));

    FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
    MapsFragment mFRaFragment = new MapsFragment();
    mTransaction.add(R.id.frame_containerone, mFRaFragment);
    mTransaction.commit();

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show();
    } else {
        showGPSDisabledAlertToUser();
    }

    //        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
    //            Toast.makeText(this, "Network is Enabled in your devide", Toast.LENGTH_SHORT).show();
    //        }else{
    //            showNetDisabledAlertToUser();
    //        }
    createNotification();
}

From source file:com.appdevper.mediaplayer.activity.ActionBarCastActivity.java

@Override
public void onBackPressed() {
    // If the drawer is open, back will close it
    if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
        mDrawerLayout.closeDrawers();//from  www .  j av a 2 s  .c  om
        return;
    }
    // Otherwise, it may return to the previous fragment stack
    FragmentManager fragmentManager = getFragmentManager();
    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
    } else {
        // Lastly, it will rely on the system behavior for back
        super.onBackPressed();
    }
}

From source file:com.goftagram.telegram.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    if (type != 3) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    }/*from www. j  a va2 s. c o m*/
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (type != 0) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (type == 1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView
                        .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(
                        LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView
                    .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (type == 1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    return true;
                }
                return false;
            }
        });
        passwordEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (passwordEditText.length() == 4) {
                    if (type == 2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (type == 1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });
        if (android.os.Build.VERSION.SDK_INT < 11) {
            passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                public void onCreateContextMenu(ContextMenu menu, View v,
                        ContextMenu.ContextMenuInfo menuInfo) {
                    menu.clear();
                }
            });
        } else {
            passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public void onDestroyActionMode(ActionMode mode) {
                }

                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    return false;
                }
            });
        }

        if (type == 1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, R.drawable.bar_selector);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item,
                    LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(1));
                } else if (i == passcodeRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("Disabled", R.string.Disabled);
                            } else if (value == 1) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 1));
                            } else if (value == 2) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 5));
                            } else if (value == 3) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 1));
                            } else if (value == 4) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 5));
                            }
                            return "";
                        }
                    });
                    builder.setView(numberPicker);
                    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}

From source file:com.iangclifton.android.floatlabel.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }/*from w w  w  .j  a v  a2 s .c  o  m*/

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = parentRight - width - lp.rightMargin;
            break;
        case Gravity.LEFT:
        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

private void recompute(int width) {
    if (text != null) {
        // work out the top padding and line height to align text to a 4dp grid
        final float fourDip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
                getResources().getDisplayMetrics());

        // ensure that the first line's baselines sits on 4dp grid by setting the top padding
        final Paint.FontMetricsInt fm = paint.getFontMetricsInt();
        final int gridAlignedTopPadding = (int) (fourDip
                * (float) Math.ceil((unalignedTopPadding + Math.abs(fm.ascent)) / fourDip)
                - Math.ceil(Math.abs(fm.ascent)));
        super.setPadding(getPaddingLeft(), gridAlignedTopPadding, getPaddingTop(), getPaddingBottom());

        // ensures line height is a multiple of 4dp
        final int fontHeight = Math.abs(fm.ascent - fm.descent) + fm.leading;
        final int baselineAlignedLineHeight = (int) (fourDip * (float) Math.ceil(lineHeightHint / fourDip));

        // before we can workout indents we need to know how many lines of text there are;
        // so we need to create a temporary layout :(
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f).setBreakStrategy(breakStrategy)
                .build();/*from   w  w w .ja v a  2  s  .  c  o m*/
        final int preIndentedLineCount = layout.getLineCount();

        // now we can calculate the indents required for the given fab gravity
        final boolean gravityTop = (fabGravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP;
        final boolean gravityLeft = (fabGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT;
        // we want to iterate forward/backward over the lines depending on whether the fab
        // overlap vertical gravity is top/bottom
        int currentLine = gravityTop ? 0 : preIndentedLineCount - 1;
        int remainingHeightOverlap = fabOverlapHeight - (gravityTop ? getPaddingTop() : getPaddingBottom());
        final int[] leftIndents = new int[preIndentedLineCount];
        final int[] rightIndents = new int[preIndentedLineCount];
        do {
            if (remainingHeightOverlap > 0) {
                // still have overlap height to consume, set the appropriate indent
                leftIndents[currentLine] = gravityLeft ? fabOverlapWidth : 0;
                rightIndents[currentLine] = gravityLeft ? 0 : fabOverlapWidth;
                remainingHeightOverlap -= baselineAlignedLineHeight;
            } else {
                // have consumed the overlap height: no indent
                leftIndents[currentLine] = 0;
                rightIndents[currentLine] = 0;
            }
            if (gravityTop) { // iterate forward over the lines
                currentLine++;
            } else { // iterate backward over the lines
                currentLine--;
            }
        } while (gravityTop ? currentLine < preIndentedLineCount : currentLine >= 0);

        // now that we know the indents, create the actual layout
        layout = StaticLayout.Builder.obtain(text, 0, text.length(), paint, width)
                .setLineSpacing(baselineAlignedLineHeight - fontHeight, 1f)
                .setIndents(leftIndents, rightIndents).setBreakStrategy(breakStrategy).build();

        // ensure that the view's height sits on the grid (as we've changed padding etc).
        final int height = getPaddingTop() + layout.getHeight() + getPaddingBottom();
        final float overhang = height % fourDip;
        if (overhang != 0) {
            super.setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
                    unalignedBottomPadding + (int) (fourDip - overhang));
        }
    }
}

From source file:com.hippo.widget.Slider.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    mPopup.showAtLocation(this, Gravity.TOP | Gravity.LEFT, mPopupX, mPopupY);
}

From source file:com.dldzkj.app.renxing.MainActivity.java

public void OpenLeftMenu() {
    mDrawerLayout.openDrawer(Gravity.LEFT);
    mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.LEFT);
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@SuppressLint("RtlHardcoded")
private void drawTaskbar() {
    IconCache.getInstance(this).clearCache();

    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);/*from w w  w  .ja v a  2  s . c o m*/

    // Determine where to show the taskbar on screen
    switch (U.getTaskbarPosition(this)) {
    case "bottom_left":
        layoutId = R.layout.taskbar_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        positionIsVertical = false;
        break;
    case "bottom_vertical_left":
        layoutId = R.layout.taskbar_vertical;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        positionIsVertical = true;
        break;
    case "bottom_right":
        layoutId = R.layout.taskbar_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        positionIsVertical = false;
        break;
    case "bottom_vertical_right":
        layoutId = R.layout.taskbar_vertical;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        positionIsVertical = true;
        break;
    case "top_left":
        layoutId = R.layout.taskbar_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        positionIsVertical = false;
        break;
    case "top_vertical_left":
        layoutId = R.layout.taskbar_top_vertical;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        positionIsVertical = true;
        break;
    case "top_right":
        layoutId = R.layout.taskbar_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        positionIsVertical = false;
        break;
    case "top_vertical_right":
        layoutId = R.layout.taskbar_top_vertical;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        positionIsVertical = true;
        break;
    }

    // Initialize views
    int theme = 0;

    SharedPreferences pref = U.getSharedPreferences(this);
    switch (pref.getString("theme", "light")) {
    case "light":
        theme = R.style.AppTheme;
        break;
    case "dark":
        theme = R.style.AppTheme_Dark;
        break;
    }

    boolean altButtonConfig = pref.getBoolean("alt_button_config", false);

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
    layout = (LinearLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
    taskbar = (LinearLayout) layout.findViewById(R.id.taskbar);
    scrollView = (FrameLayout) layout.findViewById(R.id.taskbar_scrollview);

    if (altButtonConfig) {
        space = (Space) layout.findViewById(R.id.space_alt);
        layout.findViewById(R.id.space).setVisibility(View.GONE);
    } else {
        space = (Space) layout.findViewById(R.id.space);
        layout.findViewById(R.id.space_alt).setVisibility(View.GONE);
    }

    space.setOnClickListener(v -> toggleTaskbar());

    startButton = (ImageView) layout.findViewById(R.id.start_button);
    int padding;

    if (pref.getBoolean("app_drawer_icon", false)) {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, R.mipmap.ic_launcher));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt);
    } else {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.all_apps_button_icon));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
    }

    startButton.setPadding(padding, padding, padding, padding);
    startButton.setOnClickListener(ocl);
    startButton.setOnLongClickListener(view -> {
        openContextMenu();
        return true;
    });

    startButton.setOnGenericMotionListener((view, motionEvent) -> {
        if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY)
            openContextMenu();

        return false;
    });

    refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000);
    if (refreshInterval == 0)
        refreshInterval = 100;

    sortOrder = pref.getString("sort_order", "false");
    runningAppsOnly = pref.getString("recents_amount", "past_day").equals("running_apps_only");

    switch (pref.getString("recents_amount", "past_day")) {
    case "past_day":
        searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY;
        break;
    case "app_start":
        long oneDayAgo = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY;
        long appStartTime = pref.getLong("time_of_service_start", System.currentTimeMillis());
        long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime();
        long startTime = deviceStartTime > appStartTime ? deviceStartTime : appStartTime;

        searchInterval = startTime > oneDayAgo ? startTime : oneDayAgo;
        break;
    }

    Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU");
    LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent);

    if (altButtonConfig) {
        button = (Button) layout.findViewById(R.id.hide_taskbar_button_alt);
        layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE);
    } else {
        button = (Button) layout.findViewById(R.id.hide_taskbar_button);
        layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE);
    }

    try {
        button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf"));
    } catch (RuntimeException e) {
        /* Gracefully fail */ }

    updateButton(false);
    button.setOnClickListener(v -> toggleTaskbar());

    LinearLayout buttonLayout = (LinearLayout) layout.findViewById(
            altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout);
    if (buttonLayout != null)
        buttonLayout.setOnClickListener(v -> toggleTaskbar());

    LinearLayout buttonLayoutToHide = (LinearLayout) layout.findViewById(
            altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt);
    if (buttonLayoutToHide != null)
        buttonLayoutToHide.setVisibility(View.GONE);

    int backgroundTint = U.getBackgroundTint(this);
    int accentColor = U.getAccentColor(this);

    dashboardButton = (FrameLayout) layout.findViewById(R.id.dashboard_button);
    navbarButtons = (LinearLayout) layout.findViewById(R.id.navbar_buttons);

    dashboardEnabled = pref.getBoolean("dashboard", false);
    if (dashboardEnabled) {
        layout.findViewById(R.id.square1).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square2).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square3).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square4).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square5).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square6).setBackgroundColor(accentColor);

        dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(TaskbarService.this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD")));
    } else
        dashboardButton.setVisibility(View.GONE);

    if (pref.getBoolean("button_back", false)) {
        navbarButtonsEnabled = true;

        ImageView backButton = (ImageView) layout.findViewById(R.id.button_back);
        backButton.setVisibility(View.VISIBLE);
        backButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });
    }

    if (pref.getBoolean("button_home", false)) {
        navbarButtonsEnabled = true;

        ImageView homeButton = (ImageView) layout.findViewById(R.id.button_home);
        homeButton.setVisibility(View.VISIBLE);
        homeButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });

        homeButton.setOnLongClickListener(v -> {
            Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
            voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            try {
                startActivity(voiceSearchIntent);
            } catch (ActivityNotFoundException e) {
                /* Gracefully fail */ }

            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);

            return true;
        });

        homeButton.setOnGenericMotionListener((view13, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                    && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
                voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                try {
                    startActivity(voiceSearchIntent);
                } catch (ActivityNotFoundException e) {
                    /* Gracefully fail */ }

                if (pref.getBoolean("hide_taskbar", true)
                        && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                    hideTaskbar(true);
            }
            return true;
        });
    }

    if (pref.getBoolean("button_recents", false)) {
        navbarButtonsEnabled = true;

        ImageView recentsButton = (ImageView) layout.findViewById(R.id.button_recents);
        recentsButton.setVisibility(View.VISIBLE);
        recentsButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            recentsButton.setOnLongClickListener(v -> {
                U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                if (pref.getBoolean("hide_taskbar", true)
                        && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                    hideTaskbar(true);

                return true;
            });

            recentsButton.setOnGenericMotionListener((view13, motionEvent) -> {
                if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                        && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                    U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                    if (pref.getBoolean("hide_taskbar", true)
                            && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                        hideTaskbar(true);
                }
                return true;
            });
        }
    }

    if (!navbarButtonsEnabled)
        navbarButtons.setVisibility(View.GONE);

    layout.setBackgroundColor(backgroundTint);
    layout.findViewById(R.id.divider).setBackgroundColor(accentColor);
    button.setTextColor(accentColor);

    if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace())
        showTaskbar(false);
    else if (!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false))
        toggleTaskbar();

    LocalBroadcastManager.getInstance(this).unregisterReceiver(showReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(tempShowReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(tempHideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(showReceiver,
            new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(tempShowReceiver,
            new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(tempHideReceiver,
            new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR"));

    startRefreshingRecents();

    windowManager.addView(layout, params);

    isFirstStart = false;
}