List of usage examples for android.view View TEXT_ALIGNMENT_CENTER
int TEXT_ALIGNMENT_CENTER
To view the source code for android.view View TEXT_ALIGNMENT_CENTER.
Click Source Link
From source file:org.mozilla.focus.utils.ViewUtils.java
/** * Create a snackbar with Focus branding (See #193). *//*w w w . j a va2 s . c om*/ public static void showBrandedSnackbar(View view, @StringRes int resId, int delayMillis) { final Context context = view.getContext(); final Snackbar snackbar = Snackbar.make(view, resId, Snackbar.LENGTH_LONG); final View snackbarView = snackbar.getView(); snackbarView.setBackgroundColor(ContextCompat.getColor(context, R.color.snackbarBackground)); final TextView snackbarTextView = (TextView) snackbarView .findViewById(android.support.design.R.id.snackbar_text); snackbarTextView.setTextColor(ContextCompat.getColor(context, R.color.snackbarTextColor)); snackbarTextView.setGravity(Gravity.CENTER); snackbarTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); view.postDelayed(new Runnable() { @Override public void run() { snackbar.show(); } }, delayMillis); }
From source file:com.wubydax.dbeditor.TableValuesFragment.java
private void showDialog(final String key, final String value, final int position) { @SuppressLint("InflateParams") View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_layout, null, false); TextView keyText = (TextView) view.findViewById(R.id.textKey); final EditText editText = (EditText) view.findViewById(R.id.valueEditText); final ScrollView scroll = (ScrollView) view.findViewById(R.id.ScrollView1); if (value.matches("\\d+(?:\\.\\d+)?")) { editText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); editText.setSingleLine(true);/*from w w w.j a va2 s .c o m*/ } else { editText.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); editText.setHint(getResources().getString(R.string.enter_string)); } keyText.setText(key); editText.setText(value); editText.setSelection(editText.getText().length()); scroll.post(new Runnable() { @Override public void run() { scroll.fullScroll(View.FOCUS_DOWN); } }); new AlertDialog.Builder(getActivity()).setTitle(getResources().getString(R.string.change_value)) .setView(view).setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newValue = editText.getText().toString(); boolean isGranted = Settings.System.canWrite(getActivity()); if (!isGranted) { Intent grantPermission = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); startActivity(grantPermission); } else { switch (mTableName) { case "system": Settings.System.putString(getActivity().getContentResolver(), key, newValue); break; case "global": Settings.Global.putString(getActivity().getContentResolver(), key, newValue); break; case "secure": Settings.Secure.putString(getActivity().getContentResolver(), key, newValue); break; } mList.get(position).value = newValue; } mRecyclerView.getAdapter().notifyDataSetChanged(); } }).show(); }
From source file:com.novemser.voicetest.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.activity_template); initView();// w ww .java 2 s. com //test.db? db = openOrCreateDatabase("alarm.db", Context.MODE_PRIVATE, null); mAdapter = new ListMessageAdapter(this, mDatas); mChatView.setAdapter(mAdapter); packageManager = getPackageManager(); // Context BaseAction.context = getApplicationContext(); SpeechUtility.createUtility(getApplicationContext(), SpeechConstant.APPID + "=573d5744"); //1.RecognizerDialog mDialog = new RecognizerDialog(this, null); mIat = SpeechRecognizer.createRecognizer(getApplicationContext(), null); //2.accent? language? mDialog.setParameter(SpeechConstant.LANGUAGE, "zh_cn"); mDialog.setParameter(SpeechConstant.ACCENT, "mandarin"); //?UI???onResult? // // mDialog.setParameter("asr_sch", "1"); // mDialog.setParameter("nlp_version", "2.0"); //3.? mDialog.setListener(new RecognizerDialogListener() { @Override public void onResult(RecognizerResult recognizerResult, boolean b) { Log.d("VoiceResult", recognizerResult.getResultString()); printResult(recognizerResult); } @Override public void onError(SpeechError speechError) { } }); // 4. mStartVoiceRecord.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //dialog mDialog.show(); } }); // ?TTS initTTS(); // 5.?? understander = TextUnderstander.createTextUnderstander(this, null); // 6.??? SharedPreferences sharedPreferences = getSharedPreferences("user", MODE_PRIVATE); if (!sharedPreferences.getBoolean("isContactUploaded", false)) { SharedPreferences.Editor editor = sharedPreferences.edit(); ContactManager manager = ContactManager.createManager(this, contactListener); manager.asyncQueryAllContactsName(); editor.putBoolean("isContactUploaded", true); editor.apply(); } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.title_toolbar)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { toolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); } setSupportActionBar(toolbar); DrawerLayout 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(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); new Thread(new Runnable() { /** * ? */ @Override public void run() { //? Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveInfoList = packageManager.queryIntentActivities(mainIntent, 0); //??? Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(packageManager)); for (ResolveInfo res : resolveInfoList) { String pkg = res.activityInfo.packageName; String cls = res.activityInfo.name; String name = res.loadLabel(packageManager).toString(); Log.d("ApplicationInfo:", "Pkg:" + pkg + " Class:" + cls + " Name:" + name); } } }).start(); // ? mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); }
From source file:it.unime.mobility4ckan.MainActivity.java
private void setDatasetName() { DinamicView dinamicView = new DinamicView(getApplicationContext()); dinamicView.getNoteLabel().setText(getString(R.string.note_dialog)); dinamicView.getNoteLabel().setTextSize(12); nameText = new EditText(getApplicationContext()); nameText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); nameText.setGravity(Gravity.CENTER); nameText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); nameText.setTextColor(Color.BLACK); nameText.setSingleLine(true);//from w w w . j a va2s. c om nameText.setTextSize(18); dinamicView.getBodyLayout().addView(nameText); final AlertDialog mDialog = new AlertDialog.Builder(this) .setMessage(getString(R.string.inserisci_nome_dataset)).setView(dinamicView).setCancelable(false) .setPositiveButton("OK", null).create(); mDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = mDialog.getButton(AlertDialog.BUTTON_POSITIVE); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { datasetName = nameText.getText().toString().trim().toLowerCase(); String regexp = "^[a-z-0-9_]*$"; Matcher matcher = Pattern.compile(regexp).matcher(datasetName); if (matcher.find()) { mDialog.dismiss(); datasetNameText.setText(datasetName); startTimer(); } else { nameText.getText().clear(); nameText.setError(getString(R.string.note_dialog)); } } }); } }); mDialog.show(); }
From source file:com.facebook.litho.widget.TextSpec.java
private static Alignment getAlignment(int viewTextAlignment, int gravity) { final Alignment alignment; switch (viewTextAlignment) { case View.TEXT_ALIGNMENT_GRAVITY: alignment = getAlignment(gravity); break;// ww w . ja v a 2s . co m case View.TEXT_ALIGNMENT_TEXT_START: alignment = ALIGN_NORMAL; break; case View.TEXT_ALIGNMENT_TEXT_END: alignment = ALIGN_OPPOSITE; break; case View.TEXT_ALIGNMENT_CENTER: alignment = ALIGN_CENTER; break; case View.TEXT_ALIGNMENT_VIEW_START: // unsupported, default to normal alignment = ALIGN_NORMAL; break; case View.TEXT_ALIGNMENT_VIEW_END: // unsupported, default to opposite alignment = ALIGN_OPPOSITE; break; case View.TEXT_ALIGNMENT_INHERIT: // unsupported, default to gravity alignment = getAlignment(gravity); break; default: alignment = textAlignment; break; } return alignment; }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
public static void createViewRunnables() { viewRunnables = new HashMap<>(30); viewRunnables.put("scaleType", new ViewParamRunnable() { @Override//w w w.ja v a 2s . co m public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof ImageView) { ImageView.ScaleType scaleType = ((ImageView) view).getScaleType(); switch (value.toLowerCase()) { case "center": scaleType = ImageView.ScaleType.CENTER; break; case "center_crop": scaleType = ImageView.ScaleType.CENTER_CROP; break; case "center_inside": scaleType = ImageView.ScaleType.CENTER_INSIDE; break; case "fit_center": scaleType = ImageView.ScaleType.FIT_CENTER; break; case "fit_end": scaleType = ImageView.ScaleType.FIT_END; break; case "fit_start": scaleType = ImageView.ScaleType.FIT_START; break; case "fit_xy": scaleType = ImageView.ScaleType.FIT_XY; break; case "matrix": scaleType = ImageView.ScaleType.MATRIX; break; } ((ImageView) view).setScaleType(scaleType); } } }); viewRunnables.put("orientation", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof LinearLayout) { ((LinearLayout) view).setOrientation( value.equals("vertical") ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL); } } }); viewRunnables.put("text", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setText(value); } } }); viewRunnables.put("textSize", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, DimensionConverter.stringToDimension(value, view.getResources().getDisplayMetrics())); } } }); viewRunnables.put("textColor", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setTextColor(parseColor(view, value)); } } }); viewRunnables.put("textStyle", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { int typeFace = Typeface.NORMAL; if (value.contains("bold")) typeFace |= Typeface.BOLD; else if (value.contains("italic")) typeFace |= Typeface.ITALIC; ((TextView) view).setTypeface(null, typeFace); } } }); viewRunnables.put("textAlignment", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { int alignment = View.TEXT_ALIGNMENT_TEXT_START; switch (value) { case "center": alignment = View.TEXT_ALIGNMENT_CENTER; break; case "left": case "textStart": break; case "right": case "textEnd": alignment = View.TEXT_ALIGNMENT_TEXT_END; break; } view.setTextAlignment(alignment); } else { int gravity = Gravity.LEFT; switch (value) { case "center": gravity = Gravity.CENTER; break; case "left": case "textStart": break; case "right": case "textEnd": gravity = Gravity.RIGHT; break; } ((TextView) view).setGravity(gravity); } } }); viewRunnables.put("ellipsize", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { TextUtils.TruncateAt where = TextUtils.TruncateAt.END; switch (value) { case "start": where = TextUtils.TruncateAt.START; break; case "middle": where = TextUtils.TruncateAt.MIDDLE; break; case "marquee": where = TextUtils.TruncateAt.MARQUEE; break; case "end": break; } ((TextView) view).setEllipsize(where); } } }); viewRunnables.put("singleLine", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { ((TextView) view).setSingleLine(); } } }); viewRunnables.put("hint", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof EditText) { ((EditText) view).setHint(value); } } }); viewRunnables.put("inputType", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof TextView) { int inputType = 0; switch (value) { case "textEmailAddress": inputType |= InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS; break; case "number": inputType |= InputType.TYPE_CLASS_NUMBER; break; case "phone": inputType |= InputType.TYPE_CLASS_PHONE; break; } if (inputType > 0) ((TextView) view).setInputType(inputType); } } }); viewRunnables.put("gravity", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { int gravity = parseGravity(value); if (view instanceof TextView) { ((TextView) view).setGravity(gravity); } else if (view instanceof LinearLayout) { ((LinearLayout) view).setGravity(gravity); } else if (view instanceof RelativeLayout) { ((RelativeLayout) view).setGravity(gravity); } } }); viewRunnables.put("src", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { if (view instanceof ImageView) { String imageName = value; if (imageName.startsWith("//")) imageName = "http:" + imageName; if (imageName.startsWith("http")) { if (imageLoader != null) { if (attrs.containsKey("cornerRadius")) { int radius = DimensionConverter.stringToDimensionPixelSize( attrs.get("cornerRadius"), view.getResources().getDisplayMetrics()); imageLoader.loadRoundedImage((ImageView) view, imageName, radius); } else { imageLoader.loadImage((ImageView) view, imageName); } } } else if (imageName.startsWith("@drawable/")) { imageName = imageName.substring("@drawable/".length()); ((ImageView) view).setImageDrawable(getDrawableByName(view, imageName)); } } } }); viewRunnables.put("visibility", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { int visibility = View.VISIBLE; String visValue = value.toLowerCase(); if (visValue.equals("gone")) visibility = View.GONE; else if (visValue.equals("invisible")) visibility = View.INVISIBLE; view.setVisibility(visibility); } }); viewRunnables.put("clickable", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { view.setClickable(value.equals("true")); } }); viewRunnables.put("tag", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { // Sigh, this is dangerous because we use tags for other purposes if (view.getTag() == null) view.setTag(value); } }); viewRunnables.put("onClick", new ViewParamRunnable() { @Override public void apply(View view, String value, ViewGroup parent, Map<String, String> attrs) { view.setOnClickListener(getClickListener(parent, value)); } }); }
From source file:plugin.google.maps.GoogleMaps.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override/*from w w w. java 2s. com*/ public View getInfoContents(Marker marker) { String title = marker.getTitle(); String snippet = marker.getSnippet(); if ((title == null) && (snippet == null)) { return null; } JSONObject properties = null; JSONObject styles = null; String propertyId = "marker_property_" + marker.getId(); PluginEntry pluginEntry = this.plugins.get("Marker"); PluginMarker pluginMarker = (PluginMarker) pluginEntry.plugin; if (pluginMarker.objects.containsKey(propertyId)) { properties = (JSONObject) pluginMarker.objects.get(propertyId); if (properties.has("styles")) { try { styles = (JSONObject) properties.getJSONObject("styles"); } catch (JSONException e) { } } } // Linear layout LinearLayout windowLayer = new LinearLayout(activity); windowLayer.setPadding(3, 3, 3, 3); windowLayer.setOrientation(LinearLayout.VERTICAL); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER; windowLayer.setLayoutParams(layoutParams); //---------------------------------------- // text-align = left | center | right //---------------------------------------- int gravity = Gravity.LEFT; int textAlignment = View.TEXT_ALIGNMENT_GRAVITY; if (styles != null) { try { String textAlignValue = styles.getString("text-align"); switch (TEXT_STYLE_ALIGNMENTS.valueOf(textAlignValue)) { case left: gravity = Gravity.LEFT; textAlignment = View.TEXT_ALIGNMENT_GRAVITY; break; case center: gravity = Gravity.CENTER; textAlignment = View.TEXT_ALIGNMENT_CENTER; break; case right: gravity = Gravity.RIGHT; textAlignment = View.TEXT_ALIGNMENT_VIEW_END; break; } } catch (Exception e) { } } if (title != null) { if (title.indexOf("data:image/") > -1 && title.indexOf(";base64,") > -1) { String[] tmp = title.split(","); Bitmap image = PluginUtil.getBitmapFromBase64encodedImage(tmp[1]); image = PluginUtil.scaleBitmapForDevice(image); ImageView imageView = new ImageView(this.cordova.getActivity()); imageView.setImageBitmap(image); windowLayer.addView(imageView); } else { TextView textView = new TextView(this.cordova.getActivity()); textView.setText(title); textView.setSingleLine(false); int titleColor = Color.BLACK; if (styles != null && styles.has("color")) { try { titleColor = PluginUtil.parsePluginColor(styles.getJSONArray("color")); } catch (JSONException e) { } } textView.setTextColor(titleColor); textView.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setTextAlignment(textAlignment); } //---------------------------------------- // font-style = normal | italic // font-weight = normal | bold //---------------------------------------- int fontStyle = Typeface.NORMAL; if (styles != null) { try { if ("italic".equals(styles.getString("font-style"))) { fontStyle = Typeface.ITALIC; } } catch (JSONException e) { } try { if ("bold".equals(styles.getString("font-weight"))) { fontStyle = fontStyle | Typeface.BOLD; } } catch (JSONException e) { } } textView.setTypeface(Typeface.DEFAULT, fontStyle); windowLayer.addView(textView); } } if (snippet != null) { //snippet = snippet.replaceAll("\n", ""); TextView textView2 = new TextView(this.cordova.getActivity()); textView2.setText(snippet); textView2.setTextColor(Color.GRAY); textView2.setTextSize((textView2.getTextSize() / 6 * 5) / density); textView2.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView2.setTextAlignment(textAlignment); } windowLayer.addView(textView2); } return windowLayer; }