效果图:

img

使用:

img

2个类:

CircleImageView类:

package com.lzyi.tpm.utils;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.RectF;

import android.util.AttributeSet;

import io.jchat.android.view.BaseImageView;

public class CircleImageViewextends BaseImageView {

public CircleImageView(Context context) {

super(context);

}

public CircleImageView(Context context, AttributeSet attrs) {

super(context, attrs);

}

public CircleImageView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

public static BitmapgetBitmap(int width, int height) {

Bitmap bitmap = Bitmap.createBitmap(width, height,

​ Bitmap.Config.ARGB_8888);

​ Canvas canvas =new Canvas(bitmap);

​ Paint paint =new Paint(Paint.ANTI_ALIAS_FLAG);

​ paint.setColor(Color.BLACK);

​ canvas.drawOval(new RectF(0.0f, 0.0f, width, height), paint);

​ return bitmap;

}

@Override

public BitmapgetBitmap() {

return getBitmap(getWidth(), getHeight());

}

}

BaseImageView类:

package io.jchat.android.view;

import android.annotation.SuppressLint;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.PorterDuff;

import android.graphics.PorterDuffXfermode;

import android.graphics.Xfermode;

import android.graphics.drawable.Drawable;

import android.util.AttributeSet;

import android.util.Log;

import android.widget.ImageView;

import java.lang.ref.WeakReference;

public abstract class BaseImageViewextends ImageView {

private static final StringTAG = BaseImageView.class.getSimpleName();

protected ContextmContext;

private static final XfermodesXfermode =new PorterDuffXfermode(PorterDuff.Mode.DST_IN);

// private BitmapShader mBitmapShader;

private BitmapmMaskBitmap;

private PaintmPaint;

private WeakReferencemWeakBitmap;

public BaseImageView(Context context) {

super(context);

​ sharedConstructor(context);

}

public BaseImageView(Context context, AttributeSet attrs) {

super(context, attrs);

​ sharedConstructor(context);

}

public BaseImageView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

​ sharedConstructor(context);

}

private void sharedConstructor(Context context) {

mContext = context;

​ mPaint =new Paint(Paint.ANTI_ALIAS_FLAG);

}

public void invalidate() {

mWeakBitmap =null;

​ if (mMaskBitmap !=null) {mMaskBitmap.recycle(); }

super.invalidate();

}

@SuppressLint(“DrawAllocation”)

@Override

protected void onDraw(Canvas canvas) {

if (!isInEditMode()) {

int i = canvas.saveLayer(0.0f, 0.0f, getWidth(), getHeight(),

​ null, Canvas.ALL_SAVE_FLAG);

​ try {

Bitmap bitmap =mWeakBitmap !=null ?mWeakBitmap.get() :null;

​ // Bitmap not loaded.

​ if (bitmap ==null || bitmap.isRecycled()) {

Drawable drawable = getDrawable();

​ if (drawable !=null) {

// Allocation onDraw but it’s ok because it will not always be called.

​ bitmap = Bitmap.createBitmap(getWidth(),

​ getHeight(), Bitmap.Config.ARGB_8888);

​ Canvas bitmapCanvas =new Canvas(bitmap);

​ drawable.setBounds(0, 0, getWidth(), getHeight());

​ drawable.draw(bitmapCanvas);

​ // If mask is already set, skip and use cached mask.

​ if (mMaskBitmap ==null ||mMaskBitmap.isRecycled()) {

mMaskBitmap = getBitmap();

​ }

// Draw Bitmap.

​ mPaint.reset();

​ mPaint.setFilterBitmap(false);

​ mPaint.setXfermode(sXfermode);

// mBitmapShader = new BitmapShader(mMaskBitmap,

// Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

// mPaint.setShader(mBitmapShader);

​ bitmapCanvas.drawBitmap(mMaskBitmap, 0.0f, 0.0f, mPaint);

​ mWeakBitmap =new WeakReference(bitmap);

​ }

}

// Bitmap already loaded.

​ if (bitmap !=null) {

mPaint.setXfermode(null);

// mPaint.setShader(null);

​ canvas.drawBitmap(bitmap, 0.0f, 0.0f, mPaint);

return;

​ }

}catch (Exception e) {

System.gc();

​ Log.e(TAG, String.format(“Failed to draw, Id :: %s. Error occurred :: %s”, getId(), e.toString()));

​ }finally {

canvas.restoreToCount(i);

​ }

}else {

super.onDraw(canvas);

​ }

}

