List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
From source file:com.wangbb.naruto.app.view.PagerSlidingTabStrip.java
private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId, int iIconLocation) { // final View tabView = ((Activity) getContext()).getLayoutInflater() // .inflate(iLayoutResId, null); // TextView tab_text_textview = (TextView) // tabView.findViewById(iTextId); // tab_text_textview.setText(title); LinearLayout tabView = new LinearLayout(getContext()); tabView.setGravity(Gravity.CENTER);/*from ww w . j a va2 s. c o m*/ TextView tab_text_textview = new TextView(getContext()); tab_text_textview.setId(position); tab_text_textview.setText(title); tab_text_textview.setGravity(Gravity.CENTER_VERTICAL); tab_text_textview.setSingleLine(); // tab_text_textview.setTextColor(tabTextColor); // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color)); // XmlPullParser xrp = getResources().getXml(tabTextColor); // try { // ColorStateList csl = ColorStateList.createFromXml(getResources(), // xrp); // if (tab_text_textview != null) { tab_text_textview.setTextColor(tabTextColor); // } // } catch (Exception e) { // // } tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle); LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (iconResId != 0) { // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds( // iconResId, 0, 0, 0); // Drawable mDrawable = ((Activity) getContext()).getResources() // .getDrawable(iconResId); // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(), // mDrawable.getMinimumHeight()); int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding); ImageView icon = new ImageView(getContext()); icon.setImageResource(iconResId); icon.setScaleType(ScaleType.CENTER_INSIDE); LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, iIconHeight); switch (iIconLocation) { case 1: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 2: // tab_text_textview.setCompoundDrawables(null, mDrawable, null, // null); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(icon, lpImage); lpText.topMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 3: // tab_text_textview.setCompoundDrawables(null, null, mDrawable, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(tab_text_textview, lpText); lpImage.leftMargin = iPandding; tabView.addView(icon, lpImage); break; case 4: // tab_text_textview.setCompoundDrawables(null, null, null, // mDrawable); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(tab_text_textview, lpText); lpImage.topMargin = iPandding; tabView.addView(icon, lpImage); break; default: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; } // tab_text_textview // .setCompoundDrawablePadding((int) ((Activity) getContext()) // .getResources() // .getDimension(R.dimen.common_padding)); } else { tabView.addView(tab_text_textview, lpText); } tabView.setFocusable(true); tabView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0); tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:com.example.fragmentdemo.views.PagerSlidingTabStrip.java
private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId, int iIconLocation) { // final View tabView = ((Activity) getContext()).getLayoutInflater() // .inflate(iLayoutResId, null); // TextView tab_text_textview = (TextView) // tabView.findViewById(iTextId); // tab_text_textview.setText(title); LinearLayout tabView = new LinearLayout(getContext()); tabView.setGravity(Gravity.CENTER);/* w w w . j a v a2 s . c om*/ TextView tab_text_textview = new TextView(getContext()); tab_text_textview.setId(position); tab_text_textview.setText(title); tab_text_textview.setGravity(Gravity.CENTER_VERTICAL); tab_text_textview.setSingleLine(); // tab_text_textview.setTextColor(tabTextColor); // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color)); XmlPullParser xrp = getResources().getXml(tabTextColor); try { ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp); if (tab_text_textview != null) { tab_text_textview.setTextColor(csl); } } catch (Exception e) { } tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle); LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (iconResId != 0) { // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds( // iconResId, 0, 0, 0); // Drawable mDrawable = ((Activity) getContext()).getResources() // .getDrawable(iconResId); // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(), // mDrawable.getMinimumHeight()); int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding); ImageView icon = new ImageView(getContext()); icon.setImageResource(iconResId); icon.setScaleType(ScaleType.CENTER_INSIDE); LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, iIconHeight); switch (iIconLocation) { case 1: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 2: // tab_text_textview.setCompoundDrawables(null, mDrawable, null, // null); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(icon, lpImage); lpText.topMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 3: // tab_text_textview.setCompoundDrawables(null, null, mDrawable, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(tab_text_textview, lpText); lpImage.leftMargin = iPandding; tabView.addView(icon, lpImage); break; case 4: // tab_text_textview.setCompoundDrawables(null, null, null, // mDrawable); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(tab_text_textview, lpText); lpImage.topMargin = iPandding; tabView.addView(icon, lpImage); break; default: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; } // tab_text_textview // .setCompoundDrawablePadding((int) ((Activity) getContext()) // .getResources() // .getDimension(R.dimen.common_padding)); } else { tabView.addView(tab_text_textview, lpText); } tabView.setFocusable(true); tabView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0); tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:com.xargsgrep.portknocker.activity.EditHostActivity.java
private boolean validateAndDisplayErrors(Host host) { // boolean validHostname = HOSTNAME_PATTERN.matcher(host.getHostname()).matches(); // boolean validIP = InetAddressUtils.isIPv4Address(host.getHostname()); String errorText = ""; if (StringUtils.isBlank(host.getLabel())) { errorText = getString(R.string.toast_msg_enter_label); } else if (StringUtils.isBlank(host.getHostname())) { errorText = getString(R.string.toast_msg_enter_hostname); }/* w ww . jav a 2 s .c o m*/ // else if (!validHostname && !validIP) { // errorText = getString(R.string.toast_msg_invalid_hostname); // } else if (host.getPorts() == null || host.getPorts().size() == 0) { errorText = getString(R.string.toast_msg_enter_port); } else if (host.getDelay() > MAX_DELAY_VALUE) { errorText = getString(R.string.toast_msg_delay_max_value) + MAX_DELAY_VALUE; } else { for (Port port : host.getPorts()) { if (port.getPort() > MAX_PORT_VALUE) { errorText = getString(R.string.toast_msg_invalid_port) + port.getPort(); break; } } } if (StringUtils.isNotBlank(errorText)) { Toast toast = Toast.makeText(this, errorText, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return false; } return true; }
From source file:self.philbrown.droidQuery.Example.ExampleActivity.java
/** * Refreshes the list of cells containing App.net messages. This <em>ListView</em> is actually * a <em>scrollable LinearLayout</em>, and is assembled in much the same way a layout would be * made using <em>JavaScript</em>, with the <em>CSS3</em> attribute <em>overscroll-y: scroll</em>. * <br>/*from w ww. ja v a 2 s .c o m*/ * For this example, the public stream is retrieved using <em>ajax</em>, and for each message * received, a new cell is created. For each cell, a new <em>ajax</em> request is started to * retrieve the thumbnail image for the user. As all these events occur on a background thread, the * main ScrollView is populated with cells and displayed to the user. * <br> * The stream <em>JSON</em> request is performed in a <em>global ajax</em> request, which will * trigger the global start and stop events (which show a progress indicator, using a droidQuery * extension). The image get requests are not global, so they will not trigger global events. */ public void refresh() { $.ajax(new AjaxOptions().url("https://alpha-api.app.net/stream/0/posts/stream/global").dataType("json") .type("GET").error(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object error, int status, String reason Object error = params[0]; int status = (Integer) params[1]; String reason = (String) params[2]; Log.w("app.net Client", "Could not complete request: " + reason); } }).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object, reason JSONObject json = (JSONObject) params[0]; String reason = (String) params[1]; try { Map<String, ?> map = $.map(json); JSONArray datas = (JSONArray) map.get("data"); if (datas.length() != 0) { //clear old subviews in layout $.with(ExampleActivity.this, R.id.example_layout).selectChildren().remove(); //get each message infos and create a cell for (int i = 0; i < datas.length(); i++) { JSONObject jdata = (JSONObject) datas.get(i); Map<String, ?> data = $.map(jdata); String text = data.get("text").toString(); Map<String, ?> user = $.map((JSONObject) data.get("user")); String username = user.get("username").toString(); String avatarURL = ((JSONObject) user.get("avatar_image")).getString("url"); //get Avatar image in a new task (but go ahead and create the cell for now) LinearLayout cell = new LinearLayout(ExampleActivity.this); LinearLayout.LayoutParams cell_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); cell_params.bottomMargin = 5; cell.setLayoutParams(cell_params); cell.setOrientation(LinearLayout.HORIZONTAL); cell.setWeightSum(8); cell.setPadding(5, 5, 5, 5); cell.setBackgroundColor(Color.parseColor("#333333")); final LinearLayout fcell = cell; //contains the image location ImageView image = new ImageView(ExampleActivity.this); image.setId(99); LinearLayout.LayoutParams ip_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); ip_params.weight = 2; image.setLayoutParams(ip_params); image.setPadding(0, 0, 5, 0); $.with(image).attr("alpha", 0.0f); cell.addView(image); final ImageView fimage = image; //the text location in the cell LinearLayout body = new LinearLayout(ExampleActivity.this); LinearLayout.LayoutParams body_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); body_params.weight = 5; body.setLayoutParams(body_params); body.setOrientation(LinearLayout.VERTICAL); body.setGravity(Gravity.CENTER_VERTICAL); cell.addView(body); //the username TextView name = new TextView(ExampleActivity.this); LinearLayout.LayoutParams name_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); name.setLayoutParams(name_params); name.setTextColor(Color.GRAY); name.setText(username); body.addView(name); //the message TextView message = new TextView(ExampleActivity.this); LinearLayout.LayoutParams msg_params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); message.setLayoutParams(msg_params); message.setTextColor(Color.WHITE); message.setTextSize(18); message.setText(text); body.addView(message); CheckBox checkbox = new CheckBox(ExampleActivity.this); LinearLayout.LayoutParams box_params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT); box_params.weight = 1; checkbox.setLayoutParams(box_params); cell.addView(checkbox); $.with(ExampleActivity.this, R.id.example_layout).add(cell); //$.with(fimage).image(avatarURL, 200, 200, $.noop()); $.ajax(new AjaxOptions(avatarURL).type("GET").dataType("image").imageHeight(200) .imageWidth(200).global(false).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object, reason Bitmap src = (Bitmap) params[0]; String reason = (String) params[1]; $.with(fimage).val(src); try { $.with(fimage) .fadeIn(new AnimationOptions("{ duration: 400 }")); } catch (Throwable e) { e.printStackTrace(); } LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) fcell .getLayoutParams(); try { lparams.height = Math.min(src.getWidth(), fimage.getWidth()); } catch (Throwable t) { //ignore NPE } fcell.setLayoutParams(lparams); } }).error(new Function() { @Override public void invoke($ droidQuery, Object... params) { //Object error, int status, String reason Object error = params[0]; int status = (Integer) params[1]; String reason = (String) params[2]; Log.w("app.net Client", "Could not complete image request: " + reason); } })); } } else { Log.w("app.net client", "could not update data"); } } catch (Throwable t) { t.printStackTrace(); } } })); }
From source file:org.telegram.ui.TwoStepVerificationActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/*from ww w . j a v a 2 s . c o m*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { processDone(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ActionBarMenu menu = actionBar.createMenu(); doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); scrollView = new ScrollView(context); scrollView.setFillViewport(true); frameLayout.addView(scrollView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) scrollView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; scrollView.setLayoutParams(layoutParams); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); scrollView.addView(linearLayout); ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams(); layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT; layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT; linearLayout.setLayoutParams(layoutParams2); titleTextView = new TextView(context); //titleTextView.setTextColor(0xff757575); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); titleTextView.setGravity(Gravity.CENTER_HORIZONTAL); linearLayout.addView(titleTextView); LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) titleTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = Gravity.CENTER_HORIZONTAL; layoutParams3.topMargin = AndroidUtilities.dp(38); titleTextView.setLayoutParams(layoutParams3); 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); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setTypeface(Typeface.DEFAULT); AndroidUtilities.clearCursorDrawable(passwordEditText); linearLayout.addView(passwordEditText); layoutParams3 = (LinearLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams3.topMargin = AndroidUtilities.dp(32); layoutParams3.height = AndroidUtilities.dp(36); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); layoutParams3.gravity = Gravity.TOP | Gravity.LEFT; layoutParams3.width = LayoutHelper.MATCH_PARENT; passwordEditText.setLayoutParams(layoutParams3); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) { processDone(); return true; } return false; } }); 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; } }); bottomTextView = new TextView(context); //bottomTextView.setTextColor(0xff757575); bottomTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); bottomTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP); bottomTextView.setText(LocaleController.getString("YourEmailInfo", R.string.YourEmailInfo)); linearLayout.addView(bottomTextView); layoutParams3 = (LinearLayout.LayoutParams) bottomTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP; layoutParams3.topMargin = AndroidUtilities.dp(30); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); bottomTextView.setLayoutParams(layoutParams3); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL); linearLayout.addView(linearLayout2); layoutParams3 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = LayoutHelper.MATCH_PARENT; linearLayout2.setLayoutParams(layoutParams3); bottomButton = new TextView(context); bottomButton.setTextColor(0xff4d83b3); bottomButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); bottomButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM); bottomButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip)); bottomButton.setPadding(0, AndroidUtilities.dp(10), 0, 0); linearLayout2.addView(bottomButton); layoutParams3 = (LinearLayout.LayoutParams) bottomButton.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM; layoutParams3.bottomMargin = AndroidUtilities.dp(14); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); bottomButton.setLayoutParams(layoutParams3); bottomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (type == 0) { if (currentPassword.has_recovery) { needShowProgress(); TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { needHideProgress(); if (error == null) { final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response; AlertDialog.Builder builder = new AlertDialog.Builder( getParentActivity()); builder.setMessage(LocaleController.formatString("RestoreEmailSent", R.string.RestoreEmailSent, res.email_pattern)); builder.setTitle( LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity( 1); fragment.currentPassword = currentPassword; fragment.currentPassword.email_unconfirmed_pattern = res.email_pattern; fragment.passwordSetState = 4; presentFragment(fragment); } }); Dialog dialog = showDialog(builder.create()); if (dialog != null) { dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false); } } else { if (error.text.startsWith("FLOOD_WAIT")) { int time = Utilities.parseInt(error.text); String timeString; if (time < 60) { timeString = LocaleController.formatPluralString("Seconds", time); } else { timeString = LocaleController.formatPluralString("Minutes", time / 60); } showAlertWithText( LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString)); } else { showAlertWithText( LocaleController.getString("AppName", R.string.AppName), error.text); } } } }); } }, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin); } else { showAlertWithText( LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle), LocaleController.getString("RestorePasswordNoEmailText", R.string.RestorePasswordNoEmailText)); } } else { if (passwordSetState == 4) { showAlertWithText( LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle), LocaleController.getString("RestoreEmailTroubleText", R.string.RestoreEmailTroubleText)); } else { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("YourEmailSkipWarningText", R.string.YourEmailSkipWarningText)); builder.setTitle( LocaleController.getString("YourEmailSkipWarning", R.string.YourEmailSkipWarning)); builder.setPositiveButton( LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { email = ""; setNewPassword(false); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } } }); if (type == 0) { progressView = new FrameLayout(context); frameLayout.addView(progressView); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; progressView.setLayoutParams(layoutParams); progressView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER; progressView.setLayoutParams(layoutParams); listView = new ListView(context); listView.setDivider(null); listView.setEmptyView(progressView); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); 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 == setPasswordRow || i == changePasswordRow) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1); fragment.currentPasswordHash = currentPasswordHash; fragment.currentPassword = currentPassword; presentFragment(fragment); } else if (i == setRecoveryEmailRow || i == changeRecoveryEmailRow) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1); fragment.currentPasswordHash = currentPasswordHash; fragment.currentPassword = currentPassword; fragment.emailOnly = true; fragment.passwordSetState = 3; presentFragment(fragment); } else if (i == turnPasswordOffRow || i == abortPasswordRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("TurnPasswordOffQuestion", R.string.TurnPasswordOffQuestion)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { setNewPassword(true); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); updateRows(); actionBar.setTitle(LocaleController.getString("TwoStepVerification", R.string.TwoStepVerification)); titleTextView.setText( LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword)); } else if (type == 1) { setPasswordSetState(passwordSetState); } return fragmentView; }
From source file:org.telegram.ui.Components.ShareAlert.java
public ShareAlert(final Context context, MessageObject messageObject, final String text, boolean publicChannel, final String copyLink) { super(context, true); shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow); linkToCopy = copyLink;//from www .j a v a 2 s . co m sendingMessageObject = messageObject; searchAdapter = new ShareSearchAdapter(context); isPublicChannel = publicChannel; sendingText = text; if (publicChannel) { loadingLink = true; TLRPC.TL_channels_exportMessageLink req = new TLRPC.TL_channels_exportMessageLink(); req.id = messageObject.getId(); req.channel = MessagesController.getInputChannel(messageObject.messageOwner.to_id.channel_id); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { if (response != null) { exportedMessageLink = (TLRPC.TL_exportedMessageLink) response; if (copyLinkOnEnd) { copyLink(context); } } loadingLink = false; } }); } }); } containerView = new FrameLayout(context) { private boolean ignoreLayout = false; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent e) { return !isDismissed() && super.onTouchEvent(e); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); if (Build.VERSION.SDK_INT >= 21) { height -= AndroidUtilities.statusBarHeight; } int size = Math.max(searchAdapter.getItemCount(), listAdapter.getItemCount()); int contentSize = AndroidUtilities.dp(48) + Math.max(3, (int) Math.ceil(size / 4.0f)) * AndroidUtilities.dp(100) + backgroundPaddingTop; int padding = contentSize < height ? 0 : height - (height / 5 * 3) + AndroidUtilities.dp(8); if (gridView.getPaddingTop() != padding) { ignoreLayout = true; gridView.setPadding(0, padding, 0, AndroidUtilities.dp(8)); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); updateLayout(); } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected void onDraw(Canvas canvas) { shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } }; containerView.setWillNotDraw(false); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); frameLayout = new FrameLayout(context); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background)); frameLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); doneButton = new LinearLayout(context); doneButton.setOrientation(LinearLayout.HORIZONTAL); doneButton.setBackgroundDrawable( Theme.createBarSelectorDrawable(Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false)); doneButton.setPadding(AndroidUtilities.dp(21), 0, AndroidUtilities.dp(21), 0); frameLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (selectedDialogs.isEmpty() && (isPublicChannel || linkToCopy != null)) { if (linkToCopy == null && loadingLink) { copyLinkOnEnd = true; Toast.makeText(ShareAlert.this.getContext(), LocaleController.getString("Loading", R.string.Loading), Toast.LENGTH_SHORT).show(); } else { copyLink(ShareAlert.this.getContext()); } dismiss(); } else { if (sendingMessageObject != null) { ArrayList<MessageObject> arrayList = new ArrayList<>(); arrayList.add(sendingMessageObject); for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) { SendMessagesHelper.getInstance().sendMessage(arrayList, entry.getKey()); } } else if (sendingText != null) { for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) { SendMessagesHelper.getInstance().sendMessage(sendingText, entry.getKey(), null, null, true, null, null, null); } } dismiss(); } } }); doneButtonBadgeTextView = new TextView(context); doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); doneButtonBadgeTextView.setTextColor(Theme.SHARE_SHEET_BADGE_TEXT_COLOR); doneButtonBadgeTextView.setGravity(Gravity.CENTER); doneButtonBadgeTextView.setBackgroundResource(R.drawable.bluecounter); doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23)); doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); doneButton.addView(doneButtonBadgeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0)); doneButtonTextView = new TextView(context); doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButtonTextView.setGravity(Gravity.CENTER); doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.search_share); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setPadding(0, AndroidUtilities.dp(2), 0, 0); imageView.getDrawable().setTint(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR); frameLayout.addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.CENTER_VERTICAL)); nameTextView = new EditText(context); nameTextView.setHint(LocaleController.getString("ShareSendTo", R.string.ShareSendTo)); nameTextView.setMaxLines(1); nameTextView.setSingleLine(true); nameTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); nameTextView.setBackgroundDrawable(null); nameTextView.setHintTextColor(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR); nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); AndroidUtilities.clearCursorDrawable(nameTextView); nameTextView.setTextColor(Theme.SHARE_SHEET_EDIT_TEXT_COLOR); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 48, 2, 96, 0)); nameTextView.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) { String text = nameTextView.getText().toString(); if (text.length() != 0) { if (gridView.getAdapter() != searchAdapter) { topBeforeSwitch = getCurrentTop(); gridView.setAdapter(searchAdapter); searchAdapter.notifyDataSetChanged(); } if (searchEmptyView != null) { searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult)); } } else { if (gridView.getAdapter() != listAdapter) { int top = getCurrentTop(); searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats)); gridView.setAdapter(listAdapter); listAdapter.notifyDataSetChanged(); if (top > 0) { layoutManager.scrollToPositionWithOffset(0, -top); } } } if (searchAdapter != null) { searchAdapter.searchDialogs(text); } } }); gridView = new RecyclerListView(context); gridView.setTag(13); gridView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); gridView.setClipToPadding(false); gridView.setLayoutManager(layoutManager = new GridLayoutManager(getContext(), 4)); gridView.setHorizontalScrollBarEnabled(false); gridView.setVerticalScrollBarEnabled(false); gridView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { Holder holder = (Holder) parent.getChildViewHolder(view); if (holder != null) { int pos = holder.getAdapterPosition(); outRect.left = pos % 4 == 0 ? 0 : AndroidUtilities.dp(4); outRect.right = pos % 4 == 3 ? 0 : AndroidUtilities.dp(4); } else { outRect.left = AndroidUtilities.dp(4); outRect.right = AndroidUtilities.dp(4); } } }); containerView.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); gridView.setAdapter(listAdapter = new ShareDialogsAdapter(context)); gridView.setGlowColor(0xfff5f6f7); gridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (position < 0) { return; } TLRPC.TL_dialog dialog; if (gridView.getAdapter() == listAdapter) { dialog = listAdapter.getItem(position); } else { dialog = searchAdapter.getItem(position); } if (dialog == null) { return; } ShareDialogCell cell = (ShareDialogCell) view; if (selectedDialogs.containsKey(dialog.id)) { selectedDialogs.remove(dialog.id); cell.setChecked(false, true); } else { selectedDialogs.put(dialog.id, dialog); cell.setChecked(true, true); } updateSelectedCount(); } }); gridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateLayout(); } }); searchEmptyView = new EmptyTextProgressView(context); searchEmptyView.setShowAtCenter(true); searchEmptyView.showTextView(); searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats)); gridView.setEmptyView(searchEmptyView); containerView.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); containerView.addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow); containerView.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); updateSelectedCount(); if (!DialogsActivity.dialogsLoaded) { MessagesController.getInstance().loadDialogs(0, 100, true); ContactsController.getInstance().checkInviteText(); DialogsActivity.dialogsLoaded = true; } if (listAdapter.dialogs.isEmpty()) { NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload); } }
From source file:com.vuze.android.remote.AndroidUtilsUI.java
public static AlertDialog.Builder createTextBoxDialog(Context context, int newtag_title, int newtag_hint, final OnTextBoxDialogClick onClickListener) { AlertDialog.Builder builder = new AlertDialog.Builder(context); FrameLayout container = new FrameLayout(context); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_VERTICAL; container.setMinimumHeight(AndroidUtilsUI.dpToPx(100)); int padding = AndroidUtilsUI.dpToPx(20); params.leftMargin = padding;/*from w w w. ja v a 2 s . c o m*/ params.rightMargin = padding; final MaterialEditText textView = AndroidUtilsUI.createFancyTextView(context); textView.setHint(newtag_hint); textView.setFloatingLabelText(context.getResources().getString(newtag_hint)); textView.setSingleLine(); textView.setLayoutParams(params); container.addView(textView); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { builder.setInverseBackgroundForced(true); } builder.setView(container); builder.setTitle(newtag_title); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { onClickListener.onClick(dialog, which, textView); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); return builder; }
From source file:com.cooltechworks.views.ScratchTextView.java
private int[] getTextBounds(float scale) { int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); int vwidth = getWidth(); int vheight = getHeight(); int centerX = vwidth / 2; int centerY = vheight / 2; TextPaint paint = getPaint();//from w w w . ja va 2 s . c o m String text = getText().toString(); int[] dimens = getTextDimens(text, paint); int width = dimens[0]; int height = dimens[1]; int lines = getLineCount(); height = height * lines; width = width / lines; int left = 0; int top = 0; if (height > vheight) { height = vheight - (paddingBottom + paddingTop); } else { height = (int) (height * scale); } if (width > vwidth) { width = vwidth - (paddingLeft + paddingRight); } else { width = (int) (width * scale); } int gravity = getGravity(); //todo Gravity.START if ((gravity & Gravity.LEFT) == Gravity.LEFT) { left = paddingLeft; } //todo Gravity.END else if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) { left = (vwidth - paddingRight) - width; } else if ((gravity & Gravity.CENTER_HORIZONTAL) == Gravity.CENTER_HORIZONTAL) { left = centerX - width / 2; } if ((gravity & Gravity.TOP) == Gravity.TOP) { top = paddingTop; } else if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { top = (vheight - paddingBottom) - height; } else if ((gravity & Gravity.CENTER_VERTICAL) == Gravity.CENTER_VERTICAL) { top = centerY - height / 2; } return new int[] { left, top, left + width, top + height }; }
From source file:net.mypapit.mobile.callsignview.MainActivity.java
private void showToast(String message) { Context context = getApplicationContext(); LayoutInflater inflater = getLayoutInflater(); View customToastroot = inflater.inflate(R.layout.custom_toast, null); TextView tvToast = (TextView) customToastroot.findViewById(R.id.tvToast); tvToast.setText(message);// w ww .jav a 2 s. c o m Toast customtoast = new Toast(context); customtoast.setView(customToastroot); customtoast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0); customtoast.setDuration(Toast.LENGTH_SHORT); customtoast.show(); }
From source file:com.mattprecious.prioritysms.activity.ProfileListActivity.java
private void configureActionBar() { actionBarSwitch = new Switch(this, null, R.attr.switchStyleAb); actionBarSwitch.setChecked(preferences.getBoolean(getString(R.string.pref_key_enabled), false)); actionBarSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override/*from ww w .j a va 2s. c o m*/ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { preferences.edit().putBoolean(getString(R.string.pref_key_enabled), isChecked).commit(); } }); final int padding = getResources().getDimensionPixelSize(R.dimen.action_bar_switch_padding); actionBarSwitch.setPadding(0, 0, padding, 0); getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT)); }