Example usage for android.text Html toHtml

List of usage examples for android.text Html toHtml

Introduction

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

Prototype

@Deprecated
public static String toHtml(Spanned text) 

Source Link

Usage

From source file:com.github.irshulx.Components.InputExtensions.java

public CustomEditText getNewEditTextInst(final String hint, CharSequence text) {
    final CustomEditText editText = new CustomEditText(
            new ContextThemeWrapper(this.editorCore.getContext(), R.style.WysiwygEditText));
    addEditableStyling(editText);//from  w ww .jav a  2 s.c  o m
    editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    if (hint != null) {
        editText.setHint(hint);
    }
    if (text != null) {
        setText(editText, text);
    }

    /**
     * create tag for the editor
     */

    EditorControl editorTag = editorCore.createTag(EditorType.INPUT);
    editorTag.textSettings = new TextSettings(this.DEFAULT_TEXT_COLOR);
    editText.setTag(editorTag);
    editText.setBackgroundDrawable(
            ContextCompat.getDrawable(this.editorCore.getContext(), R.drawable.invisible_edit_text));
    editText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return editorCore.onKey(v, keyCode, event, editText);
        }
    });
    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                editText.clearFocus();
            } else {
                editorCore.setActiveView(v);
            }
        }
    });
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {

            String text = Html.toHtml(editText.getText());
            Object tag = editText.getTag(R.id.control_tag);
            if (s.length() == 0 && tag != null)
                editText.setHint(tag.toString());
            if (s.length() > 0) {
                /*
                 * if user had pressed enter, replace it with br
                 */
                for (int i = 0; i < s.length(); i++) {
                    if (s.charAt(i) == '\n') {
                        CharSequence subChars = s.subSequence(0, i);
                        SpannableStringBuilder ssb = new SpannableStringBuilder(subChars);
                        text = Html.toHtml(ssb);
                        if (text.length() > 0)
                            setText(editText, text);

                        if (i + 1 == s.length()) {
                            s.clear();
                        }

                        int index = editorCore.getParentView().indexOfChild(editText);
                        /* if the index was 0, set the placeholder to empty, behaviour happens when the user just press enter
                         */
                        if (index == 0) {
                            editText.setHint(null);
                            editText.setTag(R.id.control_tag, hint);
                        }
                        int position = index + 1;
                        CharSequence newText = null;
                        SpannableStringBuilder editable = new SpannableStringBuilder();
                        int lastIndex = s.length();
                        int nextIndex = i + 1;
                        if (nextIndex < lastIndex) {
                            newText = s.subSequence(nextIndex, lastIndex);
                            for (int j = 0; j < newText.length(); j++) {
                                editable.append(newText.charAt(j));
                                if (newText.charAt(j) == '\n') {
                                    editable.append('\n');
                                }
                            }
                        }
                        insertEditText(position, hint, editable);
                        break;
                    }
                }
            }
            if (editorCore.getEditorListener() != null) {
                editorCore.getEditorListener().onTextChanged(editText, s);
            }
        }
    });
    if (this.lineSpacing != -1) {
        setLineSpacing(editText, this.lineSpacing);
    }
    return editText;
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case android.R.id.home:
        // app icon in action bar clicked; go home
        finish();/*from   w  w  w .  j a  v  a2s  .c  om*/
        return true;
    case R.id.menu_message_compose_add_attachment_images:
        requestForAttachmentIntent(ATTACHMENT_TYPE.IMAGE);
        return true;
    case R.id.menu_message_compose_add_attachment_files:
        requestForAttachmentIntent(ATTACHMENT_TYPE.TEXT_FILE);
        return true;
    //??
    case R.id.menu_message_compose_send:

        EditText edtSubject = (EditText) findViewById(R.id.edtMessageSubject);
        EditText edtBody = (EditText) findViewById(R.id.edtMessageBody);
        edtSubject.setError(null);
        edtBody.setError(null);
        if (selectedPartners.size() == 0) {
            Toast.makeText(this, "", Toast.LENGTH_LONG).show();
        } else if (TextUtils.isEmpty(edtSubject.getText())) {
            edtSubject.setError("? !");
        } else if (TextUtils.isEmpty(edtBody.getText())) {
            edtBody.setError("?!");
        } else {

            Toast.makeText(this, "??...", Toast.LENGTH_LONG).show();
            String subject = edtSubject.getText().toString();
            String body = edtBody.getText().toString();
            //oe?
            Ir_AttachmentDBHelper attachment = new Ir_AttachmentDBHelper(MainActivity.context);
            JSONArray newAttachmentIds = new JSONArray();
            for (Uri file : file_uris) {
                // oe?????
                File fileData = new File(file.getPath());
                ContentValues values = new ContentValues();
                values.put("datas_fname", getFilenameFromUri(file));
                values.put("res_model", "mail.compose.message");
                values.put("company_id", scope.User().getCompany_id());
                values.put("type", "binary");
                values.put("res_id", 0);
                values.put("file_size", fileData.length());
                values.put("db_datas", Base64Helper.fileUriToBase64(file, getContentResolver()));
                values.put("name", getFilenameFromUri(file));
                int newId = attachment.create(attachment, values);
                newAttachmentIds.put(newId);
            }

            // TASK: sending mail
            HashMap<String, Object> values = new HashMap<String, Object>();
            values.put("subject", subject);
            if (is_note_body) {
                values.put("body", Html.toHtml(edtBody.getText()));
            } else {
                values.put("body", body);
            }
            values.put("partner_ids", getPartnersId());
            values.put("attachment_ids", newAttachmentIds);

            if (is_reply) {
                SendMailMessageReply sendMessageRply = new SendMailMessageReply(values);
                sendMessageRply.execute((Void) null);
            } else {
                SendMailMessage sendMessage = new SendMailMessage(values);
                sendMessage.execute((Void) null);
            }

        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.openerp.addons.note.EditNoteFragment.java

public void updateNote(int row_id) {

    try {/* w  w  w . ja v a2  s.  c om*/
        JSONArray tagID = db.getSelectedTagId(selectedTags);
        long stage_id = Long.parseLong(stages.get(noteStages.getSelectedItem().toString()));
        ContentValues values = new ContentValues();
        JSONObject vals = new JSONObject();

        // If Pad Installed Over Server
        if (padAdded) {
            JSONArray url = new JSONArray();
            url.put(originalMemo);
            JSONObject obj = oe_obj.call_kw("pad.common", "pad_get_content", url);

            // HTMLHelper helper = new HTMLHelper();
            String link = HTMLHelper.htmlToString(obj.getString("result"));
            values.put("stage_id", stage_id);
            vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString()));

            values.put("name", db.generateName(link));
            vals.put("name", values.get("name").toString());

            values.put("memo", obj.getString("result"));
            vals.put("memo", values.get("memo").toString());

            values.put("note_pad_url", originalMemo);
            vals.put("note_pad_url", values.get("note_pad_url").toString());
        } // If Pad Not Installed Over Server
        else {
            values.put("stage_id", stage_id);
            vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString()));

            values.put("name", db.generateName(noteMemo.getText().toString()));
            vals.put("name", values.get("name").toString());

            values.put("memo", Html.toHtml(noteMemo.getText()));
            vals.put("memo", values.get("memo").toString());
        }

        JSONArray tag_ids = new JSONArray();
        tag_ids.put(6);
        tag_ids.put(false);
        JSONArray c_ids = new JSONArray(tagID.toString());
        tag_ids.put(c_ids);
        vals.put("tag_ids", new JSONArray("[" + tag_ids.toString() + "]"));

        // This will update Notes over Server And Local database
        db = new NoteDBHelper(scope.context());
        if (oe_obj.updateValues(db.getModelName(), vals, row_id)) {
            db.write(db, values, row_id, true);
            db.executeSQL("delete from note_note_note_tag_rel where note_note_id = ? and oea_name = ?",
                    new String[] { row_id + "", scope.User().getAndroidName() });
            for (int i = 0; i < tagID.length(); i++) {
                ContentValues rel_vals = new ContentValues();
                rel_vals.put("note_note_id", row_id);
                rel_vals.put("note_tag_id", tagID.getInt(i));
                rel_vals.put("oea_name", scope.User().getAndroidName());
                SQLiteDatabase insertDb = db.getWritableDatabase();
                insertDb.insert("note_note_note_tag_rel", null, rel_vals);
                insertDb.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:sjizl.com.ChatActivityFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LayoutInflater factory = LayoutInflater.from(getActivity());
    View myView = factory.inflate(R.layout.activity_chat_fragment, null);

    if (CommonUtilities.isInternetAvailable(getActivity().getApplicationContext())) //returns true if internet available
    {/*www  .  j a  v a 2s  . com*/

        SharedPreferences sp = getActivity().getApplicationContext().getSharedPreferences("loginSaved",
                Context.MODE_PRIVATE);
        pid = sp.getString("pid", null);
        naam = sp.getString("naam", null);
        username = sp.getString("username", null);
        password = sp.getString("password", null);
        foto = sp.getString("foto", null);
        foto_num = sp.getString("foto_num", null);
        Bundle bundle = getActivity().getIntent().getExtras();

        Bundle args = getArguments();

        Log.i("args", args.toString());
        if (args != null && args.containsKey("pid_user")) {

            pid_user = args.getString("pid_user");
            user = args.getString("user");
            user_foto_num = args.getString("user_foto_num");
            user_foto = args.getString("user_foto");
        } else {

            pid_user = bundle.getString("pid_user");
            user = bundle.getString("user");
            user_foto_num = bundle.getString("user_foto_num");
            user_foto = bundle.getString("user_foto");

        }
        // Toast.makeText(getApplicationContext(), "pid_user"+pid_user, Toast.LENGTH_SHORT).show();

        if (user.equalsIgnoreCase(naam.toString())) {
            Toast.makeText(getActivity().getApplicationContext(), "You can't message yourself!",
                    Toast.LENGTH_SHORT).show();
            getActivity().finish();
        }

        AbsListViewBaseActivity.imageLoader
                .init(ImageLoaderConfiguration.createDefault(getActivity().getBaseContext()));

        getActivity().registerReceiver(mHandleMessageReceiver2, new IntentFilter(DISPLAY_MESSAGE_ACTION));

        imageLoader.loadImage("https://www.sjizl.com/fotos/" + user_foto_num + "/thumbs/" + user_foto + "",
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                        d1 = new BitmapDrawable(getResources(), loadedImage);

                    }
                });

        imageLoader.loadImage("https://www.sjizl.com/fotos/" + foto_num + "/thumbs/" + foto + "",
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                        d2 = new BitmapDrawable(getResources(), loadedImage);

                    }
                });

        smilbtn = (ImageView) myView.findViewById(R.id.smilbtn);
        listView = (ListView) myView.findViewById(android.R.id.list);
        underlayout = (LinearLayout) myView.findViewById(R.id.underlayout);
        smiles_layout = (LinearLayout) myView.findViewById(R.id.smiles);
        textView1_bgtext = (TextView) getActivity().findViewById(R.id.textView1_bgtext);
        textView1_bgtext.setText(user);
        imageView2_dashboard = (ImageView) getActivity().findViewById(R.id.imageView2_dashboard);
        imageView1_logo = (ImageView) getActivity().findViewById(R.id.imageView1_logo);
        imageView_bericht = (ImageView) getActivity().findViewById(R.id.imageView_bericht);
        textView2_under_title = (TextView) getActivity().findViewById(R.id.textView2_under_title);
        right_lin = (LinearLayout) getActivity().findViewById(R.id.right_lin);
        left_lin1 = (LinearLayout) getActivity().findViewById(R.id.left_lin1);
        left_lin3 = (LinearLayout) getActivity().findViewById(R.id.left_lin3);
        left_lin4 = (LinearLayout) getActivity().findViewById(R.id.left_lin4);
        middle_lin = (LinearLayout) getActivity().findViewById(R.id.middle_lin);
        smile_lin = (LinearLayout) myView.findViewById(R.id.smile_lin);
        ber_lin = (LinearLayout) myView.findViewById(R.id.ber_lin);
        progressBar_hole = (ProgressBar) getActivity().findViewById(R.id.progressBar_hole);
        progressBar_hole.setVisibility(View.INVISIBLE);
        imageLoader.displayImage("http://sjizl.com/fotos/" + user_foto_num + "/thumbs/" + user_foto,
                imageView2_dashboard, options);
        new UpdateChat().execute();
        mNewMessage = (EditText) myView.findViewById(R.id.newmsg);
        ber_lin = (LinearLayout) myView.findViewById(R.id.ber_lin);

        /*
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    
                    
                    
            imageLoader.loadImage("http://sjizl.com/fotos/"+user_foto_num+"/thumbs/"+user_foto, new SimpleImageLoadingListener() {
               @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        super.onLoadingComplete(imageUri, view, loadedImage);
                
        Bitmap LoadedImage2 = loadedImage;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
           if(loadedImage!=null){
        LoadedImage2 = CommonUtilities.fastblur16(loadedImage, 4,getApplicationContext());
           }
        }
                
        if (Build.VERSION.SDK_INT >= 16) {
                
           listView.setBackground(new BitmapDrawable(getApplicationContext().getResources(), LoadedImage2));
                
          } else {
                
             listView.setBackgroundDrawable(new BitmapDrawable(LoadedImage2));
          }
                
        }
        }
            );
        }
        */

        listView.setOnScrollListener(new OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                mScrollState = scrollState;
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
            }

        });
        listView.setLongClickable(true);
        registerForContextMenu(listView);

        DisplayMetrics metrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
        viewPager_smiles = new ViewPager(getActivity());
        viewPager_smiles.setId(0x1000);
        LayoutParams layoutParams555 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        layoutParams555.width = LayoutParams.MATCH_PARENT;
        layoutParams555.height = (metrics.heightPixels / 2);
        viewPager_smiles.setLayoutParams(layoutParams555);
        TabsPagerAdapter mAdapter = new TabsPagerAdapter(getActivity().getSupportFragmentManager(),
                mNewMessage);
        viewPager_smiles.setAdapter(mAdapter);
        LayoutInflater inflater2 = null;
        viewPager_smiles.setVisibility(View.VISIBLE);
        smiles_layout.addView(viewPager_smiles);
        smiles_layout.setVisibility(View.GONE);

        left_lin4.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    Intent profile = new Intent(getActivity().getApplicationContext(),
                            ProfileActivityMain.class);
                    profile.putExtra("user", user);
                    profile.putExtra("user_foto", user_foto);
                    profile.putExtra("user_foto_num", user_foto_num);
                    profile.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(profile);
                }
                return false;
            }
        });
        middle_lin.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    Intent profile = new Intent(getActivity().getApplicationContext(),
                            ProfileActivityMain.class);
                    profile.putExtra("user", user);
                    profile.putExtra("user_foto", user_foto);
                    profile.putExtra("user_foto_num", user_foto_num);
                    profile.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(profile);
                }
                return false;
            }
        });

        smile_lin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                opensmiles();
            }
        });

        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent dashboard = new Intent(getActivity().getApplicationContext(), ProfileActivityMain.class);
                dashboard.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                dashboard.putExtra("user", ArrChatLines.get(position).getNaam());
                dashboard.putExtra("user_foto", foto);
                dashboard.putExtra("user_foto_num", foto_num);
                startActivity(dashboard);
            }
        });

        mNewMessage.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    v.setFocusable(true);
                    v.setFocusableInTouchMode(true);

                    smiles_layout.setVisibility(View.GONE);
                    smilbtn.setImageResource(R.drawable.emoji_btn_normal);
                    return false;
                }
                return false;
            }
        });

        TextWatcher textWatcher = new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                //after text changed
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                CommonUtilities
                        .startandsendwebsock("" + pid_user + " " + naam + " " + pid + " is typing to you ...");
            }

            @Override
            public void afterTextChanged(Editable s) {
                /*
                 AsyncHttpClient.getDefaultInstance().websocket("ws://sjizl.com:9300", "my-protocol", new WebSocketConnectCallback() {
                  @Override
                     public void onCompleted(Exception ex, WebSocket webSocket) {
                         if (ex != null) {
                   ex.printStackTrace();
                   return;
                         }
                         webSocket.send(""+pid_user+" "+naam+" "+pid+" is typing to you ...");
                                 
                         webSocket.close();
                     }
                 });
                 */
            }
        };

        mNewMessage.addTextChangedListener(textWatcher);

        ber_lin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SpannableStringBuilder spanStr = (SpannableStringBuilder) mNewMessage.getText();
                Spanned cs = (Spanned) mNewMessage.getText();
                String a = Html.toHtml(spanStr);
                String text = mNewMessage.getText().toString();
                mNewMessage.setText("");
                mNewMessage.requestFocus();
                mybmp2 = "http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto;
                if (text.length() < 1) {
                } else {
                    addItem(foto, foto_num, "0", naam, text.toString(),
                            "http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, "", a);
                }
            }
        });

        hideSoftKeyboard();

    } else {

        Intent dashboard = new Intent(getActivity().getApplicationContext(), NoInternetActivity.class);
        dashboard.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(dashboard);

        getActivity().finish();
    }
    mNewMessage.clearFocus();
    listView.requestFocus();

    final String wsuri = "ws://sjizl.com:9300";

    WebSocketConnection mConnection8 = new WebSocketConnection();

    if (mConnection8.isConnected()) {
        mConnection8.reconnect();

    } else {
        try {
            mConnection8.connect(wsuri, new WebSocketConnectionHandler() {

                @Override
                public void onOpen() {
                    Log.d("TAG", "Status: Connected to " + wsuri);

                }

                @Override
                public void onTextMessage(String payload) {

                    if (payload.contains("message send")) {
                        String[] parts = payload.split(" ");
                        String zender = parts[0];
                        String send_from = parts[1];
                        String send_name = parts[2];
                        String send_foto = parts[3];
                        String send_foto_num = parts[4];
                        String send_xxx = parts[5];

                        //      Toast.makeText(getApplication(), "" +   "\n zender: "+zender+"" +   "\n pid_user: "+pid_user+"" +"\n pid: "+pid+"" +
                        //         "\n send_from: "+send_from, 
                        //                  Toast.LENGTH_LONG).show();
                        if (zender.equalsIgnoreCase(pid) || zender.equalsIgnoreCase(pid_user)) {

                            if (send_from.equalsIgnoreCase(pid_user) || send_from.equalsIgnoreCase(pid)) {

                                //Toast.makeText(getApplication(), "uu",    Toast.LENGTH_LONG).show();

                                new UpdateChat().execute();

                            }
                        }

                    } else if (payload.contains("is typing to you")) {

                        String[] parts = payload.split(" ");
                        String part1 = parts[0]; // 004
                        is_typing_name = parts[1]; // 034556
                        if (is_typing_name.equalsIgnoreCase(user)) {

                            if (ArrChatLines.size() > 0) {
                                oldvalue = ArrChatLines.get(0).getLaatstOnline();

                            } else {
                                oldvalue = textView2_under_title.getText().toString();
                            }

                            Timer t = new Timer(false);
                            t.schedule(new TimerTask() {
                                @Override
                                public void run() {
                                    getActivity().runOnUiThread(new Runnable() {
                                        public void run() {
                                            textView2_under_title.setText("typing ...");
                                        }
                                    });
                                }
                            }, 2);

                            Timer t2 = new Timer(false);
                            t2.schedule(new TimerTask() {
                                @Override
                                public void run() {
                                    getActivity().runOnUiThread(new Runnable() {
                                        public void run() {
                                            textView2_under_title.setText(oldvalue);
                                        }
                                    });
                                }
                            }, 2000);
                        }

                    }
                    Log.d("TAG", "Got echo: " + payload);
                }

                @Override
                public void onClose(int code, String reason) {
                    Log.d("TAG", "Connection lost.");
                }
            });
        } catch (WebSocketException e) {
            Log.d("TAG", e.toString());
        }
    }
    return myView;

}

