Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
877 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
image/src/main/java/com/xingren/imaging/ImageTextDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.xingren.imaging; | ||
|
||
import android.app.Dialog; | ||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.view.View; | ||
import android.view.Window; | ||
import android.view.WindowManager.LayoutParams; | ||
import android.widget.EditText; | ||
import android.widget.RadioGroup; | ||
|
||
import com.xingren.imaging.core.IMGText; | ||
import com.xingren.imaging.view.IMGColorGroup; | ||
|
||
/** | ||
* Created by felix on 2017/12/1 上午11:21. | ||
*/ | ||
|
||
public class ImageTextDialog extends Dialog implements View.OnClickListener, | ||
RadioGroup.OnCheckedChangeListener { | ||
|
||
private static final String TAG = "ImageTextDialog"; | ||
|
||
private EditText mEditText; | ||
|
||
private Callback mCallback; | ||
|
||
private IMGText mDefaultText; | ||
|
||
private IMGColorGroup mColorGroup; | ||
|
||
public ImageTextDialog(Context context, Callback callback) { | ||
super(context, R.style.ImageTextDialog); | ||
setContentView(R.layout.image_text_dialog); | ||
mCallback = callback; | ||
Window window = getWindow(); | ||
if (window != null) { | ||
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
mColorGroup = findViewById(R.id.cg_colors); | ||
mColorGroup.setOnCheckedChangeListener(this); | ||
mEditText = findViewById(R.id.et_text); | ||
|
||
findViewById(R.id.tv_cancel).setOnClickListener(this); | ||
findViewById(R.id.tv_done).setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
if (mDefaultText != null) { | ||
setText(mDefaultText); | ||
mDefaultText = null; | ||
} | ||
mColorGroup.setCheckColor(mEditText.getCurrentTextColor()); | ||
} | ||
|
||
public void setText(IMGText text) { | ||
if (mEditText != null) { | ||
mEditText.setText(text.getText()); | ||
mEditText.setTextColor(text.getColor()); | ||
if (!text.isEmpty()) { | ||
mEditText.setSelection(mEditText.length()); | ||
} | ||
} else mDefaultText = text; | ||
} | ||
|
||
public void reset() { | ||
setText(new IMGText(null, Color.WHITE)); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
int vid = v.getId(); | ||
if (vid == R.id.tv_done) { | ||
onDone(); | ||
} else if (vid == R.id.tv_cancel) { | ||
dismiss(); | ||
} | ||
} | ||
|
||
private void onDone() { | ||
String text = mEditText.getText().toString(); | ||
if (!TextUtils.isEmpty(text) && mCallback != null) { | ||
mCallback.onText(new IMGText(text, mEditText.getCurrentTextColor())); | ||
} | ||
dismiss(); | ||
} | ||
|
||
@Override | ||
public void onCheckedChanged(RadioGroup group, int checkedId) { | ||
mEditText.setTextColor(mColorGroup.getCheckColor()); | ||
} | ||
|
||
public interface Callback { | ||
|
||
void onText(IMGText text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.xingren.imaging.core; | ||
|
||
import android.graphics.Color; | ||
import android.text.TextUtils; | ||
|
||
/** | ||
* Created by felix on 2017/12/1 下午2:43. | ||
*/ | ||
|
||
public class IMGText { | ||
|
||
private String text; | ||
|
||
private int color = Color.WHITE; | ||
|
||
public IMGText(String text, int color) { | ||
this.text = text; | ||
this.color = color; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
public int getColor() { | ||
return color; | ||
} | ||
|
||
public void setColor(int color) { | ||
this.color = color; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return TextUtils.isEmpty(text); | ||
} | ||
|
||
public int length() { | ||
return isEmpty() ? 0 : text.length(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "IMGText{" + | ||
"text='" + text + '\'' + | ||
", color=" + color + | ||
'}'; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
image/src/main/java/com/xingren/imaging/view/IMGColorGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.xingren.imaging.view; | ||
|
||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.util.AttributeSet; | ||
import android.widget.RadioGroup; | ||
|
||
/** | ||
* Created by felix on 2017/12/1 下午3:07. | ||
*/ | ||
|
||
public class IMGColorGroup extends RadioGroup { | ||
|
||
public IMGColorGroup(Context context) { | ||
super(context); | ||
} | ||
|
||
public IMGColorGroup(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public int getCheckColor() { | ||
int checkedId = getCheckedRadioButtonId(); | ||
IMGColorRadio radio = findViewById(checkedId); | ||
if (radio != null) { | ||
return radio.getColor(); | ||
} | ||
return Color.WHITE; | ||
} | ||
|
||
public void setCheckColor(int color) { | ||
int count = getChildCount(); | ||
for (int i = 0; i < count; i++) { | ||
IMGColorRadio radio = (IMGColorRadio) getChildAt(i); | ||
if (radio.getColor() == color) { | ||
radio.setChecked(true); | ||
break; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.