Java Code Examples for android.widget.TextView#append()

The following examples show how to use android.widget.TextView#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginActivity.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private void d()
{
    z = findViewById(0x7f0a003a);
    B = findViewById(0x7f0a003c);
    r = (Button)findViewById(0x7f0a003f);
    r.setOnClickListener(this);
    s = (Button)findViewById(0x7f0a0040);
    s.setOnClickListener(this);
    C = (TextView)findViewById(0x7f0a003e);
    String s1 = getString(0x7f0d01dd);
    C.setText(Html.fromHtml(getResources().getString(0x7f0d003b)));
    SpannableString spannablestring = new SpannableString(s1);
    spannablestring.setSpan(new d(this), 0, s1.length(), 33);
    C.setHighlightColor(0);
    C.append(spannablestring);
    C.setMovementMethod(LinkMovementMethod.getInstance());
}
 
Example 2
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
@Override
public void onCallStateChanged(int state, String number) {
    String phoneState = number;
    switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:
            phoneState += "CALL_STATE_IDLE\n";
            break;
        case TelephonyManager.CALL_STATE_RINGING:
            phoneState += "CALL_STATE_RINGING\n";
            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            phoneState += "CALL_STATE_OFFHOOK\n";
            break;
    }
    TextView textView = findViewById(R.id.textView);
    textView.append(phoneState);
}
 
Example 3
Source File: AnalyzerViews.java    From audio-analyzer-for-android with Apache License 2.0 6 votes vote down vote up
void showInstructions() {
    TextView tv = new TextView(activity);
    tv.setMovementMethod(LinkMovementMethod.getInstance());
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    tv.setText(fromHtml(activity.getString(R.string.instructions_text)));
    PackageInfo pInfo = null;
    String version = "\n" + activity.getString(R.string.app_name) + "  Version: ";
    try {
        pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        version += pInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        version += "(Unknown)";
    }
    tv.append(version);
    new AlertDialog.Builder(activity)
            .setTitle(R.string.instructions_title)
            .setView(tv)
            .setNegativeButton(R.string.dismiss, null)
            .create().show();
}
 
Example 4
Source File: SupplementalInfoRetriever.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
@Override
protected final void onPostExecute(Object arg) {
  TextView textView = textViewRef.get();
  if (textView != null) {
    for (CharSequence content : newContents) {
      textView.append(content);
    }
    textView.setMovementMethod(LinkMovementMethod.getInstance());
  }
  HistoryManager historyManager = historyManagerRef.get();
  if (historyManager != null) {
    for (String[] text : newHistories) {
      historyManager.addHistoryItemDetails(text[0], text[1]);
    }
  }
}
 
Example 5
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // COMPLETED (3) Use findViewById to get a reference to the TextView from the layout
    mToysListTextView = (TextView) findViewById(R.id.tv_toy_names);

    // COMPLETED (4) Use the static ToyBox.getToyNames method and store the names in a String array
    String toyNames[] = ToyBox.getToyNames();

    // COMPLETED (5) Loop through each toy and append the name to the TextView (add \n for spacing)
    for(String toyName:toyNames) {
        mToysListTextView.append(toyName + "\n\n\n");
    }
}
 
Example 6
Source File: LLSettingsFragment.java    From BTChat with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	
	AppSettings.initializeAppSettings(mContext);
	
	View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
	
	// 'Run in background' setting
	mCheckBackground = (CheckBox) rootView.findViewById(R.id.check_background_service);
	mCheckBackground.setChecked(AppSettings.getBgService());
	mCheckBackground.setOnCheckedChangeListener(new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			AppSettings.setSettingsValue(AppSettings.SETTINGS_BACKGROUND_SERVICE, isChecked, 0, null);
			mFragmentListener.OnFragmentCallback(IFragmentListener.CALLBACK_RUN_IN_BACKGROUND, 0, 0, null, null,null);
		}
	});
	
	mTextIot = (TextView) rootView.findViewById(R.id.text_iot_guide);
	mTextIot.append("\n\nthingspeak:key=xxx&field1=xxx[*]\n\n-> HTTP request: http://184.106.153.149/update?key=xxx&field1=xxx");
	
	
	return rootView;
}
 
Example 7
Source File: ContactsView.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
	TextView contactView = (TextView) findViewById(R.id.contactview);

	Cursor cursor = getContacts();

	while (cursor.moveToNext()) {

		String displayName = cursor.getString(cursor
				.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
		contactView.append("Name: ");
		contactView.append(displayName);
		contactView.append("\n");
	}
	// Closing the cursor
	cursor.close();
}
 
