Skip to content

Commit

Permalink
Add attributes to customize icon size and background
Browse files Browse the repository at this point in the history
  • Loading branch information
starshipcoder committed Oct 1, 2020
1 parent 7fe161e commit 09b83c5
Show file tree
Hide file tree
Showing 31 changed files with 183 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chinalwb.are.Util;
import com.chinalwb.are.demo.R;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Bold;

public class ARE_ToolItem_MyBold extends ARE_ToolItem_Bold {
Expand All @@ -18,13 +16,7 @@ public View getView(Context context) {
return mToolItemView;
}
if (mToolItemView == null) {
ImageView imageView = new ImageView(context);
int size = Util.getPixelByDp(context, 40);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size, size);
imageView.setLayoutParams(params);
imageView.setImageResource(R.drawable.my_bold);
imageView.bringToFront();
mToolItemView = imageView;
mToolItemView = createIcon(context, R.drawable.my_bold);
}

return mToolItemView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import com.chinalwb.are.AREditText
import com.chinalwb.are.Util
import com.chinalwb.are.demo.R
import com.chinalwb.are.styles.ARE_Emoji
import com.chinalwb.are.styles.IARE_Style
import com.chinalwb.are.styles.toolitems.ARE_ToolItem_Abstract
import com.chinalwb.are.styles.toolitems.IARE_ToolItem_Updater
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_Link

