Example usage for android.text Html fromHtml

List of usage examples for android.text Html fromHtml

Introduction

In this page you can find the example usage for android.text Html fromHtml.

Prototype

@Deprecated
public static Spanned fromHtml(String source) 

Source Link

Document

Returns displayable styled text from the provided HTML string with the legacy flags #FROM_HTML_MODE_LEGACY .

Usage

From source file:com.keepsafe.switchboard.example.SwitchBoardExampleAppActivity.java

@Override
protected void onResume() {
    super.onResume();
    //see if we're in experiment "homeScreenMessage" that we defined on the server
    if (SwitchBoard.isInExperiment(this, "homeScreenMessage")) {
        Log.d(TAG, "isInExperiment homeScreen");
        //check if the experiment has values. Only needed when passing custom variables
        if (SwitchBoard.hasExperimentValues(this, "homeScreenMessage")) {
            Log.d(TAG, "has values");
            TextView tv = (TextView) findViewById(R.id.messagebox);
            tv.setVisibility(View.VISIBLE);

            //get experiment values
            JSONObject values = SwitchBoard.getExperimentValueFromJson(this, "homeScreenMessage");
            try {
                //getting the user specific values
                String message = values.getString("message");
                String messageTitle = values.getString("messageTitle");

                tv.setText(Html.fromHtml(message));
                Log.d(TAG, "set message text in UI");

                /* Track the view in your preferred analytics
                 * using messageTitle to track test 
                 *///w ww  .  j a v a2 s .  co  m

                //tracks when user clicks on HTML link from your A/B test
                tv.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        /* Track the click in your preferred analytics
                         * using messageTitle to track test 
                         */
                    }
                });

            } catch (JSONException e) {
                //catches if your requested JSON object is not in values
                e.printStackTrace();
            }
        }
    }
}

From source file:com.bangz.smartmute.RulelistAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    int idxName = cursor.getColumnIndex(RulesColumns.NAME);
    int idxRuleType = cursor.getColumnIndex(RulesColumns.RULETYPE);
    int idxCondition = cursor.getColumnIndex(RulesColumns.CONDITION);
    int idxSecondCondition = cursor.getColumnIndex(RulesColumns.SECONDCONDITION);
    int idxActivited = cursor.getColumnIndex(RulesColumns.ACTIVATED);

    ViewHolder vh = (ViewHolder) view.getTag();

    String name = cursor.getString(idxName);

    if (name == null || (name != null && name.isEmpty()))
        name = context.getString(R.string.noname);
    vh.txtRuleName.setText(name);//from   w w  w  .  j a va 2  s.  com

    int[] ruletypeiconids = { 0, R.drawable.ic_location, R.drawable.ic_wifi, R.drawable.ic_clock };
    int ruletype = cursor.getInt(idxRuleType);

    vh.imageType.setImageResource(ruletypeiconids[ruletype]);

    String strcondition = cursor.getString(idxCondition);
    Condition condition = ConditionFactory.CreateCondition(strcondition);
    vh.txtDetail.setText(Html.fromHtml(condition.description(context)));

    if (ruletype == RulesColumns.RT_WIFI) {
        String ssid = ((WifiCondition) condition).getSSID();
        vh.txtRuleName.setText(ssid);
    }

    int activeted = cursor.getInt(idxActivited);
    vh.switchActivited.setChecked(activeted != 0);
    vh.switchActivited.setTag(cursor.getLong(cursor.getColumnIndex(RulesColumns._ID)));
    //super.bindView(view, context, cursor);
}

From source file:com.pixellostudio.qqdroid.BaseQuote.java

