WIWdnf2016裸体补丁丁,有Character和Item2个文件包,要怎么用?

/ TiYuZhiTongChe_Android
项目语言:None
权限:read-only(如需更高权限请先加入项目)
TiYuZhiTongChe_Android/
Index: anim/YiRotate3dAnimation.java
===================================================================
--- anim/YiRotate3dAnimation.java (revision 0)
+++ anim/YiRotate3dAnimation.java (revision 2)
@@ -0,0 +1,91 @@
+package com.ikantech.support.
+import android.view.animation.A
+import android.view.animation.T
+import android.graphics.C
+import android.graphics.M
+ * An animation that rotates the view on the Y axis between two specified
+ * angles. This animation also adds a translation on the Z axis (depth) to
+ * improve the effect.
+public class YiRotate3dAnimation extends Animation
+ private final float mFromD
+ private final float mToD
+ private final float mCenterX;
+ private final float mCenterY;
+ private final float mDepthZ;
+ private final boolean mR
+ private Camera mC
* Creates a new 3D rotation on the Y axis. The rotation is defined by its
* start angle and its end angle. Both angles are in degrees. The rotation
* is performed around a center point on the 2D space, definied by a pair of
* X and Y coordinates, called centerX and centerY. When the animation
* starts, a translation on the Z axis (depth) is performed. The length of
* the translation can be specified, as well as whether the translation
* should be reversed in time.
* @param fromDegrees
the start angle of the 3D rotation
* @param toDegrees
the end angle of the 3D rotation
* @param centerX
the X center of the 3D rotation
* @param centerY
the Y center of the 3D rotation
* @param reverse
true if the translation should be reversed, false otherwise
+ public YiRotate3dAnimation(float fromDegrees, float toDegrees,
float centerX, float centerY, float depthZ, boolean reverse)
mFromDegrees = fromD
mToDegrees = toD
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mReverse =
+ @Override
+ public void initialize(int width, int height, int parentWidth,
int parentHeight)
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
+ @Override
+ protected void applyTransformation(float interpolatedTime, Transformation t)
final float fromDegrees = mFromD
float degrees = fromDegrees
+ ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mC
final Matrix matrix = t.getMatrix();
camera.save();
if (mReverse)
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
Property changes on: anim/YiRotate3dAnimation.java
___________________________________________________________________
Added: svn:executable
Index: listener/YiHttpResponseListener.java
===================================================================
--- listener/YiHttpResponseListener.java (revision 0)
+++ listener/YiHttpResponseListener.java (revision 2)
@@ -0,0 +1,8 @@
+package com.ikantech.support.
+import com.ikantech.support.net.YiHttpR
+public interface YiHttpResponseListener
+ void onHttpResponse(YiHttpResponse response);
Property changes on: listener/YiHttpResponseListener.java
___________________________________________________________________
Added: svn:executable
Index: listener/YiImageLoaderListener.java
===================================================================
--- listener/YiImageLoaderListener.java (revision 0)
+++ listener/YiImageLoaderListener.java (revision 2)
@@ -0,0 +1,8 @@
+package com.ikantech.support.
+import android.graphics.B
+public interface YiImageLoaderListener
+ void onImageLoaded(String url, Bitmap bitmap);
Property changes on: listener/YiImageLoaderListener.java
___________________________________________________________________
Added: svn:executable
Index: net/InHttpHelper.java
===================================================================
--- net/InHttpHelper.java (revision 0)
+++ net/InHttpHelper.java (revision 2)
@@ -0,0 +1,218 @@
+package com.ikantech.support.
+import java.io.BufferedR
+import java.io.IOE
+import java.io.InputStreamR
+import java.net.URI;
+import java.net.URLE
+import java.util.L
+import org.apache.http.H
+import org.apache.http.HttpR
+import org.apache.http.NameValueP
+import org.apache.http.client.HttpC
+import org.apache.http.client.entity.UrlEncodedFormE
+import org.apache.http.client.methods.HttpG
+import org.apache.http.client.methods.HttpP
+import org.apache.http.conn.ConnectTimeoutE
+import org.apache.http.impl.client.DefaultHttpC
+import org.apache.http.params.HttpConnectionP
+import com.ikantech.support.util.YiA
+import com.ikantech.support.util.YiL
+public class InHttpHelper
+ // http request time out
+ private static int TIME_OUT_DELAY = 10000;
+ // no instance
+ private InHttpHelper()
+ public static YiHttpResponse execute(YiHttpRequest request)
YiHttpResponse response = new YiHttpResponse(request.getUrl());
response.setResponseId(request.getRequestId());
response.setUid(request.getUid());
if (request.getMode().equals(YiHttpRequest.YiHttpRequestMode.MODE_GET))
executeHttpGet(request, response);
executeHttpPost(request, response);
+ // use apache http client.
+ protected static void executeHttpGet(YiHttpRequest request,
YiHttpResponse response)
String result =
BufferedReader reader =
HttpClient client = new DefaultHttpClient();
int timeOut = TIME_OUT_DELAY;
if(request.getTimeOut() & 0) {
timeOut = request.getTimeOut();
client.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT,
timeOut); // 超时设置
client.getParams().setIntParameter(
HttpConnectionParams.CONNECTION_TIMEOUT, TIME_OUT_DELAY);// 连接超时
HttpGet httpGet = new HttpGet();
String url = request.getUrl();
boolean pafix = url.indexOf('?') & -1;
if (request.getParams() != null)
List&NameValuePair& params = request.getParams();
for (int i = 0; i & params.size(); i++)
NameValuePair pair = params.get(i);
if(i == 0 && !pafix) {
url += &?& + pair.getName() + &=& + URLEncoder.encode(pair.getValue(), &UTF-8&);
url += &&& + pair.getName() + &=& + URLEncoder.encode(pair.getValue(), &UTF-8&);
httpGet.setURI(new URI(url));
YiLog.getInstance().i(httpGet.getURI().toString());
Header[] headers = request.getHeaders();
if(headers != null) {
for (Header header : headers)
httpGet.addHeader(header);
HttpResponse httpResponse = client.execute(httpGet);
response.setHeaders(httpResponse.getAllHeaders());
reader = new BufferedReader(new InputStreamReader(httpResponse
.getEntity().getContent(), request.getResponseCharset()));
StringBuffer strBuffer = new StringBuffer(&&);
String line =
while ((line = reader.readLine()) != null)
strBuffer.append(line);
result = strBuffer.toString();
response.setResponse(result);
catch (ConnectTimeoutException timeoutException)
response.setErrorCode(YiHttpResponse.ERROR_TIME_OUT);
YiLog.getInstance().e(timeoutException, &executeHttpGet error:&);
catch (Exception e)
response.setErrorCode(YiHttpResponse.ERROR_UNKNOWN);
YiLog.getInstance().e(e, &executeHttpGet error:&);
if (reader != null)
reader.close();
catch (IOException e)
YiLog.getInstance().e(e,
&executeHttpGet close reader error:&);
+ protected static void executeHttpPost(YiHttpRequest request,
YiHttpResponse response)
String result =
BufferedReader reader =
HttpClient client = new DefaultHttpClient();
int timeOut = TIME_OUT_DELAY;
if(request.getTimeOut() & 0) {
timeOut = request.getTimeOut();
client.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT,
timeOut); // 超时设置
client.getParams().setIntParameter(
HttpConnectionParams.CONNECTION_TIMEOUT, TIME_OUT_DELAY);// 连接超时
HttpPost httpPost = new HttpPost();
httpPost.setURI(new URI(request.getUrl()));
Header[] headers = request.getHeaders();
if(headers != null) {
for (Header header : headers)
httpPost.addHeader(header);
if (request.getParams() != null)
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
request.getParams());
httpPost.setEntity(formEntity);
HttpResponse httpResponse = client.execute(httpPost);
response.setHeaders(httpResponse.getAllHeaders());
reader = new BufferedReader(new InputStreamReader(httpResponse
.getEntity().getContent(), request.getResponseCharset()));
StringBuffer strBuffer = new StringBuffer(&&);
String line =
while ((line = reader.readLine()) != null)
strBuffer.append(line);
result = strBuffer.toString();
response.setResponse(result);
catch (ConnectTimeoutException timeoutException)
response.setErrorCode(YiHttpResponse.ERROR_TIME_OUT);
YiLog.getInstance().e(timeoutException, &executeHttpPost error:&);
catch (Exception e)
response.setErrorCode(YiHttpResponse.ERROR_UNKNOWN);
e.printStackTrace();
YiLog.getInstance().e(e, &executeHttpPost error:&);
if (reader != null)
reader.close();
catch (IOException e)
YiLog.getInstance().e(e,
&executeHttpPost close reader error:&);
Property changes on: net/InHttpHelper.java
___________________________________________________________________
Added: svn:executable
Index: net/YiHttpRequest.java
===================================================================
--- net/YiHttpRequest.java (revision 0)
+++ net/YiHttpRequest.java (revision 2)
@@ -0,0 +1,142 @@
+package com.ikantech.support.
+import java.util.ArrayL
+import java.util.L
+import org.apache.http.H
+import org.apache.http.NameValueP
+import org.apache.http.message.BasicNameValueP
+public class YiHttpRequest
+ public enum YiHttpRequestMode
MODE_GET, MODE_POST
+ private YiHttpRequestM
+ private int requestId;
+ private S
+ private String responseC
+ private Header[]
+ private int timeO
+ private List&NameValuePair&
+ public YiHttpRequest(String url, YiHttpRequestMode mode)
if (url == null || mode == null)
throw new NullPointerException(&params non-null&);
this.url =
this.mode =
this.requestId = -1;
this.uid = -1;
this.timeOut = -1;
this.responseCharset = &utf-8&;
+ public int getUid()
+ public void setUid(int uid)
this.uid =
+ public int getRequestId()
return requestId;
+ public void setRequestId(int requestId)
this.requestId = requestId;
+ public List&NameValuePair& getParams()
+ public void setParams(List&NameValuePair& params)
this.params =
+ public YiHttpRequestMode getMode()
+ public String getUrl()
+ public void setUrl(String url)
this.url =
+ protected void initParams()
if (params == null)
params = new ArrayList&NameValuePair&();
+ public void addParam(String key, String value)
initParams();
params.add(new BasicNameValuePair(key, value));
+ public void addParam(String key, long value)
this.addParam(key, String.valueOf(value));
+ public void addParam(String key, boolean value)
this.addParam(key, String.valueOf(value));
+ public void clearParam() {
params.clear();
+ public String getResponseCharset()
return responseC
+ public void setResponseCharset(String responseCharset)
this.responseCharset = responseC
+ public Header[] getHeaders()
+ public void setHeaders(Header[] headers)
this.headers =
+ public int getTimeOut()
return timeO
+ public void setTimeOut(int timeOut)
this.timeOut = timeO
Property changes on: net/YiHttpRequest.java
___________________________________________________________________
Added: svn:executable
Index: net/YiHttpResponse.java
===================================================================
--- net/YiHttpResponse.java (revision 0)
+++ net/YiHttpResponse.java (revision 2)
@@ -0,0 +1,96 @@
+package com.ikantech.support.
+import org.apache.http.H
+public class YiHttpResponse
+ public static final int ERROR_TIME_OUT = -100;
+ public static final int ERROR_UNKNOWN = -2;
+ public static final int SUCCESS = 0;
+ private int errorC
+ private int responseId;
+ private S
+ private Header[]
+ private Header[] headers2;
+ private S
+ public YiHttpResponse(String url)
if (url == null)
throw new NullPointerException(&params non-null&);
this.url =
this.errorCode = SUCCESS;
this.responseId = -1;
this.response = &&;
this.uid = -1;
+ public int getUid()
+ public void setUid(int uid)
this.uid =
+ public int getErrorCode()
return errorC
+ public void setErrorCode(int errorCode)
this.errorCode = errorC
+ public int getResponseId()
return responseId;
+ public void setResponseId(int responseId)
this.responseId = responseId;
+ public String getResponse()
+ public void setResponse(String response)
this.response =
+ public String getUrl()
+ public Header[] getHeaders()
+ public void setHeaders(Header[] headers)
this.headers =
+ public Header[] getHeaders2()
return headers2;
+ public void setHeaders2(Header[] headers2)
this.headers2 = headers2;
Property changes on: net/YiHttpResponse.java
___________________________________________________________________
Added: svn:executable
Index: common/ViewHolder.java
===================================================================
--- common/ViewHolder.java (revision 0)
+++ common/ViewHolder.java (revision 2)
@@ -0,0 +1,89 @@
+package com.
+import android.content.C
+import android.util.SparseA
+import android.view.LayoutI
+import android.view.V
+import android.view.ViewG
+import android.widget.TextV
+public class ViewHolder
+ private final SparseArray&View& mV
+ private int mP
+ private View mConvertV
+ private ViewHolder(Context context, ViewGroup parent, int layoutId,
int position)
this.mPosition =
this.mViews = new SparseArray&View&();
mConvertView = LayoutInflater.from(context).inflate(layoutId, parent,
mConvertView.setTag(this);
* 拿到一个ViewHolder对象
* @param context
* @param convertView
* @param parent
* @param layoutId
* @param position
+ public static ViewHolder get(Context context, View convertView,
ViewGroup parent, int layoutId, int position)
if (convertView == null)
return new ViewHolder(context, parent, layoutId, position);
return (ViewHolder) convertView.getTag();
+ public View getConvertView()
return mConvertV
* 通过控件的Id获取对于的控件,如果没有则加入views
* @param viewId
+ public &T extends View& T findViewById(int viewId)
View view = mViews.get(viewId);
if (view == null)
view = mConvertView.findViewById(viewId);
mViews.put(viewId, view);
return (T)
+ public int getPosition()
* 为TextView设置字符串
* @param viewId
* @param text
+ public ViewHolder setText(int viewId, String text)
TextView view = findViewById(viewId);
view.setText(text);
Property changes on: common/ViewHolder.java
___________________________________________________________________
Added: svn:executable
Index: common/YiPinnedHeaderExListViewMng.java
===================================================================
--- common/YiPinnedHeaderExListViewMng.java (revision 0)
+++ common/YiPinnedHeaderExListViewMng.java (revision 2)
@@ -0,0 +1,274 @@
+package com.
+import android.view.V
+import android.view.View.OnClickL
+import android.widget.AbsListV
+import android.widget.AbsListView.OnScrollL
+import android.widget.ExpandableListV
+import android.widget.ExpandableListView.OnGroupCollapseL
+import android.widget.ExpandableListView.OnGroupExpandL
+import android.widget.FrameL
+import com.ikantech.support.adapter.PinnedHeaderExpandableListViewA
+ * 功能描述:组标题会停留在top处的ExpandableListView, QQ的好友列表展示效果
+ * @author njzhufeifei
下午12:42:16
+public class YiPinnedHeaderExListViewMng
+ // top处显示的header内容
+ private View topH
+ /** topHeader可见且填充完内容后的高度 */
+ int topHeaderH
+ /** 所有group在所有item(包括所有group和child)中的potision */
+ int[] groupPositionInAllI
+ /** 记录group是否打开 */
+ boolean[] groupO
+ /** 当前topHeader中应该是第几个group */
+ int currentGroupP
+ /** group 总数 */
+ int groupC
+ ExpandableListV
+ /** 自定义的adapter */
+ PinnedHeaderExpandableListViewA
+ private OnPinnedHeaderChangeListener mL
* @param elv
ExpandableListView
* @param ela
PinnedHeaderExpandableListAdapter 扩展的ExpandableListAdapter接口
* @param topHeader
浮在top处header
* @param topHeaderTxt
浮在top处的group的文本
* @param topHeaderImg
浮在top处的group的logo图片
* @param openIconId
打开情况下的logo图片 id
+ public YiPinnedHeaderExListViewMng(ExpandableListView elv,
PinnedHeaderExpandableListViewAdapter ela, View header)
this.elv =
this.ela =
this.topHeader =
// 去除所有group左侧默认的图标
this.elv.setGroupIndicator(null);
this.groupCount = this.ela.getGroupCount();
this.groupPositionInAllItem =
this.groupOpen =
// 计算group在所有item中的potision
calculateGroupPosition();
// 初始化ExpandableListView的监听器
initExpandableListViewListeners();
+ private void initExpandableListViewListeners()
topHeader.setOnClickListener(new OnClickListener()
public void onClick(View v)
elv.collapseGroup(currentGroupPosition);
elv.setSelectedGroup(currentGroupPosition);
/** 监听父节点打开的事件 */
elv.setOnGroupExpandListener(new OnGroupExpandListener()
public void onGroupExpand(int groupPosition)
calculateGroupPosition();// 重新计算group position
/** 监听父节点关闭的事件 */
elv.setOnGroupCollapseListener(new OnGroupCollapseListener()
public void onGroupCollapse(int groupPosition)
calculateGroupPosition();// 重新计算group position
/** 通过setOnScrollListener来监听列表上下滑动时item显示和消失的事件 */
elv.setOnScrollListener(new OnScrollListener()
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount)
if (ela.getGroupCount() & 1)
if(groupCount != ela.getGroupCount()) {
calculateGroupPosition();
currentGroupPosition = calculateCurrentGroupPosition(firstVisibleItem);
/** 滑动经过未打开的group的时候topHeader隐藏,一旦遇到打开的则显现 */
if (groupOpen[currentGroupPosition])
{ // 当前group是打开的
topHeaderTxt.setText(ela.getGroup(currentGroupPosition)
.toString());
if(mListener != null) {
mListener.onPinnedHeaderChanged(currentGroupPosition);
// 计算topHeader正常的时候(text和img都放进去的且VISIBLE时候)的高度
topHeaderHeight = topHeaderHeight == 0 ? topHeader
.getHeight() : topHeaderH
if (firstVisibleItem == 0)
View view2 = elv.getChildAt(0);
if (view2.getTop() & 0)
topHeader.setVisibility(View.VISIBLE);
topHeader.setVisibility(View.INVISIBLE);
topHeader.setVisibility(View.VISIBLE);
topHeader.setVisibility(FrameLayout.INVISIBLE);
/** 当前topHeader被下一个group推上去的特效 */
View nextGroup = ela.getGroupView(currentGroupPosition + 1);
// 当前group不是最后一个group,且topHeader是可见的
if (nextGroup != null
&& topHeader.getVisibility() == FrameLayout.VISIBLE)
if (nextGroup.getTop() &= 0
&& nextGroup.getTop() &= topHeaderHeight)
topHeader.layout(0, nextGroup.getTop()
- topHeaderHeight, topHeader.getWidth(),
nextGroup.getTop());
else if (nextGroup.getTop() & topHeaderHeight)
* 解决快速向下滑动导致nextGroup.getTop() & topHeaderHeight,但上
* 面还没来得及layout() header的时候可能会出先header只出现一部分的问题
topHeader.layout(0, 0, topHeader.getWidth(),
topHeaderHeight);
else if (nextGroup == null)
{ // 当前group是最后一个group
topHeader.layout(0, 0, topHeader.getWidth(),
topHeaderHeight);
public void onScrollStateChanged(AbsListView view, int scrollState)
* 计算group在所有item中的potision
+ private void calculateGroupPosition()
int itemPostitons = 0;
groupCount = ela.getGroupCount();
groupPositionInAllItem = new int[groupCount];
groupOpen = new boolean[groupCount];
for (int i = 1; i & groupC i++)
// 打开的才计算childCount
if (elv.isGroupExpanded(i - 1))
itemPostitons = itemPostitons + ela.getChildrenCount(i - 1) + 1;
groupPositionInAllItem[i] = itemP
groupOpen[i - 1] =
itemPostitons = itemPostitons + 1;
groupPositionInAllItem[i] = itemP
groupOpen[i - 1] =
+ public void setOnPinnedHeaderChangeListener(OnPinnedHeaderChangeListener listener) {
mListener =
* 当前第一个可见item所属第几个group
* @param firstVisibleItem
当前第一个可见的item position
+ private int calculateCurrentGroupPosition(int firstVisibleItem)
firstVisibleItem++; // 第一个可见的被header挡住了,算是第二个可见的为第一个
int result = 0;
for (int i = 0; i & groupC i++)
if (i + 1 & groupCount)
if (firstVisibleItem &= groupPositionInAllItem[i]
&& firstVisibleItem &= groupPositionInAllItem[i + 1])
if (firstVisibleItem &= groupPositionInAllItem[i])
+ public interface OnPinnedHeaderChangeListener{
void onPinnedHeaderChanged(int groupPosition);
Property changes on: common/YiPinnedHeaderExListViewMng.java
___________________________________________________________________
Added: svn:executable
Index: common/YiCrashHandler.java
===================================================================
--- common/YiCrashHandler.java (revision 0)
+++ common/YiCrashHandler.java (revision 2)
@@ -0,0 +1,223 @@
+package com.
+import java.io.F
+import java.io.FileOutputS
+import java.io.PrintW
+import java.io.StringW
+import java.io.W
+import java.lang.Thread.UncaughtExceptionH
+import java.lang.reflect.F
+import java.text.DateF
+import java.text.SimpleDateF
+import java.util.D
+import java.util.HashM
+import java.util.M
+import android.annotation.SuppressL
+import android.content.C
+import android.content.pm.PackageI
+import android.content.pm.PackageM
+import android.content.pm.PackageManager.NameNotFoundE
+import android.os.B
+import android.os.E
+import com.ikantech.support.util.YiFileU
+import com.ikantech.support.util.YiL
+ * UncaughtException处理类,当程序发生Uncaught异常的时候,由该类来接管程序,并记录发送错误报告.
+ * @author saint
+public class YiCrashHandler implements UncaughtExceptionHandler {
+ protected static String mPath = YiFileUtils.getStorePath() + &ik/ikcrash/&;
+ // 系统默认的UncaughtException处理类
+ private Thread.UncaughtExceptionHandler mDefaultH
+ // CrashHandler实例
+ private static YiCrashHandler mInstance =
+ // 程序的Context对象
+ protected Context mC
+ // 用来存储设备信息和异常信息
+ private Map&String, String& mInfos = new HashMap&String, String&();
+ // 用于格式化日期,作为日志文件名的一部分
+ @SuppressLint(&SimpleDateFormat&)
+ private DateFormat mDateFormatter = new SimpleDateFormat(
&yyyy-MM-dd-HH-mm-ss&);
+ /** 保证只有一个YiCrashHandler实例 */
+ private YiCrashHandler() {
+ /** 获取YiCrashHandler实例 ,单例模式 */
+ public static YiCrashHandler getInstance() {
if (mInstance == null) {
mInstance = new YiCrashHandler();
+ public static void setLogPath(String path) {
YiLog.getInstance().i(path);
* @param context
+ public void init(Context context) {
mContext =
// 获取系统默认的UncaughtException处理器
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
// 设置该CrashHandler为程序的默认处理器
Thread.setDefaultUncaughtExceptionHandler(this);
* 当UncaughtException发生时会转入该函数来处理
+ @Override
+ public void uncaughtException(Thread thread, Throwable ex) {
if (!handleException(ex) && mDefaultHandler != null) {
// 如果用户没有处理则让系统默认的异常处理器来处理
mDefaultHandler.uncaughtException(thread, ex);
Thread.sleep(3000);
} catch (InterruptedException e) {
YiLog.getInstance().e(e, &error : &);
// 退出程序
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
* 自定义错误处理,收集错误信息 发送错误报告等操作均在此完成.
* @param ex
* @return true:如果处理了该异常信息;否则返回false.
+ protected boolean handleException(Throwable ex) {
if (ex == null) {
// 使用Toast来显示异常信息
// new Thread()
// @Override
// public void run()
// Looper.prepare();
// Toast.makeText(mContext, &很抱歉,程序出现异常,即将退出.&, Toast.LENGTH_LONG)
// .show();
// Looper.loop();
// }.start();
// 收集设备参数信息
collectDeviceInfo(mContext);
// 保存日志文件
saveCrashInfo2File(ex);
YiLog.getInstance().e(ex, &crash handler exception:&);
* 收集设备参数信息
* @param ctx
+ public void collectDeviceInfo(Context ctx) {
PackageManager pm = ctx.getPackageManager();
PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(),
PackageManager.GET_ACTIVITIES);
String time = mDateFormatter.format(new Date());
mInfos.put(&crash_time&, time);
if (pi != null) {
String versionName = pi.versionName == null ? &null&
: pi.versionN
String versionCode = pi.versionCode + &&;
mInfos.put(&versionName&, versionName);
mInfos.put(&versionCode&, versionCode);
} catch (NameNotFoundException e) {
YiLog.getInstance().e(e,
&an error occured when collect package info&);
Field[] fields = Build.class.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
mInfos.put(field.getName(), field.get(null).toString());
YiLog.getInstance()
.d(field.getName() + & : & + field.get(null));
} catch (Exception e) {
YiLog.getInstance().e(e,
&an error occured when collect crash info&);
* 保存错误信息到文件中
* @param ex
* @return 返回文件名称,便于将文件传送到服务器
+ protected String saveCrashInfo2File(Throwable ex) {
if (mPath == null)
StringBuffer sb = new StringBuffer();
for (Map.Entry&String, String& entry : mInfos.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
sb.append(key + &=& + value + &\n&);
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
Throwable cause = ex.getCause();
while (cause != null) {
cause.printStackTrace(printWriter);
cause = cause.getCause();
printWriter.close();
String result = writer.toString();
sb.append(result);
long timestamp = System.currentTimeMillis();
String time = mDateFormatter.format(new Date());
String fileName = &crash-& + time + &-& + timestamp + &.log&;
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
File dir = new File(mPath);
if (!dir.exists()) {
dir.mkdirs();
FileOutputStream fos1 = new FileOutputStream(mPath + fileName);
fos1.write(sb.toString().getBytes());
fos1.close();
FileOutputStream fos2 = new FileOutputStream(mPath
+ &crash.log&);
fos2.write(sb.toString().getBytes());
fos2.close();
return fileN
} catch (Exception e) {
YiLog.getInstance().e(e, &an error occured while writing file...&);
\ No newline at end of file
Property changes on: common/YiCrashHandler.java
___________________________________________________________________
Added: svn:executable
Index: ui/YiUIBaseActivity.java
===================================================================
--- ui/YiUIBaseActivity.java (revision 0)
+++ ui/YiUIBaseActivity.java (revision 2)
@@ -0,0 +1,130 @@
+package com.ikantech.support.
+import android.content.DialogInterface.OnCancelL
+import android.os.B
+import android.os.H
+import android.text.E
+import android.view.V
+import com.ikantech.support.R;
+import com.ikantech.support.proxy.YiDialogProxy.YiDialogExtP
+import com.ikantech.support.proxy.YiHandlerP
+import com.ikantech.support.proxy.YiHandlerProxy.YiHandlerP
+import com.ikantech.support.util.YiL
+import com.ikantech.support.util.YiU
+public abstract class YiUIBaseActivity extends YiBaseActivity implements
YiHandlerProxiable, YiDialogExtProxiable
+ private YiHandlerProxy mHandlerP
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
initViews();
initDatas();
installListeners();
+ @Override
+ protected void onDestroy()
uninstallListeners();
super.onDestroy();
+ protected abstract void initViews();
+ protected abstract void initDatas();
+ protected abstract void installListeners();
+ protected abstract void uninstallListeners();
+ protected boolean isStringInvalid(String str)
return YiUtils.isStringInvalid(str);
+ protected boolean isStringInvalid(Editable editable)
return YiUtils.isStringInvalid(editable.toString());
+ public void showMsgDialog(int res)
showMsgDialog(getString(res));
+ public void showMsgDialog(String detials)
showMsgDialog(null, detials, getString(R.string.str_ok), null, null,
+ public void showMsgDialog(String detials, String btnLeft)
showMsgDialog(null, detials, btnLeft, null, null, null);
+ public void showMsgDialog(String title, String detials, String btnLeft)
showMsgDialog(title, detials, btnLeft, null, null, null);
+ public void showMsgDialog(String title, String detials, String btnLeft, View.OnClickListener btnLeftListener)
showMsgDialog(title, detials, btnLeft, null, btnLeftListener, null);
+ public void showMsgDialog(String detials, String btnLeft,
View.OnClickListener btnLeftListener)
showMsgDialog(null, detials, btnLeft, null, btnLeftListener, null);
+ public void showMsgDialog(String title, String detials, String btnLeft,
String btnRight, View.OnClickListener btnLeftListener,
View.OnClickListener btnRightListener)
mActivityProxy.showMsgDialog(title, detials, btnLeft, btnRight,
btnLeftListener, btnRightListener);
+ public void showProgressDialog(int resid)
showProgressDialog(getString(resid), null, true);
+ public void showProgressDialog(String msg)
showProgressDialog(msg, null, true);
+ public void showProgressDialog(String msg, OnCancelListener listener,
boolean cancelable)
mActivityProxy.showProgressDialog(msg, listener, cancelable);
+ /*******************************************************************************
* HandlerProxy
*******************************************************************************/
+ protected void initHandlerProxy()
if (mHandlerProxy == null)
mHandlerProxy = new YiHandlerProxy(this, this);
+ @Override
+ public Handler getHandler()
initHandlerProxy();
return mHandlerProxy.getHandler();
Property changes on: ui/YiUIBaseActivity.java
___________________________________________________________________
Added: svn:executable
Index: ui/YiBaseActivity.java
===================================================================
--- ui/YiBaseActivity.java (revision 0)
+++ ui/YiBaseActivity.java (revision 2)
@@ -0,0 +1,140 @@
+package com.ikantech.support.
+import net.tsz.afinal.FinalA
+import android.content.C
+import android.content.ServiceC
+import android.content.pm.ActivityI
+import android.os.B
+import android.support.v4.app.FragmentA
+import android.view.WindowM
+import android.view.inputmethod.InputMethodM
+import com.ikantech.support.proxy.YiActivityP
+import com.ikantech.support.proxy.YiDialogP
+import com.ikantech.support.proxy.YiDialogProxy.YiDialogP
+import com.ikantech.support.proxy.YiLocalServiceBinderProxy.YiLocalServiceServiceBinderP
+import com.ikantech.support.proxy.YiToastProxy.YiToastP
+import com.ikantech.support.service.YiLocalService.YiLocalServiceB
+import com.ikantech.support.util.YiL
+public class YiBaseActivity extends FinalActivity implements YiToastProxiable,
YiLocalServiceServiceBinderProxiable, YiDialogProxiable
+ protected YiActivityProxy mActivityP
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mActivityProxy = new YiActivityProxy(this);
+ @Override
+ protected void onDestroy()
mActivityProxy.onDestroy();
super.onDestroy();
+ public void hideKeyboard() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
+ /*******************************************************************************
* ToastProxy
*******************************************************************************/
+ @Override
+ public void showToast(int resourceId)
mActivityProxy.showToast(resourceId);
+ @Override
+ public void showToast(String text)
mActivityProxy.showToast(text);
+ /*******************************************************************************
* LocalServiceBinderProxy
*******************************************************************************/
+ @Override
+ public void installLocalServiceBinder()
// TODO Auto-generated method stub
mActivityProxy.installLocalServiceBinder();
+ @Override
+ public void installLocalServiceBinder(ServiceConnection connection)
// TODO Auto-generated method stub
mActivityProxy.installLocalServiceBinder(connection);
+ @Override
+ public void uninstallLocalServiceBinder()
// TODO Auto-generated method stub
mActivityProxy.uninstallLocalServiceBinder();
+ @Override
+ public YiLocalServiceBinder getLocalService()
// TODO Auto-generated method stub
return mActivityProxy.getLocalService();
+ /*******************************************************************************
* DialogProxy
*******************************************************************************/
+ @Override
+ public void showMsgDialog()
// TODO Auto-generated method stub
mActivityProxy.showMsgDialog();
+ @Override
+ public void showMsgDialogWithSize(int width, int height)
// TODO Auto-generated method stub
mActivityProxy.showMsgDialogWithSize(width, height);
+ @Override
+ public void showProgressDialog()
// TODO Auto-generated method stub
mActivityProxy.showProgressDialog();
+ @Override
+ public void cancelProgressDialog()
// TODO Auto-generated method stub
mActivityProxy.cancelProgressDialog();
+ @Override
+ public YiDialogProxy getDialogProxy()
// TODO Auto-generated method stub
return mActivityProxy.getDialogProxy();
+ @Override
+ public void cancelMsgDialog()
// TODO Auto-generated method stub
mActivityProxy.cancelMsgDialog();
Property changes on: ui/YiBaseActivity.java
___________________________________________________________________
Added: svn:executable
Index: ui/YiHttpBaseActivity.java
===================================================================
--- ui/YiHttpBaseActivity.java (revision 0)
+++ ui/YiHttpBaseActivity.java (revision 2)
@@ -0,0 +1,43 @@
+package com.ikantech.support.
+import android.content.ServiceC
+import android.os.B
+import com.ikantech.support.listener.YiHttpResponseL
+import com.ikantech.support.net.YiHttpR
+public abstract class YiHttpBaseActivity extends YiUIBaseActivity implements
YiHttpResponseListener
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
installLocalServiceBinder(onInstallLocalServiceBinder());
+ @Override
+ protected void onDestroy()
uninstallLocalServiceBinder();
super.onDestroy();
+ @Override
+ public void onHttpResponse(final YiHttpResponse response)
runOnUiThread(new Runnable()
public void run()
onUIHttpResponse(response);
+ protected abstract ServiceConnection onInstallLocalServiceBinder();
+ protected abstract void onUIHttpResponse(YiHttpResponse response);
Property changes on: ui/YiHttpBaseActivity.java
___________________________________________________________________
Added: svn:executable
Index: ui/YiFragmentBaseActivity.java
===================================================================
--- ui/YiFragmentBaseActivity.java (revision 0)
+++ ui/YiFragmentBaseActivity.java (revision 2)
@@ -0,0 +1,202 @@
+package com.ikantech.support.
+import android.content.DialogInterface.OnCancelL
+import android.content.pm.ActivityI
+import android.content.ServiceC
+import android.os.B
+import android.os.H
+import android.support.v4.app.FragmentA
+import android.view.V
+import com.ikantech.support.R;
+import com.ikantech.support.proxy.YiActivityP
+import com.ikantech.support.proxy.YiDialogP
+import com.ikantech.support.proxy.YiDialogProxy.YiDialogExtP
+import com.ikantech.support.proxy.YiDialogProxy.YiDialogP
+import com.ikantech.support.proxy.YiHandlerP
+import com.ikantech.support.proxy.YiHandlerProxy.YiHandlerP
+import com.ikantech.support.proxy.YiLocalServiceBinderProxy.YiLocalServiceServiceBinderP
+import com.ikantech.support.proxy.YiToastProxy.YiToastP
+import com.ikantech.support.service.YiLocalService.YiLocalServiceB
+public abstract class YiFragmentBaseActivity extends FragmentActivity implements
YiToastProxiable, YiLocalServiceServiceBinderProxiable,
YiDialogProxiable, YiDialogExtProxiable,YiHandlerProxiable
+ protected YiActivityProxy mActivityP
+ private YiHandlerProxy mHandlerP
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mActivityProxy = new YiActivityProxy(this);
+ @Override
+ protected void onDestroy()
mActivityProxy.onDestroy();
super.onDestroy();
+ /*******************************************************************************
* ToastProxy
*******************************************************************************/
+ @Override
+ public void showToast(int resourceId)
mActivityProxy.showToast(resourceId);
+ @Override
+ public void showToast(String text)
mActivityProxy.showToast(text);
+ /*******************************************************************************
* LocalServiceBinderProxy
*******************************************************************************/
+ @Override
+ public void installLocalServiceBinder()
// TODO Auto-generated method stub
mActivityProxy.installLocalServiceBinder();
+ @Override
+ public void installLocalServiceBinder(ServiceConnection connection)
// TODO Auto-generated method stub
mActivityProxy.installLocalServiceBinder(connection);
+ @Override
+ public void uninstallLocalServiceBinder()
// TODO Auto-generated method stub
mActivityProxy.uninstallLocalServiceBinder();
+ @Override
+ public YiLocalServiceBinder getLocalService()
// TODO Auto-generated method stub
return mActivityProxy.getLocalService();
+ /*******************************************************************************
* DialogProxy
*******************************************************************************/
+ @Override
+ public void showMsgDialog()
// TODO Auto-generated method stub
mActivityProxy.showMsgDialog();
+ @Override
+ public void showMsgDialogWithSize(int width, int height)
// TODO Auto-generated method stub
mActivityProxy.showMsgDialogWithSize(width, height);
+ @Override
+ public void showProgressDialog()
// TODO Auto-generated method stub
mActivityProxy.showProgressDialog();
+ @Override
+ public void cancelProgressDialog()
// TODO Auto-generated method stub
mActivityProxy.cancelProgressDialog();
+ @Override
+ public YiDialogProxy getDialogProxy()
// TODO Auto-generated method stub
return mActivityProxy.getDialogProxy();
+ @Override
+ public void cancelMsgDialog()
// TODO Auto-generated method stub
mActivityProxy.cancelMsgDialog();
+ public void showMsgDialog(int res)
showMsgDialog(getString(res));
+ public void showMsgDialog(String detials)
showMsgDialog(null, detials, getString(R.string.str_ok), null, null,
+ public void showMsgDialog(String detials, String btnLeft)
showMsgDialog(null, detials, btnLeft, null, null, null);
+ public void showMsgDialog(String title, String detials, String btnLeft)
showMsgDialog(title, detials, btnLeft, null, null, null);
+ public void showMsgDialog(String detials, String btnLeft,
View.OnClickListener btnLeftListener)
showMsgDialog(null, detials, btnLeft, null, btnLeftListener, null);
+ public void showMsgDialog(String title, String detials, String btnLeft,
String btnRight, View.OnClickListener btnLeftListener,
View.OnClickListener btnRightListener)
mActivityProxy.showMsgDialog(title, detials, btnLeft, btnRight, btnLeftListener, btnRightListener);
+ public void showProgressDialog(int resid)
showProgressDialog(getString(resid), null, true);
+ public void showProgressDialog(String msg)
showProgressDialog(msg, null, true);
+ public void showProgressDialog(String msg, OnCancelListener listener,
boolean cancelable)
mActivityProxy.showProgressDialog(msg, listener, cancelable);
+ /*******************************************************************************
* HandlerProxy
*******************************************************************************/
+ protected void initHandlerProxy()
if (mHandlerProxy == null)
mHandlerProxy = new YiHandlerProxy(this, this);
+ @Override
+ public Handler getHandler()
initHandlerProxy();
return mHandlerProxy.getHandler();
Property changes on: ui/YiFragmentBaseActivity.java
___________________________________________________________________
Added: svn:executable
Index: util/YiApi.java
===================================================================
--- util/YiApi.java (revision 0)
+++ util/YiApi.java (revision 2)
@@ -0,0 +1,13 @@
+package com.ikantech.support.
+import java.lang.annotation.ElementT
+import java.lang.annotation.R
+import java.lang.annotation.RetentionP
+import java.lang.annotation.T
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.METHOD})
+public abstract @interface YiApi
Property changes on: util/YiApi.java
___________________________________________________________________
Added: svn:executable
Index: util/YiPrefsKeeper.java
===================================================================
--- util/YiPrefsKeeper.java (revision 0)
+++ util/YiPrefsKeeper.java (revision 2)
@@ -0,0 +1,64 @@
+package com.ikantech.support.
+import android.content.C
+import android.content.SharedP
+import android.content.SharedPreferences.E
+public class YiPrefsKeeper
+ // instance no need.
+ private YiPrefsKeeper()
+ public static void write(Context context, YiPrefsKeepable v)
SharedPreferences preferences = context.getSharedPreferences(
v.getPrefsName(), Context.MODE_PRIVATE);
Editor editor = preferences.edit();
v.save(editor);
+ public static void read(Context context, YiPrefsKeepable v)
SharedPreferences preferences = context.getSharedPreferences(
v.getPrefsName(), Context.MODE_PRIVATE);
v.restore(preferences);
catch (Exception e)
YiLog.getInstance().e(e, &read %s failed.&,
v.getClass().getSimpleName());
+ public static void clear(Context context, YiPrefsKeepable v)
SharedPreferences preferences = context.getSharedPreferences(
v.getPrefsName(), Context.MODE_PRIVATE);
Editor editor = preferences.edit();
editor.clear();
catch (Exception e)
YiLog.getInstance().e(e, &clear %s failed.&,
v.getClass().getSimpleName());
+ public interface YiPrefsKeepable
void save(Editor editor);
void restore(SharedPreferences preferences);
String getPrefsName();
Property changes on: util/YiPrefsKeeper.java
___________________________________________________________________
Added: svn:executable
Index: util/YiDeviceUtils.java
===================================================================
--- util/YiDeviceUtils.java (revision 0)
+++ util/YiDeviceUtils.java (revision 2)
@@ -0,0 +1,131 @@
+package com.ikantech.support.
+import java.io.F
+import java.io.FileF
+import java.lang.reflect.F
+import java.util.regex.P
+import android.content.C
+import android.content.pm.ApplicationI
+import android.content.pm.PackageI
+import android.content.pm.PackageM
+import android.content.pm.PackageManager.NameNotFoundE
+import android.os.E
+import android.util.DisplayM
+public class YiDeviceUtils {
+ private YiDeviceUtils() {
+ public static DisplayMetrics getDisplayMetrics(Context context) {
return context.getResources().getDisplayMetrics();
+ public static int getWidthPixels(Context context) {
return context.getResources().getDisplayMetrics().widthP
+ public static int getHeightPixels(Context context) {
return context.getResources().getDisplayMetrics().heightP
+ public static int dip2px(Context context, float dip) {
float scale = context.getResources().getDisplayMetrics().
return (int) (dip * scale + 0.5f);
+ public static int px2dip(Context context, float px) {
float scale = context.getResources().getDisplayMetrics().
return (int) (px / scale + 0.5f);
+ public static int getApiLevel() {
return android.os.Build.VERSION.SDK_INT;
+ public static boolean isCompatible(int apiLevel) {
return android.os.Build.VERSION.SDK_INT &= apiL
+ public static String getCpuAbi() {
if (isCompatible(4)) {
field = android.os.Build.class.getField(&CPU_ABI&);
return field.get(null).toString();
} catch (Exception e) {
YiLog.getInstance().w(e,
&Announce to be android 1.6 but no CPU ABI field&);
return &armeabi&;
+ public final static int getNumCores() {
// Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {
public boolean accept(File pathname) {
// Check if filename is &cpu&, followed by a single digit number
if (Pattern.matches(&cpu[0-9]&, pathname.getName())) {
// Get directory containing CPU info
File dir = new File(&/sys/devices/system/cpu/&);
// Filter to only list the devices we care about
File[] files = dir.listFiles(new CpuFilter());
// Return the number of cores (virtual CPU devices)
return files.
} catch (Exception e) {
return Runtime.getRuntime().availableProcessors();
+ public static boolean isInstalledOnSdCard(Context context) {
// check for API level 8 and higher
if (isCompatible(8)) {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
ApplicationInfo ai = pi.applicationI
return (ai.flags & 0x /*
* ApplicationInfo.
* FLAG_EXTERNAL_STORAGE
*/) == 0x /*
* ApplicationInfo.
* FLAG_EXTERNAL_STORAGE
} catch (NameNotFoundException e) {
// check for API level 7 - check files dir
String filesDir = context.getFilesDir().getAbsolutePath();
if (filesDir.startsWith(&/data/&)) {
} else if (filesDir.contains(Environment
.getExternalStorageDirectory().getPath())) {
} catch (Throwable e) {
+ public static boolean isPermission(Context context, String permission,
String packages) {
PackageManager pm = context.getPackageManager();
return PackageManager.PERMISSION_GRANTED == pm.checkPermission(
permission, packages);
Property changes on: util/YiDeviceUtils.java
___________________________________________________________________
Added: svn:executable
Index: util/YiFileUtils.java
===================================================================
--- util/YiFileUtils.java (revision 0)
+++ util/YiFileUtils.java (revision 2)
@@ -0,0 +1,123 @@
+package com.ikantech.support.
+import java.io.F
+import android.content.C
+import android.content.pm.PackageM
+import android.os.E
+public class YiFileUtils {
+ public static final String FILE_SUFFIX = &.ik&;
+ private static String mStorePath =
+ private static Context mContext =
+ private YiFileUtils() {
+ public static void register(Context context) {
mContext =
+ public static String getStorePath() {
if (mStorePath == null) {
String path = Environment.getExternalStorageDirectory().getPath();
if (path == null
|| !Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) { // 部分手机没有sd卡会报空指针
path = mContext.getFilesDir().getPath();
if (!path.endsWith(&/&)) {
path = path + &/&;
mStorePath =
return mStoreP
+ public static void deleteFile(File file) {
if (file.exists()) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (File file2 : files) {
if (file2.isDirectory()) {
deleteFile(file2);
file2.deleteOnExit();
file.deleteOnExit();
+ // 删除指定文件夹下所有文件
+ // param path 文件夹完整绝对路径
+ public static boolean delAllFile(String path) {
boolean flag =
File file = new File(path);
if (!file.exists()) {
if (!file.isDirectory()) {
String[] tempList = file.list();
File temp =
for (int i = 0; i & tempList. i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
temp = new File(path + File.separator + tempList[i]);
if (temp.isFile()) {
temp.delete();
if (temp.isDirectory()) {
delAllFile(path + &/& + tempList[i]);// 先删除文件夹里面的文件
delFolder(path + &/& + tempList[i]);// 再删除空文件夹
+ // 删除文件夹
+ // param folderPath 文件夹完整绝对路径
+ public static void delFolder(String folderPath) {
delAllFile(folderPath); // 删除完里面所有内容
String filePath = folderP
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); // 删除空文件夹
} catch (Exception e) {
e.printStackTrace();
+ public static boolean hasSdcard() {
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED)) {
* 权限判断
* @param context
* @param permission
+// public static boolean checkPermission(Context context , String permission){
int res=context.checkCallingOrSelfPermission(permission);
return (res==PackageManager.PERMISSION_GRANTED);
Property changes on: util/YiFileUtils.java
___________________________________________________________________
Added: svn:executable
Index: util/YiImageUtil.java
===================================================================
--- util/YiImageUtil.java (revision 0)
+++ util/YiImageUtil.java (revision 2)
@@ -0,0 +1,1394 @@
+package com.ikantech.support.
+import java.io.F
+import java.io.FileInputS
+import java.io.FileNotFoundE
+import java.io.FileOutputS
+import java.io.IOE
+import java.io.InputS
+import java.net.MalformedURLE
+import java.net.URL;
+import android.app.A
+import android.content.C
+import android.database.C
+import android.graphics.B
+import android.pressF
+import android.graphics.Bitmap.C
+import android.graphics.BitmapF
+import android.graphics.C
+import android.graphics.C
+import android.graphics.LinearG
+import android.graphics.M
+import android.graphics.P
+import android.graphics.PixelF
+import android.graphics.PorterDuff.M
+import android.graphics.PorterDuffX
+import android.graphics.R
+import android.graphics.RectF;
+import android.graphics.Shader.TileM
+import android.graphics.drawable.D
+import android.net.U
+import android.provider.MediaS
+import android.provider.MediaStore.Images.T
+import android.util.L
+import android.view.V
+import android.widget.ListV
+public class YiImageUtil
* 加载本地图片
* @param url
+ public static Bitmap getLoacalBitmap(String url)
if (null == url)
FileInputStream fis = new FileInputStream(url);
return BitmapFactory.decodeStream(fis);
catch (FileNotFoundException e)
e.printStackTrace();
* 图片转化成成文件
* @param fileName
* @param bmp
+ public static boolean bitmapToFile(String fileName, Bitmap bmp)
FileOutputStream out = new FileOutputStream(fileName);
pressFormat.JPEG, 90, out);
catch (Exception e)
e.printStackTrace();
+ public static Bitmap getImageWithSizeLimit(String path, int w, int h)
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds =
Bitmap bmp = BitmapFactory.decodeFile(path, bmpFactoryOptions);
float scale = 1.0F;
if (bmpFactoryOptions.inTargetDensity & 0
&& bmpFactoryOptions.inDensity & 0)
scale = (float) bmpFactoryOptions.inTargetDensity
/ bmpFactoryOptions.inD
int heightR
if (h == -1)
heightRatio = 2;
heightRatio = (int) Math.round((bmpFactoryOptions.outHeight
* scale + 0.5)
/ (float) h);
int widthR
if (w == -1)
widthRatio = 2;
widthRatio = (int) Math.round((bmpFactoryOptions.outWidth
* scale + 0.5)
/ (float) w);
// 如果图片太大,则缩小之
if (heightRatio &= 2 && widthRatio &= 2)
bmpFactoryOptions.inSampleSize = (int) Math
.ceil((heightRatio & widthRatio ? heightRatio
: widthRatio) / 2.0);
YiLog.getInstance().i(YiLog.tag,&image %d
wr : %d , hr : %d&,
bmpFactoryOptions.inSampleSize, heightRatio, widthRatio);
bmpFactoryOptions.inJustDecodeBounds =
bmp = BitmapFactory.decodeFile(path, bmpFactoryOptions);
return getImageWithSizeLimit(bmp, w, h);
catch (Exception ex)
+ public static Bitmap getImageWithSizeLimit(Bitmap bitmap, int w, int h)
Bitmap bmp =
float heightRatio = bitmap.getHeight() / (float)
float widthRatio = bitmap.getWidth() / (float)
// 如果图片太大,则缩小之
if (heightRatio & 1.0F && widthRatio & 1.0F)
float scale = heightRatio & widthRatio ? widthRatio
bmp = Bitmap.createScaledBitmap(bitmap,
(int) (bitmap.getWidth() / scale),
(int) (bitmap.getHeight() / scale), true);
if (!bitmap.isRecycled())
bitmap.recycle();
catch (Exception ex)
+ // 通过文件路径返回图片的原始宽高
+ public static int[] getImageWidhtHeightFromFilePath(String filePath)
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds =
File imageFile = new File(filePath);
InputStream is = new FileInputStream(imageFile);
BitmapFactory.decodeStream(is, null, options);
return new int[]
{ options.outWidth, options.outHeight };
catch (FileNotFoundException e)
e.printStackTrace();
+ // 缩放图片
+ public static Bitmap zoomImg(Bitmap bm, int newWidth, int newHeight)
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) /
float scaleHeight = ((float) newHeight) /
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
+ // 根据文件路径filePath获得image_id
+ public static int getImageIdFromPath(Activity activity, String filePath)
String[] projection =
{ MediaStore.Images.Media._ID };
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String where = String.format(&_data like '%s' &, filePath);
Cursor cursor = MediaStore.Images.Media.query(
activity.getContentResolver(), uri, projection, where, null);
int image_id = 0;
if (cursor.getCount() != 0)
cursor.moveToFirst();
image_id = cursor.getInt(cursor
.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
cursor.close();
return image_
+ // 通过imageId找到缩略图bitmap的Uri
+ public static Uri getBitmapFromImageId(Activity activity, int imageId)
String[] tinyImgPprojection =
{ MediaStore.Images.Thumbnails._ID };
Cursor tinyCursor = Thumbnails.queryMiniThumbnail(
activity.getContentResolver(), imageId, Thumbnails.MINI_KIND,
tinyImgPprojection);
if (tinyCursor.getCount() != 0)
tinyCursor.moveToFirst();
int tinyImgId = tinyCursor.getInt(tinyCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
tinyCursor.close();
return Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
String.valueOf(tinyImgId));
tinyCursor.close();
+ // 通过url返回bitmap
+ public static Bitmap loadImageFromUrl(String url)
InputStream i =
m = new URL(url);
i = (InputStream) m.getContent();
catch (MalformedURLException e1)
e1.printStackTrace();
catch (IOException e)
e.printStackTrace();
return BitmapFactory.decodeStream(i);
+ // 放大缩小图片
+ public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h)
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
float scaleWidht = ((float) w / width);
float scaleHeight = ((float) h / height);
matrix.postScale(scaleWidht, scaleHeight);
Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
matrix, true);
+ // 将Drawable转化为Bitmap
+ public static Bitmap drawableToBitmap(Drawable drawable)
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, drawable
.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);
+ public static String SaveBitmap(Bitmap bmp, String name)
File file = new File(&mnt/sdcard/picture/&);
String path =
if (!file.exists())
file.mkdirs();
path = file.getPath() + &/& +
FileOutputStream fileOutputStream = new FileOutputStream(path);
pressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
catch (Exception e)
e.printStackTrace();
+ public static String saveToLocal(Bitmap bm)
String path = &/sdcard/test.jpg&;
FileOutputStream fos = new FileOutputStream(path);
bm.compress(CompressFormat.JPEG, 75, fos);
fos.flush();
fos.close();
catch (FileNotFoundException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
+ // 获得圆角图片的方法
+ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx)
return getRoundedCornerBitmap(bitmap, roundPx, bitmap.getWidth(),
bitmap.getHeight());
+ // 获得圆角图片的方法
+ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx,
int w, int h)
Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, w, h);
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0xFF, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap,
new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), rect,
+ // 获得带倒影的图片方法
+ public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap)
final int reflectionGap = 4;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2,
width, height / 2, matrix, false);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
(height + height / 2), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(bitmap, 0, 0, null);
Paint deafalutPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
// Set the Transfer mode to be porter duff and destination in
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// Draw a rectangle using the paint with our linear gradient
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
+ reflectionGap, paint);
return bitmapWithR
* 读取资源图片
* @param context
* @param resId
+ public static Bitmap readBitMap(Context context, int resId)
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable =
opt.inInputShareable =
// 获取资源图片
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is, null, opt);
* 从sd卡读取图片
* @param path
+ public static Bitmap readBitMap(String path)
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Config.ARGB_8888;
Bitmap bm = BitmapFactory.decodeFile(path, options);
* 图片旋转
* @param bmp
* @param degree
+ public static Bitmap postRotateBitamp(Bitmap bmp, float degree)
// 获得Bitmap的高和宽
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
// 产生resize后的Bitmap对象
Matrix matrix = new Matrix();
matrix.postRotate(degree);
Bitmap resizeBmp = Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight,
matrix, true);
return resizeB
+ // 图片翻转
+ public static Bitmap reverseBitmap(Bitmap bmp, int flag)
float[] floats =
switch (flag)
case 0: // 水平反转
floats = new float[]
{ -1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f };
case 1: // 垂直反转
floats = new float[]
{ 1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f };
if (floats != null)
Matrix matrix = new Matrix();
matrix.setValues(floats);
return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
bmp.getHeight(), matrix, true);
* 组合涂鸦图片和源图片
* @param src
* @param watermark
+ public static Bitmap doodle(Bitmap src, Bitmap watermark, int x, int y)
// 另外创建一张图片
Bitmap newb = Bitmap.createBitmap(src.getWidth(), src.getHeight(),
Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图
Canvas canvas = new Canvas(newb);
canvas.drawBitmap(src, 0, 0, null);// 在 0,0坐标开始画入原图片src
canvas.drawBitmap(watermark,
(src.getWidth() - watermark.getWidth()) / 2,
(src.getHeight() - watermark.getHeight()) / 2, null); // 涂鸦图片画到原图片中间位置
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
watermark.recycle();
watermark =
* 图片上写文字
* @param src源图片
* @param msg文字
* @param x
* @param y
+ public static Bitmap drawText(Bitmap src, String msg, int x, int y)
// 另外创建一张图片
Canvas canvas = new Canvas(src);
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawText(msg, x, y, paint);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
+ public static Bitmap oldRemeber(Bitmap bmp)
// if (YiImageCache.get(&oldRemeber&) != null)
// return YiImageCache.get(&oldRemeber&);
// 速度测试
long start = System.currentTimeMillis();
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
int pixColor = 0;
int pixR = 0;
int pixG = 0;
int pixB = 0;
int newR = 0;
int newG = 0;
int newB = 0;
int[] pixels = new int[width * height];
bmp.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i & i++)
for (int k = 0; k & k++)
pixColor = pixels[width * i + k];
pixR = Color.red(pixColor);
pixG = Color.green(pixColor);
pixB = Color.blue(pixColor);
newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);
newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);
newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);
int newColor = Color.argb(255, newR & 255 ? 255 : newR,
newG & 255 ? 255 : newG, newB & 255 ? 255 : newB);
pixels[width * i + k] = newC
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
long end = System.currentTimeMillis();
Log.e(&may&, &used time=& + (end - start));
// YiImageCache.put(&oldRemeber&, bitmap);
* 模糊效果
* @param bmp
+ public static Bitmap blurImage(Bitmap bmp)
// if (YiImageCache.get(&blurImage&) != null)
// return YiImageCache.get(&blurImage&);
// 速度测试
long start = System.currentTimeMillis();
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
int pixColor = 0;
int newR = 0;
int newG = 0;
int newB = 0;
int newColor = 0;
int[][] colors = new int[9][3];
for (int i = 1, length = width - 1; i & i++)
for (int k = 1, len = height - 1; k & k++)
for (int m = 0; m & 9; m++)
int s = 0;
int p = 0;
switch (m)
s = i - 1;
p = k - 1;
p = k - 1;
s = i + 1;
p = k - 1;
s = i + 1;
s = i + 1;
p = k + 1;
p = k + 1;
s = i - 1;
p = k + 1;
s = i - 1;
pixColor = bmp.getPixel(s, p);
colors[m][0] = Color.red(pixColor);
colors[m][1] = Color.green(pixColor);
colors[m][2] = Color.blue(pixColor);
for (int m = 0; m & 9; m++)
newR += colors[m][0];
newG += colors[m][1];
newB += colors[m][2];
newR = (int) (newR / 9F);
newG = (int) (newG / 9F);
newB = (int) (newB / 9F);
newR = Math.min(255, Math.max(0, newR));
newG = Math.min(255, Math.max(0, newG));
newB = Math.min(255, Math.max(0, newB));
newColor = Color.argb(255, newR, newG, newB);
bitmap.setPixel(i, k, newColor);
long end = System.currentTimeMillis();
Log.e(&blurImage()&, &used time=& + (end - start));
// YiImageCache.put(&blurImage&, bitmap);
* 柔化效果(高斯模糊)(优化后比上面快三倍)
* @param bmp
+ public static Bitmap blurImageAmeliorate(Bitmap bmp)
// if (YiImageCache.get(&blurImageAmeliorate&) != null)
// return YiImageCache.get(&blurImageAmeliorate&);
long start = System.currentTimeMillis();
// 高斯矩阵
int[] gauss = new int[]
{ 1, 2, 1, 2, 4, 2, 1, 2, 1 };
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
int pixR = 0;
int pixG = 0;
int pixB = 0;
int pixColor = 0;
int newR = 0;
int newG = 0;
int newB = 0;
int delta = 16; // 值越小图片会越亮,越大则越暗
int idx = 0;
int[] pixels = new int[width * height];
bmp.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 1, length = height - 1; i & i++)
for (int k = 1, len = width - 1; k & k++)
for (int m = -1; m &= 1; m++)
for (int n = -1; n &= 1; n++)
pixColor = pixels[(i + m) * width + k + n];
pixR = Color.red(pixColor);
pixG = Color.green(pixColor);
pixB = Color.blue(pixColor);
newR = newR + (int) (pixR * gauss[idx]);
newG = newG + (int) (pixG * gauss[idx]);
newB = newB + (int) (pixB * gauss[idx]);
newR = Math.min(255, Math.max(0, newR));
newG = Math.min(255, Math.max(0, newG));
newB = Math.min(255, Math.max(0, newB));
pixels[i * width + k] = Color.argb(255, newR, newG, newB);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
long end = System.currentTimeMillis();
Log.d(&blurImageAmeliorate&, &used time=& + (end - start));
// YiImageCache.put(&blurImageAmeliorate&, bitmap);
+ public static Bitmap sketch(Bitmap bmp)
// if (YiImageCache.get(&sketch&) != null)
// return YiImageCache.get(&sketch&);
long start = System.currentTimeMillis();
int pos, row, col,
int width = bmp.getWidth();
int height = bmp.getHeight();
int[] pixSrc = new int[width * height];
int[] pixNvt = new int[width * height];
// 先对图象的像素处理成灰度颜色后再取反
bmp.getPixels(pixSrc, 0, width, 0, 0, width, height);
for (row = 0; row & row++)
for (col = 0; col & col++)
pos = row * width +
pixSrc[pos] = (Color.red(pixSrc[pos])
+ Color.green(pixSrc[pos]) + Color.blue(pixSrc[pos])) / 3;
pixNvt[pos] = 255 - pixSrc[pos];
// 对取反的像素进行高斯模糊, 强度可以设置,暂定为5.0
gaussGray(pixNvt, 5.0, 5.0, width, height);
// 灰度颜色和模糊后像素进行差值运算
for (row = 0; row & row++)
for (col = 0; col & col++)
pos = row * width +
clr = pixSrc[pos] && 8;
clr /= 256 - pixNvt[pos];
clr = Math.min(clr, 255);
pixSrc[pos] = Color.rgb(clr, clr, clr);
bmp.setPixels(pixSrc, 0, width, 0, 0, width, height);
long end = System.currentTimeMillis();
Log.d(&blurImageAmeliorate&, &used time=& + (end - start));
// YiImageCache.put(&sketch&, bmp);
+ private static int gaussGray(int[] psrc, double horz, double vert,
int width, int height)
int[] dst,
double[] n_p, n_m, d_p, d_m, bd_p, bd_m;
double[] val_p, val_m;
int i, j, t, k, row, col,
int[] initial_p, initial_m;
double std_
int row_stride =
int max_len = Math.max(width, height);
int sp_p_idx, sp_m_idx, vp_idx, vm_
val_p = new double[max_len];
val_m = new double[max_len];
n_p = new double[5];
n_m = new double[5];
d_p = new double[5];
d_m = new double[5];
bd_p = new double[5];
bd_m = new double[5];
src = new int[max_len];
dst = new int[max_len];
initial_p = new int[4];
initial_m = new int[4];
// 垂直方向
if (vert & 0.0)
vert = Math.abs(vert) + 1.0;
std_dev = Math.sqrt(-(vert * vert) / (2 * Math.log(1.0 / 255.0)));
// 初试化常量
findConstants(n_p, n_m, d_p, d_m, bd_p, bd_m, std_dev);
for (col = 0; col & col++)
for (k = 0; k & max_ k++)
val_m[k] = val_p[k] = 0;
for (t = 0; t & t++)
src[t] = psrc[t * row_stride + col];
sp_p_idx = 0;
sp_m_idx = height - 1;
vp_idx = 0;
vm_idx = height - 1;
initial_p[0] = src[0];
initial_m[0] = src[height - 1];
for (row = 0; row & row++)
terms = (row & 4) ? row : 4;
for (i = 0; i &= i++)
val_p[vp_idx] += n_p[i] * src[sp_p_idx - i] - d_p[i]
* val_p[vp_idx - i];
val_m[}

我要回帖

更多关于 dnf2016裸体补丁 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信