提交 2eb5a87a 编写于 作者: H huangziwei

美化交互ui

上级 8f0b29df
......@@ -19,5 +19,5 @@ android {
}
dependencies {
compile 'com.forward.androids:androids:1.1.1'
compile 'com.forward.androids:androids:1.1.4'
}
package cn.hzw.graffiti;
import android.app.Activity;
import android.app.Dialog;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import cn.forward.androids.base.InjectionLayoutInflater;
import cn.forward.androids.utils.StatusBarUtil;
/**
* Created by huangziwei on 2017/4/21.
*/
public class DialogController {
public static Dialog showEnterCancelDialog(Activity activity, String title, String msg, final View.OnClickListener enterClick, final View.OnClickListener cancelClick) {
return showMsgDialog(activity, title, msg, activity.getString(R.string.graffiti_cancel),
activity.getString(R.string.graffiti_enter), enterClick, cancelClick);
}
public static Dialog showEnterDialog(Activity activity, String title, String msg, final View.OnClickListener enterClick) {
return showMsgDialog(activity, title, msg, null,
activity.getString(R.string.graffiti_enter), enterClick, null);
}
public static Dialog showMsgDialog(Activity activity, String title, String msg, String btn01, String btn02, final View.OnClickListener enterClick, final View.OnClickListener cancelClick) {
final Dialog dialog = getDialog(activity);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
StatusBarUtil.setStatusBarTranslucent(dialog.getWindow(), true, false);
dialog.show();
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
final Dialog finalDialog = dialog;
View.OnClickListener onClickListener = new View.OnClickListener() {
public void onClick(View v) {
if (v.getId() == R.id.dialog_bg) {
finalDialog.dismiss();
} else if (v.getId() == R.id.dialog_enter_btn_02) {
finalDialog.dismiss();
if (enterClick != null) {
enterClick.onClick(v);
}
} else if (v.getId() == R.id.dialog_enter_btn_01) {
finalDialog.dismiss();
if (cancelClick != null) {
cancelClick.onClick(v);
}
}
}
};
View view = InjectionLayoutInflater.from(activity).inflate(R.layout.graffiti_dialog, null,
InjectionLayoutInflater.getViewOnClickListenerInjector(onClickListener));
dialog.setContentView(view);
if (TextUtils.isEmpty(title))
{
dialog.findViewById(R.id.dialog_title).setVisibility(View.GONE);
dialog.findViewById(R.id.dialog_list_title_divider).setVisibility(View.GONE);
} else
{
TextView titleView = (TextView) dialog.findViewById(R.id.dialog_title);
titleView.setText(title);
}
if (TextUtils.isEmpty(msg))
{
dialog.findViewById(R.id.dialog_enter_msg).setVisibility(View.GONE);
} else
{
TextView titleView = (TextView) dialog.findViewById(R.id.dialog_enter_msg);
titleView.setText(Html.fromHtml(msg));
}
if (TextUtils.isEmpty(btn01))
{
dialog.findViewById(R.id.dialog_enter_btn_01).setVisibility(View.GONE);
} else
{
TextView textView = (TextView) dialog.findViewById(R.id.dialog_enter_btn_01);
textView.setText(btn01);
}
if (TextUtils.isEmpty(btn02))
{
dialog.findViewById(R.id.dialog_enter_btn_02).setVisibility(View.GONE);
} else
{
TextView textView = (TextView) dialog.findViewById(R.id.dialog_enter_btn_02);
textView.setText(btn02);
}
return dialog;
}
private static Dialog getDialog(Activity activity) {
boolean fullScreen = (activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Dialog dialog = null;
if (fullScreen) {
dialog = new Dialog(activity, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
} else {
dialog = new Dialog(activity, android.R.style.Theme_Translucent_NoTitleBar);
}
return dialog;
}
}
package cn.hzw.graffiti;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
import android.text.TextUtils;
import android.view.MotionEvent;
......@@ -32,6 +27,7 @@ import java.io.IOException;
import cn.forward.androids.utils.ImageUtils;
import cn.forward.androids.utils.LogUtil;
import cn.forward.androids.utils.StatusBarUtil;
import cn.forward.androids.utils.ThreadUtil;
/**
......@@ -153,6 +149,7 @@ public class GraffitiActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StatusBarUtil.setStatusBarTranslucent(this, true, false);
if (mGraffitiParams == null) {
mGraffitiParams = getIntent().getExtras().getParcelable(KEY_PARAMS);
}
......@@ -252,7 +249,7 @@ public class GraffitiActivity extends Activity {
mPaintSizeBar.setProgress((int) (mGraffitiView.getPaintSize() + 0.5f));
}
mPaintSizeBar.setMax((int) (Math.min(mGraffitiView.getBitmapWidthOnView(), mGraffitiView.getBitmapHeightOnView()) / 3 * DrawUtil.GRAFFITI_PIXEL_UNIT));
mPaintSizeView.setText("" + mPaintSizeBar.getProgress());
findViewById(R.id.btn_pen_hand).performClick();
findViewById(R.id.btn_hand_write).performClick();
}
......@@ -282,7 +279,7 @@ public class GraffitiActivity extends Activity {
@Override
public void onEditText(boolean showDialog, String string) {
mSettingsPanel.removeCallbacks(mHideDelayRunnable);
}
});
mGraffitiView.setIsDrawableOutside(mGraffitiParams.mIsDrawableOutside);
......@@ -542,42 +539,47 @@ public class GraffitiActivity extends Activity {
}
if (v.getId() == R.id.btn_clear) {
new AlertDialog.Builder(GraffitiActivity.this)
.setTitle(R.string.graffiti_clear_screen)
.setMessage(R.string.graffiti_cant_undo_after_clearing)
.setPositiveButton(R.string.graffiti_enter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mGraffitiView.clear();
}
})
.setNegativeButton(R.string.graffiti_cancel, null)
.show();
if (!(GraffitiParams.getDialogInterceptor() != null
&& GraffitiParams.getDialogInterceptor().onShow(GraffitiActivity.this, mGraffitiView, GraffitiParams.DialogType.CLEAR_ALL))) {
DialogController.showEnterCancelDialog(GraffitiActivity.this,
getString(R.string.graffiti_clear_screen), getString(R.string.graffiti_cant_undo_after_clearing),
new View.OnClickListener() {
@Override
public void onClick(View v) {
mGraffitiView.clear();
}
}, null
);
}
mDone = true;
} else if (v.getId() == R.id.btn_undo) {
mGraffitiView.undo();
mDone = true;
} else if (v.getId() == R.id.btn_set_color) {
new ColorPickerDialog(GraffitiActivity.this, mGraffitiView.getGraffitiColor().getColor(), "画笔颜色",
new ColorPickerDialog.OnColorChangedListener() {
public void colorChanged(int color) {
mBtnColor.setBackgroundColor(color);
if (mGraffitiView.isSelectedText()) {
mGraffitiView.setSelectedTextColor(color);
} else {
mGraffitiView.setColor(color);
if (!(GraffitiParams.getDialogInterceptor() != null
&& GraffitiParams.getDialogInterceptor().onShow(GraffitiActivity.this, mGraffitiView, GraffitiParams.DialogType.COLOR_PICKER))) {
new ColorPickerDialog(GraffitiActivity.this, mGraffitiView.getGraffitiColor().getColor(), "画笔颜色",
new ColorPickerDialog.OnColorChangedListener() {
public void colorChanged(int color) {
mBtnColor.setBackgroundColor(color);
if (mGraffitiView.isSelectedText()) {
mGraffitiView.setSelectedTextColor(color);
} else {
mGraffitiView.setColor(color);
}
}
}
@Override
public void colorChanged(Drawable color) {
mBtnColor.setBackgroundDrawable(color);
if (mGraffitiView.isSelectedText()) {
mGraffitiView.setSelectedTextColor(ImageUtils.getBitmapFromDrawable(color));
} else {
mGraffitiView.setColor(ImageUtils.getBitmapFromDrawable(color));
@Override
public void colorChanged(Drawable color) {
mBtnColor.setBackgroundDrawable(color);
if (mGraffitiView.isSelectedText()) {
mGraffitiView.setSelectedTextColor(ImageUtils.getBitmapFromDrawable(color));
} else {
mGraffitiView.setColor(ImageUtils.getBitmapFromDrawable(color));
}
}
}
}).show();
}).show();
}
mDone = true;
}
if (mDone) {
......@@ -602,20 +604,20 @@ public class GraffitiActivity extends Activity {
finish();
return;
}
new AlertDialog.Builder(GraffitiActivity.this).setTitle(R.string.graffiti_saving_picture)
.setIcon(android.R.drawable.ic_dialog_info)
.setPositiveButton(R.string.graffiti_enter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
mGraffitiView.save();
}
})
.setNegativeButton(R.string.graffiti_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
}).show();
if (!(GraffitiParams.getDialogInterceptor() != null
&& GraffitiParams.getDialogInterceptor().onShow(GraffitiActivity.this, mGraffitiView, GraffitiParams.DialogType.SAVE))) {
DialogController.showEnterCancelDialog(GraffitiActivity.this, getString(R.string.graffiti_saving_picture), null, new View.OnClickListener() {
@Override
public void onClick(View v) {
mGraffitiView.save();
}
}, new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
mDone = true;
} else if (v.getId() == R.id.btn_centre_pic) {
mGraffitiView.centrePic();
......@@ -672,7 +674,7 @@ public class GraffitiActivity extends Activity {
public void onBackPressed() {
if (mBtnMovePic.isSelected()) {
mBtnMovePic.setSelected(false);
mBtnMovePic.performClick();
return;
} else {
findViewById(R.id.graffiti_btn_back).performClick();
......
package cn.hzw.graffiti;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.View;
/**
* 涂鸦参数
......@@ -107,4 +109,32 @@ public class GraffitiParams implements Parcelable {
public int describeContents() {
return 0;
}
private static DialogInterceptor sDialogInterceptor;
/**
* 设置涂鸦中对话框的拦截器,如点击返回按钮(或返回键)弹出保存对话框,可以进行拦截,弹出自定义的对话框
* 切记:需要自行处理内存泄漏的问题!!!
*/
public static void setDialogInterceptor(DialogInterceptor interceptor) {
sDialogInterceptor = interceptor;
}
public static DialogInterceptor getDialogInterceptor() {
return sDialogInterceptor;
}
public enum DialogType {
SAVE, CLEAR_ALL, COLOR_PICKER;
}
public interface DialogInterceptor {
/**
* @param activity
* @param graffitiView
* @param dialogType 对话框类型
* @return 返回true表示拦截
*/
boolean onShow(Activity activity, GraffitiView graffitiView, DialogType dialogType);
}
}
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/SecondaryProgress" android:drawable="@android:color/transparent" />
<item android:id="@+id/progress" android:drawable="@drawable/graffiti_bar_up" />
<item
android:id="@android:id/background">
<nine-patch
android:src="@drawable/graffiti_bar_background"/>
</item>
<item
android:id="@android:id/progress">
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="horizontal"
android:gravity="left">
<nine-patch
android:src="@drawable/graffiti_bar_progress"/>
</clip>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
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 copySelected 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.
<item android:drawable="@drawable/bg_normal" />
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/graffiti_thumb_dn" />
<item android:state_pressed="true"
android:drawable="@drawable/graffiti_thumb_pressed" />
<!-- 焦点状态 -->
<item android:state_focused="true"
android:drawable="@drawable/graffiti_thumb_up" />
android:drawable="@drawable/graffiti_thumb_normal" />
<!-- 默认状态 -->
<item android:drawable="@drawable/graffiti_thumb_up" />
<item android:drawable="@drawable/graffiti_thumb_normal" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#232323"
......@@ -11,14 +12,15 @@
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
<cn.forward.androids.views.MaskImageView
android:id="@+id/graffiti_btn_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="返回"
android:textColor="#ffffff"
android:textSize="18dp"/>
android:layout_width="@dimen/title_bar_height"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/graffiti_btn_back"
android:visibility="visible"
app:miv_is_ignore_alpha="true"
app:miv_mask_color="#a8a8a8"/>
<FrameLayout
android:layout_width="1dp"
......@@ -59,13 +61,15 @@
android:visibility="visible"/>
</FrameLayout>
<ImageView
<cn.forward.androids.views.MaskImageView
android:id="@+id/graffiti_btn_finish"
android:layout_width="@dimen/title_bar_height"
android:layout_height="@dimen/title_bar_height"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/graffiti_btn_finish"
android:visibility="visible"/>
android:visibility="visible"
app:miv_is_ignore_alpha="true"
app:miv_mask_color="#a8a8a8"/>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/dialog_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#88000000"
android:fitsSystemWindows="true"
android:paddingBottom="10dp"
android:paddingTop="10dp"
app:injectListener="true">
<cn.forward.androids.views.SLinearLayout
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:clickable="true"
android:minWidth="280dp"
android:orientation="vertical"
android:paddingBottom="3.5dp"
android:paddingTop="0dp"
app:sel_background="#ffffff"
app:sel_background_corners="5dp">
<TextView
android:id="@+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:ellipsize="middle"
android:gravity="center"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:text=""
android:textColor="#2b2b2b"
android:textSize="20dp"
android:textStyle="bold"/>
<FrameLayout
android:id="@+id/dialog_list_title_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#dfdfdf"
/>
<TextView
android:id="@+id/dialog_enter_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:minWidth="50dp"
android:padding="20dp"
android:textColor="#2b2b2b"
android:textSize="16dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<cn.forward.androids.views.STextView
android:id="@+id/dialog_enter_btn_01"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textColor="#bebebe"
android:textSize="20dp"
app:injectListener="true"
app:stv_text_color_pressed="#88bebebe"/>
<cn.forward.androids.views.STextView
android:id="@+id/dialog_enter_btn_02"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textColor="#11cfff"
android:textSize="20dp"
app:injectListener="true"
app:stv_text_color_pressed="#8811cfff"/>
</LinearLayout>
</cn.forward.androids.views.SLinearLayout>
</FrameLayout>
\ No newline at end of file
......@@ -42,6 +42,20 @@ public class GraffitiActivity extends Activity {
}
```
```java
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQ_CODE_GRAFFITI) {
if (resultCode == GraffitiActivity.RESULT_OK) {
// 获取涂鸦后的图片
String path = data.getStringExtra(GraffitiActivity.KEY_IMAGE_PATH);
...
} else if (resultCode == GraffitiActivity.RESULT_ERROR) {
...
}
}
}
```
```java
/**
* 涂鸦参数
......@@ -95,7 +109,7 @@ public static class GraffitiParams implements Parcelable {
### 依赖
```
dependencies {
compile 'com.forward.androids:androids:1.1.1'
compile 'com.forward.androids:androids:1.1.4'
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册