android.text.Html Java Examples

The following examples show how to use android.text.Html. 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: FullscreenActivity.java    From comfortreader with GNU General Public License v3.0 6 votes vote down vote up
public void playAutomated(int milliseconds){

        Log.i("Fullscreen", "automatic loading webview");
        String html =  segmenterObject.getsegmentoutputNextTick(tickdistance);
        contentView.setText(Html.fromHtml(html));
		settingsload.saveAddReadCharacters(tickdistance);
		settingsload.saveAddReadingTime(milliseconds);
		if (segmenterObject.tickposition == 0){
		texthaschanged();
		}
    	if (segmenterObject.finished){
    		stop();
			controlsView2.setVisibility(View.VISIBLE);
    	}
    	
    }
 
Example #2
Source File: SimpleVrPanoramaActivity.java    From PanoramaGL with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the app is launched via the app icon or an intent using the adb command above. This
 * initializes the app and loads the image to render.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main_layout);

  // Make the source link clickable.
  TextView sourceText = (TextView) findViewById(R.id.source);
  sourceText.setText(Html.fromHtml(getString(R.string.source)));
  sourceText.setMovementMethod(LinkMovementMethod.getInstance());

  panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view);
  panoWidgetView.setEventListener(new ActivityEventListener());

  // Initial launch of the app or an Activity recreation due to rotation.
  handleIntent(getIntent());
}
 
Example #3
Source File: HelpActivity.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View view, ViewGroup container) {
	
	ViewHolder mHolder;
	if (view != null) {
		mHolder = (ViewHolder) view.getTag();
	} else {
		view = makeLayout();
		mHolder = new ViewHolder(view);
		view.setTag(mHolder);
	}
	
	// Get the key and value from our LinkedHashMap.
	final Entry<CharSequence, Integer> mEntry = mItems.get(position);
	final CharSequence mMessage = mEntry.getKey();
	final int mImageRes = mEntry.getValue();

	// Set the values from our ViewHolder.
	mHolder.mText.setText(((mMessage instanceof String) ? Html.fromHtml((String) mMessage) : mMessage));
	if (mImageRes != R.id.help_text && mImageRes != 0) {
		mHolder.mText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, mImageRes);
	}

	return view;
}
 
Example #4
Source File: FaBoConnectFragment.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * ログ表示用TextViewにメッセージを追加します.
 *
 * @param msg 追加するメッセージ
 */
private synchronized void addLogMessage(final String msg) {
    String lastMsg = mTextViewLog.getText().toString();
    if (DEBUG) {
        Log.i(TAG, "lastMsg" + lastMsg);
    }

    String newMsg = lastMsg;
    if (!lastMsg.isEmpty()) {
        newMsg += "<br>";
    }
    newMsg += "<font color=\"#00FF00\"> ✓ </font>" + msg;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        mTextViewLog.setText(Html.fromHtml(newMsg, 0));
    } else {
        mTextViewLog.setText(Html.fromHtml(newMsg));
    }
}
 
Example #5
Source File: AnagramsActivity.java    From jterm-cswithandroid with Apache License 2.0 6 votes vote down vote up
private void processWord(EditText editText) {
    TextView resultView = (TextView) findViewById(R.id.resultView);
    String word = editText.getText().toString().trim().toLowerCase();
    if (word.length() == 0) {
        return;
    }
    String color = "#cc0029";
    if (dictionary.isGoodWord(word, currentWord) && anagrams.contains(word)) {
        anagrams.remove(word);
        color = "#00aa29";
    } else {
        word = "X " + word;
    }
    resultView.append(Html.fromHtml(String.format("<font color=%s>%s</font><BR>", color, word)));
    editText.setText("");
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.show();
}
 
