kopia lustrzana https://github.com/olgamiller/SSTVEncoder2
Added outline color selection (ColorFragment)
Added ACTION_UP to onTouchEvent and onColorSelected and onCancel to Listener in ColorPaletteViewpull/3/head
rodzic
b5915841fb
commit
605a34b5d3
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
Copyright 2017 Olga Miller <olga.rgb@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package om.sstvencoder;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import om.sstvencoder.ColorPalette.ColorPaletteView;
|
||||
|
||||
public class ColorFragment extends DialogFragment
|
||||
implements ColorPaletteView.OnColorSelectedListener {
|
||||
|
||||
public interface OnColorSelectedListener {
|
||||
void onColorSelected(DialogFragment fragment, int color);
|
||||
}
|
||||
|
||||
private List<OnColorSelectedListener> mListeners;
|
||||
private int mColor;
|
||||
|
||||
public ColorFragment() {
|
||||
mListeners = new ArrayList<>();
|
||||
mColor = Color.WHITE;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
public void addOnColorSelectedListener(OnColorSelectedListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_color, null);
|
||||
ColorPaletteView colorView = (ColorPaletteView) view.findViewById(R.id.select_color);
|
||||
colorView.setColor(mColor);
|
||||
colorView.addOnColorSelectedListener(this);
|
||||
builder.setTitle(R.string.outline_color);
|
||||
builder.setView(view);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorChanged(View v, int color) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorSelected(View v, int color) {
|
||||
for (OnColorSelectedListener listener : mListeners)
|
||||
listener.onColorSelected(this, color);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(View v) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
|
@ -28,11 +28,15 @@ import java.util.ArrayList;
|
|||
|
||||
public class ColorPaletteView extends View {
|
||||
|
||||
public interface OnChangeListener {
|
||||
void onChange(View v, int color);
|
||||
public interface OnColorSelectedListener {
|
||||
void onColorChanged(View v, int color);
|
||||
|
||||
void onColorSelected(View v, int color);
|
||||
|
||||
void onCancel(View v);
|
||||
}
|
||||
|
||||
private final ArrayList<OnChangeListener> mListeners;
|
||||
private final ArrayList<OnColorSelectedListener> mListeners;
|
||||
private final IColorPalette mPalette;
|
||||
|
||||
public ColorPaletteView(Context context, AttributeSet attrs) {
|
||||
|
@ -72,6 +76,16 @@ public class ColorPaletteView extends View {
|
|||
consumed = true;
|
||||
break;
|
||||
}
|
||||
case MotionEvent.ACTION_UP: {
|
||||
float x = e.getX();
|
||||
float y = e.getY();
|
||||
if (getLeft() <= x && x <= getRight() && getTop() <= y && y <= getBottom())
|
||||
colorSelectedCallback();
|
||||
else
|
||||
cancelCallback();
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return consumed || super.onTouchEvent(e);
|
||||
}
|
||||
|
@ -79,17 +93,29 @@ public class ColorPaletteView extends View {
|
|||
private void update(float x, float y) {
|
||||
if (mPalette.selectColor(x, y)) {
|
||||
invalidate();
|
||||
callback();
|
||||
colorChangedCallback();
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnChangeListener(OnChangeListener listener) {
|
||||
public void addOnColorSelectedListener(OnColorSelectedListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
private void callback() {
|
||||
for (OnChangeListener listener : mListeners) {
|
||||
listener.onChange(this, mPalette.getSelectedColor());
|
||||
private void colorChangedCallback() {
|
||||
for (OnColorSelectedListener listener : mListeners) {
|
||||
listener.onColorChanged(this, mPalette.getSelectedColor());
|
||||
}
|
||||
}
|
||||
|
||||
private void colorSelectedCallback() {
|
||||
for (OnColorSelectedListener listener : mListeners) {
|
||||
listener.onColorSelected(this, mPalette.getSelectedColor());
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelCallback() {
|
||||
for (OnColorSelectedListener listener : mListeners) {
|
||||
listener.onCancel(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package om.sstvencoder;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
|
@ -24,6 +25,7 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
|
@ -33,11 +35,13 @@ import java.util.List;
|
|||
import om.sstvencoder.ColorPalette.ColorPaletteView;
|
||||
import om.sstvencoder.TextOverlay.Label;
|
||||
|
||||
public class EditTextActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
|
||||
public class EditTextActivity extends AppCompatActivity
|
||||
implements AdapterView.OnItemSelectedListener, ColorFragment.OnColorSelectedListener {
|
||||
public static final int REQUEST_CODE = 101;
|
||||
public static final String EXTRA = "EDIT_TEXT_EXTRA";
|
||||
private EditText mEditText;
|
||||
private ColorPaletteView mColorPaletteView;
|
||||
private int mOutlineColor;
|
||||
private float mTextSize, mOutlineSize;
|
||||
private FontFamilySet mFontFamilySet;
|
||||
private FontFamilySet.FontFamily mSelectedFontFamily;
|
||||
|
@ -68,6 +72,9 @@ public class EditTextActivity extends AppCompatActivity implements AdapterView.O
|
|||
updateBoldAndItalic();
|
||||
mEditOutline.setChecked(label.getOutline());
|
||||
initOutlineSizeSpinner(label.getOutlineSize());
|
||||
mOutlineColor = label.getOutlineColor();
|
||||
Button colorButton = (Button) findViewById(R.id.edit_outline_color);
|
||||
colorButton.setBackgroundColor(mOutlineColor);
|
||||
}
|
||||
|
||||
private void initFontFamilySpinner(String familyName) {
|
||||
|
@ -174,6 +181,20 @@ public class EditTextActivity extends AppCompatActivity implements AdapterView.O
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void onOutlineColorClick(View view) {
|
||||
ColorFragment fragment = new ColorFragment();
|
||||
fragment.setColor(mOutlineColor);
|
||||
fragment.addOnColorSelectedListener(this);
|
||||
fragment.show(getSupportFragmentManager(), ColorFragment.class.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorSelected(DialogFragment fragment, int color) {
|
||||
mOutlineColor = color;
|
||||
Button colorButton = (Button) findViewById(R.id.edit_outline_color);
|
||||
colorButton.setBackgroundColor(mOutlineColor);
|
||||
}
|
||||
|
||||
private void done() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EXTRA, getLabel());
|
||||
|
@ -192,6 +213,7 @@ public class EditTextActivity extends AppCompatActivity implements AdapterView.O
|
|||
label.setForeColor(mColorPaletteView.getColor());
|
||||
label.setOutline(mEditOutline.isChecked());
|
||||
label.setOutlineSize(mOutlineSize);
|
||||
label.setOutlineColor(mOutlineColor);
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.7"
|
||||
android:checked="true"
|
||||
android:text="@string/bold"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -75,9 +74,36 @@
|
|||
android:id="@+id/edit_outline_size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.7"
|
||||
android:layout_weight="0.3"
|
||||
android:minHeight="32sp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.4"
|
||||
android:clickable="true"
|
||||
android:onClick="onOutlineColorClick"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/edit_outline_color"
|
||||
android:layout_width="32sp"
|
||||
android:layout_height="32sp"
|
||||
android:background="@android:color/white"
|
||||
android:onClick="onOutlineColorClick"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/outline_color"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="6sp"
|
||||
android:clickable="true"
|
||||
android:onClick="onOutlineColorClick"
|
||||
android:text="@string/outline_color"
|
||||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<om.sstvencoder.ColorPalette.ColorPaletteView
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<om.sstvencoder.ColorPalette.ColorPaletteView
|
||||
android:id="@+id/select_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="236dp"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -36,4 +36,5 @@
|
|||
<string name="bold">Bold</string>
|
||||
<string name="italic">Italic</string>
|
||||
<string name="outline">Outline</string>
|
||||
<string name="outline_color">Outline Color</string>
|
||||
</resources>
|
Ładowanie…
Reference in New Issue