Example 8
Source File: RegisterActivity.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
protected void onPostExecute(CollectionResponseMessageData messages) {
  // Check if exception was thrown
  if (exceptionThrown != null) {
    Log.e(RegisterActivity.class.getName(), 
        "Exception when listing Messages", exceptionThrown);
    showDialog("Failed to retrieve the last 5 messages from " +
    		"the endpoint at " + messageEndpoint.getBaseUrl() +
    		", check log for details");
  }
  else {
    TextView messageView = (TextView) findViewById(R.id.msgView);
    messageView.setText("Last 5 Messages read from " + 
        messageEndpoint.getBaseUrl() + ":\n");
    for(MessageData message : messages.getItems()) {
      messageView.append(message.getMessage() + "\n");
    }
  }
}
 
Example 9
Source File: BookMarkAdapter.java    From BookReader with Apache License 2.0 6 votes vote down vote up
@Override
public void convert(EasyLVHolder holder, int position, BookMark item) {
    TextView tv = holder.getView(R.id.tvMarkItem);

    SpannableString spanText = new SpannableString((position + 1) + ". " + item.title + ": ");
    spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.light_coffee)),
            0, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

    tv.setText(spanText);

    if (item.desc != null) {
        tv.append(item.desc
                .replaceAll(" ", "")
                .replaceAll(" ", "")
                .replaceAll("\n", ""));
    }

}
 
Example 10
Source File: StreamHeader.java    From Klyph with MIT License 5 votes vote down vote up
private void manageStory(HeaderHolder holder)
{
	if (holder.getStoryView().get() != null)
	{
		TextView view = holder.getStoryView().get();

		if (holder.getStory() != null && holder.getStory().length() > 0)
		{
			view.setText(holder.getStory());

			if (holder.getTags() != null && holder.getTags().size() > 0)
			{
				TextViewUtil.setTextClickableForTags(getContext(view), view,
						holder.getTags(), specialLayout == SpecialLayout.STREAM_DETAIL);
			}
		}
		else
		{
			view.setText(holder.getAuthorName());

				TextViewUtil.setElementClickable(getContext(view), view,
					holder.getAuthorName(), holder.getAuthorId(),
					holder.getAuthorType(), specialLayout == SpecialLayout.STREAM_DETAIL);

			if (holder.getTargetId() != null && holder.getTargetId().length() > 0
					&& holder.getTargetName().length() > 0
					&& !holder.getTargetId().equals(holder.getAuthorId()))
			{
				view.append(" > " + holder.getTargetName());

					TextViewUtil.setElementClickable(getContext(view), view,
						holder.getTargetName(), holder.getTargetId(),
						holder.getTargetType(), specialLayout == SpecialLayout.STREAM_DETAIL);
			}
		}

		view.setVisibility(View.VISIBLE);
	}
}
 
Example 11
Source File: AnagramsActivity.java    From jterm-cswithandroid with Apache License 2.0 5 votes vote down vote up
public boolean defaultAction(View view) {
    TextView gameStatus = (TextView) findViewById(R.id.gameStatusView);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    EditText editText = (EditText) findViewById(R.id.editText);
    TextView resultView = (TextView) findViewById(R.id.resultView);
    if (currentWord == null) {
        currentWord = dictionary.pickGoodStarterWord();
        anagrams = dictionary.getAnagramsWithOneMoreLetter(currentWord);
        gameStatus.setText(Html.fromHtml(String.format(START_MESSAGE, currentWord.toUpperCase(), currentWord)));
        fab.setImageResource(android.R.drawable.ic_menu_help);
        fab.hide();
        resultView.setText("");
        editText.setText("");
        editText.setEnabled(true);
        editText.requestFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    } else {
        editText.setText(currentWord);
        editText.setEnabled(false);
        fab.setImageResource(android.R.drawable.ic_media_play);
        currentWord = null;
        resultView.append(TextUtils.join("\n", anagrams));
        gameStatus.append(" Hit 'Play' to start again");
    }
    return true;
}
 
Example 12
Source File: AboutActivity.java    From upcKeygen with GNU General Public License v2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.about_fragment, container, false);
    TextView text = ((TextView) rootView.findViewById(R.id.text_about));

    switch (currentSection){
        case 1:
            text.setMovementMethod(LinkMovementMethod.getInstance());
            text.setText(R.string.pref_about_desc);
            try {
                PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
                String version = pInfo.versionName;
                text.append(version);
            } catch(Exception e){
                Log.e(TAG, "Exception in getting app version", e);
            }
        break;

        case 2:
            text.setText(R.string.dialog_about_credits_desc);
            text.setMovementMethod(LinkMovementMethod.getInstance());
            break;

        case 3:
            text.setText(R.string.dialog_about_license_desc);
            text.setMovementMethod(LinkMovementMethod.getInstance());
        break;
    }

    return rootView;
}
 
