修改动画资源文件获取方式,剥离R文件的依赖

This commit is contained in:
zftlive@163.com 2015-10-26 15:06:10 +08:00
parent 427faff0d5
commit 65d66ce82a
4 changed files with 366 additions and 339 deletions

View File

@ -17,8 +17,8 @@ import android.view.ViewConfiguration;
import android.view.Window;
import android.view.WindowManager;
import com.zftlive.android.R;
import com.zftlive.android.library.MApplication;
import com.zftlive.android.library.tools.ToolResource;
import com.zftlive.android.library.widget.SwipeBackLayout;
/**
@ -227,13 +227,13 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
super.finish();
switch (mAnimationType) {
case IBaseActivity.LEFT_RIGHT:
overridePendingTransition(0, R.anim.base_slide_right_out);
overridePendingTransition(0, BaseView.gainResId(mApplication, BaseView.ANIM, "base_slide_right_out"));
break;
case IBaseActivity.TOP_BOTTOM:
overridePendingTransition(0, R.anim.base_push_up_out);
overridePendingTransition(0, BaseView.gainResId(mApplication, BaseView.ANIM, "base_push_up_out"));
break;
case IBaseActivity.FADE_IN_OUT:
overridePendingTransition(0, R.anim.base_fade_out);
overridePendingTransition(0, BaseView.gainResId(mApplication, BaseView.ANIM, "base_fade_out"));
break;
default:
break;

View File

@ -11,6 +11,7 @@ import android.view.WindowManager;
/**
* 自定义控件基础类
*
* @author 曾繁添
* @version 1.0
*
@ -23,6 +24,9 @@ public abstract class BaseView extends View {
/*** 资源类型-attr **/
public static final String ATTR = "attr";
/*** 资源类型-anim **/
public static final String ANIM = "anim";
/*** 资源类型-bool **/
public static final String BOOL = "bool";
@ -60,7 +64,7 @@ public abstract class BaseView extends View {
protected Context mContext;
/** 日志输出标志 **/
protected final String TAG = this.getClass().getSimpleName();
protected final static String TAG = BaseView.class.getSimpleName();
public BaseView(Context context) {
this(context, null);
@ -78,14 +82,14 @@ public abstract class BaseView extends View {
/**
* 获取屏幕宽度
*
* @param mContext 上下文
* @return
*/
public int gainScreenWidth(Context mContext){
public static int gainScreenWidth(Context mContext) {
// 获取屏幕分辨率
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.widthPixels;
@ -93,64 +97,65 @@ public abstract class BaseView extends View {
/**
* 根据手机的分辨率从 dip 的单位 转成为 px(像素)
* @param context
* 环境
* @param dpValue
* 需要转化的dip值
*
* @param mContext 环境
* @param dpValue 需要转化的dip值
* @return int 转化后的px值
*/
public int dipToPx(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
public static int dipToPx(Context mContext, float dipValue) {
final float scale = mContext.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
/**
* 根据手机的分辨率从 px(像素) 的单位 转成为 dip
* @param context
* 环境
* @param pxValue
* 需要转换的像素值
*
* @param mContext 环境
* @param pxValue 需要转换的像素值
* @return int 转化后的dip值
*/
public int pxToDip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
public static int pxToDip(Context mContext, float pxValue) {
final float scale = mContext.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
/**
* 将px值转换为sp值保证文字大小不变
* @param context
*
* @param mContext
* @param pxValue
*/
public int pxTosp(Context context, float pxValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
public static int pxTosp(Context mContext, float pxValue) {
final float fontScale = mContext.getResources().getDisplayMetrics().scaledDensity;
return (int) (pxValue / fontScale + 0.5f);
}
/**
* 将sp值转换为px值保证文字大小不变
*
* @param spValue
* @param fontScale
* DisplayMetrics类中属性scaledDensity
* @param fontScale DisplayMetrics类中属性scaledDensity
*/
public int spTopx(Context context, float spValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
public static int spTopx(Context mContext, float spValue) {
final float fontScale = mContext.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}
/**
* 获取当前分辨率下指定单位对应的像素大小根据设备信息
* px,dip,sp -> px<br><br>
* 获取当前分辨率下指定单位对应的像素大小根据设备信息 px,dip,sp -> px<br>
* <br>
*
* 用法:getRawSize(context,TypedValue.COMPLEX_UNIT_DIP,itemSpaceDp)<br><br>
* 用法:getRawSize(context,TypedValue.COMPLEX_UNIT_DIP,itemSpaceDp)<br>
* <br>
*
* 代码摘自TextView.setTextSize()
*
* @param mContext 上下文
* @param unit TypedValue.COMPLEX_UNIT_*
* @param size
* @return
*/
public int gainRawSize(Context mContext, int unit, float size) {
public static int gainRawSize(Context mContext, int unit, float size) {
Resources r;
if (mContext == null)
r = Resources.getSystem();
@ -162,12 +167,13 @@ public abstract class BaseView extends View {
/**
* 获取资源文件id
*
* @param mContext 上下文
* @param resType 资源类型drawable/string/layout/style/dimen/color/array等
* @param resName 资源文件名称
* @return
*/
public int gainResId(Context mContext,String resType,String resName){
public static int gainResId(Context mContext, String resType, String resName) {
int result = -1;
try {
String packageName = mContext.getPackageName();

View File

@ -1,20 +1,20 @@
package com.zftlive.android.library.base;
import java.io.Serializable;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.zftlive.android.R;
import com.zftlive.android.library.MApplication;
import com.zftlive.android.library.config.SysEnv;
import com.zftlive.android.library.data.DTO;
import com.zftlive.android.library.tools.ToolAlert;
import com.zftlive.android.library.tools.ToolAlert.ILoadingOnKeyListener;
import java.io.Serializable;
/**
* 基本的操作共通抽取
*
* @author 曾繁添
* @version 1.0
*
@ -35,6 +35,7 @@ public class Operation {
/**
* 跳转Activity
*
* @param activity 需要跳转至的Activity
*/
public void forward(Class activity) {
@ -43,6 +44,7 @@ public class Operation {
/**
* 跳转Activity
*
* @param activity 需要跳转至的Activity
*/
public void forward(String className) {
@ -51,6 +53,7 @@ public class Operation {
/**
* 跳转Activity
*
* @param activity 需要跳转至的Activity
* @param animaType 动画类型IBaseActivity.LEFT_RIGHT/TOP_BOTTOM/FADE_IN_OUT
*/
@ -60,13 +63,19 @@ public class Operation {
mContext.startActivity(mIntent);
switch (animaType) {
case IBaseActivity.LEFT_RIGHT:
mContext.overridePendingTransition(R.anim.base_slide_right_in, R.anim.base_slide_remain);
int inLFAnim = BaseView.gainResId(mApplication, BaseView.ANIM, "base_slide_right_in");
int outLFAnim = BaseView.gainResId(mApplication, BaseView.ANIM, "base_slide_remain");
mContext.overridePendingTransition(inLFAnim, outLFAnim);
break;
case IBaseActivity.TOP_BOTTOM:
mContext.overridePendingTransition(R.anim.base_push_up_in,R.anim.base_push_up_out);
int inTBAnim = BaseView.gainResId(mApplication, BaseView.ANIM, "base_push_up_in");
int outTBAnim = BaseView.gainResId(mApplication, BaseView.ANIM, "base_push_up_out");
mContext.overridePendingTransition(inTBAnim, outTBAnim);
break;
case IBaseActivity.FADE_IN_OUT:
mContext.overridePendingTransition(R.anim.base_fade_in, R.anim.base_fade_out);
int inFAnim = BaseView.gainResId(mApplication, BaseView.ANIM, "base_fade_in");
int outFAnim = BaseView.gainResId(mApplication, BaseView.ANIM, "base_fade_out");
mContext.overridePendingTransition(inFAnim, outFAnim);
break;
default:
break;
@ -75,6 +84,7 @@ public class Operation {
/**
* 设置传递参数
*
* @param value 数据传输对象
*/
public void addParameter(DTO value) {
@ -83,6 +93,7 @@ public class Operation {
/**
* 设置传递参数
*
* @param key 参数key
* @param value 数据传输对象
*/
@ -92,6 +103,7 @@ public class Operation {
/**
* 设置传递参数
*
* @param key 参数key
* @param value 数据传输对象
*/
@ -101,6 +113,7 @@ public class Operation {
/**
* 设置传递参数
*
* @param key 参数key
* @param value 数据传输对象
*/
@ -110,6 +123,7 @@ public class Operation {
/**
* 设置传递参数
*
* @param key 参数key
* @param value 数据传输对象
*/
@ -119,6 +133,7 @@ public class Operation {
/**
* 获取跳转时设置的参数
*
* @param key
* @return
*/
@ -135,6 +150,7 @@ public class Operation {
/**
* 获取跳转参数集合
*
* @return
*/
public DTO getParameters() {
@ -144,6 +160,7 @@ public class Operation {
/**
* 设置全局Application传递参数
*
* @param strKey 参数key
* @param value 数据传输对象
*/
@ -153,6 +170,7 @@ public class Operation {
/**
* 获取跳转时设置的参数
*
* @param strKey
* @return
*/
@ -162,6 +180,7 @@ public class Operation {
/**
* 弹出等待对话框
*
* @param message 提示信息
*/
public void showLoading(String message) {
@ -170,6 +189,7 @@ public class Operation {
/**
* 弹出等待对话框
*
* @param message 提示信息
* @param listener 按键监听器
*/
@ -179,6 +199,7 @@ public class Operation {
/**
* 更新等待对话框显示文本
*
* @param message 需要更新的文本内容
*/
public void updateLoadingText(String message) {

View File

@ -104,7 +104,7 @@ public class AnimationInActivity extends BaseActivity implements View.OnClickLis
switch (mAnimSp.getSelectedItemPosition()) {
case 0:
//淡入淡出效果
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
overridePendingTransition(R.anim.base_fade_in, R.anim.base_fade_out);
//Android内置的
//overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
break;
@ -136,7 +136,7 @@ public class AnimationInActivity extends BaseActivity implements View.OnClickLis
break;
case 7:
//下往上推出效果
overridePendingTransition(R.anim.push_up_in,R.anim.push_up_out);
overridePendingTransition(R.anim.base_push_up_in,R.anim.base_push_up_out);
break;
case 8:
//左右交错效果