public abstract BitmapgetBitmap();

}

1.打开 IDEA ,选择 File - Settings - Plugins - Browse repositories
打开 IDEA,选择 File - Settings - Plugins - Browse repositories 后,输入 alibaba 选中 Alibaba Java Coding Guidelines,点击 Install。
2.重启IDEA,开始使用
安装后,会提示你重启 IDEA 已启用插件,重启后就可以在你的项目上疯狂点击右键了,当然菜单栏也会出现俩按钮,它有个快捷键是Ctrl+Shift+Alt+J。
image.png
选中某一个类,或者在这个类里边右键也可以
image.png
重启后再工具栏按钮下拉框就会多一个阿里编码规约按钮,然后点击编码规约扫描,就会扫描你当前的项目了。

不扫不知道。一扫吓一跳,以前不以为然的写法,都会在这暴露无疑,重点是对于有线程安全问题的代码他也会提示。这很重要!!!
image.png

####一 database navigator
database navigator是android studio的一个插件,可以用来查看sqlite数据库,也可以查看MySQL等其他数据库。
####二 安装插件
搜索并安装插件
安装完成后会提示重启android studio,重启后,右侧出现DB Browser,至此安装完成。
image.png
####三 导出database
在device file explore中找到应用的db文件(在android studio 3.0才有该功能,之前的版本用DDMS导出)
#####1.打开device file explore
第一种:主体窗口的右下角,点击后直接打开
image.png
第二种:通过工具栏打开, View > Tool Windows > Device File Explore
image.png
这样就可以找到我们安装的app里的文件了。贴一张效果图:
image.png
####找到手机里的db文件一般在data-包名-databases下的
右键文件,导出到电脑中
image.png
####四 使用database navigator查看数据库
1、连接数据库
image.png
2、添加刚刚导出的数据库文件
image.png
image.png
3、打开SQL命令行工具
image.png
4、输入sql语句
image.png

1
2
//LOCAL_SYSTEM_MSG表名称
select * from LOCAL_SYSTEM_MSG

5、查看结果
image.png
#####注意android greenDao生成的不是db文件需要将文件末尾修改.db即可

作为蛋蛋忧伤的程序员,在开发过程中,英文的命名是一件很要命的事情,不是词穷,就是拼音一顿命名,好阔怕的赶脚。每个程序员身边都有一个《有道》默默陪伴着!
Translation 的使用:File->Settings->Plugins-> 输入Translation即可,如下图
image.png

####修改默认快捷键?
File->Settings->keymap 输入translate
image.png
设置完成之后的效果:

image.png
捕获logcat 下的日志翻译也是阔以的:
image.png

在Android应用开发的时候经常会用到View的setVisibility()方法来动态隐藏和显示view,但是这样子是没有过渡动画的,变化的时候会显得很生硬。

LayoutTransition是一个在4.0新引入的Api,主要功能是在ViewGroup的layout发生变化的时候能够自动创建动画。具体使用的时候,首先创建一个LayoutTransition对象,并在容器布局调用setLayoutTransition(LayoutTransition)方法。这样,每当有子view从容器中出现或消失的时候,默认的animator就会被自动调用。当然,你也可以通过setAnimator()来设置自定义的动画。

java中设置:

1
2
3
ViewGroup  container = (ViewGroup) findViewById(R.id.container);
LayoutTransition transition = new LayoutTransition();
container.setLayoutTransition(transition);

此外xml文件中我们在容器的中下面一句代码:

1
android:animateLayoutChanges="true"

在4.1 JellyBean上还有一个增强的功能,可以在容器内的子view的layout发生变化时也播放动画,用法如下:

1
2
LayoutTransition transition = container.getLayoutTransition();
transition.enableTransitionType(LayoutTransition.CHANGING);

效果图:
timg.gif

什么是共享元素呢?可以理解为当页面跳转是,看起来一个View属于界面A又属于界面B。 看一下下边这个效果:
788873382-5a434d32c235f_articlex.gif

#####Step1:

1
2
3
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowContentTransitions">true</item>
</style>