Example 13
Source File: DActivity.java    From MRouter with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_range_layout);
    TextView textView = (TextView) findViewById(R.id.text_name);
    textView.setText("D");
    findViewById(R.id.btn_start_activity).setVisibility(View.GONE);

    findViewById(R.id.btn_finish_range_by_class).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_range_begin_router_path1).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_range_begin_router_path2).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_range_begin_router_path3).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_all_start_to).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_all_start_to_by_router_path).setVisibility(View.VISIBLE);

    findViewById(R.id.btn_finish_top_activity).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_activity_by_class).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_activity_by_router_path).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_all_activity).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_all_activity_except_activity_class).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_all_activity_except_router_path).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_all_activity_except_by_list).setVisibility(View.VISIBLE);
    findViewById(R.id.btn_finish_all_activity_by_list).setVisibility(View.VISIBLE);


    int count = RouterActivityManager.get().getActivityCount();
    textView.append("\n\nactivity count:");
    textView.append("" + count);
}
 
Example 14
Source File: MainActivity.java    From Floo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  TextView text = (TextView) findViewById(R.id.text);
  Map<String, Target> targetMap = Floo.getTargetMap();
  for (Map.Entry<String, Target> entry : targetMap.entrySet()) {
    text.append(entry.getKey());
    text.append("\t\t <-> \t\t");
    text.append(entry.getValue().toTargetUrl());
    text.append("\n");
  }
}
 
Example 15
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_forecast);

    // COMPLETED (2) Use findViewById to get a reference to the weather display TextView
    mWeatherTextView = (TextView) findViewById(R.id.tv_weather_data);

    // COMPLETED (3) Create an array of Strings that contain fake weather data
    String[] dummyWeatherData = {
            "Today, May 17 - Clear - 17°C / 15°C",
            "Tomorrow - Cloudy - 19°C / 15°C",
            "Thursday - Rainy- 30°C / 11°C",
            "Friday - Thunderstorms - 21°C / 9°C",
            "Saturday - Thunderstorms - 16°C / 7°C",
            "Sunday - Rainy - 16°C / 8°C",
            "Monday - Partly Cloudy - 15°C / 10°C",
            "Tue, May 24 - Meatballs - 16°C / 18°C",
            "Wed, May 25 - Cloudy - 19°C / 15°C",
            "Thu, May 26 - Stormy - 30°C / 11°C",
            "Fri, May 27 - Hurricane - 21°C / 9°C",
            "Sat, May 28 - Meteors - 16°C / 7°C",
            "Sun, May 29 - Apocalypse - 16°C / 8°C",
            "Mon, May 30 - Post Apocalypse - 15°C / 10°C",
    };

    // COMPLETED (4) Append each String from the fake weather data array to the TextView
    for (String dummyWeatherDay : dummyWeatherData) {
        mWeatherTextView.append(dummyWeatherDay + "\n\n\n");
    }
}
 
Example 16
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the activity is first created. This is where you should do all of your normal
 * static set up: create views, bind data to lists, etc.
 * <p>
 * Always followed by onStart().
 *
 * @param savedInstanceState The Activity's previously frozen state, if there was one.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mLifecycleDisplay = (TextView) findViewById(R.id.tv_lifecycle_events_display);

    /*
     * If savedInstanceState is not null, that means our Activity is not being started for the
     * first time. Even if the savedInstanceState is not null, it is smart to check if the
     * bundle contains the key we are looking for. In our case, the key we are looking for maps
     * to the contents of the TextView that displays our list of callbacks. If the bundle
     * contains that key, we set the contents of the TextView accordingly.
     */
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(LIFECYCLE_CALLBACKS_TEXT_KEY)) {
            String allPreviousLifecycleCallbacks = savedInstanceState
                    .getString(LIFECYCLE_CALLBACKS_TEXT_KEY);
            mLifecycleDisplay.setText(allPreviousLifecycleCallbacks);
        }
    }

    // COMPLETED (4) Iterate backwards through mLifecycleCallbacks, appending each String and a newline to mLifecycleDisplay
    for (int i = mLifecycleCallbacks.size() - 1; i >= 0; i--) {
        mLifecycleDisplay.append(mLifecycleCallbacks.get(i) + "\n");
    }
    // COMPLETED (5) Clear mLifecycleCallbacks after iterating through it
    mLifecycleCallbacks.clear();

    logAndAppend(ON_CREATE);
}
 