/** Called when the activity is first created. */
@Override/*from   w  w w.j  a  va 2s.  c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setActionBarContentView(R.layout.show);

    getActionBar().setTitle(title);

    getActionBar().addItem(getActionBar().newActionBarItem(NormalActionBarItem.class)
            .setDrawable(R.drawable.seemore).setContentDescription("List"), R.id.actionbar_seemore);

    view = (ListView) findViewById(R.id.ListView);

    view.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            menu.add(0, 1, 0, R.string.sharequote);
        }
    });

    adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1);
    adapter2 = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(BaseQuote.this);

            TextView txt = new TextView(this.getContext());
            txt.setTextSize(Float.parseFloat(pref.getString("policesize", "20")));
            txt.setText(Html.fromHtml(this.getItem(position)));

            if (pref.getString("design", "blackonwhite").equals("blackonwhite")) {
                txt.setTextColor(Color.BLACK);
                txt.setBackgroundColor(Color.WHITE);
                txt.setBackgroundDrawable(
                        this.getContext().getResources().getDrawable(R.drawable.quote_gradient_white));
            } else if (pref.getString("design", "blackonwhite").equals("whiteonblack")) {
                txt.setTextColor(Color.WHITE);
                txt.setBackgroundColor(Color.BLACK);
                txt.setBackgroundDrawable(
                        this.getContext().getResources().getDrawable(R.drawable.quote_gradient_black));
            }

            return txt;
        }

    };

    String[] liste = (String[]) getLastNonConfigurationInstance();

    if (liste != null && liste.length != 0) {
        for (int i = 0; i < liste.length; i++) {
            adapter.add(liste[i]);
            adapter2.add(liste[i]);
        }

        this.setTitle(name);
    } else {
        new LoadQuotes().execute();
    }

    view.setAdapter(adapter2);
}

From source file:lv.vizzual.numuri.service.operators.LVDataProvider.java

private String extractNetworkProvider(String page) {
    String provider = null;//from   w  ww .  jav  a  2s .  c o  m

    if (page.contains("Mintes laik? var veikt tikai 5 pieprasjumus!")) {
        throw new RequestLimitReachedException();
    }

    String exp = "Pakalpojuma nodroin?t?js </td><td><b>(.*?)</b>";
    Pattern pattern = Pattern.compile(exp, Pattern.DOTALL | Pattern.UNIX_LINES);
    Matcher matcher = pattern.matcher(page);
    if (matcher.find()) {
        String providerHTML = matcher.group(1);
        provider = Html.fromHtml(providerHTML).toString();
    }

    return cleanNetworkProvider(provider);
}

From source file:com.crossword.activity.FeedbackActivity.java

public void postMessage() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(Crossword.MAIL_URL);
    try {//from   ww  w  .j a  v  a 2 s  .  c om
        EditText feedMessage = (EditText) findViewById(R.id.feed_message);

        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("from",
                android.os.Build.MODEL + " (" + android.os.Build.VERSION.RELEASE + ")"));
        nameValuePairs.add(new BasicNameValuePair("message", feedMessage.getText().toString()));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        if (response.getStatusLine().getStatusCode() == 200) {
            runOnUiThread(new Runnable() {
                public void run() {
                    Toast.makeText(FeedbackActivity.this, R.string.feedback_send_success, Toast.LENGTH_SHORT)
                            .show();
                }
            });
            finish();
            return;
        }

        String line;
        StringBuilder total = new StringBuilder();
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        while ((line = rd.readLine()) != null) {
            total.append(line);
        }
        error = Html.fromHtml(total.toString()).toString();
    } catch (ClientProtocolException e) {
        error = getResources().getString(R.string.exception_network);
        e.printStackTrace();
    } catch (IOException e) {
        error = getResources().getString(R.string.exception_network);
        e.printStackTrace();
    }
}

From source file:com.bordengrammar.bordengrammarapp.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View myInflatedView = inflater.inflate(R.layout.fragment_home, container, false);
    GoogleMap map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
    ut.logIt("1");
    try {//from   w w w .  j  a  v  a  2  s  . co m
        Marker borden = map.addMarker(new MarkerOptions().position(BORDEN).snippet("This is where we are")
                .title("Borden Grammar School")
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
        map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        map.setMyLocationEnabled(true);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(BORDEN, 15));
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

    assert myInflatedView != null;
    TextView t = (TextView) myInflatedView.findViewById(R.id.tweet);
    //t.setText('"' + readPrefs("twitter") + '"');
    if (!readPrefs("link").isEmpty()) {
        t.setText('"' + readPrefs("twitter") + '"' + " - View Link");
        t.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity().getApplicationContext(), LinkActivity.class);
                intent.putExtra("link", readPrefs("link"));
                startActivity(intent);
            }
        });
    } else {

    }
    TextView t1;

    t1 = (TextView) myInflatedView.findViewById(R.id.date);
    String t1source = "<b>" + "&#64;" + "bordengrammar" + "</b>" + " | " + readPrefs("twittertime");
    t1.setText(Html.fromHtml(t1source));

    TextView info = (TextView) myInflatedView.findViewById(R.id.info);
    String sourceString = "<b>" + "Borden Grammar School" + "</b> "
            + "is a selective boy's grammar school in Sittingbourne, with a fierce commitment to educate, inspire and prepare students academically and socially";
    info.setText(Html.fromHtml(sourceString));

    //now for contact stuff

    return myInflatedView;
}

From source file:fm.smart.r1.CreateSoundActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ExceptionHandler.register(this);
    setContentView(R.layout.create_sound);
    final Intent queryIntent = getIntent();
    Bundle extras = queryIntent.getExtras();
    item_id = (String) extras.get("item_id");
    id = (String) extras.get("id");
    goal_id = (String) extras.get("goal_id"); // not being added at present
    // TODO/* www.  j  a va  2  s. c  o m*/
    to_record = (String) extras.get("to_record");
    sound_type = extras.getString("sound_type");

    recorder = new MediaRecorder();

    TextView text = (TextView) findViewById(R.id.create_sound_text);
    text.setText(Html.fromHtml(to_record));
    button = (Button) findViewById(R.id.create_sound_submit);
    button.setOnClickListener(this);

}