Example #6
Source File: KcaInfoActivity.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_info);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(getResources().getString(R.string.setting_menu_app_info));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    app_gpl = (TextView) findViewById(R.id.app_gpl);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        app_gpl.setText(Html.fromHtml(KcaUtils.format(getString(R.string.ia_gpl), getString(R.string.app_brand)), Html.FROM_HTML_MODE_LEGACY));
    } else {
        app_gpl.setText(Html.fromHtml((KcaUtils.format(getString(R.string.ia_gpl), getString(R.string.app_brand)))));
    }
    app_gpl.setMovementMethod(LinkMovementMethod.getInstance());
}
 
Example #7
Source File: BlePeripheralsAdapter.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
private static Spanned getAdvertisementDescription(Context context, BlePeripheral blePeripheral) {
    final int deviceType = BleScanner.getDeviceType(blePeripheral);

    String text;
    switch (deviceType) {
        case kDeviceType_Beacon:
            text = getBeaconAdvertisementDescription(context, blePeripheral);
            break;

        case kDeviceType_UriBeacon:
            text = getUriBeaconAdvertisementDescription(context, blePeripheral);
            break;

        default:
            text = getCommonAdvertisementDescription(context, blePeripheral);
            break;
    }

    Spanned result;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        result = Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY);
    } else {
        result = Html.fromHtml(text);
    }
    return result;
}
 
Example #8
Source File: HtmlFormatter.java    From standardlib with Apache License 2.0 6 votes vote down vote up
public static Spanned format(String html, Boolean withImages) {
    if (!withImages) {
        html = html.replaceAll("<img.+?>", "");
    }
    return Html.fromHtml(html, null, new Html.TagHandler() {
        @Override
        public void handleTag(boolean opening,
                              String tag,
                              Editable output,
                              XMLReader xmlReader) {
            if (opening && tag.equals("li")) {
                output.append("\n")
                      .append("\t\u2022 ");
            }
        }
    });
}
 
Example #9
Source File: InitialDetailDialogs.java    From kute with Apache License 2.0 6 votes vote down vote up
private void addBottomDots(int currentPage) {
    dots = new TextView[3];
    int colorsActive = ResourcesCompat.getColor(getResources(), R.color.dot_active, null);
    int colorsInactive = ResourcesCompat.getColor(getResources(), R.color.dot_inactive, null);
    dotsLayout.removeAllViews();
    for (int i = 0; i < dots.length; i++) {
        dots[i] = new TextView(this);
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // a certain method is not valid for versions below adroid nougat
            dots[i].setText(Html.fromHtml("&#8226;", Html.FROM_HTML_MODE_COMPACT));
        }
        else
        {
            dots[i].setText(Html.fromHtml("&#8226;"));
        }
        dots[i].setTextSize(35);
        dots[i].setTextColor(colorsInactive);
        dotsLayout.addView(dots[i]);
    }

    if (dots.length > 0)
        dots[currentPage].setTextColor(colorsActive);
}
 
Example #10
Source File: MainActivity.java    From andela-crypto-app with Apache License 2.0 6 votes vote down vote up
private void init() {
    emptyText.setText(Html.fromHtml(getString(R.string.text_empty_message)));

    adapter = new CardsAdapter();
    adapter.setOnItemClickListener(this);
    adapter.setOnCardActionListener(this);
    adapter.setEmptyView(emptyView);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);

    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);

    List<Country> all = countryBox.getAll();
    adapter.setCountries(all);
    loadRates(all.toArray(new Country[0]));

    swipeRefreshLayout.setOnRefreshListener(() ->
            loadRates(adapter.getCountries().toArray(new Country[0])));
}
 
Example #11
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
private void onAppUpdated(int versionCode) {
    String changelog = ChangelogStringBuilder.getChangelog(getResources(), versionCode);
    if (changelog == null || changelog.isEmpty())
        return;
    CharSequence spannedChangelog = Html.fromHtml(changelog);
    AlertDialog dialog = new AlertDialog.Builder(this)
            .setTitle(string.changelog)
            .setCancelable(true)
            .setPositiveButton(android.R.string.ok, (dialog12, which) -> dialog12.dismiss())
            .setNegativeButton(string.rate_us, (dialog1, which) -> {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.geecko.QuickLyric")));
                dialog1.dismiss();
            })
            .setNeutralButton(string.translate_us, (dialog3, which) -> {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/quicklyric")));
                dialog3.dismiss();
            })
            .setMessage(spannedChangelog)
            .create();
    dialog.show();
}
 