From source file:sjizl.com.ChatActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (CommonUtilities.isInternetAvailable(getApplicationContext())) //returns true if internet available
    {//  w w w.  ja  v  a  2s.c  o  m

        SharedPreferences sp = getApplicationContext().getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
        pid = sp.getString("pid", null);
        naam = sp.getString("naam", null);
        username = sp.getString("username", null);
        password = sp.getString("password", null);
        foto = sp.getString("foto", null);
        foto_num = sp.getString("foto_num", null);
        Bundle bundle = getIntent().getExtras();
        pid_user = bundle.getString("pid_user");
        user = bundle.getString("user");
        user_foto_num = bundle.getString("user_foto_num");
        user_foto = bundle.getString("user_foto");

        // Toast.makeText(getApplicationContext(), "pid_user"+pid_user, Toast.LENGTH_SHORT).show();

        if (user.equalsIgnoreCase(naam.toString())) {
            Toast.makeText(getApplicationContext(), "You can't message yourself!", Toast.LENGTH_SHORT).show();
            finish();
        }

        AbsListViewBaseActivity.imageLoader.init(ImageLoaderConfiguration.createDefault(getBaseContext()));

        //registerReceiver(mHandleMessageReceiver2, new IntentFilter(DISPLAY_MESSAGE_ACTION));
        setContentView(R.layout.activity_chat);

        imageLoader.loadImage("https://www.sjizl.com/fotos/" + user_foto_num + "/thumbs/" + user_foto + "",
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                        d1 = new BitmapDrawable(getResources(), loadedImage);

                    }
                });

        imageLoader.loadImage("https://www.sjizl.com/fotos/" + foto_num + "/thumbs/" + foto + "",
                new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {

                        d2 = new BitmapDrawable(getResources(), loadedImage);

                    }
                });

        smilbtn = (ImageView) findViewById(R.id.smilbtn);
        listView = (ListView) findViewById(android.R.id.list);
        underlayout = (LinearLayout) findViewById(R.id.underlayout);
        smiles_layout = (LinearLayout) findViewById(R.id.smiles);
        textView1_bgtext = (TextView) findViewById(R.id.textView1_bgtext);
        textView1_bgtext.setText(user);
        imageView2_dashboard = (ImageView) findViewById(R.id.imageView2_dashboard);
        imageView1_logo = (ImageView) findViewById(R.id.imageView1_logo);
        imageView_bericht = (ImageView) findViewById(R.id.imageView_bericht);
        textView2_under_title = (TextView) findViewById(R.id.textView2_under_title);
        right_lin = (LinearLayout) findViewById(R.id.right_lin);
        left_lin1 = (LinearLayout) findViewById(R.id.left_lin1);
        left_lin3 = (LinearLayout) findViewById(R.id.left_lin3);
        left_lin4 = (LinearLayout) findViewById(R.id.left_lin4);
        middle_lin = (LinearLayout) findViewById(R.id.middle_lin);
        smile_lin = (LinearLayout) findViewById(R.id.smile_lin);
        ber_lin = (LinearLayout) findViewById(R.id.ber_lin);
        progressBar_hole = (ProgressBar) findViewById(R.id.progressBar_hole);
        progressBar_hole.setVisibility(View.INVISIBLE);
        imageLoader.displayImage("http://sjizl.com/fotos/" + user_foto_num + "/thumbs/" + user_foto,
                imageView2_dashboard, options);
        new UpdateChat().execute();
        mNewMessage = (EditText) findViewById(R.id.newmsg);

        ber_lin = (LinearLayout) findViewById(R.id.ber_lin);
        photosend = (ImageView) findViewById(R.id.photosend);

        /*
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    
                    
                    
            imageLoader.loadImage("http://sjizl.com/fotos/"+user_foto_num+"/thumbs/"+user_foto, new SimpleImageLoadingListener() {
               @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        super.onLoadingComplete(imageUri, view, loadedImage);
                
        Bitmap LoadedImage2 = loadedImage;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
           if(loadedImage!=null){
        LoadedImage2 = CommonUtilities.fastblur16(loadedImage, 4,getApplicationContext());
           }
        }
                
        if (Build.VERSION.SDK_INT >= 16) {
                
           listView.setBackground(new BitmapDrawable(getApplicationContext().getResources(), LoadedImage2));
                
          } else {
                
             listView.setBackgroundDrawable(new BitmapDrawable(LoadedImage2));
          }
                
        }
        }
            );
        }
        */
        final ImageView left_button;
        left_button = (ImageView) findViewById(R.id.imageView1_back);
        CommonUtilities u = new CommonUtilities();
        u.setHeaderConrols(getApplicationContext(), this, right_lin, left_lin3, left_lin4, left_lin1,
                left_button);

        listView.setOnScrollListener(new OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                mScrollState = scrollState;
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
            }

        });
        listView.setLongClickable(true);
        registerForContextMenu(listView);

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        viewPager_smiles = new ViewPager(this);
        viewPager_smiles.setId(0x1000);
        LayoutParams layoutParams555 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        layoutParams555.width = LayoutParams.MATCH_PARENT;
        layoutParams555.height = (metrics.heightPixels / 2);
        viewPager_smiles.setLayoutParams(layoutParams555);
        TabsPagerAdapter mAdapter = new TabsPagerAdapter(getSupportFragmentManager(), mNewMessage);
        viewPager_smiles.setAdapter(mAdapter);
        LayoutInflater inflater = null;
        viewPager_smiles.setVisibility(View.VISIBLE);
        smiles_layout.addView(viewPager_smiles);
        smiles_layout.setVisibility(View.GONE);

        left_lin4.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    Intent profile = new Intent(getApplicationContext(), ProfileActivityMain.class);
                    profile.putExtra("user", user);
                    profile.putExtra("user_foto", user_foto);
                    profile.putExtra("user_foto_num", user_foto_num);
                    profile.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(profile);
                }
                return false;
            }
        });
        middle_lin.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    Intent profile = new Intent(getApplicationContext(), ProfileActivityMain.class);
                    profile.putExtra("user", user);
                    profile.putExtra("user_foto", user_foto);
                    profile.putExtra("user_foto_num", user_foto_num);
                    profile.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(profile);
                }
                return false;
            }
        });

        smile_lin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                opensmiles();
            }
        });

        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent dashboard = new Intent(getApplicationContext(), ProfileActivityMain.class);
                dashboard.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                dashboard.putExtra("user", ArrChatLines.get(position).getNaam());
                dashboard.putExtra("user_foto", foto);
                dashboard.putExtra("user_foto_num", foto_num);
                startActivity(dashboard);
            }
        });

        mNewMessage.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    v.setFocusable(true);
                    v.setFocusableInTouchMode(true);

                    smiles_layout.setVisibility(View.GONE);
                    smilbtn.setImageResource(R.drawable.emoji_btn_normal);
                    return false;
                }
                return false;
            }
        });

        TextWatcher textWatcher = new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                //after text changed
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                if (ArrChatLines.get(0).getblocked_profile().equals("1")) {

                } else if (ArrChatLines.get(0).getblocked_profile2().equals("1")) {

                } else {
                    CommonUtilities.startandsendwebsock(
                            "" + pid_user + " " + naam + " " + pid + " is typing to you ...");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
                /*
                 AsyncHttpClient.getDefaultInstance().websocket("ws://sjizl.com:9300", "my-protocol", new WebSocketConnectCallback() {
                  @Override
                     public void onCompleted(Exception ex, WebSocket webSocket) {
                         if (ex != null) {
                   ex.printStackTrace();
                   return;
                         }
                         webSocket.send(""+pid_user+" "+naam+" "+pid+" is typing to you ...");
                                 
                         webSocket.close();
                     }
                 });
                 */
            }
        };

        photosend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ArrChatLines.get(0).getblocked_profile().equals("1")) {

                } else if (ArrChatLines.get(0).getblocked_profile2().equals("1")) {

                } else {
                    openGallery(SELECT_FILE1);
                }
            }
        });

        mNewMessage.addTextChangedListener(textWatcher);

        ber_lin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SpannableStringBuilder spanStr = (SpannableStringBuilder) mNewMessage.getText();
                Spanned cs = (Spanned) mNewMessage.getText();
                String a = Html.toHtml(spanStr);
                String text = mNewMessage.getText().toString();
                mNewMessage.setText("");
                mNewMessage.requestFocus();
                mybmp2 = "http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto;
                if (text.length() < 1) {
                } else {
                    addItem(foto, foto_num, "0", naam, text.toString(),
                            "http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, "", a);
                }
            }
        });

        hideSoftKeyboard();

    } else {

        Intent dashboard = new Intent(getApplicationContext(), NoInternetActivity.class);
        dashboard.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(dashboard);

        finish();
    }
    mNewMessage.clearFocus();
    listView.requestFocus();

    final String wsuri = "ws://sjizl.com:9300";

    WebSocketConnection mConnection8 = new WebSocketConnection();

    if (mConnection8.isConnected()) {
        mConnection8.reconnect();

    } else {
        try {
            mConnection8.connect(wsuri, new WebSocketConnectionHandler() {

                @Override
                public void onOpen() {
                    Log.d("TAG", "Status: Connected to " + wsuri);

                }

                @Override
                public void onTextMessage(String payload) {

                    if (payload.contains("message send")) {
                        String[] parts = payload.split(" ");
                        String zender = parts[0];
                        String send_from = parts[1];
                        String send_name = parts[2];
                        String send_foto = parts[3];
                        String send_foto_num = parts[4];
                        String send_xxx = parts[5];

                        //      Toast.makeText(getApplication(), "" +   "\n zender: "+zender+"" +   "\n pid_user: "+pid_user+"" +"\n pid: "+pid+"" +
                        //         "\n send_from: "+send_from, 
                        //                  Toast.LENGTH_LONG).show();
                        if (zender.equalsIgnoreCase(pid) || zender.equalsIgnoreCase(pid_user)) {

                            if (send_from.equalsIgnoreCase(pid_user) || send_from.equalsIgnoreCase(pid)) {

                                //Toast.makeText(getApplication(), "uu",    Toast.LENGTH_LONG).show();

                                new UpdateChat().execute();

                            }
                        }

                    } else if (payload.contains("is typing to you")) {

                        String[] parts = payload.split(" ");
                        String part1 = parts[0]; // 004
                        is_typing_name = parts[1]; // 034556
                        if (is_typing_name.equalsIgnoreCase(user)) {

                            if (ArrChatLines.size() > 0) {
                                oldvalue = ArrChatLines.get(0).getLaatstOnline();

                            } else {
                                oldvalue = textView2_under_title.getText().toString();
                            }

                            Timer t = new Timer(false);
                            t.schedule(new TimerTask() {
                                @Override
                                public void run() {
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            textView2_under_title.setText("typing ...");
                                        }
                                    });
                                }
                            }, 2);

                            Timer t2 = new Timer(false);
                            t2.schedule(new TimerTask() {
                                @Override
                                public void run() {
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            textView2_under_title.setText(oldvalue);
                                        }
                                    });
                                }
                            }, 2000);
                        }

                    }
                    Log.d("TAG", "Got echo: " + payload);
                }

                @Override
                public void onClose(int code, String reason) {
                    Log.d("TAG", "Connection lost.");
                }
            });
        } catch (WebSocketException e) {
            Log.d("TAG", e.toString());
        }
    }

}

