List of usage examples for android.widget TextView TextView
public TextView(Context context)
From source file:com.shengtao.chat.chatUI.adapter.MessageAdapter.java
private void setRobotMenuMessageLayout(LinearLayout parentView, JSONArray jsonArr) { try {//from ww w .jav a2 s . com parentView.removeAllViews(); for (int i = 0; i < jsonArr.length(); i++) { final String itemStr = jsonArr.getString(i); final TextView textView = new TextView(context); textView.setText(itemStr); textView.setTextSize(15); try { XmlPullParser xrp = context.getResources().getXml(drawable.menu_msg_text_color); textView.setTextColor(ColorStateList.createFromXml(context.getResources(), xrp)); } catch (Exception e) { e.printStackTrace(); } textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((ChatActivity) context).sendText(itemStr); } }); LinearLayout.LayoutParams llLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); llLp.bottomMargin = DensityUtil.dip2px(context, 3); llLp.topMargin = DensityUtil.dip2px(context, 3); parentView.addView(textView, llLp); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.apps.gator.DisplayTranslationActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ServiceUtility serviceUtility = new ServiceUtility(); // retrieve the shared preferences file which has stored the radio // buttons state information. final SharedPreferences prefs = this.getSharedPreferences(MainActivity.PREFS_NAME, Context.MODE_PRIVATE); // Get the message from the intent final Intent intent = getIntent(); final String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); // Create the text view final TextView textView = new TextView(this); textView.setTextSize(20);// w w w .j av a2 s . co m // Logic to determine if the user selected to translate from English to // Malayalam or Malayalam to English. if (prefs.getBoolean(MainActivity.RADIO_BUTTON_MALAYALAM, false)) { final Translator translator = Translator.Factory.create(TranslateType.ENGLISH_TO_MALAYALAM); final TranslatorResponse response = translator.translate(message); switch (response.getLookupResponseMap().size()) { case 0: textView.setText(response.getLookupResponse()); break; default: final StringBuilder stringBuilder = serviceUtility.buildIndividualLookupResponse(response); textView.setText(stringBuilder); break; } } else if (prefs.getBoolean(MainActivity.RADIO_BUTTON_ENGLISH, false)) { final Translator translator = Translator.Factory.create(TranslateType.MALAYALM_TO_ENGLISH); final TranslatorResponse response = translator.translate(message); switch (response.getLookupResponseMap().size()) { case 0: textView.setText(response.getLookupResponse()); break; default: final StringBuilder stringBuilder = serviceUtility.buildIndividualLookupResponse(response); textView.setText(stringBuilder); break; } } // Fall back logic to make sure the User experience is not // affected. else { textView.setText( "Please select if you would like to translate to Malayalam or English on the Home View"); } // Set the text view as the activity layout setContentView(textView); }
From source file:com.citrus.sample.WalletPaymentFragment.java
void showTokenizedPrompt() { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); final String message = "Auto Load Money with Saved Card"; String positiveButtonText = "Auto Load"; LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final TextView labelamt = new TextView(getActivity()); final EditText editAmount = new EditText(getActivity()); final TextView labelAmount = new TextView(getActivity()); final EditText editLoadAmount = new EditText(getActivity()); final TextView labelMobileNo = new TextView(getActivity()); final EditText editThresholdAmount = new EditText(getActivity()); final Button btnSelectSavedCards = new Button(getActivity()); btnSelectSavedCards.setText("Select Saved Card"); editLoadAmount.setSingleLine(true);//from ww w . j a va 2 s.c om editThresholdAmount.setSingleLine(true); editAmount.setSingleLine(true); labelamt.setText("Load Amount"); labelAmount.setText("Auto Load Amount"); labelMobileNo.setText("Threshold Amount"); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); labelamt.setLayoutParams(layoutParams); editAmount.setLayoutParams(layoutParams); labelAmount.setLayoutParams(layoutParams); labelMobileNo.setLayoutParams(layoutParams); editLoadAmount.setLayoutParams(layoutParams); editThresholdAmount.setLayoutParams(layoutParams); btnSelectSavedCards.setLayoutParams(layoutParams); btnSelectSavedCards.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCitrusClient.getWallet(new Callback<List<PaymentOption>>() { @Override public void success(List<PaymentOption> paymentOptions) { walletList.clear(); for (PaymentOption paymentOption : paymentOptions) { if (paymentOption instanceof CreditCardOption) { if (Arrays.asList(AUTO_LOAD_CARD_SCHEMS) .contains(((CardOption) paymentOption).getCardScheme().toString())) walletList.add(paymentOption); //only available for Master and Visa Credit Card.... } } savedOptionsAdapter = new SavedOptionsAdapter(getActivity(), walletList); showSavedAccountsDialog(); } @Override public void error(CitrusError error) { Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show(); } }); } }); linearLayout.addView(labelamt); linearLayout.addView(editAmount); linearLayout.addView(labelAmount); linearLayout.addView(editLoadAmount); linearLayout.addView(labelMobileNo); linearLayout.addView(editThresholdAmount); linearLayout.addView(btnSelectSavedCards); int paddingPx = Utils.getSizeInPx(getActivity(), 32); linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); editLoadAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); editThresholdAmount.setInputType(InputType.TYPE_CLASS_NUMBER); alert.setTitle("Auto Load Money with Saved Card"); alert.setMessage(message); alert.setView(linearLayout); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { final String amount = editAmount.getText().toString(); final String loadAmount = editLoadAmount.getText().toString(); final String thresHoldAmount = editThresholdAmount.getText().toString(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0); if (TextUtils.isEmpty(amount)) { Toast.makeText(getActivity(), "Amount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(loadAmount)) { Toast.makeText(getActivity(), "Load Amount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(thresHoldAmount)) { Toast.makeText(getActivity(), "thresHoldAmount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(thresHoldAmount) < new Double("500")) { Toast.makeText(getActivity(), "thresHoldAmount should not be less than 500", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(loadAmount) < new Double(thresHoldAmount)) { Toast.makeText(getActivity(), "Load Amount should not be less than thresHoldAmount", Toast.LENGTH_SHORT).show(); return; } if (otherPaymentOption == null) { Toast.makeText(getActivity(), "Saved Card Option is null.", Toast.LENGTH_SHORT).show(); } try { PaymentType paymentType = new PaymentType.LoadMoney(new Amount(amount), otherPaymentOption); mCitrusClient.autoLoadMoney((PaymentType.LoadMoney) paymentType, new Amount(thresHoldAmount), new Amount(loadAmount), new Callback<SubscriptionResponse>() { @Override public void success(SubscriptionResponse subscriptionResponse) { Logger.d("AUTO LOAD RESPONSE ***" + subscriptionResponse.getSubscriptionResponseMessage()); Toast.makeText(getActivity(), subscriptionResponse.getSubscriptionResponseMessage(), Toast.LENGTH_SHORT).show(); } @Override public void error(CitrusError error) { Logger.d("AUTO LOAD ERROR ***" + error.getMessage()); Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show(); } }); } catch (CitrusException e) { e.printStackTrace(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); editLoadAmount.requestFocus(); alert.show(); }
From source file:com.example.SmartBoard.DrawingView.java
public Bitmap textToBitmap(String text, int color, float posX, float posY, int size) { TextView textView = new TextView(getContext()); textView.setVisibility(View.VISIBLE); textView.setTextColor(color);//from w w w . j a v a 2 s .c om textView.setMaxWidth(500); textView.setMaxHeight(500); textView.setMaxLines(4); textView.setX(posX); textView.setY(posY); textView.setText(text); textView.setTextSize(size); LinearLayout layout = new LinearLayout(getContext()); layout.addView(textView); layout.measure(500, 500); layout.layout(0, 0, 500, 500); textView.setDrawingCacheEnabled(true); textView.buildDrawingCache(); Bitmap bm = textView.getDrawingCache(); return bm; }
From source file:com.example.drugsformarinemammals.Dose_Information.java
private void displayMessage(String messageTitle, String message) { AlertDialog.Builder myalert = new AlertDialog.Builder(this); TextView title = new TextView(this); title.setTypeface(Typeface.SANS_SERIF); title.setTextSize(20);/*from w ww . ja v a2 s . c o m*/ title.setTextColor(getResources().getColor(R.color.blue)); title.setPadding(8, 8, 8, 8); title.setText("Synchronization"); title.setGravity(Gravity.CENTER_VERTICAL); LinearLayout layout = new LinearLayout(this); TextView text = new TextView(this); text.setTypeface(Typeface.SANS_SERIF); text.setTextSize(20); text.setPadding(10, 10, 10, 10); text.setText(message); layout.addView(text); myalert.setView(layout); myalert.setCustomTitle(title); myalert.setCancelable(true); myalert.show(); }
From source file:com.android.contacts.common.list.ContactListItemView.java
/** * Sets section header or makes it invisible if the title is null. *///from w ww .ja va2 s. c o m public void setSectionHeader(String title) { if (!TextUtils.isEmpty(title)) { if (mHeaderTextView == null) { mHeaderTextView = new TextView(getContext()); mHeaderTextView.setTextAppearance(getContext(), R.style.SectionHeaderStyle); mHeaderTextView.setGravity(ViewUtil.isViewLayoutRtl(this) ? Gravity.RIGHT : Gravity.LEFT); addView(mHeaderTextView); } setMarqueeText(mHeaderTextView, title); mHeaderTextView.setVisibility(View.VISIBLE); mHeaderTextView.setAllCaps(true); } else if (mHeaderTextView != null) { mHeaderTextView.setVisibility(View.GONE); } }
From source file:com.sdspikes.fireworks.FireworksActivity.java
private TextView makeAttributeTextView(final int rank, final GameState.CardColor color) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); int oneButtonWidth = mDiscardWidthR2 / 10; int marginWidth = oneButtonWidth / 10; params.setMargins(marginWidth, 5, marginWidth, 5); params.width = oneButtonWidth - marginWidth * 2; params.height = params.width;//from w w w . java 2s. c o m TextView textView = new TextView(this); textView.setLayoutParams(params); textView.setText(String.valueOf(rank)); if (rank == -1) textView.setText(" "); textView.setGravity(Gravity.CENTER); textView.setBackgroundResource(HandFragment.cardColorToBGColor.get(color)); textView.setTextColor(getResources().getColor(HandFragment.cardColorToTextColor(color))); textView.setVisibility(View.VISIBLE); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "clicked on an attribute button: " + GameState.Card.cardColorToString(color) + " " + rank); List<GameState.Card> hand = mTurnData.state.hands.get(mRecipientPlayer).hand; List<Integer> locations = new ArrayList<Integer>(); String info = ""; if (rank == -1) { info = GameState.Card.cardColorToString(color); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).color == color) locations.add(i); } } else { info = HandFragment.rankToString(rank); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).rank == rank) locations.add(i); } } if (locations.size() == 0) { Toast.makeText(FireworksActivity.this, mIdToName.get(mRecipientPlayer) + " does not have any " + info, Toast.LENGTH_SHORT); } else { int[] positions = new int[locations.size()]; for (int i = 0; i < positions.length; i++) { // Make the positions 1-indexed positions[i] = locations.get(i) + 1; } LogItem item = new InfoLogItem(mMyId, mRecipientPlayer, info, positions); actionLog.add(item.toString()); mTurnData.state.hintsRemaining--; mTurnData.state.currentPlayerId = mTurnData.state.hands .get(mTurnData.state.currentPlayerId).nextPlayerId; togglePlayOptionsVisible(PlayOptions.turnMessage); broadcastGameInfo(item.getJSONObject()); updateAllPlayers(mTurnData.getJSONObject()); mRecipientPlayer = null; } } }); return textView; }
From source file:nf.frex.android.FrexActivity.java
public static void showYesNoDialog(Context context, int titleId, String message, DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener, DialogInterface.OnCancelListener cancelListener) { TextView textView = new TextView(context); textView.setSingleLine(false);/* w w w .j a v a2 s . c om*/ textView.setPadding(10, 10, 10, 10); textView.setText(message); AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle(titleId); b.setView(textView); b.setCancelable(true); if (yesListener != null) { b.setPositiveButton(android.R.string.yes, yesListener); } if (noListener != null) { b.setNegativeButton(android.R.string.no, noListener); } if (cancelListener != null) { b.setOnCancelListener(cancelListener); } b.show(); }
From source file:com.android.contacts.list.ContactListItemView.java
private void addTextHeader(String title) { mHeaderView = new TextView(getContext()); final TextView headerTextView = (TextView) mHeaderView; headerTextView.setTextAppearance(getContext(), R.style.SectionHeaderStyle); headerTextView.setGravity(Gravity.CENTER_HORIZONTAL); updateHeaderText(headerTextView, title); addView(headerTextView);/*w ww . j a v a2s .co m*/ }
From source file:com.gizwits.smartlight.activity.MainListActivity.java
/** * Inits the views.//from ww w . j av a 2 s .c om */ private void initViews() { mView = (SlidingMenu) findViewById(R.id.main_layout); llFooter = (LinearLayout) findViewById(R.id.llFooter); alpha_bg = (Button) findViewById(R.id.black_alpha_bg); tvLName = (TextView) findViewById(R.id.show_led_name); tvSceneName = (TextView) findViewById(R.id.show_scene_name); tvEditSceneName = (EditText) findViewById(R.id.scene_name); //etGroup = (ImageView) findViewById(R.id.edit_group); llBottom = (LinearLayout) findViewById(R.id.llBottom); ivMenu = (ImageView) findViewById(R.id.ivMenu); tvTitle = (TextView) findViewById(R.id.tvTitle); ivEdit = (ImageView) findViewById(R.id.ivEdit); ivEdit.setTag("1"); sclContent = (RefreshableListView) findViewById(R.id.sclContent); btnSwitch = (TextView) findViewById(R.id.btnSwitch); sbLightness = (SeekBar) findViewById(R.id.sbLightness); sbSaturation = (SeekBar) findViewById(R.id.sbSaturation); sbColor = (ColorSelectSeekBar) findViewById(R.id.sbcolor); addSceneButton = (Button) findViewById(R.id.btn_addscene); sceneLayout = (RelativeLayout) findViewById(R.id.relativeLayout2); //sceneRemove = (ImageView) findViewById(R.id.scene_remove); iftttButton = (Button) findViewById(R.id.ifttt); screenWidth = getWindowManager().getDefaultDisplay().getWidth(); //For lightness text_light = new TextView(this); text_light.setBackgroundColor(Color.rgb(254, 254, 254)); text_light.setTextColor(Color.rgb(0, 161, 229)); text_light.setTextSize(12); layoutParams_light = new ViewGroup.LayoutParams(screenWidth, 50); textMoveLayout = (TextMoveLayout) findViewById(R.id.textLayout1); textMoveLayout.addView(text_light, layoutParams_light); text_light.layout(0, 20, screenWidth, 40); //For hue text_hue = new TextView(this); text_hue.setBackgroundColor(Color.rgb(254, 254, 254)); text_hue.setTextColor(Color.rgb(0, 161, 229)); text_hue.setTextSize(12); layoutParams_hue = new ViewGroup.LayoutParams(screenWidth, 50); textMoveLayout = (TextMoveLayout) findViewById(R.id.textLayout2); textMoveLayout.addView(text_hue, layoutParams_hue); text_hue.layout(0, 20, screenWidth, 40); //For saturation text_saturation = new TextView(this); text_saturation.setBackgroundColor(Color.rgb(254, 254, 254)); text_saturation.setTextColor(Color.rgb(0, 161, 229)); text_saturation.setTextSize(12); layoutParams_saturation = new ViewGroup.LayoutParams(screenWidth, 50); textMoveLayout = (TextMoveLayout) findViewById(R.id.textLayout3); textMoveLayout.addView(text_saturation, layoutParams_saturation); text_saturation.layout(0, 20, screenWidth, 40); mAdapter = new MenuDeviceAdapter(this, bindlist); lvDevice = (ListView) findViewById(R.id.lvDevice); lvDevice.setAdapter(mAdapter); progressDialog = new ProgressDialog(MainListActivity.this); progressDialog.setCancelable(false); progressDialog.setMessage("Device connecting,waiting....."); mSceneAdapter = new ItemListBaseAdapter(this, R.layout.list_scene, scene_details); sceneListView = (ListView) findViewById(R.id.listView_Scene); sceneListView.setAdapter(mSceneAdapter); }