Example #12
Source File: UEFontAwesome.java    From Auie with GNU General Public License v2.0 6 votes vote down vote up
public UEFontAwesomeDrawable(Context context, final View view, String text, int color) {
	this.text = Html.fromHtml(text).toString();
	mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
	mTextPaint.setTypeface(typeface);
	mTextPaint.setDither(true);
	mTextPaint.setColor(color);
	mTextPaint.setTextAlign(Paint.Align.CENTER);
	mTextPaint.measureText(text);
	view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
		@Override
		public boolean onPreDraw() {
			width = view.getWidth();
			height = view.getHeight();
			mTextPaint.setTextSize(Math.min(width, height));
			view.getViewTreeObserver().removeOnPreDrawListener(this);
			return false;
		}
	});
}
 
Example #13
Source File: ArtistView.java    From Cheerleader with Apache License 2.0 6 votes vote down vote up
/**
 * Set the {@link SoundCloudUser} used as model.
 *
 * @param artist user used as artist.
 */
public void setModel(SoundCloudUser artist) {
    mModel = artist;
    if (mModel != null) {
        Picasso.with(getContext())
                .load(
                        SoundCloudArtworkHelper.getCoverUrl(
                                mModel,
                                SoundCloudArtworkHelper.XLARGE
                        )
                )
                .fit()
                .centerInside()
                .into(mAvatar);
        mArtistName.setText(mModel.getFullName());
        mTracks.setText(
                String.format(
                        getResources().getString(R.string.artist_view_track_count),
                        mModel.getTrackCount()
                )
        );
        mDescription.setText(Html.fromHtml(mModel.getDescription()));
        this.setVisibility(VISIBLE);
    }
}
 
Example #14
Source File: TutorialActivity.java    From incubator-taverna-mobile with Apache License 2.0 6 votes vote down vote up
public void addBottomDots(int currentPage) {
    TextView[] dots = new TextView[TutorialSliderEnum.values().length];

    int[] colorsActive = getResources().getIntArray(R.array.array_dot_active);
    int[] colorsInactive = getResources().getIntArray(R.array.array_dot_inactive);

    dotsLayout.removeAllViews();
    for (int i = 0; i < dots.length; i++) {
        dots[i] = new TextView(this);
        dots[i].setText(Html.fromHtml("&#8226;"));
        dots[i].setTextSize(35);
        dots[i].setTextColor(colorsInactive[currentPage]);
        dotsLayout.addView(dots[i]);
    }

    if (dots.length > 0)
        dots[currentPage].setTextColor(colorsActive[currentPage]);
}
 
Example #15
Source File: TopicReplyAdapter.java    From diycode with Apache License 2.0 6 votes vote down vote up
/**
 * 在此处处理数据
 *
 * @param position 位置
 * @param holder   view holder
 * @param bean     数据
 */
@Override public void convert(int position, RecyclerViewHolder holder, TopicReply bean) {
    final User user = bean.getUser();
    holder.setText(R.id.username, user.getLogin());
    holder.setText(R.id.time, TimeUtil.computePastTime(bean.getUpdated_at()));

    ImageView avatar = holder.get(R.id.avatar);
    ImageUtils.loadImage(mContext, user.getAvatar_url(), avatar);
    TextView content = holder.get(R.id.content);
    // TODO 评论区代码问题
    content.setText(Html.fromHtml(HtmlUtil.removeP(bean.getBody_html()), new GlideImageGetter(mContext, content), null));

    holder.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(mContext, UserActivity.class);
            intent.putExtra(UserActivity.USER, user);
            mContext.startActivity(intent);
        }
    }, R.id.avatar, R.id.username);
}
 