From source file:com.ideateam.plugin.Emailer.java

private void SendEmail(String email, String subject, String text, String attachFile) {

    String attachPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/UAR2015/" + attachFile;
    File file = new File(attachPath);

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(text));

    this.cordova.getActivity().startActivity(Intent.createChooser(intent, "Send email..."));

}

From source file:com.activiti.android.app.fragments.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    getToolbar().setVisibility(View.GONE);

    webView = (WebView) v.findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(R.id.empty);
    emptyTextView = (TextView) v.findViewById(R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final Activity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override//from  ww w  .  j  a  v a  2  s .  c  om
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            getActivity().setProgressBarIndeterminateVisibility(true);
            refreshIcon.setVisible(false);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }

            if (getActivity() != null) {
                getActivity().setProgressBarIndeterminateVisibility(false);
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:com.github.sgelb.booket.SearchResultActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_results);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    noResults = (TextView) findViewById(R.id.noResultsTextView);
    defaultThumbnail = BitmapFactory.decodeResource(getResources(), R.drawable.ic_default_cover);

    bookList = new ArrayList<>();
    resultList = (ListView) findViewById(R.id.searchResultsList);
    downloadProgressBar = (ProgressBar) findViewById(R.id.downloadProgressBar);
    datasource = new BooksDataSource(this);

    BookInfos bookInfos = new BookInfos();
    bookInfos.execute(createUrl());//from   ww  w .ja v a 2  s. c  o  m
    adapter = new BookResultAdapter(bookList, this);
    resultList.setAdapter(adapter);

    // Save book in database
    resultList.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {

            AlertDialog alert = new AlertDialog.Builder(SearchResultActivity.this).create();
            alert.setTitle(
                    Html.fromHtml(getString(R.string.dialog_save_book, bookList.get(position).getTitle())));
            alert.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok), new OnClickListener() {
                public void onClick(final DialogInterface dialog, final int which) {
                    saveBook(position);
                }
            });
            alert.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new OnClickListener() {
                public void onClick(final DialogInterface dialog, final int which) {
                }
            });
            alert.show();

            return true;
        }
    });

    // Expand list row
    resultList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            adapter.toggleExpand(view, position);
        }
    });

}