Example 17
Source File: CharacteristicOperationFragment.java    From FastBle with Apache License 2.0 5 votes vote down vote up
private void addText(TextView textView, String content) {
    textView.append(content);
    textView.append("\n");
    int offset = textView.getLineCount() * textView.getLineHeight();
    if (offset > textView.getHeight()) {
        textView.scrollTo(0, offset - textView.getHeight());
    }
}
 
Example 18
Source File: Server_Fragment.java    From bluetooth with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	// Inflate the layout for this fragment
	View myView = inflater.inflate(R.layout.fragment_server, container, false);
	//text field for output info.
	output = (TextView) myView.findViewById(R.id.sv_output);

	btn_start = (Button) myView.findViewById(R.id.start_server);

	btn_start.setOnClickListener( new View.OnClickListener(){
		@Override
		public void onClick(View v) {
			output.append("Starting server\n");
			 startServer();
		}
	});


	//setup the bluetooth adapter.
	mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
	if (mBluetoothAdapter == null) {
		// Device does not support Bluetooth
		output.append("No bluetooth device.\n");
		btn_start.setEnabled(false);
	}

	return myView;
}
 
Example 19
Source File: ContactablesLoaderCallbacks.java    From android-BasicContactables with Apache License 2.0 4 votes vote down vote up
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
    TextView tv  = (TextView) ((Activity)mContext).findViewById(R.id.sample_output);
    if(tv == null) {
        Log.e(TAG, "TextView is null?!");
    } else if (mContext == null) {
        Log.e(TAG, "Context is null?");
    } else {
        Log.e(TAG, "Nothing is null?!");
    }

    // Reset text in case of a previous query
    tv.setText(mContext.getText(R.string.intro_message) + "\n\n");

    if (cursor.getCount() == 0) {
        return;
    }

    // Pulling the relevant value from the cursor requires knowing the column index to pull
    // it from.
    // BEGIN_INCLUDE(get_columns)
    int phoneColumnIndex = cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER);
    int emailColumnIndex = cursor.getColumnIndex(CommonDataKinds.Email.ADDRESS);
    int nameColumnIndex = cursor.getColumnIndex(CommonDataKinds.Contactables.DISPLAY_NAME);
    int lookupColumnIndex = cursor.getColumnIndex(CommonDataKinds.Contactables.LOOKUP_KEY);
    int typeColumnIndex = cursor.getColumnIndex(CommonDataKinds.Contactables.MIMETYPE);
    // END_INCLUDE(get_columns)

    cursor.moveToFirst();
    // Lookup key is the easiest way to verify a row of data is for the same
    // contact as the previous row.
    String lookupKey = "";
    do {
        // BEGIN_INCLUDE(lookup_key)
        String currentLookupKey = cursor.getString(lookupColumnIndex);
        if (!lookupKey.equals(currentLookupKey)) {
            String displayName = cursor.getString(nameColumnIndex);
            tv.append(displayName + "\n");
            lookupKey = currentLookupKey;
        }
        // END_INCLUDE(lookup_key)

        // BEGIN_INCLUDE(retrieve_data)
        // The data type can be determined using the mime type column.
        String mimeType = cursor.getString(typeColumnIndex);
        if (mimeType.equals(CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
            tv.append("\tPhone Number: " + cursor.getString(phoneColumnIndex) + "\n");
        } else if (mimeType.equals(CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
            tv.append("\tEmail Address: " + cursor.getString(emailColumnIndex) + "\n");
        }
        // END_INCLUDE(retrieve_data)

        // Look at DDMS to see all the columns returned by a query to Contactables.
        // Behold, the firehose!
        for(String column : cursor.getColumnNames()) {
            Log.d(TAG, column + column + ": " +
                    cursor.getString(cursor.getColumnIndex(column)) + "\n");
        }
    } while (cursor.moveToNext());
}
 
Example 20
Source File: InternalFileWriteReadActivity.java    From coursera-android with MIT License 3 votes vote down vote up
private void readFileAndDisplay(TextView tv) throws IOException {

		FileInputStream fis = openFileInput(fileName);
		BufferedReader br = new BufferedReader(new InputStreamReader(fis));

		String line;
		String sep = System.getProperty("line.separator");

		while (null != (line = br.readLine())) {
			tv.append(line + sep);
		}

		br.close();

	}