Search in sources :

Example 1 with MyColorPicker

use of me.yluo.ruisiapp.widget.MyColorPicker 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 2 with MyColorPicker

use of me.yluo.ruisiapp.widget.MyColorPicker 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

ProgressDialog (android.app.ProgressDialog)2 Bundle (android.os.Bundle)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 Spinner (android.widget.Spinner)2 TextView (android.widget.TextView)2 MyColorPicker (me.yluo.ruisiapp.widget.MyColorPicker)2 MySmileyPicker (me.yluo.ruisiapp.widget.MySmileyPicker)2 MySpinner (me.yluo.ruisiapp.widget.MySpinner)2 EmotionInputHandler (me.yluo.ruisiapp.widget.emotioninput.EmotionInputHandler)2 Manifest (android.Manifest)1 Activity (android.app.Activity)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 Bitmap (android.graphics.Bitmap)1