From source file:com.github.irshulx.Components.InputExtensions.java

public void insertLink(String uri) {
    EditorType editorType = editorCore.getControlType(editorCore.getActiveView());
    EditText editText = (EditText) editorCore.getActiveView();
    if (editorType == EditorType.INPUT || editorType == EditorType.UL_LI) {
        String text = Html.toHtml(editText.getText());
        if (TextUtils.isEmpty(text))
            text = "<p dir=\"ltr\"></p>";
        text = trimLineEnding(text);//w  w  w  . java 2 s  . c o  m
        Document _doc = Jsoup.parse(text);
        Elements x = _doc.select("p");
        String existing = x.get(0).html();
        x.get(0).html(existing + " <a href='" + uri + "'>" + uri + "</a>");
        Spanned toTrim = Html.fromHtml(x.toString());
        CharSequence trimmed = noTrailingwhiteLines(toTrim);
        editText.setText(trimmed); //
        editText.setSelection(editText.getText().length());
    }
}

From source file:com.cw.litenote.note.Note_adapter.java

private String getHtmlStringWithViewPort(int position, int viewPort) {
    int mStyle = Note.mStyle;

    System.out.println("Note_adapter / _getHtmlStringWithViewPort");
    String strTitle = db_page.getNoteTitle(position, true);
    String strBody = db_page.getNoteBody(position, true);
    String linkUri = db_page.getNoteLinkUri(position, true);

    // replace note title
    //TitleBody,YouTube linkWeb linkTitlelinktitle,Gray?
    boolean bSetGray = false;
    if (Util.isEmptyString(strTitle) && Util.isEmptyString(strBody)) {
        if (Util.isYouTubeLink(linkUri)) {
            strTitle = Util.getYouTubeTitle(linkUri);
            bSetGray = true;/*from w  w  w .j a  va 2 s.c o m*/
        } else if (linkUri.startsWith("http")) {
            strTitle = mWebTitle;
            bSetGray = true;
        }
    }

    Long createTime = db_page.getNoteCreatedTime(position, true);
    String head = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<html><head>"
            + "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />";

    if (viewPort == VIEW_PORT_BY_NONE) {
        head = head + "<head>";
    } else if (viewPort == VIEW_PORT_BY_DEVICE_WIDTH) {
        head = head + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" + "<head>";
    } else if (viewPort == VIEW_PORT_BY_SCREEN_WIDTH) {
        //           int screen_width = UtilImage.getScreenWidth(act);
        int screen_width = 640;
        head = head + "<meta name=\"viewport\" content=\"width=" + String.valueOf(screen_width)
                + ", initial-scale=1\">" + "<head>";
    }

    String separatedLineTitle = (!Util.isEmptyString(strTitle)) ? "<hr size=2 color=blue width=99% >" : "";
    String separatedLineBody = (!Util.isEmptyString(strBody)) ? "<hr size=1 color=black width=99% >" : "";

    // title
    if (!Util.isEmptyString(strTitle)) {
        Spannable spanTitle = new SpannableString(strTitle);
        Linkify.addLinks(spanTitle, Linkify.ALL);
        spanTitle.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_CENTER), 0, spanTitle.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        //ref http://stackoverflow.com/questions/3282940/set-color-of-textview-span-in-android
        if (bSetGray) {
            ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.GRAY);
            spanTitle.setSpan(foregroundSpan, 0, spanTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        strTitle = Html.toHtml(spanTitle);
    } else
        strTitle = "";

    // body
    if (!Util.isEmptyString(strBody)) {
        Spannable spanBody = new SpannableString(strBody);
        Linkify.addLinks(spanBody, Linkify.ALL);
        strBody = Html.toHtml(spanBody);
    } else
        strBody = "";

    // set web view text color
    String colorStr = Integer.toHexString(ColorSet.mText_ColorArray[mStyle]);
    colorStr = colorStr.substring(2);

    String bgColorStr = Integer.toHexString(ColorSet.mBG_ColorArray[mStyle]);
    bgColorStr = bgColorStr.substring(2);

    return head + "<body color=\"" + bgColorStr + "\">" + "<br>" + //Note: text mode needs this, otherwise title is overlaid
            "<p align=\"center\"><b>" + "<font color=\"" + colorStr + "\">" + strTitle + "</font>" + "</b></p>"
            + separatedLineTitle + "<p>" + "<font color=\"" + colorStr + "\">" + strBody + "</font>" + "</p>"
            + separatedLineBody + "<p align=\"right\">" + "<font color=\"" + colorStr + "\">"
            + Util.getTimeString(createTime) + "</font>" + "</p>" + "</body></html>";
}

