List of usage examples for android.widget TextView TextView
public TextView(Context context)
From source file:com.team1.soccerplayers.layout.PlayerInfoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check whether we're recreating a previously destroyed instance if (savedInstanceState != null) { // Restore value of members from saved state playerName = savedInstanceState.getString(STATE_PLAYER); } else {// w ww.ja v a 2s . com // Probably initialize members with default values for a new instance setContentView(R.layout.activity_player_info); Intent intent = getIntent(); playerName = intent.getStringExtra(DisplayFavoritePlayersActivity.EXTRA_MESSAGE); } if (playerName.contains(" ")) { firstName = playerName.split(" "); } if (playerName.contains(" ")) { APILink = "https://api.datamarket.azure.com/Bing/Search/v1/News?Query=%27" + firstName[0].trim() + "%20" + firstName[1].trim() + "%20%27&$format=json"; } else { APILink = "https://api.datamarket.azure.com/Bing/Search/v1/News?Query=%27" + playerName + "%20%27&$format=json"; } //Toast.makeText(PlayerInfoActivity.this, "resrult: " + playerName, Toast.LENGTH_SHORT).show(); ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { DownloadTask downloadTask = new DownloadTask(); downloadTask.execute(); } else { Toast.makeText(PlayerInfoActivity.this, "Unable to Connect to the server, Please try later.", Toast.LENGTH_SHORT).show(); } infoListView = (ListView) findViewById(android.R.id.list); final TextView title1 = new TextView(this); final TextView summary1 = new TextView(this); infoListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { HashMap<String, String> map = (HashMap<String, String>) infoListView.getItemAtPosition(position); page = map.get("Url"); int fadedTitleColor = getResources().getColor(R.color.marked_as_read_title_text); int fadedSummaryColor = getResources().getColor(R.color.marked_as_read_summary_text); profileView(view); } }); }
From source file:br.org.funcate.dynamicforms.views.GSketchView.java
/** * @param noteId the id of the note this image belows to. * @param fragmentDetail the fragment detail to use. * @param attrs attributes. * @param requestCode the code for starting the activity with result. * @param parentView parent//w w w .jav a2s .co m * @param label label * @param value value * @param constraintDescription constraints */ public GSketchView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode, LinearLayout parentView, String label, String value, String constraintDescription) { super(fragmentDetail.getActivity(), attrs); this.noteId = noteId; _value = value; final FragmentActivity activity = fragmentDetail.getActivity(); LinearLayout textLayout = new LinearLayout(activity); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(activity); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(activity.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); final Button button = new Button(activity); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); button.setText(R.string.draw_sketch); textLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); double[] gpsLocation = PositionUtilities.getGpsLocationFromPreferences(preferences); Date currentDate = new Date(); String sketchImageName = ImageUtilities.getSketchImageName(currentDate); File tempDir = ResourcesManager.getInstance(getContext()).getTempDir(); File sketchFile = new File(tempDir, sketchImageName); /* * open markers for new sketch */ MarkersUtilities.launch(fragmentDetail, sketchFile, gpsLocation, requestCode); } catch (Exception e) { //GPLog.error(this, null, e); Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } } }); ScrollView scrollView = new ScrollView(activity); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, 150); scrollView.setLayoutParams(scrollLayoutParams); parentView.addView(scrollView); imageLayout = new LinearLayout(activity); LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); imageLayout.setLayoutParams(imageLayoutParams); // imageLayout.setMinimumHeight(200); imageLayout.setOrientation(LinearLayout.HORIZONTAL); scrollView.addView(imageLayout); // scrollView.setFillViewport(true); try { refresh(activity); } catch (Exception e) { //GPLog.error(this, null, e); Toast.makeText(this.getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.JoinNotificationObj.java
@Override public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { TextView valueTV = new TextView(context); valueTV.setText("I'm here!"); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV);//from w w w .ja va 2 s.com }
From source file:jp.ne.sakura.kkkon.java.net.socketimpl.testapp.android.SocketImplHookTestApp.java
/** Called when the activity is first created. */ @Override/*www. jav a 2 s. co m*/ public void onCreate(Bundle savedInstanceState) { final Context context = this.getApplicationContext(); { SocketImplHookFactory.initialize(); } { ProxySelector proxySelector = ProxySelector.getDefault(); Log.d(TAG, "proxySelector=" + proxySelector); if (null != proxySelector) { URI uri = null; try { uri = new URI("http://www.google.com/"); } catch (URISyntaxException e) { Log.d(TAG, e.toString()); } List<Proxy> proxies = proxySelector.select(uri); if (null != proxies) { for (final Proxy proxy : proxies) { Log.d(TAG, " proxy=" + proxy); } } } } super.onCreate(savedInstanceState); /* Create a TextView and set its content. * the text is retrieved by calling a native * function. */ LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); TextView tv = new TextView(this); tv.setText("ExceptionHandler"); layout.addView(tv); Button btn1 = new Button(this); btn1.setText("invoke Exception"); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final int count = 2; int[] array = new int[count]; int value = array[count]; // invoke IndexOutOfBOundsException } }); layout.addView(btn1); { Button btn = new Button(this); btn.setText("upload http AsyncTask"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(String... paramss) { Boolean result = true; Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid()); try { //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS) Log.d(TAG, "fng=" + Build.FINGERPRINT); final List<NameValuePair> list = new ArrayList<NameValuePair>(16); list.add(new BasicNameValuePair("fng", Build.FINGERPRINT)); HttpPost httpPost = new HttpPost(paramss[0]); //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) ); httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(5 * 1000)); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(5 * 1000)); Log.d(TAG, "socket.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1)); Log.d(TAG, "connection.timeout=" + httpClient.getParams() .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1)); // <uses-permission android:name="android.permission.INTERNET"/> // got android.os.NetworkOnMainThreadException, run at UI Main Thread HttpResponse response = httpClient.execute(httpPost); Log.d(TAG, "response=" + response.getStatusLine().getStatusCode()); } catch (Exception e) { Log.d(TAG, "got Exception. msg=" + e.getMessage(), e); result = false; } Log.d(TAG, "upload finish"); return result; } }; asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug"); asyncTask.isCancelled(); } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(0.0.0.0)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { destHost = InetAddress.getByName("0.0.0.0"); if (null != destHost) { try { if (destHost.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + destHost.toString() + " reachable"); } else { Log.d(TAG, "destHost=" + destHost.toString() + " not reachable"); } } catch (IOException e) { } } } catch (UnknownHostException e) { } Log.d(TAG, "destHost=" + destHost); } }); thread.start(); try { thread.join(1000); } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(www.google.com)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("www.google.com"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } { Button btn = new Button(this); btn.setText("pre DNS query(kkkon.sakura.ne.jp)"); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { isReachable = false; Thread thread = new Thread(new Runnable() { public void run() { try { InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp"); if (null == dest) { dest = destHost; } if (null != dest) { try { if (dest.isReachable(5 * 1000)) { Log.d(TAG, "destHost=" + dest.toString() + " reachable"); isReachable = true; } else { Log.d(TAG, "destHost=" + dest.toString() + " not reachable"); } destHost = dest; } catch (IOException e) { } } else { } } catch (UnknownHostException e) { Log.d(TAG, "dns error" + e.toString()); destHost = null; } { if (null != destHost) { Log.d(TAG, "destHost=" + destHost); } } } }); thread.start(); try { thread.join(); { final String addr = (null == destHost) ? ("") : (destHost.toString()); final String reachable = (isReachable) ? ("reachable") : ("not reachable"); Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable, Toast.LENGTH_LONG); toast.show(); } } catch (InterruptedException e) { } } }); layout.addView(btn); } setContentView(layout); }
From source file:com.blockhead.gussilva.threemorewords.GameActivity.java
public void createAnswerView(String currWord, TextView[] currAnswerView, LinearLayout currWordLayout) { //Set TextViews text to letter of the answer for Word 1 for (int c = 0; c < currWord.length(); c++) { currAnswerView[c] = new TextView(this); currAnswerView[c].setText("" + currWord.charAt(c)); //Set TextView Properties currAnswerView[c].setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); currAnswerView[c].setGravity(Gravity.CENTER); currAnswerView[c].setTextColor(Color.TRANSPARENT); //So that user does not see that answer currAnswerView[c].setBackgroundResource(R.drawable.letter_bg); //add to layout currWordLayout.addView(currAnswerView[c]); }/*from w ww. j a va2s . co m*/ chancesLeftView.setTextColor(getResources().getColor(R.color.chances_good)); chancesLeftView.setText(numChances + " chances left"); }
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
@Override protected void onFinishInflate() { super.onFinishInflate(); if (mLeftViewId != 0 && mSwipeLeftHorizontal == null) { View view = findViewById(mLeftViewId); mSwipeLeftHorizontal = new SwipeLeftHorizontal(view); }//from w w w . ja v a 2 s . c o m if (mRightViewId != 0 && mSwipeRightHorizontal == null) { View view = findViewById(mRightViewId); mSwipeRightHorizontal = new SwipeRightHorizontal(view); } if (mContentViewId != 0 && mContentView == null) { mContentView = findViewById(mContentViewId); } else { TextView errorView = new TextView(getContext()); errorView.setClickable(true); errorView.setGravity(Gravity.CENTER); errorView.setTextSize(16); errorView.setText("You may not have set the ContentView."); mContentView = errorView; addView(mContentView); } }
From source file:com.iStudy.Study.Renren.View.RenrenDialog.java
private void setUpTitle() { Drawable icon = getContext().getResources().getDrawable(R.drawable.renren_sdk_android_title_logo); title = new TextView(getContext()); title.setText(""); title.setTextColor(Color.WHITE); title.setGravity(Gravity.CENTER_VERTICAL); title.setTypeface(Typeface.DEFAULT_BOLD); title.setBackgroundColor(RENREN_BLUE); title.setBackgroundResource(R.drawable.renren_sdk_android_title_bg); title.setCompoundDrawablePadding(6); title.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); content.addView(title);/* w ww . j a va2 s. c om*/ }
From source file:com.mikecorrigan.trainscorekeeper.FragmentButton.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState)); View rootView = inflater.inflate(R.layout.fragment_button, container, false); Bundle args = getArguments();/*from w w w . jav a 2 s . c o m*/ if (args == null) { Log.e(TAG, "onCreateView: missing arguments"); return rootView; } // The activity must support a standard OnClickListener. final MainActivity mainActivity = (MainActivity) getActivity(); final Context context = mainActivity; players = mainActivity.getPlayers(); if (players != null) { players.addListener(mPlayersListener); } // final int index = args.getInt(ARG_INDEX); final String tabSpec = args.getString(ARG_TAB_SPEC); try { JSONObject jsonTab = new JSONObject(tabSpec); final String tabName = jsonTab.optString(JsonSpec.TAB_NAME, JsonSpec.DEFAULT_TAB_NAME); if (!TextUtils.isEmpty(tabName)) { TextView tv = (TextView) rootView.findViewById(R.id.text_view_name); tv.setText(tabName); } tabLayout = (LinearLayout) rootView; JSONArray jsonSections = jsonTab.getJSONArray(JsonSpec.SECTIONS_KEY); for (int i = 0; i < jsonSections.length(); i++) { JSONObject jsonSection = jsonSections.getJSONObject(i); LinearLayout sectionLayout = new LinearLayout(context); sectionLayout.setOrientation(LinearLayout.VERTICAL); tabLayout.addView(sectionLayout); // If a section is named, label it. final String sectionName = jsonSection.optString(JsonSpec.SECTION_NAME, JsonSpec.DEFAULT_SECTION_NAME); if (!TextUtils.isEmpty(sectionName)) { TextView textView = new TextView(context); textView.setText(sectionName); sectionLayout.addView(textView); } int numColumns = jsonSection.optInt(JsonSpec.SECTION_COLUMNS, JsonSpec.DEFAULT_SECTION_COLUMNS); List<View> buttonViews = new LinkedList<View>(); JSONArray buttons = jsonSection.getJSONArray(JsonSpec.BUTTONS_KEY); for (int k = 0; k < buttons.length(); k++) { JSONObject jsonButton = buttons.getJSONObject(k); ScoreButton buttonView = new ScoreButton(context); buttonView.setButtonSpec(jsonButton); buttonView.setOnClickListener(mainActivity.getScoreClickListener()); // Add the button to the section. buttonViews.add(buttonView); } GridView gridView = new GridView(context); gridView.setNumColumns(numColumns); gridView.setAdapter(new ViewAdapter(context, buttonViews)); sectionLayout.addView(gridView); } } catch (JSONException e) { Log.th(TAG, e, "onCreateView: failed to parse JSON"); } updateUi(); return rootView; }
From source file:samsungsami.io.example.samiremotecontrol.DeviceActivity.java
/** * Fill the device status and info table *//* w w w.j av a 2 s .c o m*/ void fillTable() { TableRow row; TextView t1, t2, t3; for (int current = 0; current < fields.size(); current++) { row = new TableRow(this); t1 = new TextView(this); t1.setTextColor(Color.GRAY); t2 = new TextView(this); t2.setTextColor(Color.BLACK); t3 = new TextView(this); t3.setTextColor(Color.BLACK); t1.setText(fields.get(current)); t2.setText(values.get(current)); t3.setText(units.get(current)); t1.setTextSize(15); t2.setTextSize(15); t3.setTextSize(15); row.addView(t1); if (fields.get(current).equals("state")) { Switch toggle = new Switch(this); toggle.setChecked(values.get(current).toLowerCase().equals("on")); toggle.setEnabled(false); row.addView(toggle); } else row.addView(t2); row.addView(t3); propertiesTableLayout.addView(row, new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // Adjust the view propertiesTableLayout.setColumnStretchable(0, true); propertiesTableLayout.setColumnStretchable(1, true); propertiesTableLayout.setColumnStretchable(2, true); } }
From source file:com.boha.malengagolf.library.util.PagerTitleStrip22.java
public PagerTitleStrip22(Context context, AttributeSet attrs) { super(context, attrs); addView(mPrevText = new TextView(context)); addView(mCurrText = new TextView(context)); addView(mNextText = new TextView(context)); final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); final int textAppearance = a.getResourceId(0, 0); if (textAppearance != 0) { mPrevText.setTextAppearance(context, textAppearance); mCurrText.setTextAppearance(context, textAppearance); mNextText.setTextAppearance(context, textAppearance); }// w w w .j ava2s .c o m final int textSize = a.getDimensionPixelSize(1, 0); if (textSize != 0) { setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } if (a.hasValue(2)) { final int textColor = a.getColor(2, 0); mPrevText.setTextColor(textColor); mCurrText.setTextColor(textColor); mNextText.setTextColor(textColor); } mGravity = a.getInteger(3, Gravity.BOTTOM); a.recycle(); mTextColor = mCurrText.getTextColors().getDefaultColor(); setNonPrimaryAlpha(SIDE_ALPHA); mPrevText.setEllipsize(TruncateAt.END); mCurrText.setEllipsize(TruncateAt.END); mNextText.setEllipsize(TruncateAt.END); boolean allCaps = false; if (textAppearance != 0) { final TypedArray ta = context.obtainStyledAttributes(textAppearance, TEXT_ATTRS); allCaps = ta.getBoolean(0, false); ta.recycle(); } if (allCaps) { setSingleLineAllCaps(mPrevText); setSingleLineAllCaps(mCurrText); setSingleLineAllCaps(mNextText); } else { mPrevText.setSingleLine(); mCurrText.setSingleLine(); mNextText.setSingleLine(); } final float density = context.getResources().getDisplayMetrics().density; mScaledTextSpacing = (int) (TEXT_SPACING * density); }