Search in sources :

Example 1 with EmotionInputHandler

use of me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler in project Ruisi by freedom10086.

the class ChatActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    smileyPicker = new MySmileyPicker(this);
    list = findViewById(R.id.list);
    input = findViewById(R.id.ed_comment);
    btnSend = findViewById(R.id.btn_send);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    adapter = new ChatListAdapter(this, datas);
    adapter.disableLoadMore();
    list.setLayoutManager(layoutManager);
    list.setAdapter(adapter);
    Bundle bundle = this.getIntent().getExtras();
    initToolBar(true, bundle.getString("username"));
    addToolbarMenu(R.drawable.ic_refresh_24dp).setOnClickListener(view -> refresh());
    url = bundle.getString("url");
    handler = new EmotionInputHandler(input, (enable, s) -> btnSend.setEnabled(enable));
    smileyPicker.setListener((str, a) -> handler.insertSmiley(str, a));
    findViewById(R.id.btn_emotion).setOnClickListener(view -> {
        smileyPicker.showAtLocation(view, Gravity.BOTTOM, 32, DimmenUtils.dip2px(ChatActivity.this, 80));
    });
    btnSend.setOnClickListener(view -> send_click());
    getData(true);
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) UrlUtils(me.yluo.ruisiapp.utils.UrlUtils) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) Intent(android.content.Intent) HashMap(java.util.HashMap) GetId(me.yluo.ruisiapp.utils.GetId) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) ArrayList(java.util.ArrayList) KeyboardUtil(me.yluo.ruisiapp.utils.KeyboardUtil) Element(org.jsoup.nodes.Element) Map(java.util.Map) View(android.view.View) HttpUtil(me.yluo.ruisiapp.myhttp.HttpUtil) Log(android.util.Log) TextResponseHandler(me.yluo.ruisiapp.myhttp.TextResponseHandler) DimmenUtils(me.yluo.ruisiapp.utils.DimmenUtils) AsyncTask(android.os.AsyncTask) ChatListAdapter(me.yluo.ruisiapp.adapter.ChatListAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) R(me.yluo.ruisiapp.R) RecyclerView(android.support.v7.widget.RecyclerView) Gravity(android.view.Gravity) List(java.util.List) ChatListData(me.yluo.ruisiapp.model.ChatListData) Document(org.jsoup.nodes.Document) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EditText(android.widget.EditText) ChatListAdapter(me.yluo.ruisiapp.adapter.ChatListAdapter) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) Bundle(android.os.Bundle) RecyclerView(android.support.v7.widget.RecyclerView) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 2 with EmotionInputHandler

use of me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler in project Ruisi by freedom10086.