From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java

/**
 * Copies text to the clipboard/*  www . ja  v  a2 s  .  c o  m*/
 *
 * @param item The context menu item that was selected.
 * @return boolean Return false to allow normal context menu processing to proceed, true to consume it here.
 */
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    if (getUserVisibleHint()) {
        String copyText = null;
        switch (item.getItemId()) {
        case R.id.copy: {
            copyText = mCopyString;
            break;
        }
        case R.id.copyall: {
            if (mNameTextView.getText() != null && mCostTextView.getText() != null
                    && mTypeTextView.getText() != null && mSetTextView.getText() != null
                    && mAbilityTextView.getText() != null && mFlavorTextView.getText() != null
                    && mPowTouTextView.getText() != null && mArtistTextView.getText() != null
                    && mNumberTextView.getText() != null) {
                // Hacky, but it works
                String costText = convertHtmlToPlainText(
                        Html.toHtml(new SpannableString(mCostTextView.getText())));
                String abilityText = convertHtmlToPlainText(
                        Html.toHtml(new SpannableString(mAbilityTextView.getText())));
                copyText = mNameTextView.getText().toString() + '\n' + costText + '\n'
                        + mTypeTextView.getText().toString() + '\n' + mSetTextView.getText().toString() + '\n'
                        + abilityText + '\n' + mFlavorTextView.getText().toString() + '\n'
                        + mPowTouTextView.getText().toString() + '\n' + mArtistTextView.getText().toString()
                        + '\n' + mNumberTextView.getText().toString();
            }
            break;
        }
        default: {
            return super.onContextItemSelected(item);
        }
        }

        if (copyText != null) {
            ClipboardManager clipboard = (ClipboardManager) (this.mActivity
                    .getSystemService(android.content.Context.CLIPBOARD_SERVICE));
            String label = getResources().getString(R.string.app_name);
            String mimeTypes[] = { ClipDescription.MIMETYPE_TEXT_PLAIN };
            ClipData cd = new ClipData(label, mimeTypes, new ClipData.Item(copyText));
            clipboard.setPrimaryClip(cd);
        }
        return true;
    }
    return false;
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Convert the body text (in {@link Spanned} form) to ready-to-send HTML format as a plain
 * String.//from  www .j av  a2 s.c om
 *
 * @param body the body text including fancy style spans
 * @param removedComposing whether the function already removed composingSpans. Necessary
 *   because we cannot call removeComposingSpans from a background thread.
 * @return HTML formatted body that's suitable for sending or saving
 */
private String spannedBodyToHtml(Spanned body, boolean removedComposing) {
    if (!removedComposing) {
        body = removeComposingSpans(body);
    }
    final HtmlifyBeginResult r = onHtmlifyBegin(body);
    return onHtmlifyEnd(Html.toHtml(r.result), r.extras);
}