mirror of https://github.com/ThmmyNoLife/mTHMMY
Thodoris1999
6 years ago
9 changed files with 244 additions and 333 deletions
@ -1,56 +0,0 @@ |
|||||
package gr.thmmy.mthmmy.editorview; |
|
||||
|
|
||||
import android.content.Context; |
|
||||
import android.content.res.TypedArray; |
|
||||
import android.util.AttributeSet; |
|
||||
import android.widget.GridLayout; |
|
||||
|
|
||||
import gr.thmmy.mthmmy.R; |
|
||||
|
|
||||
public class AutoFitGridLayout extends GridLayout { |
|
||||
private int columnWidth; |
|
||||
private int defaultColumnCount; |
|
||||
|
|
||||
public AutoFitGridLayout(Context context) { |
|
||||
super(context); |
|
||||
init(context, null, 0); |
|
||||
} |
|
||||
|
|
||||
public AutoFitGridLayout(Context context, AttributeSet attrs) { |
|
||||
super(context, attrs); |
|
||||
init(context, attrs, 0); |
|
||||
} |
|
||||
|
|
||||
public AutoFitGridLayout(Context context, AttributeSet attrs, int defStyleAttr) { |
|
||||
super(context, attrs, defStyleAttr); |
|
||||
init(context, attrs, defStyleAttr); |
|
||||
} |
|
||||
|
|
||||
public void init(Context context, AttributeSet attrs, int defStyleAttr) { |
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoFitGridLayout, 0, defStyleAttr); |
|
||||
try { |
|
||||
columnWidth = a.getDimensionPixelSize(R.styleable.AutoFitGridLayout_columnWidth, 0); |
|
||||
|
|
||||
int[] set = {android.R.attr.columnCount}; |
|
||||
a = context.obtainStyledAttributes(attrs, set, 0, defStyleAttr); |
|
||||
defaultColumnCount = a.getInt(0, 6); |
|
||||
} finally { |
|
||||
a.recycle(); |
|
||||
} |
|
||||
setColumnCount(1); |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected void onMeasure(int widthSpec, int heightSpec) { |
|
||||
super.onMeasure(widthSpec, heightSpec); |
|
||||
|
|
||||
int width = MeasureSpec.getSize(widthSpec); |
|
||||
if (columnWidth > 0 && width > 0) { |
|
||||
int totalSpace = width - getPaddingRight() - getPaddingLeft(); |
|
||||
int columnCount = Math.max(1, totalSpace / columnWidth); |
|
||||
setColumnCount(columnCount); |
|
||||
} else { |
|
||||
setColumnCount(defaultColumnCount); |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,56 @@ |
|||||
|
package gr.thmmy.mthmmy.editorview; |
||||
|
|
||||
|
import android.support.annotation.NonNull; |
||||
|
import android.support.v7.widget.AppCompatImageButton; |
||||
|
import android.support.v7.widget.RecyclerView; |
||||
|
import android.view.LayoutInflater; |
||||
|
import android.view.View; |
||||
|
import android.view.ViewGroup; |
||||
|
|
||||
|
import gr.thmmy.mthmmy.R; |
||||
|
|
||||
|
public class FormatButtonsAdapter extends RecyclerView.Adapter<FormatButtonsAdapter.FormatButtonViewHolder> { |
||||
|
private OnFormatButtonClickListener listener; |
||||
|
|
||||
|
public static final int[] FORMAT_BUTTON_IDS = {R.drawable.ic_format_bold, R.drawable.ic_format_italic, |
||||
|
R.drawable.ic_format_underlined, R.drawable.ic_strikethrough_s, R.drawable.ic_format_color_text, |
||||
|
R.drawable.ic_format_size, R.drawable.ic_text_format, R.drawable.ic_format_list_bulleted, |
||||
|
R.drawable.ic_format_align_left, R.drawable.ic_format_align_center, R.drawable.ic_format_align_right, |
||||
|
R.drawable.ic_insert_link, R.drawable.ic_format_quote, R.drawable.ic_code, R.drawable.ic_functions}; |
||||
|
|
||||
|
public FormatButtonsAdapter(OnFormatButtonClickListener listener) { |
||||
|
this.listener = listener; |
||||
|
} |
||||
|
|
||||
|
@NonNull |
||||
|
@Override |
||||
|
public FormatButtonViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
||||
|
AppCompatImageButton formatButton = (AppCompatImageButton) LayoutInflater.from(parent.getContext()) |
||||
|
.inflate(R.layout.format_button_grid_cell, parent, false); |
||||
|
return new FormatButtonViewHolder(formatButton); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onBindViewHolder(@NonNull FormatButtonViewHolder holder, int position) { |
||||
|
holder.formatButton.setImageResource(FORMAT_BUTTON_IDS[position]); |
||||
|
holder.formatButton.setOnClickListener(v -> |
||||
|
listener.onFormatButtonClick(v, FORMAT_BUTTON_IDS[holder.getAdapterPosition()])); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getItemCount() { |
||||
|
return FORMAT_BUTTON_IDS.length; |
||||
|
} |
||||
|
|
||||
|
static class FormatButtonViewHolder extends RecyclerView.ViewHolder { |
||||
|
AppCompatImageButton formatButton; |
||||
|
FormatButtonViewHolder(AppCompatImageButton formatButton) { |
||||
|
super(formatButton); |
||||
|
this.formatButton = formatButton; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public interface OnFormatButtonClickListener { |
||||
|
void onFormatButtonClick(View view, int drawableId); |
||||
|
} |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<android.support.v7.widget.AppCompatImageButton |
||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:id="@+id/bold_button" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_marginEnd="@dimen/editor_format_button_margin_between" |
||||
|
android:background="?android:selectableItemBackground" /> |
@ -1,9 +1,5 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
<resources> |
||||
<declare-styleable name="AutoFitGridLayout" > |
|
||||
<attr name="columnWidth" format="dimension" /> |
|
||||
</declare-styleable> |
|
||||
|
|
||||
<declare-styleable name="EditorView" > |
<declare-styleable name="EditorView" > |
||||
<attr name="hint" format="string" /> |
<attr name="hint" format="string" /> |
||||
</declare-styleable> |
</declare-styleable> |
||||
|
@ -1,6 +1,6 @@ |
|||||
#Sat Apr 07 11:11:36 EEST 2018 |
#Fri Sep 28 13:21:54 EEST 2018 |
||||
distributionBase=GRADLE_USER_HOME |
distributionBase=GRADLE_USER_HOME |
||||
distributionPath=wrapper/dists |
distributionPath=wrapper/dists |
||||
zipStoreBase=GRADLE_USER_HOME |
zipStoreBase=GRADLE_USER_HOME |
||||
zipStorePath=wrapper/dists |
zipStorePath=wrapper/dists |
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip |
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip |
||||
|
Loading…
Reference in new issue