Skip to content

Commit

Permalink
动态配置退出动画
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Dec 11, 2018
1 parent 4ea360b commit 38c9ccf
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions app/src/main/java/com/maning/zxingcodedemo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.maning.zxingcodedemo;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
Expand Down Expand Up @@ -37,9 +40,20 @@ protected void onCreate(Bundle savedInstanceState) {
imageView = (ImageView) findViewById(R.id.imageView);
editText = (EditText) findViewById(R.id.editText);
checkbox = (CheckBox) findViewById(R.id.checkbox);

}

public void requestCameraPerm() {
//判断权限
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CAMERA}, 10010);
}
}
}

public void scanCodeDefault(View view) {
requestCameraPerm();
MNScanManager.startScan(this, new MNScanCallback() {
@Override
public void onActivityResult(int resultCode, Intent data) {
Expand All @@ -49,6 +63,7 @@ public void onActivityResult(int resultCode, Intent data) {
}

public void scanCode(View view) {
requestCameraPerm();
MNScanConfig scanConfig = new MNScanConfig.Builder()
//设置完成震动
.isShowVibrate(false)
Expand All @@ -58,6 +73,8 @@ public void scanCode(View view) {
.isShowPhotoAlbum(true)
//打开扫描页面的动画
.setActivityOpenAnime(R.anim.activity_anmie_in)
//退出扫描页面动画
.setActivityExitAnime(R.anim.activity_anmie_out)
//自定义文案
.setScanHintText("我是自定义文字")
//扫描线的颜色
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/anim/activity_anmie_in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<scale
android:duration="400"
android:duration="200"
android:fromXScale="0.1"
android:fromYScale="0.1"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="1.0"
android:toYScale="1.0" />
<alpha
android:duration="400"
android:duration="200"
android:fromAlpha="0.1"
android:toAlpha="1.0" />
</set>
16 changes: 16 additions & 0 deletions app/src/main/res/anim/activity_anmie_out.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<scale
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%p"
android:pivotY="50%p"
android:toXScale="0.1"
android:toYScale="0.1" />
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.1" />
</set>
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.google.zxing.client.android;

import android.Manifest;
import android.app.Activity;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -92,6 +94,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private boolean is_light_on = false;
private boolean beepFlag = true;
private boolean vibrateFlag = true;
private int exitAnime = 0;
private SurfaceView surfaceView;

public Handler getHandler() {
Expand Down Expand Up @@ -168,13 +171,15 @@ public void onClick(View v) {
});
}


private void initIntent() {
Intent intent = getIntent();
String hintText = intent.getStringExtra(MNScanManager.INTENT_KEY_HINTTEXT);
String scanColor = intent.getStringExtra(MNScanManager.INTENT_KEY_SCSNCOLOR);
boolean photoFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_PHOTO_FLAG, true);
beepFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_BEEP_FLAG, true);
vibrateFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_VIBRATE_FLAG, true);
exitAnime = intent.getIntExtra(MNScanManager.INTENT_KEY_ACTIVITY_EXIT_ANIME, 0);
if (!TextUtils.isEmpty(hintText)) {
viewfinderView.setHintText(hintText);
}
Expand All @@ -184,6 +189,9 @@ private void initIntent() {
if (!photoFlag) {
btn_photo.setVisibility(View.GONE);
}
if (exitAnime == 0) {
exitAnime = R.anim.mn_scan_activity_bottom_out;
}
}

/**
Expand Down Expand Up @@ -295,6 +303,7 @@ protected void onPause() {
cameraManager.closeDriver();
//historyManager = null; // Keep for onActivityResult
if (!hasSurface) {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.removeCallback(this);
}
Expand Down Expand Up @@ -344,11 +353,10 @@ private void finishSuccess(String result) {
finishFinal();
}

private void finishFinal(){
private void finishFinal() {
this.finish();
//关闭窗体动画显示
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
// this.overridePendingTransition(R.anim.mn_scan_activity_bottom_out, android.R.anim.fade_in);
this.overridePendingTransition(0, exitAnime);
}

@Override
Expand Down Expand Up @@ -387,7 +395,7 @@ private void initCamera(SurfaceHolder surfaceHolder) {
handler = new CaptureActivityHandler(this, decodeFormats, decodeHints, characterSet, cameraManager);
}
} catch (Exception e) {
displayFrameworkBugMessageAndExit("开启摄像头异常:" + e.toString());
displayFrameworkBugMessageAndExit("open camera fail:" + e.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ public class MNScanManager {
public static final int RESULT_SUCCESS = 0;
public static final int RESULT_FAIL = 1;
public static final int RESULT_CANCLE = 2;
public static final String INTENT_KEY_RESULT_SUCCESS = "intent_key_result_success";
public static final String INTENT_KEY_RESULT_ERROR = "intent_key_result_error";
public static final String INTENT_KEY_RESULT_SUCCESS = "INTENT_KEY_RESULT_SUCCESS";
public static final String INTENT_KEY_RESULT_ERROR = "INTENT_KEY_RESULT_ERROR";


//跳转传入的数据
public static final String INTENT_KEY_HINTTEXT = "intent_key_hinttext";
public static final String INTENT_KEY_SCSNCOLOR = "intent_key_scsncolor";
public static final String INTENT_KEY_PHOTO_FLAG = "intent_key_photo_flag";
public static final String INTENT_KEY_BEEP_FLAG = "intent_key_beep_flag";
public static final String INTENT_KEY_VIBRATE_FLAG = "intent_key_vibrate_flag";
//提示文案
public static final String INTENT_KEY_HINTTEXT = "INTENT_KEY_HINTTEXT";
//扫描线的颜色
public static final String INTENT_KEY_SCSNCOLOR = "INTENT_KEY_SCSNCOLOR";
//相机是否显示
public static final String INTENT_KEY_PHOTO_FLAG = "INTENT_KEY_PHOTO_FLAG";
//识别声音
public static final String INTENT_KEY_BEEP_FLAG = "INTENT_KEY_BEEP_FLAG";
//识别震动
public static final String INTENT_KEY_VIBRATE_FLAG = "INTENT_KEY_VIBRATE_FLAG";
//扫描退出动画
public static final String INTENT_KEY_ACTIVITY_EXIT_ANIME = "INTENT_KEY_ACTIVITY_EXIT_ANIME";


public static void startScan(Activity activity, MNScanCallback scanCallback) {
Intent intent = new Intent(activity.getApplicationContext(), CaptureActivity.class);
ActResultRequest actResultRequest = new ActResultRequest(activity);
actResultRequest.startForResult(intent, scanCallback);
activity.overridePendingTransition(R.anim.mn_scan_activity_bottom_in, R.anim.mn_scan_activity_no_anim);
startScan(activity, null, scanCallback);
}

public static void startScan(Activity activity, MNScanConfig mnScanConfig, MNScanCallback scanCallback) {
Expand All @@ -52,10 +56,12 @@ public static void startScan(Activity activity, MNScanConfig mnScanConfig, MNSca
intent.putExtra(MNScanManager.INTENT_KEY_SCSNCOLOR, mnScanConfig.getScanColor());
//扫码框上面的提示文案
intent.putExtra(MNScanManager.INTENT_KEY_HINTTEXT, mnScanConfig.getScanHintText());
//退出动画
intent.putExtra(MNScanManager.INTENT_KEY_ACTIVITY_EXIT_ANIME, mnScanConfig.getActivityExitAnime());

ActResultRequest actResultRequest = new ActResultRequest(activity);
actResultRequest.startForResult(intent, scanCallback);
activity.overridePendingTransition(mnScanConfig.getActivityOpenAnime(), R.anim.mn_scan_activity_no_anim);
activity.overridePendingTransition(mnScanConfig.getActivityOpenAnime(), android.R.anim.fade_out);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import com.google.zxing.client.android.R;

import java.io.Serializable;

/**
* Created by maning on 2017/12/7.
* 启动Activity的一些配置参数
*/

public class MNScanConfig {
public class MNScanConfig implements Serializable {

private static final long serialVersionUID = -5260676142223049891L;

//是否显示相册
private boolean showPhotoAlbum;
Expand All @@ -21,6 +25,8 @@ public class MNScanConfig {
private String scanHintText;
//开启Activity动画
private int activityOpenAnime;
//关闭Activity动画
private int activityExitAnime;

private MNScanConfig() {

Expand All @@ -33,6 +39,7 @@ private MNScanConfig(Builder builder) {
scanColor = builder.scanColor;
scanHintText = builder.scanHintText;
activityOpenAnime = builder.activityOpenAnime;
activityExitAnime = builder.activityExitAnime;
}

public boolean isShowPhotoAlbum() {
Expand All @@ -59,13 +66,22 @@ public int getActivityOpenAnime() {
return activityOpenAnime;
}

public int getActivityExitAnime() {
return activityExitAnime;
}

public void setActivityExitAnime(int activityExitAnime) {
this.activityExitAnime = activityExitAnime;
}

public static class Builder {
private boolean showPhotoAlbum = true;
private boolean showBeep = true;
private boolean showVibrate = true;
private String scanColor;
private String scanHintText;
private int activityOpenAnime = R.anim.mn_scan_activity_bottom_in;
private int activityExitAnime = R.anim.mn_scan_activity_bottom_out;

public MNScanConfig builder() {
return new MNScanConfig(this);
Expand Down Expand Up @@ -101,6 +117,11 @@ public Builder setActivityOpenAnime(int activityOpenAnime) {
return this;
}

public Builder setActivityExitAnime(int activityExitAnime) {
this.activityExitAnime = activityExitAnime;
return this;
}

}

}
20 changes: 14 additions & 6 deletions libraryzxing/src/main/res/anim/mn_scan_activity_bottom_in.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="400"
android:fromYDelta="100%p"
android:toYDelta="0"
/>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300">

<alpha
android:duration="150"
android:fromAlpha="0"
android:toAlpha="1" />

<translate
android:duration="200"
android:fromYDelta="100%p"
android:toYDelta="0" />

</set>
18 changes: 13 additions & 5 deletions libraryzxing/src/main/res/anim/mn_scan_activity_bottom_out.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="400"
android:fromAlpha="1"
android:toAlpha="0"/>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha
android:duration="200"
android:fromAlpha="1"
android:toAlpha="0.5" />

<translate
android:duration="200"
android:fromYDelta="0"
android:toYDelta="100%p" />

</set>
3 changes: 0 additions & 3 deletions libraryzxing/src/main/res/anim/mn_scan_activity_no_anim.xml

This file was deleted.

Loading

0 comments on commit 38c9ccf

Please sign in to comment.