the class EditActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_topic);
    Bundle b = getIntent().getExtras();
    if (b != null) {
        pid = b.getString("PID");
        tid = b.getString("TID");
    } else {
        showToast("参数异常无法编辑");
    }
    myColorPicker = new MyColorPicker(this);
    smileyPicker = new MySmileyPicker(this);
    initToolBar(true, "编辑帖子");
    typeidSpinner = new MySpinner(this);
    View btnDone = addToolbarMenu(R.drawable.ic_done_black_24dp);
    btnDone.setOnClickListener(view -> {
        if (checkPostInput()) {
            dialog = new ProgressDialog(EditActivity.this);
            dialog.setMessage("提交中,请稍后......");
            dialog.show();
            startPost();
        }
    });
    findViewById(R.id.forum_container).setVisibility(View.GONE);
    typeIdContainer = findViewById(R.id.type_id_container);
    typeIdContainer.setVisibility(View.GONE);
    tvSelectType = findViewById(R.id.tv_select_type);
    tvSelectType.setOnClickListener(this);
    edTitle = findViewById(R.id.ed_title);
    edContent = findViewById(R.id.ed_content);
    typeidSpinner.setListener((pos, v) -> {
        typeId = typeiddatas.get(pos).fid;
        tvSelectType.setText(typeiddatas.get(pos).name);
    });
    final LinearLayout edit_bar = findViewById(R.id.edit_bar);
    for (int i = 0; i < edit_bar.getChildCount(); i++) {
        View c = edit_bar.getChildAt(i);
        if (c instanceof ImageView) {
            c.setOnClickListener(this);
        }
    }
    Spinner setSize = findViewById(R.id.action_text_size);
    setSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            // [size=7][/size]
            if (edContent == null || (edContent.getText().length() <= 0 && i == 0)) {
                return;
            }
            handleInsert("[size=" + (i + 1) + "][/size]");
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    myColorPicker.setListener((pos, v, color) -> handleInsert("[color=" + color + "][/color]"));
    EmotionInputHandler handler = new EmotionInputHandler(edContent, (enable, s) -> {
        if (enable) {
            btnDone.setVisibility(View.VISIBLE);
        } else {
            btnDone.setVisibility(View.INVISIBLE);
        }
    });
    smileyPicker.setListener(handler::insertSmiley);
    start_edit();
}
Also used : Bundle(android.os.Bundle) MySpinner(me.yluo.ruisiapp.widget.MySpinner) Spinner(android.widget.Spinner) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) MySpinner(me.yluo.ruisiapp.widget.MySpinner) MyColorPicker(me.yluo.ruisiapp.widget.MyColorPicker) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) LinearLayout(android.widget.LinearLayout)

Example 3 with EmotionInputHandler

use of me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler in project Ruisi by freedom10086.

