一個爲設計師設計的APP( ´_ゝ`)一個特別簡單項目git
主要用來練習Rx,固然這個適合初入Rx的看看。github
本身參考的教程給 Android 開發者的 RxJava 詳解算法
Github地址:Gifts-for-designers
但願給個star鼓勵下( ´_ゝ`)app
( ´_ゝ`) 好像這個項目沒有不少代碼須要解釋,不過我仍是整理一份ide
// 字體 Typeface fontFace = Typeface.createFromAsset(getAssets(), "font/Inconsolata.otf"); Typeface tvFontFace = Typeface.createFromAsset(getAssets(), "font/Lobster.ttf"); editTextHEX.setTypeface(fontFace); editTextRGB.setTypeface(fontFace); textView.setTypeface(tvFontFace);
RxTextView.textChanges(editTextHEX) .subscribeOn(AndroidSchedulers.mainThread()) .debounce(300, TimeUnit.MICROSECONDS) .map(new Func1<CharSequence, String>() { @Override public String call(CharSequence charSequence) { return charSequence.toString(); } }) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(new Action1<String>() { @Override public void call(String s) { if (s.length() == 5) { setBackground("56abe4", 0); editTextRGB.setText(""); } if (!colors.isEmpty()) { colors.clear(); adapter.notifyDataSetChanged(); } } }) .filter(new Func1<String, Boolean>() { @Override public Boolean call(String s) { return s.length() > 5; } }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<String>() { @Override public void call(String s) { setBackground(s, 0); // addColorAdapter(s); changeToRGB(s); } })
/** * @param color * @param mark 0:HEX 1:RGB */ public void setBackground(String color, int mark) { int i = 0; ValueAnimator paramInteger; Drawable localDrawable = this.relativeLayout.getBackground(); if ((localDrawable instanceof ColorDrawable)) i = ((ColorDrawable) localDrawable).getColor(); if (mark == 0) { paramInteger = ValueAnimator.ofObject(new ArgbEvaluator(), i, Color .parseColor("#" + color)); } else { paramInteger = ValueAnimator.ofObject(new ArgbEvaluator(), i, mark); } paramInteger.setDuration(500L); paramInteger.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator paramAnonymousValueAnimator) { relativeLayout.setBackgroundColor((Integer) paramAnonymousValueAnimator.getAnimatedValue()); } } ); paramInteger.start(); }
private void changeToRGB(String s) { int red = Integer.parseInt(String.valueOf(s.charAt(0)) + s.charAt(1), 16); int green = Integer.parseInt(String.valueOf(s.charAt(2)) + s.charAt(3), 16); int blue = Integer.parseInt(String.valueOf(s.charAt(4)) + s.charAt(5), 16); Log.d(TAG, red + " " + green + " " + blue); editTextRGB.setText("(" + red + "," + green + "," + blue + ")"); }
[x] 搭配色算法推薦post
[ ] 搭配色展現(RecyclerView)字體
[ ] 目前只作了16進制顏色,RGB有些邏輯問題this
[ ] 刪除過快會有卡頓(不知道如何解決)lua
[ ] 顏色保存列表spa