#####Step2:
为共享元素设置上transtionName。设置name的时候两个界面都要添加上,这样才可以检测到是哪两个元素共享。

1
2
3
4
5
6
<ImageView
android:id="@+id/image"
android:layout_width="150dp"
android:layout_height="100dp"
android:transitionName="image"
android:src="@drawable/default_image" />

也可以在代码中设置:
imageView.setTransitionName(“image”);
#####Step3:
设置好以上的参数后,就可以通过跳转来添加相应的动画了。是不是特别的简单。是的。没有错。只不过再跳转的时候还需要加点东西。看下代码:

1
2
3
4
Intent i = new Intent(mContext, Main2Activity.class);
ActivityOptionsCompat optionsCompat =
ActivityOptionsCompat.makeSceneTransitionAnimation(mContext, holder.image, "image");
startActivity(i,optionsCompat.toBundle());

通过上面的代码就可以实现ImageView的共享了。类似文章开头的效果。设置多个元素共享的时候需要这样:

1
2
3
4
5
6
Intent i = new Intent(mContext, Main2Activity.class);
Pair<View, String> pair = new Pair<View, String>(holder.image,"image");
Pair<View,String> pairText = new Pair<View, String>(holder.text,"text");
ActivityOptionsCompat optionsCompat =
ActivityOptionsCompat.makeSceneTransitionAnimation(mContext, pair,pairText);
startActivity(i,optionsCompat.toBundle());

在上面的跳转代码中我们用到了ActivityOptionsCompat的两个静态方法。分别是

1
2
makeSceneTransitionAnimation(Activity activity,View sharedElement,String sharedElementName)
makeSceneTransitionAnimation(Activity activity,Pair<View, String>... sharedElements)

通过函数的参数我们应该就可以看的明白,就不解释了。这两个函数就是用来设置共享元素的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
iv_start.setImageResource(R.drawable.start);
//进行缩放动画
ScaleAnimation scaleAnimation = new ScaleAnimation(1.4f, 1.0f, 1.4f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(4000);//动画持续时间
//动画播放完成后保持形状
scaleAnimation.setFillAfter(true);
scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
//可以在这里先进行某些操作
}
@Override
public void onAnimationEnd(Animation animation) {
//动画执行结束
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
view.startAnimation(scaleAnimation);//开始动画 要缩放哪个控件就用哪个控件来启动即可

######效果图:
20160730013335549.png

####帧动画概念以及用法
帧动画非常容易理解,其实就是简单的由N张静态图片收集起来,然后我们通过控制依次显示 这些图片,因为人眼”视觉残留”的原因,会让我们造成动画的”错觉”,跟放电影的原理一样!
#####示例:
image
#####代码实现:
首先编写我们的动画文件,非常简单,先在res下的drawable创建一个文件:

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false"
>
<!--android:oneshot是设置动画是否只是播放一次,true只播放一次,false循环播放!-->
<item android:drawable="@drawable/img_music" android:duration="200"/>
<!--drawable 引用图片或其他drawable资源 -->
<!--duration 执行时间-->
<item android:drawable="@drawable/ic_launcher" android:duration="200"/>
</animation-list>

动画有了在view中设置src或者background引用动画的drawable文件:

1
2
3
4
5
<ImageView
android:id="@+id/img_anim"
android:src="@drawable/zhen_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

控制动画的开始以及暂停:

1
2
3
4
5
        ImageView img_anim = findViewById(R.id.img_anim);
AnimationDrawable anim_drawable = (AnimationDrawable)img_anim.getDrawable();
// 这里如果是src引用的就用getDrawable()如果是background就用getBackground()强转为AnimationDrawable
anim_drawable.start();
anim_drawable.stop();

揭露效果是一个新增动画效果,体验非常不错。很多App都已经开始用起来了。
效果图:
效果图

1
2
3
4
5
6
7
8
9
10
11
12
13
<ImageView
android:id="@+id/rect"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="30dp"
android:src="@mipmap/ic_launcher" />

rect = (ImageView) findViewById(R.id.rect);

Animator animator2 = ViewAnimationUtils.createCircularReveal(rect, 0, 0, 0, (float) Math.hypot(rect.getWidth(), rect.getHeight()));
animator2.setDuration(2000);
animator2.start();