class ARE_ToolItem_Youtube : ARE_ToolItem_Abstract() {

Expand All @@ -23,15 +19,9 @@ class ARE_ToolItem_Youtube : ARE_ToolItem_Abstract() {
return mStyle ?: ARE_Style_Youtube(editText, mToolItemView as ImageView)
}

override fun getView(context: Context?): View? {
override fun getView(context: Context): View? {
return mToolItemView ?: {
val imageView = ImageView(context)
val size = Util.getPixelByDp(context, 40)
val params = LinearLayout.LayoutParams(size, size)
imageView.layoutParams = params
imageView.setImageResource(R.drawable.youtube)
imageView.bringToFront()
this.mToolItemView = imageView
mToolItemView = createIcon(context, R.drawable.youtube)
this.mToolItemView
}()
}
Expand Down
4 changes: 0 additions & 4 deletions ARE/are/src/main/java/com/chinalwb/are/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

public class Constants {

public static final int CHECKED_COLOR = 0XffFF4081; // android.R.color.holo_green_light;

public static final int UNCHECKED_COLOR = 0X00000000; // android.R.color.transparent;

public static final int COLOR_QUOTE = 0Xffcccccc;

public static final String ZERO_WIDTH_SPACE_STR = "\u200B";
Expand Down
30 changes: 13 additions & 17 deletions ARE/are/src/main/java/com/chinalwb/are/styles/ARE_Helper.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package com.chinalwb.are.styles;

import com.chinalwb.are.Constants;

import android.view.View;
import android.widget.ImageView;

public class ARE_Helper {

/**
* Updates the check status.
*
* @param areStyle
* @param checked
*/
public static void updateCheckStatus(IARE_Style areStyle, boolean checked) {
areStyle.setChecked(checked);
View imageView = areStyle.getImageView();
int color = checked ? Constants.CHECKED_COLOR : Constants.UNCHECKED_COLOR;
imageView.setBackgroundColor(color);
}


/**
* Updates the check status.
*
* @param areStyle
* @param checked
*/
public static void updateCheckStatus(IARE_Style areStyle, boolean checked) {
areStyle.setChecked(checked);
View imageView = areStyle.getImageView();
imageView.setSelected(checked);
}


}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.chinalwb.are.styles.toolbar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;

import com.chinalwb.are.AREditText;
import com.chinalwb.are.R;
import com.chinalwb.are.Util;
import com.chinalwb.are.styles.toolitems.IARE_ToolItem;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.DrawableRes;

/**
* Created by wliu on 13/08/2018.
*/
Expand All @@ -29,6 +32,11 @@ public class ARE_ToolbarDefault extends HorizontalScrollView implements IARE_Too

private AREditText mAREditText;

@DrawableRes
private int mIconBackground;
private int mIconSize;
private int mIconMargin;

public ARE_ToolbarDefault(Context context) {
this(context, null);
}
Expand All @@ -39,13 +47,13 @@ public ARE_ToolbarDefault(Context context, AttributeSet attrs) {

public ARE_ToolbarDefault(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.mContext = (Activity) context;
initSelf();
this.mContext = context;
initSelf(context, attrs);
}

@Override
public void addToolbarItem(IARE_ToolItem toolbarItem) {
toolbarItem.setToolbar(this);
toolbarItem.setToolbar(this, mIconBackground, mIconSize, mIconMargin);
mToolItems.add(toolbarItem);
View view = toolbarItem.getView(mContext);
if (view != null) {
Expand Down Expand Up @@ -75,11 +83,18 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void initSelf() {
private void initSelf(Context context, AttributeSet attrs) {
mContainer = new LinearLayout(mContext);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mContainer.setGravity(Gravity.CENTER_VERTICAL);
mContainer.setLayoutParams(params);
this.addView(mContainer);

TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ARE_ToolbarDefault);
mIconBackground = ta.getResourceId(R.styleable.ARE_ToolbarDefault_toolbarIconBackground, R.drawable.background_icon);
mIconSize = ta.getDimensionPixelSize(R.styleable.ARE_ToolbarDefault_toolbarIconSize, Util.getPixelByDp(context, 40));
mIconMargin = ta.getDimensionPixelSize(R.styleable.ARE_ToolbarDefault_toolbarIconMargin, 0);

ta.recycle();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.chinalwb.are.styles.toolitems;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.Editable;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chinalwb.are.AREditText;
import com.chinalwb.are.AREditor;
import com.chinalwb.are.Util;
import com.chinalwb.are.spans.AreQuoteSpan;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolbar.IARE_Toolbar;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;

/**
* Created by wliu on 13/08/2018.
*/
Expand All @@ -25,15 +30,21 @@ public abstract class ARE_ToolItem_Abstract implements IARE_ToolItem {
protected IARE_ToolItem_Updater mToolItemUpdater;

private IARE_Toolbar mToolbar;
@DrawableRes
protected int mIconBackground;
protected int mIconSize;
protected int mIconMargin;

@Override
public IARE_Toolbar getToolbar() {
return mToolbar;
}

@Override
public void setToolbar(IARE_Toolbar toolbar) {
public void setToolbar(IARE_Toolbar toolbar, @DrawableRes int iconBackground, int iconSize, int iconMargin) {
mToolbar = toolbar;
mIconBackground = iconBackground;
mIconSize = iconSize;
}

@Override
Expand All @@ -52,6 +63,19 @@ public AREditText getEditText() {
return mToolbar.getEditText();
}

protected ImageView createIcon(@NonNull Context context, @DrawableRes int resIcon) {
ImageView imageView = new ImageView(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mIconSize, mIconSize);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(mIconMargin);
params.setMarginStart(mIconMargin);
}
imageView.setLayoutParams(params);
imageView.setBackgroundResource(mIconBackground);
imageView.setImageResource(resIcon);
imageView.bringToFront();
return imageView;
}


protected <T> void printSpans(Class<T> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import android.text.Layout;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chinalwb.are.AREditText;
import com.chinalwb.are.R;
import com.chinalwb.are.Util;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_Alignment;

Expand Down Expand Up @@ -38,13 +36,7 @@ public View getView(Context context) {
return mToolItemView;
}
if (mToolItemView == null) {
ImageView imageView = new ImageView(context);
int size = Util.getPixelByDp(context, 40);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size, size);
imageView.setLayoutParams(params);
imageView.setImageResource(R.drawable.aligncenter);
imageView.bringToFront();
mToolItemView = imageView;
mToolItemView = createIcon(context, R.drawable.aligncenter);
}

return mToolItemView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import android.text.Layout;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chinalwb.are.AREditText;
import com.chinalwb.are.R;
import com.chinalwb.are.Util;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_Alignment;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_Hr;

/**
* Created by wliu on 13/08/2018.
Expand Down Expand Up @@ -39,13 +36,7 @@ public View getView(Context context) {
return mToolItemView;
}
if (mToolItemView == null) {
ImageView imageView = new ImageView(context);
int size = Util.getPixelByDp(context, 40);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size, size);
imageView.setLayoutParams(params);
imageView.setImageResource(R.drawable.alignleft);
imageView.bringToFront();
mToolItemView = imageView;
mToolItemView = createIcon(context, R.drawable.alignleft);
}

return mToolItemView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import android.text.Layout;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chinalwb.are.AREditText;
import com.chinalwb.are.R;
import com.chinalwb.are.Util;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_Alignment;

Expand Down Expand Up @@ -38,13 +36,7 @@ public View getView(Context context) {
return mToolItemView;
}
if (mToolItemView == null) {
ImageView imageView = new ImageView(context);
int size = Util.getPixelByDp(context, 40);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size, size);
imageView.setLayoutParams(params);
imageView.setImageResource(R.drawable.alignright);
imageView.bringToFront();
mToolItemView = imageView;
mToolItemView = createIcon(context, R.drawable.alignright);
}

return mToolItemView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chinalwb.are.AREditText;
import com.chinalwb.are.R;
import com.chinalwb.are.Util;
import com.chinalwb.are.models.AtItem;
import com.chinalwb.are.spans.AreImageSpan;
import com.chinalwb.are.styles.ARE_At;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_At;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_Image;

/**
* Created by wliu on 13/08/2018.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
import android.content.Context;
import android.text.Editable;
import android.text.style.BackgroundColorSpan;
import android.text.style.CharacterStyle;
import android.text.style.BackgroundColorSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chinalwb.are.AREditText;
import com.chinalwb.are.Constants;
import com.chinalwb.are.R;
import com.chinalwb.are.Util;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolitems.styles.ARE_Style_BackgroundColor;

Expand All @@ -22,7 +17,7 @@ public class ARE_ToolItem_BackgroundColor extends ARE_ToolItem_Abstract {
@Override
public IARE_ToolItem_Updater getToolItemUpdater() {
if (mToolItemUpdater == null) {
mToolItemUpdater = new ARE_ToolItem_UpdaterDefault(this, Constants.CHECKED_COLOR, Constants.UNCHECKED_COLOR);
mToolItemUpdater = new ARE_ToolItem_UpdaterDefault(this, mIconBackground, mIconSize);
setToolItemUpdater(mToolItemUpdater);
}
return mToolItemUpdater;
Expand All @@ -44,13 +39,7 @@ public View getView(Context context) {
return mToolItemView;
}
if (mToolItemView == null) {
ImageView imageView = new ImageView(context);
int size = Util.getPixelByDp(context, 40);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size, size);
imageView.setLayoutParams(params);
imageView.setImageResource(R.drawable.background);
imageView.bringToFront();
mToolItemView = imageView;
mToolItemView = createIcon(context, R.drawable.background);
}

return mToolItemView;
Expand Down
Loading

0 comments on commit 09b83c5

Please sign in to comment.