Example #16
Source File: TitleRetriever.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
@Override
void retrieveSupplementalInfo() {
  CharSequence contents;
  try {
    contents = HttpHelper.downloadViaHttp(httpUrl, HttpHelper.ContentType.HTML, 4096);
  } catch (IOException ioe) {
    // ignore this
    return;
  }
  if (contents != null && contents.length() > 0) {
    Matcher m = TITLE_PATTERN.matcher(contents);
    if (m.find()) {
      String title = m.group(1);
      if (title != null && !title.isEmpty()) {
        title = Html.fromHtml(title).toString();
        if (title.length() > MAX_TITLE_LEN) {
          title = title.substring(0, MAX_TITLE_LEN) + "...";
        }
        append(httpUrl, null, new String[] {title}, httpUrl);
      }
    }
  }
}
 
Example #17
Source File: DbDebugFragment.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
private void initView() throws Exception {
    if (!DebugDB.isServerRunning()) {
        DebugDB.initialize(DoraemonKit.APPLICATION, new DebugDBFactory());
        DebugDB.initialize(DoraemonKit.APPLICATION, new DebugDBEncryptFactory());
    }
    HomeTitleBar titleBar = findViewById(R.id.title_bar);
    titleBar.setListener(new HomeTitleBar.OnTitleBarClickListener() {
        @Override
        public void onRightClick() {
            finish();
        }
    });
    TextView tvTip = findViewById(R.id.tv_tip);
    tvTip.setText(Html.fromHtml(getResources().getString(R.string.dk_kit_db_debug_desc)));
    tvIp = findViewById(R.id.tv_ip);
    if (DebugDB.isServerRunning()) {
        tvIp.setText("" + DebugDB.getAddressLog().replace("Open ", "").replace("in your browser", ""));
    } else {
        tvIp.setText("servse is not start");
    }
}
 
Example #18
Source File: PreferencesAdvancedActivity.java    From flickr-uploader with GNU General Public License v2.0 6 votes vote down vote up
private void render() {
    BackgroundExecutor.execute(new Runnable() {
        @Override
        public void run() {
            final long size = FlickrUploader.getLogSize();
            final List<String> autoupload_delay_values = Arrays.asList(getResources().getStringArray(R.array.autoupload_delay_values));
            final String[] autoupload_delay_entries = getResources().getStringArray(R.array.autoupload_delay_entries);
            final String autoupload_delay_value = Utils.getStringProperty("autoupload_delay", autoupload_delay_values.get(0));
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    findPreference("clear_logs").setSummary("Files size: " + Utils.formatFileSize(size));
                    String autoupload_delay = autoupload_delay_entries[autoupload_delay_values.indexOf(autoupload_delay_value)];
                    if (autoupload_delay.equalsIgnoreCase("custom")) {
                        findPreference("autoupload_delay").setSummary(autoupload_delay);
                    } else {
                        findPreference("autoupload_delay").setSummary(autoupload_delay);
                    }
                    findPreference("upload_description").setSummary(Html.fromHtml(Utils.getUploadDescription()));
                    findPreference("custom_tags").setSummary(Utils.getStringProperty("custom_tags"));
                }
            });
        }
    });
}
 
Example #19
Source File: ContentTextViewFragment.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
private void initView(View v) {

        tvAbout=(TextView)v.findViewById(R.id.tv_about);
        tvAbout.setMovementMethod(LinkMovementMethod.getInstance());
        tvAbout.setText(Html.fromHtml((getResources().getString((R.string.app_about)))));

        ptr = (PtrClassicFrameLayout) v.findViewById(R.id.ptr_main);

        ptr.setPtrHandler(new PtrDefaultHandler() {
            @Override
            public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ptr.refreshComplete();
                    }
                }, 2000);
            }
        });
    }
 
