Skip to content

Commit

Permalink
update magic version 5.36
Browse files Browse the repository at this point in the history
  • Loading branch information
huzongyao committed May 14, 2019
1 parent 2ef030b commit ea1c8ad
Show file tree
Hide file tree
Showing 47 changed files with 1,609 additions and 1,466 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@ AndroidMagic(使用LibMagic识别文件类型)
==================
An android project to query file info with LibMagic

[![Travis](https://img.shields.io/appveyor/ci/gruntjs/grunt.svg)](https://github.com/huzongyao/AndroidMagic/releases)
[![Travis](https://img.shields.io/badge/file-v5.36-brightgreen.svg)](https://github.com/file/file)

### Introduction
The file command is "a file type guesser", that is, a command-line tool that tells you in words
what kind of data a file contains. Unlike most GUI systems, command-line UNIX systems - with this
program leading the charge - don't rely on filename extentions to tell you the type of a file,
but look at the file's actual contents. This is, of course, more reliable, but requires a bit of I/O.

### Screenshot
![screenshot](https://github.com/huzongyao/AndroidMagic/blob/master/misc/screen.gif?raw=true)

### Details
This project is for me to learn Java, NDK, and for fun.
* learn how to build ndk and sign apk with android gradle-experimental
* source code is from open source implementation of the file command
* libmagic is "a file type guesser", that tells you in words what kind of data a file contains

### 学习记录
* 使用libmagic,我们不用看文件的后缀,就可以识别出常用文件类型
* 移植LibMagic到安卓平台上, 使文件类型的识别不仅通过扩展名
* 使用gradle-experimental编译NDK
* 使用cmake编译NDK
* Java与本地代码之间内存拷贝GetByteArrayRegion
* butterknife 以及 rxjava的使用

### Useful Links
* Official Site: http://www.darwinsys.com/file/
* GitHub:https://github.com/file/file

### Screenshot
![screenshot](https://github.com/huzongyao/AndroidMagic/blob/master/misc/screen.gif?raw=true)

### About Me
* GitHub: [https://huzongyao.github.io/](https://huzongyao.github.io/)
* ITEye博客:[http://hzy3774.iteye.com/](http://hzy3774.iteye.com/)
Expand Down
34 changes: 19 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28

signingConfigs {
demokey {
Expand All @@ -15,10 +14,9 @@ android {
defaultConfig {
applicationId "com.hzy.magic.app"
minSdkVersion 15
targetSdkVersion 27
targetSdkVersion 28
versionCode 2
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionName "1.1.1"
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -35,20 +33,26 @@ android {
signingConfig signingConfigs.demokey
}
}
applicationVariants.all { variant ->
variant.outputs.all {
def fileName = project.name + '-' + variant.name + '-V' +
defaultConfig.versionName + ".apk"
outputFileName = fileName
}
}
lintOptions {
abortOnError false
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.blankj:utilcode:1.16.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.blankj:utilcode:1.23.7'
api 'io.reactivex.rxjava2:rxandroid:2.0.2'
api 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
api 'com.jakewharton:butterknife:9.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0'
implementation project(':libmagic')
}

This file was deleted.

4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.hzy.magic.app">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand All @@ -10,7 +11,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/com/hzy/magic/app/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hzy.magic.app.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.os.Build;
Expand All @@ -15,6 +15,7 @@
import android.view.MenuItem;
import android.view.View;

import com.blankj.utilcode.constant.PermissionConstants;
import com.blankj.utilcode.util.PermissionUtils;
import com.hzy.libmagic.MagicApi;
import com.hzy.magic.app.R;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
initUI();
PermissionUtils.permission(Manifest.permission.READ_EXTERNAL_STORAGE)
PermissionUtils.permission(PermissionConstants.STORAGE)
.callback(new PermissionUtils.SimpleCallback() {
@Override
public void onGranted() {
Expand All @@ -80,12 +81,14 @@ private void initUI() {
mProgressDialog.setCancelable(false);
mProgressDialog.setTitle("Please Wait...");
mPathList.setAdapter(mPathAdapter = new PathItemAdapter(this, this));
mPathList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
mPathList.setLayoutManager(new LinearLayoutManager(this,
LinearLayoutManager.HORIZONTAL, false));
mFileList.setAdapter(mFileAdapter = new FileItemAdapter(this, this));
mFileList.setLayoutManager(new LinearLayoutManager(this));
mSwipeRefresh.setOnRefreshListener(this);
}

@SuppressLint("CheckResult")
private void loadInitPath() {
final String path = Environment.getExternalStorageDirectory().getPath();
Observable.create((ObservableOnSubscribe<List<FileInfo>>) e -> {
Expand All @@ -98,6 +101,7 @@ private void loadInitPath() {
.subscribe(this);
}

@SuppressLint("CheckResult")
private void loadPathInfo(final String path) {
Observable.create((ObservableOnSubscribe<List<FileInfo>>) e -> {
List<FileInfo> infoList = FileUtils.getInfoListFromPath(path);
Expand Down Expand Up @@ -132,6 +136,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
super.onBackPressed();
}

private boolean initMagicFromAssets() {
try {
InputStream inputStream = getAssets().open("magic.mgc");
Expand Down Expand Up @@ -168,7 +177,7 @@ public void onRefresh() {
}

@Override
public void accept(List<FileInfo> fileInfos) throws Exception {
public void accept(List<FileInfo> fileInfos) {
mFileAdapter.setDataList(fileInfos);
mPathAdapter.setPathView(mCurPath);
mPathList.scrollToPosition(mPathAdapter.getItemCount() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public FileItemAdapter(Activity activity, View.OnClickListener listener) {

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View rootView = LayoutInflater.from(mActivity).inflate(R.layout.storage_list_item, parent, false);
View rootView = LayoutInflater.from(mActivity)
.inflate(R.layout.storage_list_item, parent, false);
rootView.setOnClickListener(mItemClickListener);
return new ViewHolder(rootView);
}
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/hzy/magic/app/adapter/PathItemAdapter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hzy.magic.app.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -39,20 +40,21 @@ public void setPathView(String path) {
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View rootView = LayoutInflater.from(mActivity).inflate(R.layout.path_list_item, parent, false);
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View rootView = LayoutInflater.from(mActivity)
.inflate(R.layout.path_list_item, parent, false);
rootView.setOnClickListener(mItemClickListener);
return new ViewHolder(rootView);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
String item = mPathStringList[position];
String curPath = "";
StringBuilder curPath = new StringBuilder();
for (int i = 0; i < position + 1; i++) {
curPath += mPathStringList[i] + File.separator;
curPath.append(mPathStringList[i]).append(File.separator);
}
holder.itemView.setTag(curPath);
holder.itemView.setTag(curPath.toString());
holder.pathText.setText(item);
}

Expand Down
17 changes: 0 additions & 17 deletions app/src/test/java/com/hzy/magic/app/ExampleUnitTest.java

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
15 changes: 5 additions & 10 deletions libmagic/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 28

defaultConfig {
minSdkVersion 15
targetSdkVersion 27
targetSdkVersion 28
versionCode 2
versionName "1.1.0"
versionName "1.1.1"
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
}
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-18'
arguments '-DANDROID_PLATFORM=android-21'
}
}
}
Expand All @@ -36,8 +35,4 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'junit:junit:4.12'
}

This file was deleted.

Binary file modified libmagic/src/main/assets/magic.mgc.gz
Binary file not shown.
Loading

0 comments on commit ea1c8ad

Please sign in to comment.