List of usage examples for android.widget TextView setText
@android.view.RemotableViewMethod public final void setText(@StringRes int resid)
From source file:net.bible.android.view.activity.StartupActivity.java
/** Called when the activity is first created. */ @Override// ww w . j a v a2 s . com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.startup_view); // do not show an actionBar/title on the splash screen getSupportActionBar().hide(); TextView versionTextView = (TextView) findViewById(R.id.versionText); String versionMsg = BibleApplication.getApplication().getString(R.string.version_text, CommonUtils.getApplicationVersionName()); versionTextView.setText(versionMsg); //See if any errors occurred during app initialisation, especially upgrade tasks int abortErrorMsgId = BibleApplication.getApplication().getErrorDuringStartup(); // check for SD card // it would be great to check in the Application but how to show dialog from Application? if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { abortErrorMsgId = R.string.no_sdcard_error; } // show fatal startup msg and close app if (abortErrorMsgId != 0) { Dialogs.getInstance().showErrorMsg(abortErrorMsgId, new Callback() { @Override public void okay() { // this causes the blue splashscreen activity to finish and since it is the top the app closes finish(); } }); // this aborts further initialisation but leaves blue splashscreen activity return; } // allow call back and continuation in the ui thread after JSword has been initialised final Handler uiHandler = new Handler(); final Runnable uiThreadRunnable = new Runnable() { @Override public void run() { postBasicInitialisationControl(); } }; // initialise JSword in another thread (takes a long time) then call main ui thread Handler to continue // this allows the splash screen to be displayed and an hourglass to run new Thread() { public void run() { try { // allow the splash screen to be displayed immediately CommonUtils.pauseMillis(1); // force Sword to initialise itself Initialisation.getInstance().initialiseNow(); } finally { // switch back to ui thread to continue uiHandler.post(uiThreadRunnable); } } }.start(); }
From source file:com.apptentive.android.sdk.module.engagement.interaction.view.survey.SurveyInteractionView.java
@Override public void doOnCreate(final Activity activity, Bundle savedInstanceState) { if (savedInstanceState != null) { surveySubmitted = savedInstanceState.getBoolean(KEY_SURVEY_SUBMITTED, false); }/*from w ww . j a v a2 s .co m*/ if (interaction == null || surveySubmitted) { activity.finish(); return; } activity.setContentView(R.layout.apptentive_survey); // Hide branding if needed. final View branding = activity.findViewById(R.id.apptentive_branding_view); if (branding != null) { if (Configuration.load(activity).isHideBranding(activity)) { branding.setVisibility(View.GONE); } } TextView title = (TextView) activity.findViewById(R.id.title); title.setFocusable(true); title.setFocusableInTouchMode(true); title.setText(interaction.getName()); String descriptionText = interaction.getDescription(); if (descriptionText != null) { TextView description = (TextView) activity.findViewById(R.id.description); description.setText(descriptionText); description.setVisibility(View.VISIBLE); } final Button send = (Button) activity.findViewById(R.id.send); send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Util.hideSoftKeyboard(activity, view); surveySubmitted = true; if (interaction.isShowSuccessMessage() && interaction.getSuccessMessage() != null) { SurveyThankYouDialog dialog = new SurveyThankYouDialog(activity); dialog.setMessage(interaction.getSuccessMessage()); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { activity.finish(); } }); dialog.show(); } else { activity.finish(); } EngagementModule.engageInternal(activity, interaction, EVENT_SUBMIT, data.toString()); ApptentiveDatabase.getInstance(activity).addPayload(new SurveyResponse(interaction, surveyState)); Log.d("Survey Submitted."); callListener(true); cleanup(); } }); LinearLayout questions = (LinearLayout) activity.findViewById(R.id.questions); questions.removeAllViews(); // Then render all the questions for (final Question question : interaction.getQuestions()) { if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) { TextSurveyQuestionView textQuestionView = new TextSurveyQuestionView(activity, surveyState, (SinglelineQuestion) question); textQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(textQuestionView); } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) { MultichoiceSurveyQuestionView multichoiceQuestionView = new MultichoiceSurveyQuestionView(activity, surveyState, (MultichoiceQuestion) question); multichoiceQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(multichoiceQuestionView); } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) { MultiselectSurveyQuestionView multiselectQuestionView = new MultiselectSurveyQuestionView(activity, surveyState, (MultiselectQuestion) question); multiselectQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() { public void onAnswered() { sendMetricForQuestion(activity, question); send.setEnabled(isSurveyValid()); } }); questions.addView(multiselectQuestionView); } } send.setEnabled(isSurveyValid()); // Force the top of the survey to be shown first. title.requestFocus(); }
From source file:se.anyro.nfc_reader.TagViewer.java
void buildTagViews(NdefMessage[] msgs) { if (msgs == null || msgs.length == 0) { return;/*from w w w . j av a 2s . c om*/ } LayoutInflater inflater = LayoutInflater.from(this); LinearLayout content = mTagContent; // Parse the first message in the list // Build views for all of the sub records Date now = new Date(); List<ParsedNdefRecord> records = NdefMessageParser.parse(msgs[0]); final int size = records.size(); for (int i = 0; i < size; i++) { TextView timeView = new TextView(this); timeView.setText(TIME_FORMAT.format(now)); content.addView(timeView, 0); ParsedNdefRecord record = records.get(i); content.addView(record.getView(this, inflater, content, i), 1 + i); content.addView(inflater.inflate(R.layout.tag_divider, content, false), 2 + i); } }
From source file:com.google.bazel.example.android.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_ping) { new AsyncTask<String, Void, String>() { public static final int READ_TIMEOUT_MS = 5000; public static final int CONNECTION_TIMEOUT_MS = 2000; private String inputStreamToString(InputStream stream) throws IOException { StringBuilder result = new StringBuilder(); try { BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); String line;// w ww . ja v a2 s . c om while ((line = reader.readLine()) != null) { result.append(line); } } finally { stream.close(); } return result.toString(); } private HttpURLConnection getConnection(String url) throws IOException { URLConnection urlConnection = new URL(url).openConnection(); urlConnection.setConnectTimeout(CONNECTION_TIMEOUT_MS); urlConnection.setReadTimeout(READ_TIMEOUT_MS); return (HttpURLConnection) urlConnection; } @Override protected String doInBackground(String... params) { String url = params[0]; HttpURLConnection connection = null; try { connection = getConnection(url); return new JSONObject(inputStreamToString(connection.getInputStream())) .getString("requested"); } catch (IOException e) { Log.e("background", "IOException", e); return null; } catch (JSONException e) { Log.e("background", "JSONException", e); return null; } finally { if (connection != null) { connection.disconnect(); } } } @Override protected void onPostExecute(String result) { TextView textView = (TextView) findViewById(R.id.text_view); if (result == null) { Toast.makeText(MainActivity.this, getString(R.string.error_sending_request), Toast.LENGTH_LONG).show(); textView.setText("???"); return; } textView.setText(result); } }.execute("http://10.0.2.2:8080/boop"); return true; } return super.onOptionsItemSelected(item); }
From source file:net.alchemiestick.katana.winehqappdb.filter_dialog.java
public filter_dialog(Context cx, List<NameValuePair> data) { super(cx);/*from w w w .j a v a 2s .c o m*/ this.cx = cx; this.webData = data; this.requestWindowFeature(Window.FEATURE_NO_TITLE); vocl = new View.OnClickListener() { public void onClick(View v) { onCheckboxClick(v); } }; maxLines = new OnEditorActionListener() { @Override public boolean onEditorAction(TextView tv, int action, KeyEvent key) { boolean handled = false; if (action == EditorInfo.IME_ACTION_DONE) { setMaxLines(tv.getText().toString()); tv.setText(getNamedData("iPage")); InputMethodManager imm = (InputMethodManager) tv.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(tv.getWindowToken(), 0); handled = true; } return handled; } }; rateListener = new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { rateSelected((String) parent.getItemAtPosition(pos)); } public void onNothingSelected(AdapterView<?> parent) { } }; licenseListener = new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { licenseSelected((String) parent.getItemAtPosition(pos)); } public void onNothingSelected(AdapterView<?> parent) { } }; placementListener = new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { placementSelected((String) parent.getItemAtPosition(pos)); } public void onNothingSelected(AdapterView<?> parent) { } }; }
From source file:com.feedhenry.helloworld.HelloFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = View.inflate(getActivity(), R.layout.hello_fragment, null); final TextView mResponse = (TextView) view.findViewById(R.id.cloud_response); final EditText mName = (EditText) view.findViewById(R.id.name); Button mCloudButton = (Button) view.findViewById(R.id.button); mCloudButton.setOnClickListener(new View.OnClickListener() { @Override/*from ww w . j a v a2 s . co m*/ public void onClick(final View v) { mResponse.setText(""); mCloudButton.setEnabled(false); cloudCall(v, mName.getText().toString(), mResponse); mName.setText(""); } }); return view; }
From source file:com.sftoolworks.nfcoptions.SelectActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select); nfcAdapter = NfcAdapter.getDefaultAdapter(this); pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); Intent intent = getIntent();//from w ww .j a v a 2 s . c o m Parcelable[] rawMessages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); String title = getString(R.string.default_select_title); TextView textViewBottom = (TextView) findViewById(R.id.textView2); textViewBottom.setText(""); if (rawMessages != null) { ArrayList<Object> entries = new ArrayList<Object>(); String data = null; for (Parcelable rawMessage : rawMessages) { NdefMessage message = (NdefMessage) rawMessage; NdefRecord[] records = message.getRecords(); if (records.length > 1) { byte[] bArray = records[1].getPayload(); byte languageLength = bArray[0]; languageLength++; // because of the length byte data = new String(bArray, languageLength, bArray.length - languageLength); } } try { JSONObject json = (JSONObject) new JSONTokener(data).nextValue(); if (json.has("title")) title = json.getString("title"); if (json.has("key")) selectKey = json.getString("key"); if (json.has("options")) { JSONArray arr = json.getJSONArray("options"); for (int i = 0; i < arr.length(); i++) { entries.add(parseJObject(arr.getJSONObject(i))); } } ListView list = (ListView) findViewById(R.id.listView1); list.setAdapter(new OptionListAdapter(this, entries.toArray())); list.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { CheckBox cb = (CheckBox) view.findViewById(R.id.optionListCheckBox); cb.setChecked(!cb.isChecked()); } }); textViewBottom.setText(getString(R.string.tap_again)); } catch (Exception e) { String message = getString(R.string.json_err); message += "\n"; message += e.getMessage(); Toast.makeText(this, message, Toast.LENGTH_LONG).show(); Log.d(TAG, getString(R.string.json_err)); Log.d(TAG, e.toString()); Log.d(TAG, data); } } else { title = getString(R.string.no_tag); } TextView msg = (TextView) findViewById(R.id.textView1); msg.setText(title); }
From source file:net.exclaimindustries.geohashdroid.wiki.WikiMessageEditor.java
private void updateCoords() { // Unlike in the wiki picture activity, we only have to concern // ourselves with the user's current location. No picture location, nor // any need to change a text string. Yay! Location lastLoc = getLastLocation(); TextView tv; if (lastLoc != null) { tv = (TextView) (findViewById(R.id.coordstring)); tv.setText(UnitConverter.makeFullCoordinateString(this, lastLoc, false, UnitConverter.OUTPUT_SHORT)); tv = (TextView) (findViewById(R.id.diststring)); tv.setText(UnitConverter.makeDistanceString(this, mDistFormat, mInfo.getDistanceInMeters(lastLoc))); } else {//from www. j av a2 s. co m tv = (TextView) (findViewById(R.id.coordstring)); tv.setText(R.string.standby_title); tv = (TextView) (findViewById(R.id.diststring)); tv.setText(R.string.standby_title); } }
From source file:org.deviceconnect.android.uiapp.fragment.profile.ExtraProfileFragment.java
/** * ??.// w w w .j a va2 s . c om * @param view ? */ protected void onClickSend(final View view) { // final CharSequence inter = ((TextView) getView().findViewById(R.id.fragment_extra_interface)).getText(); // final CharSequence attr = ((TextView) getView().findViewById(R.id.fragment_extra_attribute)).getText(); // final String accessToken = getAccessToken(); // final CharSequence query = ((TextView) getView().findViewById(R.id.fragment_extra_query)).getText(); final URIBuilder builder = new URIBuilder(); builder.setProfile(mProfile); if (inter != null && inter.length() > 0) { builder.setInterface(inter.toString()); } if (attr != null && attr.length() > 0) { builder.setAttribute(attr.toString()); } builder.addParameter(DConnectMessage.EXTRA_DEVICE_ID, getSmartDevice().getId()); if (accessToken != null) { builder.addParameter(DConnectMessage.EXTRA_ACCESS_TOKEN, accessToken); } if (query != null) { String path = query.toString(); if (path.length() > 0) { String[] keyvalues = path.split("&"); for (int i = 0; i < keyvalues.length; i++) { String[] kv = keyvalues[i].split("="); if (kv.length == 1) { builder.addParameter(kv[0], ""); } else if (kv.length == 2) { builder.addParameter(kv[0], kv[1]); } } } } HttpRequest request = null; try { Spinner spinner = (Spinner) getView().findViewById(R.id.spinner); String method = (String) spinner.getSelectedItem(); if (method.equals("GET")) { request = new HttpGet(builder.build()); } else if (method.equals("POST")) { request = new HttpPost(builder.build()); } else if (method.equals("PUT")) { request = new HttpPut(builder.build()); } else if (method.equals("DELETE")) { request = new HttpDelete(builder.build()); } getActivity().runOnUiThread(new Runnable() { @Override public void run() { TextView tv = (TextView) getView().findViewById(R.id.fragment_extra_request); try { String uri = builder.build().toASCIIString(); tv.setText(uri); } catch (URISyntaxException e) { tv.setText(""); } } }); } catch (URISyntaxException e) { e.printStackTrace(); } (new AsyncTask<HttpRequest, Void, DConnectMessage>() { public DConnectMessage doInBackground(final HttpRequest... args) { if (args == null || args.length <= 0) { return new DConnectResponseMessage(DConnectMessage.RESULT_ERROR); } DConnectMessage message = new DConnectResponseMessage(DConnectMessage.RESULT_ERROR); try { HttpRequest request = args[0]; HttpResponse response = getDConnectClient().execute(getDefaultHost(), request); message = (new HttpMessageFactory()).newDConnectMessage(response); } catch (IOException e) { e.printStackTrace(); } return message; } @Override protected void onPostExecute(final DConnectMessage result) { if (getActivity().isFinishing()) { return; } if (result == null) { return; } View view = getView(); if (view != null) { TextView tv = (TextView) view.findViewById(R.id.fragment_extra_response); tv.setText(result.toString()); } } }).execute(request); }
From source file:com.cs411.trackallthethings.Scan.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // show that we're doing shit bro gettingItem = ProgressDialog.show(scanContext, "", "Getting item...", true); // the scan string result String result = data.getExtras().getString("la.droid.qr.result"); Log.d("result: ", result); String[] resultSplit = result.split("\\|"); // the case where there is no item_id in the scan result if (resultSplit.length < 1) { gettingItem.dismiss();/* w ww . j av a2 s . com*/ return; } // get the item's information for (int i = 0; i < resultSplit.length; i++) { Log.d("resultSplit " + i, resultSplit[i]); } String item_id = resultSplit[resultSplit.length - 1]; Log.d("item_id: ", item_id); String responseString = ""; try { HttpGet httpget = new HttpGet( "http://www.trackallthethings.com/mobile-api/search_item?item_id=" + item_id); HttpResponse response; response = Main.httpclient.execute(httpget); HttpEntity entity = response.getEntity(); InputStream in = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder sb = new StringBuilder(); String input = null; try { while ((input = reader.readLine()) != null) { sb.append(input + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } //parse the response responseString = sb.toString(); in.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // if the response was bad if (responseString.equals("") || responseString.contains("INVALID QR SCAN")) { gettingItem.dismiss(); return; } // make the item try { JSONObject itemData = new JSONObject(responseString); scannedItem = new Item(itemData); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // if the item was made properly, let's display its info if (scannedItem != null) { TextView scanItemInfo = (TextView) findViewById(R.id.scaniteminfo); scanItemInfo.setText(scannedItem.toString()); } gettingItem.dismiss(); }