Example #20
Source File: AboutActivity.java    From Moment with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    getWindow().setStatusBarColor(Color.TRANSPARENT);
    setContentView(R.layout.about_activity);

    TextView sourceCode = (TextView) findViewById(R.id.source_code);
    sourceCode.setText(Html.fromHtml(getString(R.string.source_code)));
    sourceCode.setMovementMethod(new LinkMovementMethod());

    TextView appVersion = (TextView) findViewById(R.id.app_version);
    appVersion.setText(String.format("v%s", BuildConfig.VERSION_NAME));

    TextView openSource = (TextView) findViewById(R.id.open_source);
    openSource.setText(Html.fromHtml(getString(R.string.open_source_used)));
    openSource.setMovementMethod(new LinkMovementMethod());
}
 
Example #21
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 6 votes vote down vote up
private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id,
                                          CharSequence address, CharSequence phoneNumber, Uri websiteUri) {
    Log.e(TAG, res.getString(R.string.place_details, name, id, address, phoneNumber,
            websiteUri));
    return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber,
            websiteUri));

}
 
Example #22
Source File: StatusInstallerFragment.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
static void setUpdate(final String link, final String changelog, Context mContext) {
    mUpdateLink = link;

    mUpdateView.setVisibility(View.VISIBLE);
    mUpdateButton.setVisibility(View.VISIBLE);
    mUpdateButton.setOnClickListener(v -> new MaterialDialog.Builder(sActivity)
            .title(R.string.changes)
            .content(Html.fromHtml(changelog, Html.FROM_HTML_MODE_COMPACT))
            .onPositive((dialog, which) -> update(mContext))
            .positiveText(R.string.update)
            .negativeText(R.string.later).show());
}
 
Example #23
Source File: RegistrationIdViewHolder.java    From FCM-for-Mojo with GNU General Public License v3.0 5 votes vote down vote up
public RegistrationIdViewHolder(View itemView) {
    super(itemView);

    title = itemView.findViewById(android.R.id.title);
    summary = itemView.findViewById(android.R.id.summary);
    delete = itemView.findViewById(android.R.id.button1);

    delete.setOnClickListener(view -> {
        int index = getAdapterPosition();
        getAdapter().getItems().remove(index);
        getAdapter().notifyItemRemoved(index);
    });

    itemView.setOnClickListener(view -> {
        final Context context = view.getContext();
        new AlertDialog.Builder(context)
                .setMessage(Html.fromHtml(context.getString(R.string.dialog_token_message, getData().getId()), Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE))
                .setPositiveButton(android.R.string.copy, (dialog, which) -> ClipboardUtils.put(context, getData().getId()))
                .setNeutralButton(R.string.dialog_token_share, (dialog, which) -> context.startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
                                .putExtra(Intent.EXTRA_TEXT, FirebaseInstanceId.getInstance().getToken())
                                .setType("text/plain")
                        , context.getString(R.string.dialog_token_share))))
                .setNegativeButton(android.R.string.cancel, null)
                .show();
    });

    mDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());
}
 
Example #24
Source File: DetailFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
void setHtml(String text){
    final String stripped = stripBody(text);
    if(editor != null){
        editor.setHtml(stripped);
    }else{
        Spanned fromHtml = Html.fromHtml(stripped);
        editText.setText(fromHtml, TextView.BufferType.SPANNABLE);
    }
}
 
Example #25
Source File: ConversationsListAdapter.java    From chat21-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setTimestamp(ViewHolder holder, boolean hasNewMessages, long timestamp) {
    // format the timestamp to a pretty visible format
    String formattedTimestamp = TimeUtils.getFormattedTimestamp(holder.itemView.getContext(), timestamp);

    if (hasNewMessages) {
        // show bold text
        holder.lastMessageTimestamp.setText(Html.fromHtml("<b>" + formattedTimestamp + "</b>"));
    } else {
        // not not bold text
        holder.lastMessageTimestamp.setText(formattedTimestamp);
    }
}
 