the class NewPostActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_topic);
    initToolBar(true, "发表新帖");
    if (getIntent().getExtras() != null) {
        fid = getIntent().getExtras().getInt("FID");
        title = getIntent().getExtras().getString("TITLE");
    }
    addToolbarMenu(R.drawable.ic_send_white_24dp).setOnClickListener(this);
    myColorPicker = new MyColorPicker(this);
    smileyPicker = new MySmileyPicker(this);
    forumSpinner = new MySpinner(this);
    typeidSpinner = new MySpinner(this);
    typeIdContainer = findViewById(R.id.type_id_container);
    typeIdContainer.setVisibility(View.GONE);
    tvSelectForum = findViewById(R.id.tv_select_forum);
    tvSelectType = findViewById(R.id.tv_select_type);
    tvSelectForum.setOnClickListener(this);
    tvSelectType.setOnClickListener(this);
    edTitle = findViewById(R.id.ed_title);
    edContent = findViewById(R.id.ed_content);
    List<Category> categories = RuisUtils.getForums(this, true);
    if (categories == null) {
        showLongToast("读取板块列表出错,请确保assets目录有forums.json文件");
        finish();
        return;
    }
    for (Category c : categories) {
        if (c.canPost) {
            datas.addAll(c.forums);
        }
    }
    if (TextUtils.isEmpty(title) || fid <= 0) {
        title = datas.get(0).name;
        fid = datas.get(0).fid;
    }
    tvSelectForum.setText(title);
    forumSpinner.setData(datas);
    forumSpinner.setListener((pos, v) -> {
        fid = datas.get(pos).fid;
        tvSelectForum.setText(datas.get(pos).name);
        switchFid(fid);
    });
    typeidSpinner.setListener((pos, v) -> {
        typeId = typeiddatas.get(pos).fid;
        tvSelectType.setText(typeiddatas.get(pos).name);
    });
    final LinearLayout edit_bar = findViewById(R.id.edit_bar);
    for (int i = 0; i < edit_bar.getChildCount(); i++) {
        View c = edit_bar.getChildAt(i);
        if (c instanceof ImageView) {
            c.setOnClickListener(this);
        }
    }
    Spinner setSize = findViewById(R.id.action_text_size);
    setSize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            // [size=7][/size]
            if (edContent == null || (edContent.getText().length() <= 0 && i == 0)) {
                return;
            }
            handleInsert("[size=" + (i + 1) + "][/size]");
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    myColorPicker.setListener((pos, v, color) -> handleInsert("[color=" + color + "][/color]"));
    handler = new EmotionInputHandler(edContent, (enable, s) -> {
    });
    smileyPicker.setListener((str, a) -> {
        handler.insertSmiley(str, a);
    });
    findViewById(R.id.action_backspace).setOnLongClickListener(v -> {
        int start = edContent.getSelectionStart();
        int end = edContent.getSelectionEnd();
        if (start == 0) {
            return false;
        }
        if ((start == end) && start > 0) {
            start = start - 5;
        }
        if (start < 0) {
            start = 0;
        }
        edContent.getText().delete(start, end);
        return true;
    });
    switchFid(fid);
    checkValid();
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Date(java.util.Date) Uri(android.net.Uri) ImageView(android.widget.ImageView) ResponseHandler(me.yluo.ruisiapp.myhttp.ResponseHandler) Manifest(android.Manifest) UploadImageResponseHandler(me.yluo.ruisiapp.myhttp.UploadImageResponseHandler) MediaStore(android.provider.MediaStore) Element(org.jsoup.nodes.Element) Map(java.util.Map) View(android.view.View) RuisUtils(me.yluo.ruisiapp.utils.RuisUtils) AdapterView(android.widget.AdapterView) Log(android.util.Log) Category(me.yluo.ruisiapp.model.Category) AsyncTask(android.os.AsyncTask) ContextCompat(android.support.v4.content.ContextCompat) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ActivityCompat(android.support.v4.app.ActivityCompat) Forum(me.yluo.ruisiapp.model.Forum) R(me.yluo.ruisiapp.R) List(java.util.List) TextView(android.widget.TextView) Document(org.jsoup.nodes.Document) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) Nullable(android.support.annotation.Nullable) Context(android.content.Context) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UrlUtils(me.yluo.ruisiapp.utils.UrlUtils) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) HashMap(java.util.HashMap) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) Editable(android.text.Editable) ArrayList(java.util.ArrayList) MySpinner(me.yluo.ruisiapp.widget.MySpinner) MyColorPicker(me.yluo.ruisiapp.widget.MyColorPicker) Toast(android.widget.Toast) HttpUtil(me.yluo.ruisiapp.myhttp.HttpUtil) Parcelable(android.os.Parcelable) DimmenUtils(me.yluo.ruisiapp.utils.DimmenUtils) ComponentName(android.content.ComponentName) ProgressDialog(android.app.ProgressDialog) InputValidDialog(me.yluo.ruisiapp.widget.InputValidDialog) TextUtils(android.text.TextUtils) IOException(java.io.IOException) File(java.io.File) ResolveInfo(android.content.pm.ResolveInfo) Spinner(android.widget.Spinner) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) EditText(android.widget.EditText) App(me.yluo.ruisiapp.App) Category(me.yluo.ruisiapp.model.Category) MySpinner(me.yluo.ruisiapp.widget.MySpinner) Spinner(android.widget.Spinner) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) MySpinner(me.yluo.ruisiapp.widget.MySpinner) MyColorPicker(me.yluo.ruisiapp.widget.MyColorPicker) MySmileyPicker(me.yluo.ruisiapp.widget.MySmileyPicker) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) EmotionInputHandler(me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler) LinearLayout(android.widget.LinearLayout)

Aggregations

Bundle (android.os.Bundle)3 View (android.view.View)3 MySmileyPicker (me.yluo.ruisiapp.widget.MySmileyPicker)3 EmotionInputHandler (me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler)3 ProgressDialog (android.app.ProgressDialog)2 Context (android.content.Context)2 Intent (android.content.Intent)2 AsyncTask (android.os.AsyncTask)2 Nullable (android.support.annotation.Nullable)2 Log (android.util.Log)2 AdapterView (android.widget.AdapterView)2 EditText (android.widget.EditText)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 Spinner (android.widget.Spinner)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2