List of usage examples for android.view Gravity TOP
int TOP
To view the source code for android.view Gravity TOP.
Click Source Link
From source file:android.support.v7.internal.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }// w ww . java 2 s .c o m final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
From source file:android.support.wear.widget.drawer.WearableDrawerView.java
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); // The peek view has a layout gravity of bottom for the top drawer, and a layout gravity // of top for the bottom drawer. This is required so that the peek view shows. On the top // drawer, the bottom peeks from the top, and on the bottom drawer, the top peeks. // LayoutParams are not guaranteed to return a non-null value until a child is attached to // the window. LayoutParams peekParams = (LayoutParams) mPeekContainer.getLayoutParams(); if (!Gravity.isVertical(peekParams.gravity)) { final boolean isTopDrawer = (((LayoutParams) getLayoutParams()).gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.TOP; if (isTopDrawer) { peekParams.gravity = Gravity.BOTTOM; mPeekIcon.setImageResource(R.drawable.ws_ic_more_horiz_24dp_wht); } else {/*from www. ja va 2s . co m*/ peekParams.gravity = Gravity.TOP; mPeekIcon.setImageResource(R.drawable.ws_ic_more_vert_24dp_wht); } mPeekContainer.setLayoutParams(peekParams); } }
From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java
@Override @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void onScrollChanged() { float newTop = Math.max(mAddSchedulePlaceholderView.getTop(), mScrollView.getScrollY()); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mAddScheduleButton.getLayoutParams(); if (UIUtils.hasICS()) { mAddScheduleButton.setTranslationY(newTop); } else {//from w w w . jav a 2s . c om lp.gravity = Gravity.TOP | Gravity.START; // needed for earlier platform versions lp.topMargin = (int) newTop; mScrollView.requestLayout(); } mScrollView.getGlobalVisibleRect(mBufferRect); int parentLeft = mBufferRect.left; int parentRight = mBufferRect.right; if (mAddSchedulePlaceholderView.getGlobalVisibleRect(mBufferRect)) { lp.leftMargin = mBufferRect.left - parentLeft; lp.rightMargin = parentRight - mBufferRect.right; } mAddScheduleButton.setLayoutParams(lp); }
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 w ww . ja v a 2 s . c om*/ 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.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 ww w . j av a2s . co 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.farmerbb.taskbar.service.StartMenuService.java
@SuppressLint("RtlHardcoded") private void drawStartMenu() { IconCache.getInstance(this).clearCache(); final SharedPreferences pref = U.getSharedPreferences(this); final boolean hasHardwareKeyboard = getResources() .getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS; switch (pref.getString("show_search_bar", "keyboard")) { case "always": shouldShowSearchBox = true;/*w ww . j a v a 2s.co m*/ break; case "keyboard": shouldShowSearchBox = hasHardwareKeyboard; break; case "never": shouldShowSearchBox = false; break; } // 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, shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT); // Determine where to show the start menu on screen switch (U.getTaskbarPosition(this)) { case "bottom_left": layoutId = R.layout.start_menu_left; params.gravity = Gravity.BOTTOM | Gravity.LEFT; break; case "bottom_vertical_left": layoutId = R.layout.start_menu_vertical_left; params.gravity = Gravity.BOTTOM | Gravity.LEFT; break; case "bottom_right": layoutId = R.layout.start_menu_right; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; break; case "bottom_vertical_right": layoutId = R.layout.start_menu_vertical_right; params.gravity = Gravity.BOTTOM | Gravity.RIGHT; break; case "top_left": layoutId = R.layout.start_menu_top_left; params.gravity = Gravity.TOP | Gravity.LEFT; break; case "top_vertical_left": layoutId = R.layout.start_menu_vertical_left; params.gravity = Gravity.TOP | Gravity.LEFT; break; case "top_right": layoutId = R.layout.start_menu_top_right; params.gravity = Gravity.TOP | Gravity.RIGHT; break; case "top_vertical_right": layoutId = R.layout.start_menu_vertical_right; params.gravity = Gravity.TOP | Gravity.RIGHT; break; } // Initialize views int theme = 0; switch (pref.getString("theme", "light")) { case "light": theme = R.style.AppTheme; break; case "dark": theme = R.style.AppTheme_Dark; break; } ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme); layout = (StartMenuLayout) LayoutInflater.from(wrapper).inflate(layoutId, null); startMenu = (GridView) layout.findViewById(R.id.start_menu); if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) layout.viewHandlesBackButton(); boolean scrollbar = pref.getBoolean("scrollbar", false); startMenu.setFastScrollEnabled(scrollbar); startMenu.setFastScrollAlwaysVisible(scrollbar); startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY); if (pref.getBoolean("transparent_start_menu", false)) startMenu.setBackgroundColor(0); searchView = (SearchView) layout.findViewById(R.id.search); int backgroundTint = U.getBackgroundTint(this); FrameLayout startMenuFrame = (FrameLayout) layout.findViewById(R.id.start_menu_frame); FrameLayout searchViewLayout = (FrameLayout) layout.findViewById(R.id.search_view_layout); startMenuFrame.setBackgroundColor(backgroundTint); searchViewLayout.setBackgroundColor(backgroundTint); if (shouldShowSearchBox) { if (!hasHardwareKeyboard) searchView.setIconifiedByDefault(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (!hasSubmittedQuery) { ListAdapter adapter = startMenu.getAdapter(); if (adapter != null) { hasSubmittedQuery = true; if (adapter.getCount() > 0) { View view = adapter.getView(0, null, startMenu); LinearLayout layout = (LinearLayout) view.findViewById(R.id.entry); layout.performClick(); } else { if (pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace()) LocalBroadcastManager.getInstance(StartMenuService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR")); else LocalBroadcastManager.getInstance(StartMenuService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU")); Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, query); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); else { Uri uri = new Uri.Builder().scheme("https").authority("www.google.com") .path("search").appendQueryParameter("q", query).build(); intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } } } } } return true; } @Override public boolean onQueryTextChange(String newText) { searchView.setIconified(false); View closeButton = searchView.findViewById(R.id.search_close_btn); if (closeButton != null) closeButton.setVisibility(View.GONE); refreshApps(newText, false); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { new Handler().postDelayed(() -> { EditText editText = (EditText) searchView.findViewById(R.id.search_src_text); if (editText != null) { editText.requestFocus(); editText.setSelection(editText.getText().length()); } }, 50); } return true; } }); searchView.setOnQueryTextFocusChangeListener((view, b) -> { if (!hasHardwareKeyboard) { ViewGroup.LayoutParams params1 = startMenu.getLayoutParams(); params1.height = getResources().getDimensionPixelSize(b && !U.isServiceRunning(this, "com.farmerbb.secondscreen.service.DisableKeyboardService") ? R.dimen.start_menu_height_half : R.dimen.start_menu_height); startMenu.setLayoutParams(params1); } if (!b) { if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) LocalBroadcastManager.getInstance(StartMenuService.this) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU")); else { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } }); searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); LinearLayout powerButton = (LinearLayout) layout.findViewById(R.id.power_button); powerButton.setOnClickListener(view -> { int[] location = new int[2]; view.getLocationOnScreen(location); openContextMenu(location); }); powerButton.setOnGenericMotionListener((view, motionEvent) -> { if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { int[] location = new int[2]; view.getLocationOnScreen(location); openContextMenu(location); } return false; }); searchViewLayout.setOnClickListener(view -> searchView.setIconified(false)); startMenu.setOnItemClickListener((parent, view, position, id) -> { hideStartMenu(); AppEntry entry = (AppEntry) parent.getAdapter().getItem(position); U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(), entry.getUserId(StartMenuService.this), null, false, false); }); if (pref.getBoolean("transparent_start_menu", false)) layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0); } else searchViewLayout.setVisibility(View.GONE); textView = (TextView) layout.findViewById(R.id.no_apps_found); LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiverAlt); LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver); LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver, new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU")); LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiverAlt, new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU_ALT")); LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU")); handler = new Handler(); refreshApps(true); windowManager.addView(layout, params); }
From source file:com.yozio.demo.implementations.share.ShareButtonsActivity.java
public void showShareCommentDialog(Context context, final DialogFlowController controller) { final EditText text = new EditText(context); text.setMinLines(5);/*from www . j a va2s . c om*/ text.setGravity(Gravity.TOP); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Share"); builder.setMessage("Enter a comment (Optional)"); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { controller.onContinue(text.getText().toString()); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { controller.onCancel(); } }); AlertDialog dialog = builder.create(); dialog.setView(text); dialog.show(); }
From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java
private void addTab(int index, CharSequence text, int iconResId) { final TabView tabView = new TabView(getContext()); tabView.mIndex = index;// w ww . j a v a 2 s .c o m tabView.setTag("tavView"); tabView.setId(index); // tabView.setFocusable(true); // tabView.setOnClickListener(mTabClickListener); tabView.setText(text); //tabView.setPadding(pointSize, 0, pointSize, 0); tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); tabView.setMaxLines(1); tabView.setGravity(Gravity.CENTER); XmlPullParser xrp = getResources().getXml(R.drawable.tab_button); try { ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp); tabView.setTextColor(csl); } catch (Exception e) { } if (iconResId != 0) { //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0); } FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tabView.setLayoutParams(tabTvL); //measureView(tabView); LinearLayout layoutWraper1 = new LinearLayout(getContext()); LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1); layoutWraper1.setLayoutParams(lp1); layoutWraper1.setGravity(Gravity.CENTER); layoutWraper1.setFocusable(true); layoutWraper1.setOnClickListener(mTabClickListener); layoutWraper1.setPadding(0, 0, 0, 0); layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red); FrameLayout frameLayout = new FrameLayout(getContext()); frameLayout.setTag("framelayout"); // FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5)); FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); // frameLayout.setPadding(padding, padding, padding, padding); frameLayout.setLayoutParams(fl2); // frameLayout.addView(tabView); View hasNew = new View(getContext()); FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize); hasNew.setLayoutParams(hasNewL); hasNewL.gravity = Gravity.TOP | Gravity.RIGHT; hasNew.setBackgroundResource(R.drawable.shape_circle); FrameLayout tabTvframe = new FrameLayout(getContext()); FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tabTvframeL.gravity = Gravity.CENTER; tabTvframe.setLayoutParams(tabTvframeL); tabTvframe.addView(tabView); tabTvframe.addView(hasNew); hasNew.setVisibility(View.GONE); frameLayout.addView(tabTvframe); layoutWraper1.addView(frameLayout); tabView.setTagView(hasNew); mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1)); }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (attrs != null) { TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS); if (defAttrs != null) { int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY); if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) { throw new IllegalArgumentException("layout_gravity must be set to either top or bottom"); }/*from w w w .j a v a 2s . c om*/ mIsSlidingUp = gravity == Gravity.BOTTOM; } defAttrs.recycle(); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout); if (ta != null) { mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_collapsedHeight, -1); mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_shadowHeight, -1); mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY); mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_fadeColor, DEFAULT_FADE_COLOR); mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_dragView, -1); } ta.recycle(); } final float density = context.getResources().getDisplayMetrics().density; if (mPanelHeight == -1) { mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f); } if (mShadowHeight == -1) { mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f); } setWillNotDraw(false); mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback()); mDragHelper.setMinVelocity(mMinFlingVelocity * density); mCanSlide = true; mIsSlidingEnabled = true; ViewConfiguration vc = ViewConfiguration.get(context); mScrollTouchSlop = vc.getScaledTouchSlop(); }
From source file:com.hippo.widget.Slider.java
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); mPopup.showAtLocation(this, Gravity.TOP | Gravity.LEFT, mPopupX, mPopupY); }