1
0
mirror of https://gitlab.com/neothefox/LayTray synced 2026-03-23 21:54:54 +03:00

First phase of icon builder implementation

Added square outline
This commit is contained in:
NeoTheFox 2018-07-09 11:41:32 +03:00
parent 6c6209f251
commit 20a0c04914
4 changed files with 285 additions and 1 deletions

View File

@ -0,0 +1,136 @@
package space.neothefox.laytray;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import static android.graphics.Paint.ANTI_ALIAS_FLAG;
public class IconBuilderPreview extends View {
int mode;
int textSize;
boolean fakeBold;
int textColor;
public IconBuilderPreview(Context context) {
super(context);
initValues();
}
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initValues();
}
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initValues();
}
public IconBuilderPreview(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initValues();
}
public void initValues()
{
textSize = 48 * 10;
fakeBold = true;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mode = 2;
fakeBold = true;
int width = 48 * 10;
int height = 48 * 10;
textColor = Color.WHITE;
String text = "EN";
this.setLayoutParams(new LinearLayout.LayoutParams(height, width));
Paint paint = new Paint(ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
paint.setTextSize(textSize);
paint.setFakeBoldText(fakeBold);
paint.setColor(textColor);
switch (mode)
{
case 1: {
canvas.drawCircle(width / 2f, height / 2f, width / 2f, paint);
//paint.setAlpha(255);
paint.setColor(Color.BLACK);
paint.setTextSize(textSize);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(text, width / 2f, height / 2f + textSize / 2f, paint);
return;
}
case 2: {
canvas.drawRoundRect(new RectF(0, 0, height, width), 5, 5, paint);
//paint.setAlpha(255);
paint.setColor(Color.BLACK);
paint.setTextSize(textSize);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(text, width / 2f, height / 2f + textSize / 2f, paint);
return ;
}
case 0:
default:
paint.setTextAlign(Paint.Align.LEFT);
float baseline = -paint.ascent(); // ascent() is negative
width = (int) (paint.measureText(text) + 0.5f); // round
height = (int) (baseline + paint.descent() + 0.5f);
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
canvas.drawText(text, 0, baseline, paint);
return;
}
}
public int getMode() {
return mode;
}
public int getTextSize() {
return textSize;
}
public boolean isFakeBold() {
return fakeBold;
}
public int getTextColor() {
return textColor;
}
public void setMode(int mode) {
this.mode = mode;
}
public void setTextSize(int textSize) {
this.textSize = textSize * 10;
}
public void setFakeBold(boolean fakeBold) {
this.fakeBold = fakeBold;
}
public void setTextColor(int textColor) {
this.textColor = textColor;
}
}

View File

@ -78,7 +78,7 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
} }
//Borrowed from Ted Hopp from StackOverflow //Borrowed from Ted Hopp from StackOverflow
public Bitmap textAsBitmap(String text, float textSize, boolean fakeBold, int mode, int textColor) { public static Bitmap textAsBitmap(String text, float textSize, boolean fakeBold, int mode, int textColor) {
Paint paint = new Paint(ANTI_ALIAS_FLAG); Paint paint = new Paint(ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
paint.setTextSize(textSize); paint.setTextSize(textSize);
@ -116,6 +116,22 @@ implements SharedPreferences.OnSharedPreferenceChangeListener{
return image; return image;
} }
case 3: {
int width = 48;
int height = 48;
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawRoundRect(new RectF(0, 0, height, width), 5, 5, paint);
paint.setAlpha(255);
paint.setColor(Color.TRANSPARENT);
canvas.drawRoundRect(new RectF(2,2,height-2,width-2), 5, 5, paint);
paint.setColor(textColor);
paint.setTextSize(textSize);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(text, width / 2f, height / 2f + textSize / 2f, paint);
return image;
}
case 0: case 0:
default: default:
paint.setTextAlign(Paint.Align.LEFT); paint.setTextAlign(Paint.Align.LEFT);

View File

@ -1,6 +1,8 @@
package space.neothefox.laytray; package space.neothefox.laytray;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -12,13 +14,19 @@ import android.os.Bundle;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.RingtonePreference; import android.preference.RingtonePreference;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.SeekBar;
import java.util.List; import java.util.List;
@ -199,6 +207,71 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
// guidelines. // guidelines.
bindPreferenceSummaryToValue(findPreference("notificationImportance")); bindPreferenceSummaryToValue(findPreference("notificationImportance"));
bindPreferenceSummaryToValue(findPreference("textMode")); bindPreferenceSummaryToValue(findPreference("textMode"));
bindPreferenceSummaryToValue(findPreference("textSize"));
Preference iconBuilderPreference = getPreferenceScreen().findPreference("iconBuilderPreference");
iconBuilderPreference.setEnabled(false);
iconBuilderPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
FragmentManager fragmentManager = getFragmentManager();
IconBuilderPreferenceFragment iconBuilderPreferenceFragment = new IconBuilderPreferenceFragment();
iconBuilderPreferenceFragment.show(fragmentManager, "Icon Builder");
return true;
}
});
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class IconBuilderPreferenceFragment extends DialogFragment implements View.OnClickListener {
SeekBar xBar;
VerticalSeekBar yBar;
Button saveButton;
Button cancelButton;
IconBuilderPreview iconBuilderPreview;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_icon_builder, container);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
xBar = getView().findViewById(R.id.horSeekBar);
xBar.setMinimumHeight(10);
xBar.setMinimumWidth(100);
yBar = getView().findViewById(R.id.verSeekBar);
yBar.setMinimumHeight(100);
yBar.setMinimumWidth(10);
saveButton = getView().findViewById(R.id.saveButton);
saveButton.setOnClickListener(this);
cancelButton = getView().findViewById(R.id.closeButton);
cancelButton.setOnClickListener(this);
iconBuilderPreview = getView().findViewById(R.id.textureView);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.saveButton:
return;
case R.id.closeButton:
this.dismiss();
return;
}
}
} }
@Override @Override

View File

@ -0,0 +1,59 @@
package space.neothefox.laytray;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;
public class VerticalSeekBar extends SeekBar {
public VerticalSeekBar(Context context) {
super(context);
}
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(), 0);
super.onDraw(c);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
}