Example #26
Source File: ProxyService.java    From k3pler with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void onViewPager_select(int position){
    String pageNumHTML = "";
    int color;
    for(int i = 0; i < LayoutPagerAdapter.PagerEnum.values().length; i++){
        if(i == position)
            color = ContextCompat.getColor(getApplicationContext(), android.R.color.white);
        else
            color = ContextCompat.getColor(getApplicationContext(), R.color.color2dark);
        pageNumHTML += "<font color=\"" + color + "\">" + String.valueOf(i+1) + " " + "</font>";
    }
    txvNum.setText(Html.fromHtml(pageNumHTML));
}
 
Example #27
Source File: TouchFeedbackCodeFragment.java    From ifican with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = super.onCreateView(inflater, container, savedInstanceState);
    ButterKnife.inject(this, v);

    text4.setText(Html.fromHtml(IOUtils.readFile(getActivity(), "source/touch_anim.xml.html")));
    currentStep = 1;
    return v;
}
 
Example #28
Source File: CalibrationFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.calibration_dialog, container, false);
    mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);

    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME);
    mAccuracy = view.findViewById(R.id.accuracy_text);
    mAccuracy.setText(
            Html.fromHtml(String.format("%s: <font color='red'>%s</font>", getString(R.string.accuracy), getString(R.string.accuracy_low))));
    view.findViewById(R.id.close).setOnClickListener(v -> getParentFragment().getChildFragmentManager().beginTransaction().remove(CalibrationFragment.this).commit());
    return view;
}
 
Example #29
Source File: AboutDialog.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges app name and version name into one.
 */
@NonNull
public static Spanned getVersionName(@NonNull Context context) {
    PackageManager pm = context.getPackageManager();
    String packageName = context.getPackageName();
    String versionName;
    try {
        PackageInfo info = pm.getPackageInfo(packageName, 0);
        versionName = info.versionName;

        // Make the info part of version name a bit smaller.
        if (versionName.indexOf('-') >= 0) {
            versionName = versionName.replaceFirst("\\-", "<small>-") + "</small>";
        }
    } catch (PackageManager.NameNotFoundException e) {
        versionName = "N/A";
    }

    /*
        int[] attribute = {android.R.attr.textColorHint};
        TypedArray a = context.obtainStyledAttributes(android.R.attr.textAppearance, attribute);
        int color = a.getColor(0, 0xFF888888);
        a.recycle();
    */
    // TODO: Get the color from current theme.
    int color = 0xFF888888;

    Resources res = context.getResources();
    return Html.fromHtml(
            ResUtils.getString(res, R.string.about_dialog_title,
                    res.getString(R.string.app_name),
                    versionName,
                    Integer.toHexString(Color.red(color))
                            + Integer.toHexString(Color.green(color))
                            + Integer.toHexString(Color.blue(color)))
    );
}
 
Example #30
Source File: DictionaryListAdapter.java    From aard2-android with GNU General Public License v3.0 5 votes vote down vote up
private void setupLicenseView(SlobDescriptor desc, boolean available, View view) {
    View licenseRow= view.findViewById(R.id.dictionary_license_row);

    ImageView licenseIcon = (ImageView) view.findViewById(R.id.dictionary_license_icon);
    licenseIcon.setImageDrawable(IconMaker.text(context, IconMaker.IC_LICENSE));

    TextView licenseView = (TextView) view.findViewById(R.id.dictionary_license);
    String licenseName = desc.tags.get("license.name");
    String licenseUrl = desc.tags.get("license.url");
    CharSequence license;
    if (Util.isBlank(licenseUrl)) {
        license = licenseName;
    }
    else {
        if (Util.isBlank(licenseName)) {
            licenseName = licenseUrl;
        }
        license = Html.fromHtml(String.format(hrefTemplate, licenseUrl, licenseName));
    }
    licenseView.setText(license);
    licenseView.setTag(licenseUrl);

    int visibility = (Util.isBlank(licenseName) && Util.isBlank(licenseUrl)) ? View.GONE : View.VISIBLE;
    licenseIcon.setVisibility(visibility);
    licenseView.setVisibility(visibility);
    licenseRow.setVisibility(visibility);
    licenseRow.setEnabled(available);
}